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.

402 lines
13 KiB

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