vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
14 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. <!DOCTYPE html>
  2. <html lang="en"><head>
  3. <meta charset="utf-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="description" content="">
  7. <meta name="author" content="">
  8. <link rel="icon" HREF="favicon.ico">
  9. <title>DataView - vis.js - A dynamic, browser based visualization library.</title>
  10. <!-- Bootstrap core CSS -->
  11. <link href="../css/bootstrap.css" rel="stylesheet">
  12. <!-- Tipue vendor css -->
  13. <link href="../css/tipuesearch.css" rel="stylesheet">
  14. <link href="../css/style.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <link href="../css/prettify.css" type="text/css" rel="stylesheet"/>
  21. <script type="text/javascript" src="../js/googleAnalytics.js"></script>
  22. <script type="text/javascript" src="../js/prettify/prettify.js"></script>
  23. <script src="../js/smooth-scroll.min.js"></script>
  24. <script language="JavaScript">
  25. smoothScroll.init();
  26. </script>
  27. <script type="text/javascript" src="../js/toggleTable.js"></script>
  28. </head>
  29. <body onload="prettyPrint();">
  30. <div class="navbar-wrapper">
  31. <div class="container">
  32. <nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  33. <div class="container">
  34. <div class="navbar-header">
  35. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
  36. aria-expanded="false" aria-controls="navbar">
  37. <span class="sr-only">Toggle navigation</span>
  38. <span class="icon-bar"></span>
  39. <span class="icon-bar"></span>
  40. <span class="icon-bar"></span>
  41. </button>
  42. <a class="navbar-brand hidden-sm" href="./index.html">vis.js</a>
  43. </div>
  44. <div id="navbar" class="navbar-collapse collapse">
  45. <ul class="nav navbar-nav">
  46. <li><a href="http://www.visjs.org/index.html#modules">Modules</a></li>
  47. <li><a href="http://www.visjs.org/blog.html">Blog</a></li>
  48. <li><a href="http://www.visjs.org/index.html#download_install">Download</a></li>
  49. <li><a href="http://www.visjs.org/showcase/index.html">Showcase</a></li>
  50. <li><a href="http://www.visjs.org/index.html#contribute">Contribute</a></li>
  51. <li><a href="http://www.visjs.org/featureRequests.html">Feature requests</a></li>
  52. <li><a href="http://www.visjs.org/index.html#licenses">License</a></li>
  53. </ul>
  54. <form class="navbar-form navbar-right" role="search">
  55. <input name="q" id="tipue_search_input" autocomplete="off" type="text" class="form-control" placeholder="Enter keywords">
  56. <button type="submit" class="btn btn-default">Go!</button>
  57. </form>
  58. <div id="search-results-wrapper" class="panel panel-default">
  59. <div class="panel-body">
  60. <div id="tipue_search_content"></div>
  61. </div>
  62. </div>
  63. <div id="keyword-info" class="panel panel-success">
  64. <div class="panel-body">
  65. Found <span id="keyword-count"></span> results. Click <a id="keyword-jumper-button" href="">here</a> to jump to the first keyword occurence!
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </nav>
  71. </div>
  72. </div>
  73. <a href="https://github.com/almende/vis" class="hidden-xs hidden-sm hidden-md"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
  74. <div class="container full">
  75. <h1>DataView</h1>
  76. <h2 id="Contents">Contents</h2>
  77. <ul>
  78. <li><a href="#Overview">Overview</a></li>
  79. <li><a href="#Example">Example</a></li>
  80. <li><a href="#Construction">Construction</a></li>
  81. <li><a href="#Methods">Methods</a></li>
  82. <li><a href="#Properties">Properties</a></li>
  83. <li><a href="#Getting_Data">Getting Data</a></li>
  84. <li><a href="#Subscriptions">Subscriptions</a></li>
  85. </ul>
  86. <h2 id="Overview">Overview</h2>
  87. <p>
  88. A DataView offers a filtered and/or formatted view on a
  89. <a href="dataset.html">DataSet</a>.
  90. One can subscribe to changes in a DataView, and easily get filtered or
  91. formatted data without having to specify filters and field types all
  92. the time.
  93. </p>
  94. <h2 id="Example">Example</h2>
  95. <p>
  96. The following example shows how to use a DataView.
  97. </p>
  98. <pre class="prettyprint lang-js">
  99. // create a DataSet
  100. var data = new vis.DataSet();
  101. data.add([
  102. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  103. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  104. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  105. {id: 4, text: 'item 4'}
  106. ]);
  107. // create a DataView
  108. // the view will only contain items having a property group with value 1,
  109. // and will only output fields id, text, and date.
  110. var view = new vis.DataView(data, {
  111. filter: function (item) {
  112. return (item.group == 1);
  113. },
  114. fields: ['id', 'text', 'date']
  115. });
  116. // subscribe to any change in the DataView
  117. view.on('*', function (event, properties, senderId) {
  118. console.log('event', event, properties);
  119. });
  120. // update an item in the data set
  121. data.update({id: 2, group: 1});
  122. // get all ids in the view
  123. var ids = view.getIds();
  124. console.log('ids', ids); // will output [1, 2]
  125. // get all items in the view
  126. var items = view.get();
  127. </pre>
  128. <h2 id="Construction">Construction</h2>
  129. <p>
  130. A DataView can be constructed as:
  131. </p>
  132. <pre class="prettyprint lang-js">
  133. var data = new vis.DataView(dataset, options)
  134. </pre>
  135. <p>
  136. where:
  137. </p>
  138. <ul>
  139. <li>
  140. <code>dataset</code> is a DataSet or DataView.
  141. </li>
  142. <li>
  143. <code>options</code> is an object which can
  144. contain the following properties. Note that these properties
  145. are exactly the same as the properties available in methods
  146. <code>DataSet.get</code> and <code>DataView.get</code>.
  147. <table class="options">
  148. <tr>
  149. <th>Name</th>
  150. <th>Type</th>
  151. <th>Default</th>
  152. <th>Description</th>
  153. </tr>
  154. <tr>
  155. <td>convert</td>
  156. <td>Object.&lt;String,&nbsp;String&gt;</td>
  157. <td>none</td>
  158. <td>
  159. An object containing field names as key, and data types as value.
  160. By default, the type of the properties of an item are left
  161. unchanged. When a field type is specified, this field in the
  162. items will be converted to the specified type. This can be used
  163. for example to convert ISO strings containing a date to a
  164. JavaScript Date object, or convert strings to numbers or vice
  165. versa. The available data types are listed in section
  166. <a href="dataset.html#Data_Types">Data Types</a>.
  167. </td>
  168. </tr>
  169. <tr>
  170. <td>fields</td>
  171. <td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
  172. <td>none</td>
  173. <td>
  174. An array with field names, or an object with current field name and
  175. new field name that the field is returned as.
  176. By default, all properties of the items are emitted.
  177. When <code>fields</code> is defined, only the properties
  178. whose name is specified in <code>fields</code> will be included
  179. in the returned items.
  180. </td>
  181. </tr>
  182. <tr>
  183. <td>filter</td>
  184. <td>function</td>
  185. <td>none</td>
  186. <td>Items can be filtered on specific properties by providing a filter
  187. function. A filter function is executed for each of the items in the
  188. DataSet, and is called with the item as parameter. The function must
  189. return a boolean. All items for which the filter function returns
  190. true will be emitted.
  191. See also section <a href="dataset.html#Data_Filtering">Data Filtering</a>.</td>
  192. </tr>
  193. </table>
  194. </li>
  195. </ul>
  196. <h2 id="Methods">Methods</h2>
  197. <p>DataView contains the following methods.</p>
  198. <table class="methods">
  199. <tr>
  200. <th>Method</th>
  201. <th>Return Type</th>
  202. <th>Description</th>
  203. </tr>
  204. <tr>
  205. <td>
  206. get([options] [, data])<br>
  207. get(id [,options] [, data])<br>
  208. get(ids&nbsp;[,&nbsp;options]&nbsp;[,&nbsp;data])
  209. </td>
  210. <td>Object | Array</td>
  211. <td>
  212. Get a single item, multiple items, or all items from the DataView.
  213. Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>. When no item is found, <code>null</code> is returned when a single item was requested, and and empty Array is returned in case of multiple id's.
  214. </td>
  215. </tr>
  216. <tr>
  217. <td>
  218. getDataSet()
  219. </td>
  220. <td>DataSet</td>
  221. <td>
  222. Get the DataSet to which the DataView is connected.
  223. </td>
  224. </tr>
  225. <tr>
  226. <td>
  227. getIds([options])
  228. </td>
  229. <td>Number[]</td>
  230. <td>
  231. Get ids of all items or of a filtered set of items.
  232. Available <code>options</code> are described in section <a href="dataset.html#Data_Selection">Data Selection</a>, except that options <code>fields</code> and <code>type</code> are not applicable in case of <code>getIds</code>.
  233. </td>
  234. </tr>
  235. <tr>
  236. <td>off(event, callback)</td>
  237. <td>none</td>
  238. <td>
  239. Unsubscribe from an event, remove an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  240. </td>
  241. </tr>
  242. <tr>
  243. <td>on(event, callback)</td>
  244. <td>none</td>
  245. <td>
  246. Subscribe to an event, add an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  247. </td>
  248. </tr>
  249. <tr>
  250. <td>refresh()</td>
  251. <td>none</td>
  252. <td>
  253. Refresh the filter results of a DataView. Useful when the filter function contains dynamic properties, like:
  254. <pre class="prettyprint lang-js">var data = new vis.DataSet(...);
  255. var view = new vis.DataView(data, {
  256. filter: function (item) {
  257. return item.value > threshold;
  258. }
  259. });</pre>
  260. In this example, <code>threshold</code> is an external parameter. When the value of <code>threshold</code> changes, the DataView must be notified that the filter results may have changed by calling <code>DataView.refresh()</code>.
  261. </td>
  262. </tr>
  263. <tr>
  264. <td>
  265. setData(data)
  266. </td>
  267. <td>none</td>
  268. <td>
  269. Replace the DataSet of the DataView. Parameter <code>data</code> can be a DataSet or a DataView.
  270. </td>
  271. </tr>
  272. </table>
  273. <h2 id="Properties">Properties</h2>
  274. <p>DataView contains the following properties.</p>
  275. <table>
  276. <colgroup>
  277. <col width="200">
  278. </colgroup>
  279. <tr>
  280. <th>Property</th>
  281. <th>Type</th>
  282. <th>Description</th>
  283. </tr>
  284. <tr>
  285. <td>length</td>
  286. <td>Number</td>
  287. <td>The number of items in the DataView.</td>
  288. </tr>
  289. </table>
  290. <h2 id="Getting_Data">Getting Data</h2>
  291. <p>
  292. Data of the DataView can be retrieved using the method <code>get</code>.
  293. </p>
  294. <pre class="prettyprint lang-js">
  295. var items = view.get();
  296. </pre>
  297. <p>
  298. Data of a DataView can be filtered and formatted again, in exactly the
  299. same way as in a DataSet. See sections
  300. <a href="dataset.html#Data_Manipulation">Data Manipulation</a> and
  301. <a href="dataset.html#Data_Selection">Data Selection</a> for more
  302. information.
  303. </p>
  304. <pre class="prettyprint lang-js">
  305. var items = view.get({
  306. fields: ['id', 'score'],
  307. filter: function (item) {
  308. return (item.score > 50);
  309. }
  310. });
  311. </pre>
  312. <h2 id="Subscriptions">Subscriptions</h2>
  313. <p>
  314. One can subscribe on changes in the DataView. Subscription works exactly
  315. the same as for DataSets. See the documentation on
  316. <a href="dataset.html#Subscriptions">subscriptions in a DataSet</a>
  317. for more information.
  318. </p>
  319. <pre class="prettyprint lang-js">
  320. // create a DataSet and a view on the data set
  321. var data = new vis.DataSet();
  322. var view = new vis.DataView({
  323. filter: function (item) {
  324. return (item.group == 2);
  325. }
  326. });
  327. // subscribe to any change in the DataView
  328. view.on('*', function (event, properties, senderId) {
  329. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  330. });
  331. // add, update, and remove data in the DataSet...
  332. </pre>
  333. </div>
  334. <!-- Bootstrap core JavaScript
  335. ================================================== -->
  336. <!-- Placed at the end of the document so the pages load faster -->
  337. <script src="../js/jquery.min.js"></script>
  338. <script src="../js/bootstrap.min.js"></script>
  339. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  340. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  341. <!-- jquery extensions -->
  342. <script src="../js/jquery.highlight.js"></script>
  343. <script src="../js/jquery.url.min.js"></script>
  344. <!-- Tipue vendor js -->
  345. <script src="../js/tipuesearch.config.js"></script>
  346. <script src="../js/tipuesearch.js"></script>
  347. <!-- controller -->
  348. <script src="../js/main.js"></script>