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.

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