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.

1025 lines
31 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>DataSet - 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/featureRequests.html">Feature requests</a></li>
  52. <li><a href="http://www.visjs.org/index.html#licenses">License</a></li>
  53. </ul>
  54. <form class="navbar-form navbar-right" role="search">
  55. <input name="q" id="tipue_search_input" autocomplete="off" type="text" class="form-control" placeholder="Enter keywords">
  56. <button type="submit" class="btn btn-default">Go!</button>
  57. </form>
  58. <div id="search-results-wrapper" class="panel panel-default">
  59. <div class="panel-body">
  60. <div id="tipue_search_content"></div>
  61. </div>
  62. </div>
  63. <div id="keyword-info" class="panel panel-success">
  64. <div class="panel-body">
  65. Found <span id="keyword-count"></span> results. Click <a id="keyword-jumper-button" href="">here</a> to jump to the first keyword occurence!
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </nav>
  71. </div>
  72. </div>
  73. <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>
  74. <div class="container full">
  75. <h1>DataSet</h1>
  76. <h2 id="Contents">Contents</h2>
  77. <ul>
  78. <li><a href="#Overview">Overview</a></li>
  79. <li><a href="#Example">Example</a></li>
  80. <li><a href="#Construction">Construction</a></li>
  81. <li><a href="#Methods">Methods</a></li>
  82. <li><a href="#Properties">Properties</a></li>
  83. <li><a href="#Subscriptions">Subscriptions</a></li>
  84. <li><a href="#Data_Manipulation">Data Manipulation</a></li>
  85. <li><a href="#Data_Selection">Data Selection</a></li>
  86. </ul>
  87. <h2 id="Overview">Overview</h2>
  88. <p>
  89. Vis.js comes with a flexible DataSet, which can be used to hold and
  90. manipulate unstructured data and listen for changes in the data.
  91. The DataSet is key/value based. Data items can be added, updated and
  92. removed from the DataSet, and one can subscribe to changes in the DataSet.
  93. The data in the DataSet can be filtered and ordered, and fields (like
  94. dates) can be converted to a specific type. Data can be normalized when
  95. appending it to the DataSet as well.
  96. </p>
  97. <h2 id="Example">Example</h2>
  98. <p>
  99. The following example shows how to use a DataSet.
  100. </p>
  101. <pre class="prettyprint lang-js">
  102. // create a DataSet
  103. var options = {};
  104. var data = new vis.DataSet(options);
  105. // add items
  106. // note that the data items can contain different properties and data formats
  107. data.add([
  108. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  109. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  110. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  111. {id: 4, text: 'item 4'}
  112. ]);
  113. // subscribe to any change in the DataSet
  114. data.on('*', function (event, properties, senderId) {
  115. console.log('event', event, properties);
  116. });
  117. // update an existing item
  118. data.update({id: 2, group: 1});
  119. // remove an item
  120. data.remove(4);
  121. // get all ids
  122. var ids = data.getIds();
  123. console.log('ids', ids);
  124. // get a specific item
  125. var item1 = data.get(1);
  126. console.log('item1', item1);
  127. // retrieve a filtered subset of the data
  128. var items = data.get({
  129. filter: function (item) {
  130. return item.group == 1;
  131. }
  132. });
  133. console.log('filtered items', items);
  134. // retrieve formatted items
  135. var items = data.get({
  136. fields: ['id', 'date'],
  137. type: {
  138. date: 'ISODate'
  139. }
  140. });
  141. console.log('formatted items', items);
  142. </pre>
  143. <h2 id="Construction">Construction</h2>
  144. <p>
  145. A DataSet can be constructed as:
  146. </p>
  147. <pre class="prettyprint lang-js">
  148. var data = new vis.DataSet([data] [, options])
  149. </pre>
  150. <p>
  151. After construction, data can be added to the DataSet using the methods
  152. <code>add</code> and <code>update</code>, as described in section
  153. <a href="#Data_Manipulation">Data Manipulation</a>.
  154. </p>
  155. <p>
  156. The parameter <code>data</code> is optional and is an Array with items.
  157. </p>
  158. <p>
  159. The parameter <code>options</code> is optional and is an object which can
  160. contain the following properties:
  161. </p>
  162. <table class="options">
  163. <tr>
  164. <th>Name</th>
  165. <th>Type</th>
  166. <th>Default value</th>
  167. <th>Description</th>
  168. </tr>
  169. <tr>
  170. <td>fieldId</td>
  171. <td>String</td>
  172. <td>"id"</td>
  173. <td>
  174. The name of the field containing the id of the items.
  175. When data is fetched from a server which uses some specific
  176. field to identify items, this field name can be specified
  177. in the DataSet using the option <code>fieldId</code>.
  178. For example <a href="http://couchdb.apache.org/"
  179. target="_blank">CouchDB</a> uses the field
  180. <code>"_id"</code> to identify documents.
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>type</td>
  185. <td>Object.&lt;String,&nbsp;String&gt;</td>
  186. <td>none</td>
  187. <td>
  188. An object containing field names as key, and data types as
  189. value. By default, the type of the properties of items are left
  190. unchanged. Item properties can be normalized by specifying a
  191. field type. This is useful for example to automatically convert
  192. stringified dates coming from a server into JavaScript Date
  193. objects. The available data types are listed in section
  194. <a href="#Data_Types">Data Types</a>.
  195. </td>
  196. </tr>
  197. <tr>
  198. <td>queue</td>
  199. <td>Object | boolean</td>
  200. <td>none</td>
  201. <td>
  202. Queue data changes ('add', 'update', 'remove') and flush them at once.
  203. The queue can be flushed manually by calling
  204. <code>DataSet.flush()</code>, or can be flushed after a configured delay
  205. or maximum number of entries.
  206. <br>
  207. <br>
  208. When <code>queue</code> is true, a queue is created
  209. with default options. Options can be specified by providing an object:
  210. <ul>
  211. <li><code>delay: number</code><br>
  212. The queue will be flushed automatically after an inactivity of this
  213. delay in milliseconds. Default value is <code>null</code>.
  214. <li><code>max: number</code><br>
  215. When the queue exceeds the given maximum number
  216. of entries, the queue is flushed automatically.
  217. Default value is <code>Infinity</code>.
  218. </li>
  219. </ul>
  220. </td>
  221. </tr>
  222. </table>
  223. <h2 id="Methods">Methods</h2>
  224. <p>DataSet contains the following methods.</p>
  225. <table class="methods">
  226. <tr>
  227. <th>Method</th>
  228. <th>Return Type</th>
  229. <th>Description</th>
  230. </tr>
  231. <tr>
  232. <td>add(data [, senderId])</td>
  233. <td>Number[]</td>
  234. <td>Add one or multiple items to the DataSet. <code>data</code> can be a single item or an array with items. Adding an item will fail when there already is an item with the same id. The function returns an array with the ids of the added items. See section <a href="#Data_Manipulation">Data Manipulation</a>.</td>
  235. </tr>
  236. <tr>
  237. <td>clear([senderId])</td>
  238. <td>Number[]</td>
  239. <td>Clear all data from the DataSet. The function returns an array with the ids of the removed items.</td>
  240. </tr>
  241. <tr>
  242. <td>distinct(field)</td>
  243. <td>Array</td>
  244. <td>Find all distinct values of a specified field. Returns an unordered array containing all distinct values. If data items do not contain the specified field are ignored.</td>
  245. </tr>
  246. <tr>
  247. <td>flush()</td>
  248. <td>none</td>
  249. <td>Flush queued changes. Only available when the DataSet is configured with the option <code>queue</code>, see section <a href="#Construction">Construction</a>.</td>
  250. </tr>
  251. <tr>
  252. <td>forEach(callback&nbsp;[,&nbsp;options])</td>
  253. <td>none</td>
  254. <td>
  255. Execute a callback function for every item in the dataset.
  256. The available options are described in section <a href="#Data_Selection">Data Selection</a>.
  257. </td>
  258. </tr>
  259. <tr>
  260. <td>
  261. get([options] [, data])<br>
  262. get(id [,options] [, data])<br>
  263. get(ids [, options] [, data])
  264. </td>
  265. <td>Object | Array</td>
  266. <td>
  267. Get a single item, multiple items, or all items from the DataSet.
  268. 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.
  269. </td>
  270. </tr>
  271. <tr>
  272. <td>
  273. getDataSet()
  274. </td>
  275. <td>DataSet</td>
  276. <td>
  277. Get the DataSet itself. In case of a DataView, this function does not
  278. return the DataSet to which the DataView is connected.
  279. </td>
  280. </tr>
  281. <tr>
  282. <td>
  283. getIds([options])
  284. </td>
  285. <td>Number[]</td>
  286. <td>
  287. Get ids of all items or of a filtered set of items.
  288. Available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>, except that options <code>fields</code> and <code>type</code> are not applicable in case of <code>getIds</code>.
  289. </td>
  290. </tr>
  291. <tr>
  292. <td>map(callback [, options])</td>
  293. <td>Array</td>
  294. <td>
  295. Map every item in the DataSet.
  296. The available options are described in section <a href="#Data_Selection">Data Selection</a>.
  297. </td>
  298. </tr>
  299. <tr>
  300. <td>max(field)</td>
  301. <td>Object | null</td>
  302. <td>
  303. Find the item with maximum value of specified field. Returns <code>null</code> if no item is found.
  304. </td>
  305. </tr>
  306. <tr>
  307. <td>min(field)</td>
  308. <td>Object | null</td>
  309. <td>
  310. Find the item with minimum value of specified field. Returns <code>null</code> if no item is found.
  311. </td>
  312. </tr>
  313. <tr>
  314. <td>off(event, callback)</td>
  315. <td>none</td>
  316. <td>
  317. Unsubscribe from an event, remove an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  318. </td>
  319. </tr>
  320. <tr>
  321. <td>on(event, callback)</td>
  322. <td>none</td>
  323. <td>
  324. Subscribe to an event, add an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  325. </td>
  326. </tr>
  327. <tr>
  328. <td>
  329. remove(id [, senderId])<br>
  330. remove(ids [, senderId])
  331. </td>
  332. <td>Number[]</td>
  333. <td>
  334. Remove one or multiple items by id or by the items themselves. Returns an array with the ids of the removed items. See section <a href="#Data_Manipulation">Data Manipulation</a>.
  335. </td>
  336. </tr>
  337. <tr>
  338. <td>
  339. setOptions(options)
  340. </td>
  341. <td>none</td>
  342. <td>
  343. Set options for the DataSet. Available options:
  344. <ul>
  345. <li>
  346. <code>queue</code><br>
  347. Queue data changes ('add', 'update', 'remove') and flush them at once.
  348. The queue can be flushed manually by calling
  349. <code>DataSet.flush()</code>, or can be flushed after a configured delay
  350. or maximum number of entries.
  351. <br>
  352. <br>
  353. When <code>queue</code> is true, a queue is created with default options.
  354. When <code>queue</code> is false, an existing queue will be flushed and removed.
  355. Options can be specified by providing an object:
  356. <ul>
  357. <li><code>delay: number</code><br>
  358. The queue will be flushed automatically after an inactivity of this
  359. delay in milliseconds. Default value is <code>null</code>.
  360. <li><code>max: number</code><br>
  361. When the queue exceeds the given maximum number
  362. of entries, the queue is flushed automatically.
  363. Default value is <code>Infinity</code>.
  364. </li>
  365. </ul>
  366. </li>
  367. </ul>
  368. </td>
  369. </tr>
  370. <tr>
  371. <td>
  372. update(data [, senderId])
  373. </td>
  374. <td>Number[]</td>
  375. <td>
  376. Update one or multiple existing items. <code>data</code> can be a single item or an array with items. When an item doesn't exist, it will be created. Returns an array with the ids of the removed items. See section <a href="#Data_Manipulation">Data Manipulation</a>.
  377. </td>
  378. </tr>
  379. </table>
  380. <h2 id="Properties">Properties</h2>
  381. <p>DataSet contains the following properties.</p>
  382. <table>
  383. <tr>
  384. <th>Property</th>
  385. <th>Type</th>
  386. <th>Description</th>
  387. </tr>
  388. <tr>
  389. <td>length</td>
  390. <td>Number</td>
  391. <td>The number of items in the DataSet.</td>
  392. </tr>
  393. </table>
  394. <h2 id="Subscriptions">Subscriptions</h2>
  395. <p>
  396. One can subscribe on changes in a DataSet.
  397. A subscription can be created using the method <code>on</code>,
  398. and removed with <code>off</code>.
  399. </p>
  400. <pre class="prettyprint lang-js">
  401. // create a DataSet
  402. var data = new vis.DataSet();
  403. // subscribe to any change in the DataSet
  404. data.on('*', function (event, properties, senderId) {
  405. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  406. });
  407. // add an item
  408. data.add({id: 1, text: 'item 1'}); // triggers an 'add' event
  409. data.update({id: 1, text: 'item 1 (updated)'}); // triggers an 'update' event
  410. data.remove(1); // triggers an 'remove' event
  411. </pre>
  412. <h3 id="On">On</h3>
  413. <p>
  414. Subscribe to an event.
  415. </p>
  416. Syntax:
  417. <pre class="prettyprint lang-js">DataSet.on(event, callback)</pre>
  418. Where:
  419. <ul>
  420. <li>
  421. <code>event</code> is a String containing any of the events listed
  422. in section <a href="#Events">Events</a>.
  423. </li>
  424. <li>
  425. <code>callback</code> is a callback function which will be called
  426. each time the event occurs. The callback function is described in
  427. section <a href="#Callback">Callback</a>.
  428. </li>
  429. </ul>
  430. <h3 id="Off">Off</h3>
  431. <p>
  432. Unsubscribe from an event.
  433. </p>
  434. Syntax:
  435. <pre class="prettyprint lang-js">DataSet.off(event, callback)</pre>
  436. Where <code>event</code> and <code>callback</code> correspond with the
  437. parameters used to <a href="#On">subscribe</a> to the event.
  438. <h3 id="Events">Events</h3>
  439. <p>
  440. The following events are available for subscription:
  441. </p>
  442. <table>
  443. <tr>
  444. <th>Event</th>
  445. <th>Description</th>
  446. </tr>
  447. <tr>
  448. <td>add</td>
  449. <td>
  450. The <code>add</code> event is triggered when an item
  451. or a set of items is added, or when an item is updated while
  452. not yet existing.
  453. </td>
  454. </tr>
  455. <tr>
  456. <td>update</td>
  457. <td>
  458. The <code>update</code> event is triggered when an existing item
  459. or a set of existing items is updated.
  460. </td>
  461. </tr>
  462. <tr>
  463. <td>remove</td>
  464. <td>
  465. The <code>remove</code> event is triggered when an item
  466. or a set of items is removed.
  467. </td>
  468. </tr>
  469. <tr>
  470. <td>*</td>
  471. <td>
  472. The <code>*</code> event is triggered when any of the events
  473. <code>add</code>, <code>update</code>, and <code>remove</code>
  474. occurs.
  475. </td>
  476. </tr>
  477. </table>
  478. <h3 id="Callback">Callback</h3>
  479. <p>
  480. The callback functions of subscribers are called with the following
  481. parameters:
  482. </p>
  483. <pre class="prettyprint lang-js">
  484. function (event, properties, senderId) {
  485. // handle the event
  486. });
  487. </pre>
  488. <p>
  489. where the parameters are defined as
  490. </p>
  491. <table>
  492. <tr>
  493. <th>Parameter</th>
  494. <th>Type</th>
  495. <th>Description</th>
  496. </tr>
  497. <tr>
  498. <td>event</td>
  499. <td>String</td>
  500. <td>
  501. Any of the available events: <code>add</code>,
  502. <code>update</code>, or <code>remove</code>.
  503. </td>
  504. </tr>
  505. <tr>
  506. <td>properties</td>
  507. <td>Object&nbsp;|&nbsp;null</td>
  508. <td>
  509. Optional properties providing more information on the event.
  510. In case of the events <code>add</code>,
  511. <code>update</code>, and <code>remove</code>,
  512. <code>properties</code> is always an object containing a property
  513. <code>items</code>, which contains an array with the ids of the affected
  514. items. The <code>update</code> and <code>remove</code> events have an extra
  515. field <code>oldData</code> containing the original data of the items in the
  516. dataset before the items were updated or removed. The <code>update</code>
  517. event also contains a field <code>data</code> containing the changes:
  518. the properties of the items that are being updated.
  519. </td>
  520. </tr>
  521. <tr>
  522. <td>senderId</td>
  523. <td>String&nbsp;|&nbsp;Number</td>
  524. <td>
  525. An senderId, optionally provided by the application code
  526. which triggered the event. If senderId is not provided, the
  527. argument will be <code>null</code>.
  528. </td>
  529. </tr>
  530. </table>
  531. <h2 id="Data_Manipulation">Data Manipulation</h2>
  532. <p>
  533. The data in a DataSet can be manipulated using the methods
  534. <a href="#Add"><code>add</code></a>,
  535. <a href="#Update"><code>update</code></a>,
  536. and <a href="#Remove"><code>remove</code></a>.
  537. The DataSet can be emptied using the method
  538. <a href="#Clear"><code>clear</code></a>.
  539. </p>
  540. <pre class="prettyprint lang-js">
  541. // create a DataSet
  542. var data = new vis.DataSet();
  543. // add items
  544. data.add([
  545. {id: 1, text: 'item 1'},
  546. {id: 2, text: 'item 2'},
  547. {id: 3, text: 'item 3'}
  548. ]);
  549. // update an item
  550. data.update({id: 2, text: 'item 2 (updated)'});
  551. // remove an item
  552. data.remove(3);
  553. </pre>
  554. <h3 id="Add">Add</h3>
  555. <p>
  556. Add a data item or an array with items.
  557. </p>
  558. Syntax:
  559. <pre class="prettyprint lang-js">var addedIds = DataSet.add(data [, senderId])</pre>
  560. The argument <code>data</code> can contain:
  561. <ul>
  562. <li>
  563. An <code>Object</code> containing a single item to be
  564. added. The item must contain an id.
  565. </li>
  566. <li>
  567. An <code>Array</code> containing a list with items to be added. Each item must contain an id.
  568. </li>
  569. </ul>
  570. <p>
  571. After the items are added to the DataSet, the DataSet will
  572. trigger an event <code>add</code>. When a <code>senderId</code>
  573. is provided, this id will be passed with the triggered
  574. event to all subscribers.
  575. </p>
  576. <p>
  577. The method will throw an Error when an item with the same id
  578. as any of the added items already exists.
  579. </p>
  580. <h3 id="Update">Update</h3>
  581. <p>
  582. Update a data item or an array with items.
  583. </p>
  584. Syntax:
  585. <pre class="prettyprint lang-js">var updatedIds = DataSet.update(data [, senderId])</pre>
  586. The argument <code>data</code> can contain:
  587. <ul>
  588. <li>
  589. An <code>Object</code> containing a single item to be
  590. updated. The item must contain an id.
  591. </li>
  592. <li>
  593. An <code>Array</code> containing a list with items to be updated. Each item must contain an id.
  594. </li>
  595. </ul>
  596. <p>
  597. The provided properties will be merged in the existing item.
  598. When an item does not exist, it will be created.
  599. </p>
  600. <p>
  601. After the items are updated, the DataSet will
  602. trigger an event <code>add</code> for the added items, and
  603. an event <code>update</code>. When a <code>senderId</code>
  604. is provided, this id will be passed with the triggered
  605. event to all subscribers.
  606. </p>
  607. <h3 id="Remove">Remove</h3>
  608. <p>
  609. Remove a data item or an array with items.
  610. </p>
  611. Syntax:
  612. <pre class="prettyprint lang-js">var removedIds = DataSet.remove(id [, senderId])</pre>
  613. <p>
  614. The argument <code>id</code> can be:
  615. </p>
  616. <ul>
  617. <li>
  618. A <code>Number</code> or <code>String</code> containing the id
  619. of a single item to be removed.
  620. </li>
  621. <li>
  622. An <code>Object</code> containing the item to be deleted.
  623. The item will be deleted by its id.
  624. </li>
  625. <li>
  626. An Array containing ids or items to be removed.
  627. </li>
  628. </ul>
  629. <p>
  630. The method ignores removal of non-existing items, and returns an array
  631. containing the ids of the items which are actually removed from the
  632. DataSet.
  633. </p>
  634. <p>
  635. After the items are removed, the DataSet will
  636. trigger an event <code>remove</code> for the removed items.
  637. When a <code>senderId</code> is provided, this id will be passed with
  638. the triggered event to all subscribers.
  639. </p>
  640. <h3 id="Clear">Clear</h3>
  641. <p>
  642. Clear the complete DataSet.
  643. </p>
  644. Syntax:
  645. <pre class="prettyprint lang-js">var removedIds = DataSet.clear([senderId])</pre>
  646. <p>
  647. After the items are removed, the DataSet will
  648. trigger an event <code>remove</code> for all removed items.
  649. When a <code>senderId</code> is provided, this id will be passed with
  650. the triggered event to all subscribers.
  651. </p>
  652. <h2 id="Data_Selection">Data Selection</h2>
  653. <p>
  654. The DataSet contains functionality to format, filter, and sort data retrieved via the
  655. methods <code>get</code>, <code>getIds</code>, <code>forEach</code>, and <code>map</code>. These methods have the following syntax:
  656. </p>
  657. <pre class="prettyprint lang-js">
  658. DataSet.get([id] [, options]);
  659. DataSet.getIds([options]);
  660. DataSet.forEach(callback [, options]);
  661. DataSet.map(callback [, options]);
  662. </pre>
  663. <p>
  664. Where <code>options</code> is an Object which can have the following
  665. properties:
  666. </p>
  667. <table class="properties">
  668. <tr>
  669. <th>Name</th>
  670. <th>Type</th>
  671. <th>Required</th>
  672. <th>Description</th>
  673. </tr>
  674. <tr>
  675. <td>fields</td>
  676. <td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
  677. <td>no</td>
  678. <td>
  679. An array with field names, or an object with current field name and
  680. new field name that the field is returned as.
  681. By default, all properties of the items are emitted.
  682. When <code>fields</code> is defined, only the properties
  683. whose name is specified in <code>fields</code> will be included
  684. in the returned items.
  685. </td>
  686. </tr>
  687. <tr>
  688. <td>type</td>
  689. <td>Object.&lt;String,&nbsp;String&gt;</td>
  690. <td>no</td>
  691. <td>
  692. An object containing field names as key, and data types as value.
  693. By default, the type of the properties of an item are left
  694. unchanged. When a field type is specified, this field in the
  695. items will be converted to the specified type. This can be used
  696. for example to convert ISO strings containing a date to a
  697. JavaScript Date object, or convert strings to numbers or vice
  698. versa. The available data types are listed in section
  699. <a href="#Data_Types">Data Types</a>.
  700. </td>
  701. </tr>
  702. <tr>
  703. <td>filter</td>
  704. <td>Function</td>
  705. <td>no</td>
  706. <td>Items can be filtered on specific properties by providing a filter
  707. function. A filter function is executed for each of the items in the
  708. DataSet, and is called with the item as parameter. The function must
  709. return a boolean. All items for which the filter function returns
  710. true will be emitted.
  711. See section <a href="#Data_Filtering">Data Filtering</a>.</td>
  712. </tr>
  713. <tr>
  714. <td>order</td>
  715. <td>String | Function</td>
  716. <td>no</td>
  717. <td>Order the items by a field name or custom sort function.</td>
  718. </tr>
  719. <tr>
  720. <td>returnType</td>
  721. <td>String</td>
  722. <td>no</td>
  723. <td>Determine the type of output of the get function. Allowed values are <code>'Array' | 'Object'</code>.
  724. The default returnType is an Array. The Object type will return a JSON object with the ID's as keys.</td>
  725. </tr>
  726. </table>
  727. <p>
  728. The following example demonstrates formatting properties and filtering
  729. properties from items.
  730. </p>
  731. <pre class="prettyprint lang-js">
  732. // create a DataSet
  733. var data = new vis.DataSet();
  734. data.add([
  735. {id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true},
  736. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  737. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  738. {id: 4, text: 'item 4'}
  739. ]);
  740. // retrieve formatted items
  741. var items = data.get({
  742. fields: ['id', 'date', 'group'], // output the specified fields only
  743. type: {
  744. date: 'Date', // convert the date fields to Date objects
  745. group: 'String' // convert the group fields to Strings
  746. }
  747. });
  748. </pre>
  749. <h3 id="Getting_Data">Getting Data</h3>
  750. <p>
  751. Data can be retrieved from the DataSet using the method <code>get</code>.
  752. This method can return a single item or a list with items.
  753. </p>
  754. <p>A single item can be retrieved by its id:</p>
  755. <pre class="prettyprint lang-js">
  756. var item1 = dataset.get(1);
  757. </pre>
  758. <p>A selection of items can be retrieved by providing an array with ids:</p>
  759. <pre class="prettyprint lang-js">
  760. var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4
  761. </pre>
  762. <p>All items can be retrieved by simply calling <code>get</code> without
  763. specifying an id:</p>
  764. <pre class="prettyprint lang-js">
  765. var items = dataset.get(); // retrieve all items
  766. </pre>
  767. <h3 id="Data_Filtering">Data Filtering</h3>
  768. <p>
  769. Items can be filtered on specific properties by providing a filter
  770. function. A filter function is executed for each of the items in the
  771. DataSet, and is called with the item as parameter. The function must
  772. return a boolean. All items for which the filter function returns
  773. true will be emitted.
  774. </p>
  775. <pre class="prettyprint lang-js">
  776. // retrieve all items having a property group with value 2
  777. var group2 = dataset.get({
  778. filter: function (item) {
  779. return (item.group == 2);
  780. }
  781. });
  782. // retrieve all items having a property balance with a value above zero
  783. var positiveBalance = dataset.get({
  784. filter: function (item) {
  785. return (item.balance > 0);
  786. }
  787. });
  788. </pre>
  789. <h3 id="Data_Types">Data Types</h3>
  790. <p>
  791. DataSet supports the following data types:
  792. </p>
  793. <table class="datatypes">
  794. <tr>
  795. <th>Name</th>
  796. <th>Description</th>
  797. <th>Examples</th>
  798. </tr>
  799. <tr>
  800. <td>Boolean</td>
  801. <td>A JavaScript Boolean</td>
  802. <td>
  803. <code>true</code><br>
  804. <code>false</code>
  805. </td>
  806. </tr>
  807. <tr>
  808. <td>Number</td>
  809. <td>A JavaScript Number</td>
  810. <td>
  811. <code>32</code><br>
  812. <code>2.4</code>
  813. </td>
  814. </tr>
  815. <tr>
  816. <td>String</td>
  817. <td>A JavaScript String</td>
  818. <td>
  819. <code>"hello world"</code><br>
  820. <code>"2013-06-28"</code>
  821. </td>
  822. </tr>
  823. <tr>
  824. <td>Date</td>
  825. <td>A JavaScript Date object</td>
  826. <td>
  827. <code>new Date()</code><br>
  828. <code>new Date(2013, 5, 28)</code><br>
  829. <code>new Date(1372370400000)</code>
  830. </td>
  831. </tr>
  832. <tr>
  833. <td>Moment</td>
  834. <td>A Moment object, created with
  835. <a href="http://momentjs.com/" target="_blank">moment.js</a></td>
  836. <td>
  837. <code>moment()</code><br>
  838. <code>moment('2013-06-28')</code>
  839. </td>
  840. </tr>
  841. <tr>
  842. <td>ISODate</td>
  843. <td>A string containing an ISO Date</td>
  844. <td>
  845. <code>new Date().toISOString()</code><br>
  846. <code>"2013-06-27T22:00:00.000Z"</code>
  847. </td>
  848. </tr>
  849. <tr>
  850. <td>ASPDate</td>
  851. <td>A string containing an ASP Date</td>
  852. <td>
  853. <code>"/Date(1372370400000)/"</code><br>
  854. <code>"/Date(1198908717056-0700)/"</code>
  855. </td>
  856. </tr>
  857. </table>
  858. </div>
  859. <!-- Bootstrap core JavaScript
  860. ================================================== -->
  861. <!-- Placed at the end of the document so the pages load faster -->
  862. <script src="../js/jquery.min.js"></script>
  863. <script src="../js/bootstrap.min.js"></script>
  864. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  865. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  866. <!-- jquery extensions -->
  867. <script src="../js/jquery.highlight.js"></script>
  868. <script src="../js/jquery.url.min.js"></script>
  869. <!-- Tipue vendor js -->
  870. <script src="../js/tipuesearch.config.js"></script>
  871. <script src="../js/tipuesearch.js"></script>
  872. <!-- controller -->
  873. <script src="../js/main.js"></script>