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.

221 lines
6.6 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | DataView documentation</title>
  5. <link rel='stylesheet' href='css/style.css' type='text/css' />
  6. <link href="css/prettify.css" type="text/css" rel="stylesheet" />
  7. <link href='css/style.css' type='text/css' rel='stylesheet'>
  8. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  9. </head>
  10. <body onload="prettyPrint();">
  11. <div id="container">
  12. <h1>DataView documentation</h1>
  13. <h2 id="Contents">Contents</h2>
  14. <ul>
  15. <li><a href="#Overview">Overview</a></li>
  16. <li><a href="#Example">Example</a></li>
  17. <li><a href="#Construction">Construction</a></li>
  18. <li><a href="#Getting_Data">Getting Data</a></li>
  19. <li><a href="#Subscriptions">Subscriptions</a></li>
  20. <li><a href="#Data_Policy">Data Policy</a></li>
  21. </ul>
  22. <h2 id="Overview">Overview</h2>
  23. <p>
  24. A DataView offers a filtered and/or formatted view on a
  25. <a href="dataset.html">DataSet</a>.
  26. One can subscribe on changes in a DataView, and easily get filtered or
  27. formatted data without having to specify filters and field types all
  28. the time.
  29. </p>
  30. <h2 id="Example">Example</h2>
  31. <p>
  32. The following example shows how to use a DataView.
  33. </p>
  34. <pre class="prettyprint lang-js">
  35. // create a DataSet
  36. var data = new vis.DataSet();
  37. data.add([
  38. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  39. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  40. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  41. {id: 4, text: 'item 4'}
  42. ]);
  43. // create a DataView
  44. // the view will only contain items having a property group with value 1,
  45. // and will only output fields id, text, and date.
  46. var view = new vis.DataView(data, {
  47. filter: function (item) {
  48. return (item.group == 1);
  49. },
  50. fields: ['id', 'text', 'date']
  51. });
  52. // subscribe to any change in the DataView
  53. view.subscribe('*', function (event, params, senderId) {
  54. console.log('event', event, params);
  55. });
  56. // update an item in the data set
  57. data.update({id: 2, group: 1});
  58. // get all ids in the view
  59. var ids = view.getIds();
  60. console.log('ids', ids); // will output [1, 2]
  61. // get all items in the view
  62. var items = view.get();
  63. </pre>
  64. <h2 id="Construction">Construction</h2>
  65. <p>
  66. A DataView can be constructed as:
  67. </p>
  68. <pre class="prettyprint lang-js">
  69. var data = new vis.DataView(dataset, options)
  70. </pre>
  71. <p>
  72. where:
  73. </p>
  74. <ul>
  75. <li>
  76. <code>dataset</code> is a DataSet or DataView.
  77. </li>
  78. <li>
  79. <code>options</code> is an object which can
  80. contain the following properties. Note that these properties
  81. are exactly the same as the properties available in methods
  82. <code>DataSet.get</code> and <code>DataView.get</code>.
  83. <table>
  84. <tr>
  85. <th>Name</th>
  86. <th>Type</th>
  87. <th>Description</th>
  88. </tr>
  89. <tr>
  90. <td>convert</td>
  91. <td>Object.&lt;String,&nbsp;String&gt;</td>
  92. <td>
  93. An object containing field names as key, and data types as value.
  94. By default, the type of the properties of an item are left
  95. unchanged. When a field type is specified, this field in the
  96. items will be converted to the specified type. This can be used
  97. for example to convert ISO strings containing a date to a
  98. JavaScript Date object, or convert strings to numbers or vice
  99. versa. The available data types are listed in section
  100. <a href="dataset.html#Data_Types">Data Types</a>.
  101. </td>
  102. </tr>
  103. <tr>
  104. <td>fields</td>
  105. <td>String[&nbsp;]</td>
  106. <td>
  107. An array with field names.
  108. By default, all properties of the items are emitted.
  109. When <code>fields</code> is defined, only the properties
  110. whose name is specified in <code>fields</code> will be included
  111. in the returned items.
  112. </td>
  113. </tr>
  114. <tr>
  115. <td>filter</td>
  116. <td>function</td>
  117. <td>Items can be filtered on specific properties by providing a filter
  118. function. A filter function is executed for each of the items in the
  119. DataSet, and is called with the item as parameter. The function must
  120. return a boolean. All items for which the filter function returns
  121. true will be emitted.
  122. See also section <a href="dataset.html#Data_Filtering">Data Filtering</a>.</td>
  123. </tr>
  124. </table>
  125. </li>
  126. </ul>
  127. <h2 id="Getting_Data">Getting Data</h2>
  128. <p>
  129. Data of the DataView can be retrieved using the method <code>get</code>.
  130. </p>
  131. <pre class="prettyprint lang-js">
  132. var items = view.get();
  133. </pre>
  134. <p>
  135. Data of a DataView can be filtered and formatted again, in exactly the
  136. same way as in a DataSet. See sections
  137. <a href="dataset.html#Data_Filtering">Data Filtering</a> and
  138. <a href="dataset.html#Data_Formatting">Data Formatting</a> for more
  139. information.
  140. </p>
  141. <pre class="prettyprint lang-js">
  142. var items = view.get({
  143. fields: ['id', 'score'],
  144. filter: function (item) {
  145. return (item.score > 50);
  146. }
  147. });
  148. </pre>
  149. <h2 id="Subscriptions">Subscriptions</h2>
  150. <p>
  151. One can subscribe on changes in the DataView. Subscription works exactly
  152. the same as for DataSets. See the documentation on
  153. <a href="dataset.html#Subscriptions">subscriptions in a DataSet</a>
  154. for more information.
  155. </p>
  156. <pre class="prettyprint lang-js">
  157. // create a DataSet and a view on the data set
  158. var data = new vis.DataSet();
  159. var view = new vis.DataView({
  160. filter: function (item) {
  161. return (item.group == 2);
  162. }
  163. });
  164. // subscribe to any change in the DataView
  165. view.subscribe('*', function (event, params, senderId) {
  166. console.log('event:', event, 'params:', params, 'senderId:', senderId);
  167. });
  168. // add, update, and remove data in the DataSet...
  169. </pre>
  170. <h2 id="Data_Policy">Data Policy</h2>
  171. <p>
  172. All code and data is processed and rendered in the browser.
  173. No data is sent to any server.
  174. </p>
  175. </div>
  176. </body>
  177. </html>