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.

337 lines
9.0 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | DataView documentation</title>
  5. <link href="css/prettify.css" type="text/css" rel="stylesheet" />
  6. <link href='css/style.css' type='text/css' rel='stylesheet'>
  7. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  8. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  9. <body onload="prettyPrint();">
  10. <div id="container">
  11. <h1>DataView documentation</h1>
  12. <h2 id="Contents">Contents</h2>
  13. <ul>
  14. <li><a href="#Overview">Overview</a></li>
  15. <li><a href="#Example">Example</a></li>
  16. <li><a href="#Construction">Construction</a></li>
  17. <li><a href="#Methods">Methods</a></li>
  18. <li><a href="#Properties">Properties</a></li>
  19. <li><a href="#Getting_Data">Getting Data</a></li>
  20. <li><a href="#Subscriptions">Subscriptions</a></li>
  21. <li><a href="#Data_Policy">Data Policy</a></li>
  22. </ul>
  23. <h2 id="Overview">Overview</h2>
  24. <p>
  25. A DataView offers a filtered and/or formatted view on a
  26. <a href="dataset.html">DataSet</a>.
  27. One can subscribe on changes in a DataView, and easily get filtered or
  28. formatted data without having to specify filters and field types all
  29. the time.
  30. </p>
  31. <h2 id="Example">Example</h2>
  32. <p>
  33. The following example shows how to use a DataView.
  34. </p>
  35. <pre class="prettyprint lang-js">
  36. // create a DataSet
  37. var data = new vis.DataSet();
  38. data.add([
  39. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  40. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  41. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  42. {id: 4, text: 'item 4'}
  43. ]);
  44. // create a DataView
  45. // the view will only contain items having a property group with value 1,
  46. // and will only output fields id, text, and date.
  47. var view = new vis.DataView(data, {
  48. filter: function (item) {
  49. return (item.group == 1);
  50. },
  51. fields: ['id', 'text', 'date']
  52. });
  53. // subscribe to any change in the DataView
  54. view.on('*', function (event, properties, senderId) {
  55. console.log('event', event, properties);
  56. });
  57. // update an item in the data set
  58. data.update({id: 2, group: 1});
  59. // get all ids in the view
  60. var ids = view.getIds();
  61. console.log('ids', ids); // will output [1, 2]
  62. // get all items in the view
  63. var items = view.get();
  64. </pre>
  65. <h2 id="Construction">Construction</h2>
  66. <p>
  67. A DataView can be constructed as:
  68. </p>
  69. <pre class="prettyprint lang-js">
  70. var data = new vis.DataView(dataset, options)
  71. </pre>
  72. <p>
  73. where:
  74. </p>
  75. <ul>
  76. <li>
  77. <code>dataset</code> is a DataSet or DataView.
  78. </li>
  79. <li>
  80. <code>options</code> is an object which can
  81. contain the following properties. Note that these properties
  82. are exactly the same as the properties available in methods
  83. <code>DataSet.get</code> and <code>DataView.get</code>.
  84. <table>
  85. <tr>
  86. <th>Name</th>
  87. <th>Type</th>
  88. <th>Description</th>
  89. </tr>
  90. <tr>
  91. <td>convert</td>
  92. <td>Object.&lt;String,&nbsp;String&gt;</td>
  93. <td>
  94. An object containing field names as key, and data types as value.
  95. By default, the type of the properties of an item are left
  96. unchanged. When a field type is specified, this field in the
  97. items will be converted to the specified type. This can be used
  98. for example to convert ISO strings containing a date to a
  99. JavaScript Date object, or convert strings to numbers or vice
  100. versa. The available data types are listed in section
  101. <a href="dataset.html#Data_Types">Data Types</a>.
  102. </td>
  103. </tr>
  104. <tr>
  105. <td>fields</td>
  106. <td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
  107. <td>
  108. An array with field names, or an object with current field name and
  109. new field name that the field is returned as.
  110. By default, all properties of the items are emitted.
  111. When <code>fields</code> is defined, only the properties
  112. whose name is specified in <code>fields</code> will be included
  113. in the returned items.
  114. </td>
  115. </tr>
  116. <tr>
  117. <td>filter</td>
  118. <td>function</td>
  119. <td>Items can be filtered on specific properties by providing a filter
  120. function. A filter function is executed for each of the items in the
  121. DataSet, and is called with the item as parameter. The function must
  122. return a boolean. All items for which the filter function returns
  123. true will be emitted.
  124. See also section <a href="dataset.html#Data_Filtering">Data Filtering</a>.</td>
  125. </tr>
  126. </table>
  127. </li>
  128. </ul>
  129. <h2 id="Methods">Methods</h2>
  130. <p>DataView contains the following methods.</p>
  131. <table>
  132. <colgroup>
  133. <col width="200">
  134. </colgroup>
  135. <tr>
  136. <th>Method</th>
  137. <th>Return Type</th>
  138. <th>Description</th>
  139. </tr>
  140. <tr>
  141. <td>
  142. get([options] [, data])<br>
  143. get(id [,options] [, data])<br>
  144. get(ids [, options] [, data])
  145. </td>
  146. <td>Object | Array</td>
  147. <td>
  148. Get a single item, multiple items, or all items from the DataView.
  149. 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>.
  150. </td>
  151. </tr>
  152. <tr>
  153. <td>
  154. getDataSet()
  155. </td>
  156. <td>DataSet</td>
  157. <td>
  158. Get the DataSet to which the DataView is connected.
  159. </td>
  160. </tr>
  161. <tr>
  162. <td>
  163. getIds([options])
  164. </td>
  165. <td>Number[]</td>
  166. <td>
  167. Get ids of all items or of a filtered set of items.
  168. 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>.
  169. </td>
  170. </tr>
  171. <tr>
  172. <td>off(event, callback)</td>
  173. <td>none</td>
  174. <td>
  175. Unsubscribe from an event, remove an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  176. </td>
  177. </tr>
  178. <tr>
  179. <td>on(event, callback)</td>
  180. <td>none</td>
  181. <td>
  182. Subscribe to an event, add an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  183. </td>
  184. </tr>
  185. <tr>
  186. <td>refresh()</td>
  187. <td>none</td>
  188. <td>
  189. Refresh the filter results of a DataView. Useful when the filter function contains dynamic properties, like:
  190. <pre class="prettyprint lang-js">var data = new vis.DataSet(...);
  191. var view = new vis.DataView(data, {
  192. filter: function (item) {
  193. return item.value > threshold;
  194. }
  195. });</pre>
  196. 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>.
  197. </td>
  198. </tr>
  199. <tr>
  200. <td>
  201. setDataSet(data)
  202. </td>
  203. <td>none</td>
  204. <td>
  205. Replace the DataSet of the DataView. Parameter <code>data</code> can be a DataSet or a DataView.
  206. </td>
  207. </tr>
  208. </table>
  209. <h2 id="Properties">Properties</h2>
  210. <p>DataView contains the following properties.</p>
  211. <table>
  212. <colgroup>
  213. <col width="200">
  214. </colgroup>
  215. <tr>
  216. <th>Property</th>
  217. <th>Type</th>
  218. <th>Description</th>
  219. </tr>
  220. <tr>
  221. <td>length</td>
  222. <td>Number</td>
  223. <td>The number of items in the DataView.</td>
  224. </tr>
  225. </table>
  226. <h2 id="Getting_Data">Getting Data</h2>
  227. <p>
  228. Data of the DataView can be retrieved using the method <code>get</code>.
  229. </p>
  230. <pre class="prettyprint lang-js">
  231. var items = view.get();
  232. </pre>
  233. <p>
  234. Data of a DataView can be filtered and formatted again, in exactly the
  235. same way as in a DataSet. See sections
  236. <a href="dataset.html#Data_Manipulation">Data Manipulation</a> and
  237. <a href="dataset.html#Data_Selection">Data Selection</a> for more
  238. information.
  239. </p>
  240. <pre class="prettyprint lang-js">
  241. var items = view.get({
  242. fields: ['id', 'score'],
  243. filter: function (item) {
  244. return (item.score > 50);
  245. }
  246. });
  247. </pre>
  248. <h2 id="Subscriptions">Subscriptions</h2>
  249. <p>
  250. One can subscribe on changes in the DataView. Subscription works exactly
  251. the same as for DataSets. See the documentation on
  252. <a href="dataset.html#Subscriptions">subscriptions in a DataSet</a>
  253. for more information.
  254. </p>
  255. <pre class="prettyprint lang-js">
  256. // create a DataSet and a view on the data set
  257. var data = new vis.DataSet();
  258. var view = new vis.DataView({
  259. filter: function (item) {
  260. return (item.group == 2);
  261. }
  262. });
  263. // subscribe to any change in the DataView
  264. view.on('*', function (event, properties, senderId) {
  265. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  266. });
  267. // add, update, and remove data in the DataSet...
  268. </pre>
  269. <h2 id="Data_Policy">Data Policy</h2>
  270. <p>
  271. All code and data is processed and rendered in the browser.
  272. No data is sent to any server.
  273. </p>
  274. </div>
  275. </body>
  276. </html>