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.

391 lines
12 KiB

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