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.

839 lines
24 KiB

  1. <html>
  2. <head>
  3. <title>vis.js | timeline documentation</title>
  4. <link href='css/prettify.css' type='text/css' rel='stylesheet'>
  5. <link href='css/style.css' type='text/css' rel='stylesheet'>
  6. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <div id="container">
  10. <h1>Timeline documentation</h1>
  11. <h2 id="Overview">Overview</h2>
  12. <p>
  13. The Timeline is an interactive visualization chart to visualize data in time.
  14. The data items can take place on a single date, or have a start and end date (a range).
  15. You can freely move and zoom in the timeline by dragging and scrolling in the
  16. Timeline. Items can be created, edited, and deleted in the timeline.
  17. The time scale on the axis is adjusted automatically, and supports scales ranging
  18. from milliseconds to years.
  19. </p>
  20. <h2 id="Contents">Contents</h2>
  21. <ul>
  22. <li><a href="#Overview">Overview</a></li>
  23. <li><a href="#Example">Example</a></li>
  24. <li><a href="#Loading">Loading</a></li>
  25. <li><a href="#Data_Format">Data Format</a>
  26. <ul>
  27. <li><a href="#items">Items</a></li>
  28. <li><a href="#groups">Groups</a></li>
  29. </ul>
  30. </li>
  31. <li><a href="#Configuration_Options">Configuration Options</a></li>
  32. <li><a href="#Methods">Methods</a></li>
  33. <li><a href="#Events">Events</a></li>
  34. <li><a href="#Editing_Items">Editing Items</a></li>
  35. <li><a href="#Styles">Styles</a></li>
  36. <li><a href="#Data_Policy">Data Policy</a></li>
  37. </ul>
  38. <h2 id="Example">Example</h2>
  39. <p>
  40. The following code shows how to create a Timeline and provide it with data.
  41. More examples can be found in the <a href="../examples">examples</a> directory.
  42. </p>
  43. <pre class="prettyprint lang-html">&lt;!DOCTYPE HTML&gt;
  44. &lt;html&gt;
  45. &lt;head&gt;
  46. &lt;title&gt;Timeline | Basic demo&lt;/title&gt;
  47. &lt;style type="text/css"&gt;
  48. body, html {
  49. font-family: sans-serif;
  50. }
  51. &lt;/style&gt;
  52. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  53. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  54. &lt;/head&gt;
  55. &lt;body&gt;
  56. &lt;div id="visualization"&gt;&lt;/div&gt;
  57. &lt;script type="text/javascript"&gt;
  58. var container = document.getElementById('visualization');
  59. var items = [
  60. {id: 1, content: 'item 1', start: '2013-04-20'},
  61. {id: 2, content: 'item 2', start: '2013-04-14'},
  62. {id: 3, content: 'item 3', start: '2013-04-18'},
  63. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  64. {id: 5, content: 'item 5', start: '2013-04-25'},
  65. {id: 6, content: 'item 6', start: '2013-04-27'}
  66. ];
  67. var options = {};
  68. var timeline = new vis.Timeline(container, items, options);
  69. &lt;/script&gt;
  70. &lt;/body&gt;
  71. &lt;/html&gt;
  72. </pre>
  73. <h2 id="Loading">Loading</h2>
  74. <p>
  75. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  76. in a subfolder of your project. Include the libraries script and css files in the
  77. head of your html code:
  78. </p>
  79. <pre class="prettyprint lang-html">
  80. &lt;script src="vis/dist/vis.js"&gt;&lt;/script&gt;
  81. &lt;link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  82. </pre>
  83. The constructor of the Timeline is <code>vis.Timeline</code>
  84. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, options);</pre>
  85. The constructor accepts three parameters:
  86. <ul>
  87. <li>
  88. <code>container</code> is the DOM element in which to create the graph.
  89. </li>
  90. <li>
  91. <code>items</code> is an Array containing items. The properties of an
  92. item are described in section <a href="#Data_Format">Data Format</a>.
  93. </li>
  94. <li>
  95. <code>options</code> is an optional Object containing a name-value map
  96. with options. Options can also be set using the method
  97. <code>setOptions</code>.
  98. </li>
  99. </ul>
  100. <h2 id="Data_Format">Data Format</h2>
  101. <p>
  102. The timeline can be provided with two types of data:
  103. </p>
  104. <ul>
  105. <li><a href="#items">Items</a> containing a set of items to be displayed in time.</li>
  106. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  107. together.</li>
  108. </ul>
  109. <h3 id="items">Items</h3>
  110. <p>
  111. The Timeline uses regular Arrays and Objects as data format.
  112. Data items can contain the properties <code>start</code>,
  113. <code>end</code> (optional), <code>content</code>,
  114. <code>group</code> (optional), and <code>className</code> (optional).
  115. </p>
  116. <p>
  117. A table is constructed as:
  118. </p>
  119. <pre class="prettyprint lang-js">
  120. var items = [
  121. {
  122. start: new Date(2010, 7, 15),
  123. end: new Date(2010, 8, 2), // end is optional
  124. content: 'Trajectory A'
  125. // Optional: fields 'id', 'type', 'group', 'className'
  126. }
  127. // more items...
  128. ]);
  129. </pre>
  130. <p>
  131. The item properties are defined as:
  132. </p>
  133. <table>
  134. <tr>
  135. <th>Name</th>
  136. <th>Type</th>
  137. <th>Required</th>
  138. <th>Description</th>
  139. </tr>
  140. <tr>
  141. <td>id</td>
  142. <td>String | Number</td>
  143. <td>no</td>
  144. <td>An id for the item. Using an id is not required but highly
  145. recommended. An id is needed when dynamically adding, updating,
  146. and removing items in a DataSet.</td>
  147. </tr>
  148. <tr>
  149. <td>start</td>
  150. <td>Date</td>
  151. <td>yes</td>
  152. <td>The start date of the item, for example <code>new Date(2010,09,23)</code>.</td>
  153. </tr>
  154. <tr>
  155. <td>end</td>
  156. <td>Date</td>
  157. <td>no</td>
  158. <td>The end date of the item. The end date is optional, and can be left <code>null</code>.
  159. If end date is provided, the item is displayed as a range.
  160. If not, the item is displayed as a box.</td>
  161. </tr>
  162. <tr>
  163. <td>content</td>
  164. <td>String</td>
  165. <td>yes</td>
  166. <td>The contents of the item. This can be plain text or html code.</td>
  167. </tr>
  168. <tr>
  169. <td>type</td>
  170. <td>String</td>
  171. <td>'box'</td>
  172. <td>The type of the item. Can be 'box' (default), 'range', or 'point'.
  173. <!-- TODO: describe rangeoverflow -->
  174. </td>
  175. </tr>
  176. <tr>
  177. <td>group</td>
  178. <td>any type</td>
  179. <td>no</td>
  180. <td>This field is optional. When the group column is provided,
  181. all items with the same group are placed on one line.
  182. A vertical axis is displayed showing the groups.
  183. Grouping items can be useful for example when showing availability of multiple
  184. people, rooms, or other resources next to each other.<br>
  185. </td>
  186. </tr>
  187. <tr>
  188. <td>className</td>
  189. <td>String</td>
  190. <td>no</td>
  191. <td>This field is optional. A className can be used to give items
  192. an individual css style. For example, when an item has className
  193. 'red', one can define a css style
  194. <code>
  195. .red {
  196. background-color: red;
  197. border-color: dark-red;
  198. }
  199. </code>.
  200. More details on how to style items can be found in the section
  201. <a href="#Styles">Styles</a>.
  202. </td>
  203. </tr>
  204. </table>
  205. <h3 id="groups">Groups</h3>
  206. <p>
  207. Like the items, groups are regular JavaScript Arrays and Objects.
  208. Using groups, items can be grouped together.
  209. Items are filtered per group, and displayed as
  210. Group items can contain the properties <code>id</code>,
  211. <code>content</code>, and <code>className</code> (optional).
  212. </p>
  213. <p>
  214. Groups can be applied to a timeline using the method <code>setGroups</code>.
  215. A table with groups can be created like:
  216. </p>
  217. <pre class="prettyprint lang-js">
  218. var groups = [
  219. {
  220. id: 1,
  221. content: 'Group 1'
  222. // Optional: a field 'className'
  223. }
  224. // more groups...
  225. ]);
  226. </pre>
  227. <p>
  228. Groups can have the following properties:
  229. </p>
  230. <table>
  231. <tr>
  232. <th>Name</th>
  233. <th>Type</th>
  234. <th>Required</th>
  235. <th>Description</th>
  236. </tr>
  237. <tr>
  238. <td>id</td>
  239. <td>String | Number</td>
  240. <td>yes</td>
  241. <td>An id for the group. The group will display all items having a
  242. property <code>group</code> which matches the <code>id</code>
  243. of the group.</td>
  244. </tr>
  245. <tr>
  246. <td>content</td>
  247. <td>String</td>
  248. <td>yes</td>
  249. <td>The contents of the group. This can be plain text or html code.</td>
  250. </tr>
  251. <tr>
  252. <td>className</td>
  253. <td>String</td>
  254. <td>no</td>
  255. <td>This field is optional. A className can be used to give groups
  256. an individual css style. For example, when a group has className
  257. 'red', one can define a css style
  258. <code>
  259. .red {
  260. color: red;
  261. }
  262. </code>.
  263. More details on how to style groups can be found in the section
  264. <a href="#Styles">Styles</a>.
  265. </td>
  266. </tr>
  267. </table>
  268. <h2 id="Configuration_Options">Configuration Options</h2>
  269. <p>
  270. Options can be used to customize the timeline.
  271. Options are defined as a JSON object. All options are optional.
  272. </p>
  273. <pre class="prettyprint lang-js">
  274. var options = {
  275. width: '100%',
  276. height: '30px'
  277. };
  278. </pre>
  279. <p>
  280. The following options are available.
  281. </p>
  282. <table>
  283. <tr>
  284. <th>Name</th>
  285. <th>Type</th>
  286. <th>Default</th>
  287. <th>Description</th>
  288. </tr>
  289. <tr>
  290. <td>align</td>
  291. <td>String</td>
  292. <td>"center"</td>
  293. <td>Alignment of items with type 'box'. Available values are
  294. 'center' (default), 'left', or 'right').</td>
  295. </tr>
  296. <tr>
  297. <td>autoResize</td>
  298. <td>boolean</td>
  299. <td>true</td>
  300. <td>If true, the Timeline will automatically detect when its
  301. container is resized, and redraw itself accordingly.</td>
  302. </tr>
  303. <tr>
  304. <td>editable</td>
  305. <td>Boolean</td>
  306. <td>false</td>
  307. <td>If true, the items on the timeline can be dragged. Only applicable when option <code>selectable</code> is <code>true</code>. See also the callbacks <code>onAdd</code>, <code>onUpdate</code>, <code>onMove</code>, and <code>onRemove</code>, described in detail in section <a href="#Editing_Items">Editing Items</a>.
  308. </td>
  309. </tr>
  310. <tr>
  311. <td>end</td>
  312. <td>Date | Number | String</td>
  313. <td>none</td>
  314. <td>The initial end date for the axis of the timeline.
  315. If not provided, the latest date present in the items set is taken as
  316. end date.</td>
  317. </tr>
  318. <tr>
  319. <td>groupOrder</td>
  320. <td>String | Function</td>
  321. <td>none</td>
  322. <td>Order the groups by a field name or custom sort function.
  323. By default, groups are not ordered.
  324. </td>
  325. </tr>
  326. <tr>
  327. <td>height</td>
  328. <td>String</td>
  329. <td>none</td>
  330. <td>The height of the timeline in pixels or as a percentage.
  331. When height is undefined or null, the height of the timeline is automatically
  332. adjusted to fit the contents.
  333. It is possible to set a maximum height using option <code>maxHeight</code>
  334. to prevent the timeline from getting too high in case of automatically
  335. calculated height.
  336. </td>
  337. </tr>
  338. <tr>
  339. <td>margin.axis</td>
  340. <td>Number</td>
  341. <td>20</td>
  342. <td>The minimal margin in pixels between items and the time axis.</td>
  343. </tr>
  344. <tr>
  345. <td>margin.item</td>
  346. <td>Number</td>
  347. <td>10</td>
  348. <td>The minimal margin in pixels between items.</td>
  349. </tr>
  350. <tr>
  351. <td>max</td>
  352. <td>Date | Number | String</td>
  353. <td>none</td>
  354. <td>Set a maximum Date for the visible range.
  355. It will not be possible to move beyond this maximum.
  356. </td>
  357. </tr>
  358. <tr>
  359. <td>maxHeight</td>
  360. <td>Number</td>
  361. <td>none</td>
  362. <td>Specifies a maximum height for the Timeline in pixels.
  363. </td>
  364. </tr>
  365. <tr>
  366. <td>min</td>
  367. <td>Date | Number | String</td>
  368. <td>none</td>
  369. <td>Set a minimum Date for the visible range.
  370. It will not be possible to move beyond this minimum.
  371. </td>
  372. </tr>
  373. <tr>
  374. <td>onAdd</td>
  375. <td>Function</td>
  376. <td>none</td>
  377. <td>Callback function triggered when an item is about to be added: when the user double taps an empty space in the Timeline. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable</code> are set <code>true</code>.
  378. </td>
  379. </tr>
  380. <tr>
  381. <td>onUpdate</td>
  382. <td>Function</td>
  383. <td>none</td>
  384. <td>Callback function triggered when an item is about to be updated, when the user double taps an item in the Timeline. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable</code> are set <code>true</code>.
  385. </td>
  386. </tr>
  387. <tr>
  388. <td>onMove</td>
  389. <td>Function</td>
  390. <td>none</td>
  391. <td>Callback function triggered when an item has been moved: after the user has dragged the item to an other position. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable</code> are set <code>true</code>.
  392. </td>
  393. </tr>
  394. <tr>
  395. <td>onRemove</td>
  396. <td>Function</td>
  397. <td>none</td>
  398. <td>Callback function triggered when an item is about to be removed: when the user tapped the delete button on the top right of a selected item. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable</code> are set <code>true</code>.
  399. </td>
  400. </tr>
  401. <tr>
  402. <td>order</td>
  403. <td>Function</td>
  404. <td>none</td>
  405. <td>Provide a custom sort function to order the items. The order of the
  406. items is determining the way they are stacked. The function
  407. order is called with two parameters, both of type
  408. `vis.components.items.Item`.
  409. </td>
  410. </tr>
  411. <tr>
  412. <td>orientation</td>
  413. <td>String</td>
  414. <td>'bottom'</td>
  415. <td>Orientation of the timeline: 'top' or 'bottom' (default). If orientation is 'bottom', the time axis is drawn at the bottom, and if 'top', the axis is drawn on top.</td>
  416. </tr>
  417. <tr>
  418. <td>padding</td>
  419. <td>Number</td>
  420. <td>5</td>
  421. <td>The padding of items, needed to correctly calculate the size
  422. of item ranges. Must correspond with the css of item ranges.</td>
  423. </tr>
  424. <tr>
  425. <td>selectable</td>
  426. <td>Boolean</td>
  427. <td>true</td>
  428. <td>If true, the items on the timeline can be selected. Multiple items can be selected by long pressing them, or by using ctrl+click or shift+click. The event <code>select</code> is fired each time the selection has changed (see section <a href="#Events">Events</a>).</td>
  429. </tr>
  430. <tr>
  431. <td>showCurrentTime</td>
  432. <td>boolean</td>
  433. <td>false</td>
  434. <td>Show a vertical bar at the current time.</td>
  435. </tr>
  436. <tr>
  437. <td>showCustomTime</td>
  438. <td>boolean</td>
  439. <td>false</td>
  440. <td>Show a vertical bar displaying a custom time. This line can be dragged by the user. The custom time can be utilized to show a state in the past or in the future. When the custom time bar is dragged by the user, the event <code>timechange</code> is fired repeatedly. After the bar is dragged, the event <code>timechanged</code> is fired once.</td>
  441. </tr>
  442. <tr>
  443. <tr>
  444. <td>showMajorLabels</td>
  445. <td>boolean</td>
  446. <td>true</td>
  447. <td>By default, the timeline shows both minor and major date labels on the
  448. time axis.
  449. For example the minor labels show minutes and the major labels show hours.
  450. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  451. are shown.</td>
  452. </tr>
  453. <tr>
  454. <td>showMinorLabels</td>
  455. <td>boolean</td>
  456. <td>true</td>
  457. <td>By default, the timeline shows both minor and major date labels on the
  458. time axis.
  459. For example the minor labels show minutes and the major labels show hours.
  460. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  461. are shown. When both <code>showMajorLabels</code> and
  462. <code>showMinorLabels</code> are false, no horizontal axis will be
  463. visible.</td>
  464. </tr>
  465. <tr>
  466. <td>start</td>
  467. <td>Date | Number | String</td>
  468. <td>none</td>
  469. <td>The initial start date for the axis of the timeline.
  470. If not provided, the earliest date present in the events is taken as start date.</td>
  471. </tr>
  472. <tr>
  473. <td>type</td>
  474. <td>String</td>
  475. <td>'box'</td>
  476. <td>Specifies the type for the timeline items. Choose from 'dot' or 'point'.
  477. Note that individual items can override this global type.
  478. </td>
  479. </tr>
  480. <tr>
  481. <td>width</td>
  482. <td>String</td>
  483. <td>'100%'</td>
  484. <td>The width of the timeline in pixels or as a percentage.</td>
  485. </tr>
  486. <tr>
  487. <td>zoomMax</td>
  488. <td>Number</td>
  489. <td>315360000000000</td>
  490. <td>Set a maximum zoom interval for the visible range in milliseconds.
  491. It will not be possible to zoom out further than this maximum.
  492. Default value equals about 10000 years.
  493. </td>
  494. </tr>
  495. <tr>
  496. <td>zoomMin</td>
  497. <td>Number</td>
  498. <td>10</td>
  499. <td>Set a minimum zoom interval for the visible range in milliseconds.
  500. It will not be possible to zoom in further than this minimum.
  501. </td>
  502. </tr>
  503. </table>
  504. <h2 id="Methods">Methods</h2>
  505. <p>
  506. The Timeline supports the following methods.
  507. </p>
  508. <table>
  509. <tr>
  510. <th>Method</th>
  511. <th>Return Type</th>
  512. <th>Description</th>
  513. </tr>
  514. <tr>
  515. <td>getCustomTime()</td>
  516. <td>Date</td>
  517. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  518. </td>
  519. </tr>
  520. <tr>
  521. <td>setCustomTime(time)</td>
  522. <td>none</td>
  523. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  524. </td>
  525. </tr>
  526. <tr>
  527. <td>getSelection()</td>
  528. <td>ids</td>
  529. <td>Get an array with the ids of the currently selected items.</td>
  530. </tr>
  531. <tr>
  532. <td>on(event, callback)</td>
  533. <td>none</td>
  534. <td>Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: <code>rangechange</code>, <code>rangechanged</code>, <code>select</code>. The callback function is invoked as <code>callback(properties)</code>, where <code>properties</code> is an object containing event specific properties. See section <a href="#Events">Events for more information</a>.</td>
  535. </tr>
  536. <tr>
  537. <td>off(event, callback)</td>
  538. <td>none</td>
  539. <td>Remove an event listener created before via function <code>on(event, callback)</code>. See section <a href="#Events">Events for more information</a>.</td>
  540. </tr>
  541. <tr>
  542. <td>setGroups(groups)</td>
  543. <td>none</td>
  544. <td>Set a data set with groups for the Timeline.
  545. <code>groups</code> can be an Array with Objects,
  546. a DataSet, or a DataView. For each of the groups, the items of the
  547. timeline are filtered on the property <code>group</code>, which
  548. must correspond with the id of the group.
  549. </td>
  550. </tr>
  551. <tr>
  552. <td>setItems(items)</td>
  553. <td>none</td>
  554. <td>Set a data set with items for the Timeline.
  555. <code>items</code> can be an Array with Objects,
  556. a DataSet, or a DataView.
  557. </td>
  558. </tr>
  559. <tr>
  560. <td>setOptions(options)</td>
  561. <td>none</td>
  562. <td>Set or update options. It is possible to change any option of the timeline at any time. You can for example switch orientation on the fly.
  563. </td>
  564. </tr>
  565. <tr>
  566. <td>setSelection([ids])</td>
  567. <td>none</td>
  568. <td>Select or deselect items. Currently selected items will be unselected.
  569. </td>
  570. </tr>
  571. </table>
  572. <h2 id="Events">Events</h2>
  573. <p>
  574. Timeline fires events when changing the visible window by dragging, when
  575. selecting items, and when dragging the custom time bar.
  576. </p>
  577. <p>
  578. Here an example on how to listen for a <code>select</code> event.
  579. </p>
  580. <pre class="prettyprint lang-js">
  581. timeline.on('select', function (properties) {
  582. alert('selected items: ' + properties.nodes);
  583. });
  584. </pre>
  585. <p>
  586. A listener can be removed via the function <code>off</code>:
  587. </p>
  588. <pre class="prettyprint lang-js">
  589. function onSelect (properties) {
  590. alert('selected items: ' + properties.nodes);
  591. }
  592. // add event listener
  593. timeline.on('select', onSelect);
  594. // do stuff...
  595. // remove event listener
  596. timeline.off('select', onSelect);
  597. </pre>
  598. <p>
  599. The following events are available.
  600. </p>
  601. <table>
  602. <colgroup>
  603. <col style="width: 20%;">
  604. <col style="width: 40%;">
  605. <col style="width: 40%;">
  606. </colgroup>
  607. <tr>
  608. <th>name</th>
  609. <th>Description</th>
  610. <th>Properties</th>
  611. </tr>
  612. <tr>
  613. <td>rangechange</td>
  614. <td>Fired repeatedly when the user is dragging the timeline window.
  615. </td>
  616. <td>
  617. <ul>
  618. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  619. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  620. </ul>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td>rangechanged</td>
  625. <td>Fired once after the user has dragged the timeline window.
  626. </td>
  627. <td>
  628. <ul>
  629. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  630. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  631. </ul>
  632. </td>
  633. </tr>
  634. <tr>
  635. <td>select</td>
  636. <td>Fired after the user selects or deselects items by tapping or holding them.
  637. Not fired when the method <code>setSelection</code>is executed.
  638. </td>
  639. <td>
  640. <ul>
  641. <li><code>items</code>: an array with the ids of the selected items</li>
  642. </ul>
  643. </td>
  644. </tr>
  645. <tr>
  646. <td>timechange</td>
  647. <td>Fired repeatedly when the user is dragging the custom time bar.
  648. Only available when the custom time bar is enabled.
  649. </td>
  650. <td>
  651. <ul>
  652. <li><code>time</code> (Date): the current time.</li>
  653. </ul>
  654. </td>
  655. </tr>
  656. <tr>
  657. <td>timechanged</td>
  658. <td>Fired once after the user has dragged the custom time bar.
  659. Only available when the custom time bar is enabled.
  660. </td>
  661. <td>
  662. <ul>
  663. <li><code>time</code> (Date): the current time.</li>
  664. </ul>
  665. </td>
  666. </tr>
  667. </table>
  668. <h2 id="Editing_Items">Editing Items</h2>
  669. <p>
  670. When the Timeline is configured to be editable (both options <code>selectable</code> and <code>editable</code> are <code>true</code>), the user can move items by dragging them, can create a new item by double tapping on an empty space, can update an item by double tapping it, and can delete a selected item by clicking the delete button on the top right.
  671. </p>
  672. <p>
  673. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  674. </p>
  675. <ul>
  676. <li><code>onAdd(item, callback)</code> Fired when a new item is about to be added. If not implemented, the item will be added with default text contents.</li>
  677. <li><code>onUpdate(item, callback)</code> Fired when an item is about to be updated. This function typically has to show a dialog where the user change the item. If not implemented, nothing happens.</li>
  678. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  679. <li><code>onRemove(item, callback)</code> Fired when an item is about to be deleted. If not implemented, the item will be always removed.</li>
  680. </ul>
  681. <p>
  682. Each of the callbacks is invoked with two arguments:
  683. </p>
  684. <ul>
  685. <li><code>item</code>: the item being manipulated</li>
  686. <li><code>callback</code>: a callback function which must be invoked to report back. The callback must be invoked as <code>callback(item | null)</code>. Here, <code>item</code> can contain changes to the passed item. When invoked as <code>callback(null)</code>, the action will be cancelled.</li>
  687. </ul>
  688. <p>
  689. Example code:
  690. </p>
  691. <pre class="prettyprint lang-js">var options = {
  692. onUpdate: function (item, callback) {
  693. item.content = prompt('Edit items text:', item.content);
  694. if (item.content != null) {
  695. callback(item); // send back adjusted item
  696. }
  697. else {
  698. callback(null); // cancel updating the item
  699. }
  700. }
  701. }
  702. </pre>
  703. A full example is available here: <a href="../examples/timeline/08_validate_changes.html">08_validate_changes.html</a>.
  704. <h2 id="Styles">Styles</h2>
  705. <p>
  706. All parts of the Timeline have a class name and a default css style.
  707. The styles can be overwritten, which enables full customization of the layout
  708. of the Timeline.
  709. </p>
  710. <p>For example, to change the border and background color of all items, include the
  711. following code inside the head of your html code or in a separate stylesheet.</p>
  712. <pre class="prettyprint lang-html">&lt;style&gt;
  713. .vis.timeline .item {
  714. border-color: orange;
  715. background-color: yellow;
  716. }
  717. &lt;/style&gt;
  718. </pre>
  719. <h2 id="Data_Policy">Data Policy</h2>
  720. <p>
  721. All code and data is processed and rendered in the browser.
  722. No data is sent to any server.
  723. </p>
  724. </div>
  725. </body>
  726. </html>