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.

1023 lines
30 KiB

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> event has an extra field <code>oldData</code>
  515. containing the original data of the updated items, and a field <code>data</code>
  516. containing the changes: the properties of the items that are being updated.
  517. </td>
  518. </tr>
  519. <tr>
  520. <td>senderId</td>
  521. <td>String&nbsp;|&nbsp;Number</td>
  522. <td>
  523. An senderId, optionally provided by the application code
  524. which triggered the event. If senderId is not provided, the
  525. argument will be <code>null</code>.
  526. </td>
  527. </tr>
  528. </table>
  529. <h2 id="Data_Manipulation">Data Manipulation</h2>
  530. <p>
  531. The data in a DataSet can be manipulated using the methods
  532. <a href="#Add"><code>add</code></a>,
  533. <a href="#Update"><code>update</code></a>,
  534. and <a href="#Remove"><code>remove</code></a>.
  535. The DataSet can be emptied using the method
  536. <a href="#Clear"><code>clear</code></a>.
  537. </p>
  538. <pre class="prettyprint lang-js">
  539. // create a DataSet
  540. var data = new vis.DataSet();
  541. // add items
  542. data.add([
  543. {id: 1, text: 'item 1'},
  544. {id: 2, text: 'item 2'},
  545. {id: 3, text: 'item 3'}
  546. ]);
  547. // update an item
  548. data.update({id: 2, text: 'item 2 (updated)'});
  549. // remove an item
  550. data.remove(3);
  551. </pre>
  552. <h3 id="Add">Add</h3>
  553. <p>
  554. Add a data item or an array with items.
  555. </p>
  556. Syntax:
  557. <pre class="prettyprint lang-js">var addedIds = DataSet.add(data [, senderId])</pre>
  558. The argument <code>data</code> can contain:
  559. <ul>
  560. <li>
  561. An <code>Object</code> containing a single item to be
  562. added. The item must contain an id.
  563. </li>
  564. <li>
  565. An <code>Array</code> containing a list with items to be added. Each item must contain an id.
  566. </li>
  567. </ul>
  568. <p>
  569. After the items are added to the DataSet, the DataSet will
  570. trigger an event <code>add</code>. When a <code>senderId</code>
  571. is provided, this id will be passed with the triggered
  572. event to all subscribers.
  573. </p>
  574. <p>
  575. The method will throw an Error when an item with the same id
  576. as any of the added items already exists.
  577. </p>
  578. <h3 id="Update">Update</h3>
  579. <p>
  580. Update a data item or an array with items.
  581. </p>
  582. Syntax:
  583. <pre class="prettyprint lang-js">var updatedIds = DataSet.update(data [, senderId])</pre>
  584. The argument <code>data</code> can contain:
  585. <ul>
  586. <li>
  587. An <code>Object</code> containing a single item to be
  588. updated. The item must contain an id.
  589. </li>
  590. <li>
  591. An <code>Array</code> containing a list with items to be updated. Each item must contain an id.
  592. </li>
  593. </ul>
  594. <p>
  595. The provided properties will be merged in the existing item.
  596. When an item does not exist, it will be created.
  597. </p>
  598. <p>
  599. After the items are updated, the DataSet will
  600. trigger an event <code>add</code> for the added items, and
  601. an event <code>update</code>. When a <code>senderId</code>
  602. is provided, this id will be passed with the triggered
  603. event to all subscribers.
  604. </p>
  605. <h3 id="Remove">Remove</h3>
  606. <p>
  607. Remove a data item or an array with items.
  608. </p>
  609. Syntax:
  610. <pre class="prettyprint lang-js">var removedIds = DataSet.remove(id [, senderId])</pre>
  611. <p>
  612. The argument <code>id</code> can be:
  613. </p>
  614. <ul>
  615. <li>
  616. A <code>Number</code> or <code>String</code> containing the id
  617. of a single item to be removed.
  618. </li>
  619. <li>
  620. An <code>Object</code> containing the item to be deleted.
  621. The item will be deleted by its id.
  622. </li>
  623. <li>
  624. An Array containing ids or items to be removed.
  625. </li>
  626. </ul>
  627. <p>
  628. The method ignores removal of non-existing items, and returns an array
  629. containing the ids of the items which are actually removed from the
  630. DataSet.
  631. </p>
  632. <p>
  633. After the items are removed, the DataSet will
  634. trigger an event <code>remove</code> for the removed items.
  635. When a <code>senderId</code> is provided, this id will be passed with
  636. the triggered event to all subscribers.
  637. </p>
  638. <h3 id="Clear">Clear</h3>
  639. <p>
  640. Clear the complete DataSet.
  641. </p>
  642. Syntax:
  643. <pre class="prettyprint lang-js">var removedIds = DataSet.clear([senderId])</pre>
  644. <p>
  645. After the items are removed, the DataSet will
  646. trigger an event <code>remove</code> for all removed items.
  647. When a <code>senderId</code> is provided, this id will be passed with
  648. the triggered event to all subscribers.
  649. </p>
  650. <h2 id="Data_Selection">Data Selection</h2>
  651. <p>
  652. The DataSet contains functionality to format, filter, and sort data retrieved via the
  653. methods <code>get</code>, <code>getIds</code>, <code>forEach</code>, and <code>map</code>. These methods have the following syntax:
  654. </p>
  655. <pre class="prettyprint lang-js">
  656. DataSet.get([id] [, options]);
  657. DataSet.getIds([options]);
  658. DataSet.forEach(callback [, options]);
  659. DataSet.map(callback [, options]);
  660. </pre>
  661. <p>
  662. Where <code>options</code> is an Object which can have the following
  663. properties:
  664. </p>
  665. <table class="properties">
  666. <tr>
  667. <th>Name</th>
  668. <th>Type</th>
  669. <th>Required</th>
  670. <th>Description</th>
  671. </tr>
  672. <tr>
  673. <td>fields</td>
  674. <td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
  675. <td>no</td>
  676. <td>
  677. An array with field names, or an object with current field name and
  678. new field name that the field is returned as.
  679. By default, all properties of the items are emitted.
  680. When <code>fields</code> is defined, only the properties
  681. whose name is specified in <code>fields</code> will be included
  682. in the returned items.
  683. </td>
  684. </tr>
  685. <tr>
  686. <td>type</td>
  687. <td>Object.&lt;String,&nbsp;String&gt;</td>
  688. <td>no</td>
  689. <td>
  690. An object containing field names as key, and data types as value.
  691. By default, the type of the properties of an item are left
  692. unchanged. When a field type is specified, this field in the
  693. items will be converted to the specified type. This can be used
  694. for example to convert ISO strings containing a date to a
  695. JavaScript Date object, or convert strings to numbers or vice
  696. versa. The available data types are listed in section
  697. <a href="#Data_Types">Data Types</a>.
  698. </td>
  699. </tr>
  700. <tr>
  701. <td>filter</td>
  702. <td>Function</td>
  703. <td>no</td>
  704. <td>Items can be filtered on specific properties by providing a filter
  705. function. A filter function is executed for each of the items in the
  706. DataSet, and is called with the item as parameter. The function must
  707. return a boolean. All items for which the filter function returns
  708. true will be emitted.
  709. See section <a href="#Data_Filtering">Data Filtering</a>.</td>
  710. </tr>
  711. <tr>
  712. <td>order</td>
  713. <td>String | Function</td>
  714. <td>no</td>
  715. <td>Order the items by a field name or custom sort function.</td>
  716. </tr>
  717. <tr>
  718. <td>returnType</td>
  719. <td>String</td>
  720. <td>no</td>
  721. <td>Determine the type of output of the get function. Allowed values are <code>'Array' | 'Object'</code>.
  722. The default returnType is an Array. The Object type will return a JSON object with the ID's as keys.</td>
  723. </tr>
  724. </table>
  725. <p>
  726. The following example demonstrates formatting properties and filtering
  727. properties from items.
  728. </p>
  729. <pre class="prettyprint lang-js">
  730. // create a DataSet
  731. var data = new vis.DataSet();
  732. data.add([
  733. {id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true},
  734. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  735. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  736. {id: 4, text: 'item 4'}
  737. ]);
  738. // retrieve formatted items
  739. var items = data.get({
  740. fields: ['id', 'date', 'group'], // output the specified fields only
  741. type: {
  742. date: 'Date', // convert the date fields to Date objects
  743. group: 'String' // convert the group fields to Strings
  744. }
  745. });
  746. </pre>
  747. <h3 id="Getting_Data">Getting Data</h3>
  748. <p>
  749. Data can be retrieved from the DataSet using the method <code>get</code>.
  750. This method can return a single item or a list with items.
  751. </p>
  752. <p>A single item can be retrieved by its id:</p>
  753. <pre class="prettyprint lang-js">
  754. var item1 = dataset.get(1);
  755. </pre>
  756. <p>A selection of items can be retrieved by providing an array with ids:</p>
  757. <pre class="prettyprint lang-js">
  758. var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4
  759. </pre>
  760. <p>All items can be retrieved by simply calling <code>get</code> without
  761. specifying an id:</p>
  762. <pre class="prettyprint lang-js">
  763. var items = dataset.get(); // retrieve all items
  764. </pre>
  765. <h3 id="Data_Filtering">Data Filtering</h3>
  766. <p>
  767. Items can be filtered on specific properties by providing a filter
  768. function. A filter function is executed for each of the items in the
  769. DataSet, and is called with the item as parameter. The function must
  770. return a boolean. All items for which the filter function returns
  771. true will be emitted.
  772. </p>
  773. <pre class="prettyprint lang-js">
  774. // retrieve all items having a property group with value 2
  775. var group2 = dataset.get({
  776. filter: function (item) {
  777. return (item.group == 2);
  778. }
  779. });
  780. // retrieve all items having a property balance with a value above zero
  781. var positiveBalance = dataset.get({
  782. filter: function (item) {
  783. return (item.balance > 0);
  784. }
  785. });
  786. </pre>
  787. <h3 id="Data_Types">Data Types</h3>
  788. <p>
  789. DataSet supports the following data types:
  790. </p>
  791. <table class="datatypes">
  792. <tr>
  793. <th>Name</th>
  794. <th>Description</th>
  795. <th>Examples</th>
  796. </tr>
  797. <tr>
  798. <td>Boolean</td>
  799. <td>A JavaScript Boolean</td>
  800. <td>
  801. <code>true</code><br>
  802. <code>false</code>
  803. </td>
  804. </tr>
  805. <tr>
  806. <td>Number</td>
  807. <td>A JavaScript Number</td>
  808. <td>
  809. <code>32</code><br>
  810. <code>2.4</code>
  811. </td>
  812. </tr>
  813. <tr>
  814. <td>String</td>
  815. <td>A JavaScript String</td>
  816. <td>
  817. <code>"hello world"</code><br>
  818. <code>"2013-06-28"</code>
  819. </td>
  820. </tr>
  821. <tr>
  822. <td>Date</td>
  823. <td>A JavaScript Date object</td>
  824. <td>
  825. <code>new Date()</code><br>
  826. <code>new Date(2013, 5, 28)</code><br>
  827. <code>new Date(1372370400000)</code>
  828. </td>
  829. </tr>
  830. <tr>
  831. <td>Moment</td>
  832. <td>A Moment object, created with
  833. <a href="http://momentjs.com/" target="_blank">moment.js</a></td>
  834. <td>
  835. <code>moment()</code><br>
  836. <code>moment('2013-06-28')</code>
  837. </td>
  838. </tr>
  839. <tr>
  840. <td>ISODate</td>
  841. <td>A string containing an ISO Date</td>
  842. <td>
  843. <code>new Date().toISOString()</code><br>
  844. <code>"2013-06-27T22:00:00.000Z"</code>
  845. </td>
  846. </tr>
  847. <tr>
  848. <td>ASPDate</td>
  849. <td>A string containing an ASP Date</td>
  850. <td>
  851. <code>"/Date(1372370400000)/"</code><br>
  852. <code>"/Date(1198908717056-0700)/"</code>
  853. </td>
  854. </tr>
  855. </table>
  856. </div>
  857. <!-- Bootstrap core JavaScript
  858. ================================================== -->
  859. <!-- Placed at the end of the document so the pages load faster -->
  860. <script src="../js/jquery.min.js"></script>
  861. <script src="../js/bootstrap.min.js"></script>
  862. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  863. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  864. <!-- jquery extensions -->
  865. <script src="../js/jquery.highlight.js"></script>
  866. <script src="../js/jquery.url.min.js"></script>
  867. <!-- Tipue vendor js -->
  868. <script src="../js/tipuesearch.config.js"></script>
  869. <script src="../js/tipuesearch.js"></script>
  870. <!-- controller -->
  871. <script src="../js/main.js"></script>