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/index.html#licenses">License</a></li>
  52. </ul>
  53. <form class="navbar-form navbar-right" role="search">
  54. <input name="q" id="tipue_search_input" autocomplete="off" type="text" class="form-control" placeholder="Enter keywords">
  55. <button type="submit" class="btn btn-default">Go!</button>
  56. </form>
  57. <div id="search-results-wrapper" class="panel panel-default">
  58. <div class="panel-body">
  59. <div id="tipue_search_content"></div>
  60. </div>
  61. </div>
  62. <div id="keyword-info" class="panel panel-success">
  63. <div class="panel-body">
  64. Found <span id="keyword-count"></span> results. Click <a id="keyword-jumper-button" href="">here</a> to jump to the first keyword occurence!
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </nav>
  70. </div>
  71. </div>
  72. <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>
  73. <div class="container full">
  74. <h1>DataView</h1>
  75. <h2 id="Contents">Contents</h2>
  76. <ul>
  77. <li><a href="#Overview">Overview</a></li>
  78. <li><a href="#Example">Example</a></li>
  79. <li><a href="#Construction">Construction</a></li>
  80. <li><a href="#Methods">Methods</a></li>
  81. <li><a href="#Properties">Properties</a></li>
  82. <li><a href="#Getting_Data">Getting Data</a></li>
  83. <li><a href="#Subscriptions">Subscriptions</a></li>
  84. </ul>
  85. <h2 id="Overview">Overview</h2>
  86. <p>
  87. A DataView offers a filtered and/or formatted view on a
  88. <a href="dataset.html">DataSet</a>.
  89. One can subscribe to changes in a DataView, and easily get filtered or
  90. formatted data without having to specify filters and field types all
  91. the time.
  92. </p>
  93. <h2 id="Example">Example</h2>
  94. <p>
  95. The following example shows how to use a DataView.
  96. </p>
  97. <pre class="prettyprint lang-js">
  98. // create a DataSet
  99. var data = new vis.DataSet();
  100. data.add([
  101. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  102. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  103. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  104. {id: 4, text: 'item 4'}
  105. ]);
  106. // create a DataView
  107. // the view will only contain items having a property group with value 1,
  108. // and will only output fields id, text, and date.
  109. var view = new vis.DataView(data, {
  110. filter: function (item) {
  111. return (item.group == 1);
  112. },
  113. fields: ['id', 'text', 'date']
  114. });
  115. // subscribe to any change in the DataView
  116. view.on('*', function (event, properties, senderId) {
  117. console.log('event', event, properties);
  118. });
  119. // update an item in the data set
  120. data.update({id: 2, group: 1});
  121. // get all ids in the view
  122. var ids = view.getIds();
  123. console.log('ids', ids); // will output [1, 2]
  124. // get all items in the view
  125. var items = view.get();
  126. </pre>
  127. <h2 id="Construction">Construction</h2>
  128. <p>
  129. A DataView can be constructed as:
  130. </p>
  131. <pre class="prettyprint lang-js">
  132. var data = new vis.DataView(dataset, options)
  133. </pre>
  134. <p>
  135. where:
  136. </p>
  137. <ul>
  138. <li>
  139. <code>dataset</code> is a DataSet or DataView.
  140. </li>
  141. <li>
  142. <code>options</code> is an object which can
  143. contain the following properties. Note that these properties
  144. are exactly the same as the properties available in methods
  145. <code>DataSet.get</code> and <code>DataView.get</code>.
  146. <table class="options">
  147. <tr>
  148. <th>Name</th>
  149. <th>Type</th>
  150. <th>Default</th>
  151. <th>Description</th>
  152. </tr>
  153. <tr>
  154. <td>convert</td>
  155. <td>Object.&lt;String,&nbsp;String&gt;</td>
  156. <td>none</td>
  157. <td>
  158. An object containing field names as key, and data types as value.
  159. By default, the type of the properties of an item are left
  160. unchanged. When a field type is specified, this field in the
  161. items will be converted to the specified type. This can be used
  162. for example to convert ISO strings containing a date to a
  163. JavaScript Date object, or convert strings to numbers or vice
  164. versa. The available data types are listed in section
  165. <a href="dataset.html#Data_Types">Data Types</a>.
  166. </td>
  167. </tr>
  168. <tr>
  169. <td>fields</td>
  170. <td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
  171. <td>none</td>
  172. <td>
  173. An array with field names, or an object with current field name and
  174. new field name that the field is returned as.
  175. By default, all properties of the items are emitted.
  176. When <code>fields</code> is defined, only the properties
  177. whose name is specified in <code>fields</code> will be included
  178. in the returned items.
  179. </td>
  180. </tr>
  181. <tr>
  182. <td>filter</td>
  183. <td>function</td>
  184. <td>none</td>
  185. <td>Items can be filtered on specific properties by providing a filter
  186. function. A filter function is executed for each of the items in the
  187. DataSet, and is called with the item as parameter. The function must
  188. return a boolean. All items for which the filter function returns
  189. true will be emitted.
  190. See also section <a href="dataset.html#Data_Filtering">Data Filtering</a>.</td>
  191. </tr>
  192. </table>
  193. </li>
  194. </ul>
  195. <h2 id="Methods">Methods</h2>
  196. <p>DataView contains the following methods.</p>
  197. <table class="methods">
  198. <tr>
  199. <th>Method</th>
  200. <th>Return Type</th>
  201. <th>Description</th>
  202. </tr>
  203. <tr>
  204. <td>
  205. get([options] [, data])<br>
  206. get(id [,options] [, data])<br>
  207. get(ids&nbsp;[,&nbsp;options]&nbsp;[,&nbsp;data])
  208. </td>
  209. <td>Object | Array</td>
  210. <td>
  211. Get a single item, multiple items, or all items from the DataView.
  212. 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.
  213. </td>
  214. </tr>
  215. <tr>
  216. <td>
  217. getDataSet()
  218. </td>
  219. <td>DataSet</td>
  220. <td>
  221. Get the DataSet to which the DataView is connected.
  222. </td>
  223. </tr>
  224. <tr>
  225. <td>
  226. getIds([options])
  227. </td>
  228. <td>Number[]</td>
  229. <td>
  230. Get ids of all items or of a filtered set of items.
  231. 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>.
  232. </td>
  233. </tr>
  234. <tr>
  235. <td>off(event, callback)</td>
  236. <td>none</td>
  237. <td>
  238. Unsubscribe from an event, remove an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  239. </td>
  240. </tr>
  241. <tr>
  242. <td>on(event, callback)</td>
  243. <td>none</td>
  244. <td>
  245. Subscribe to an event, add an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  246. </td>
  247. </tr>
  248. <tr>
  249. <td>refresh()</td>
  250. <td>none</td>
  251. <td>
  252. Refresh the filter results of a DataView. Useful when the filter function contains dynamic properties, like:
  253. <pre class="prettyprint lang-js">var data = new vis.DataSet(...);
  254. var view = new vis.DataView(data, {
  255. filter: function (item) {
  256. return item.value > threshold;
  257. }
  258. });</pre>
  259. 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>.
  260. </td>
  261. </tr>
  262. <tr>
  263. <td>
  264. setData(data)
  265. </td>
  266. <td>none</td>
  267. <td>
  268. Replace the DataSet of the DataView. Parameter <code>data</code> can be a DataSet or a DataView.
  269. </td>
  270. </tr>
  271. </table>
  272. <h2 id="Properties">Properties</h2>
  273. <p>DataView contains the following properties.</p>
  274. <table>
  275. <colgroup>
  276. <col width="200">
  277. </colgroup>
  278. <tr>
  279. <th>Property</th>
  280. <th>Type</th>
  281. <th>Description</th>
  282. </tr>
  283. <tr>
  284. <td>length</td>
  285. <td>Number</td>
  286. <td>The number of items in the DataView.</td>
  287. </tr>
  288. </table>
  289. <h2 id="Getting_Data">Getting Data</h2>
  290. <p>
  291. Data of the DataView can be retrieved using the method <code>get</code>.
  292. </p>
  293. <pre class="prettyprint lang-js">
  294. var items = view.get();
  295. </pre>
  296. <p>
  297. Data of a DataView can be filtered and formatted again, in exactly the
  298. same way as in a DataSet. See sections
  299. <a href="dataset.html#Data_Manipulation">Data Manipulation</a> and
  300. <a href="dataset.html#Data_Selection">Data Selection</a> for more
  301. information.
  302. </p>
  303. <pre class="prettyprint lang-js">
  304. var items = view.get({
  305. fields: ['id', 'score'],
  306. filter: function (item) {
  307. return (item.score > 50);
  308. }
  309. });
  310. </pre>
  311. <h2 id="Subscriptions">Subscriptions</h2>
  312. <p>
  313. One can subscribe on changes in the DataView. Subscription works exactly
  314. the same as for DataSets. See the documentation on
  315. <a href="dataset.html#Subscriptions">subscriptions in a DataSet</a>
  316. for more information.
  317. </p>
  318. <pre class="prettyprint lang-js">
  319. // create a DataSet and a view on the data set
  320. var data = new vis.DataSet();
  321. var view = new vis.DataView({
  322. filter: function (item) {
  323. return (item.group == 2);
  324. }
  325. });
  326. // subscribe to any change in the DataView
  327. view.on('*', function (event, properties, senderId) {
  328. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  329. });
  330. // add, update, and remove data in the DataSet...
  331. </pre>
  332. </div>
  333. <!-- Bootstrap core JavaScript
  334. ================================================== -->
  335. <!-- Placed at the end of the document so the pages load faster -->
  336. <script src="../js/jquery.min.js"></script>
  337. <script src="../js/bootstrap.min.js"></script>
  338. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  339. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  340. <!-- jquery extensions -->
  341. <script src="../js/jquery.highlight.js"></script>
  342. <script src="../js/jquery.url.min.js"></script>
  343. <!-- Tipue vendor js -->
  344. <script src="../js/tipuesearch.config.js"></script>
  345. <script src="../js/tipuesearch.js"></script>
  346. <!-- controller -->
  347. <script src="../js/main.js"></script>