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.

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