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.

859 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 like:
  194. <pre class="prettyprint lang-css">
  195. .vis.timeline .red {
  196. color: white;
  197. background-color: red;
  198. border-color: darkred;
  199. }</pre>
  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. margin: {
  278. item: 20
  279. }
  280. };
  281. </pre>
  282. <p>
  283. The following options are available.
  284. </p>
  285. <table>
  286. <tr>
  287. <th>Name</th>
  288. <th>Type</th>
  289. <th>Default</th>
  290. <th>Description</th>
  291. </tr>
  292. <tr>
  293. <td>align</td>
  294. <td>String</td>
  295. <td>"center"</td>
  296. <td>Alignment of items with type 'box'. Available values are
  297. 'center' (default), 'left', or 'right').</td>
  298. </tr>
  299. <tr>
  300. <td>autoResize</td>
  301. <td>boolean</td>
  302. <td>true</td>
  303. <td>If true, the Timeline will automatically detect when its
  304. container is resized, and redraw itself accordingly.</td>
  305. </tr>
  306. <tr>
  307. <td>editable</td>
  308. <td>Boolean</td>
  309. <td>false</td>
  310. <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>.
  311. </td>
  312. </tr>
  313. <tr>
  314. <td>end</td>
  315. <td>Date | Number | String</td>
  316. <td>none</td>
  317. <td>The initial end date for the axis of the timeline.
  318. If not provided, the latest date present in the items set is taken as
  319. end date.</td>
  320. </tr>
  321. <tr>
  322. <td>groupOrder</td>
  323. <td>String | Function</td>
  324. <td>none</td>
  325. <td>Order the groups by a field name or custom sort function.
  326. By default, groups are not ordered.
  327. </td>
  328. </tr>
  329. <tr>
  330. <td>height</td>
  331. <td>String</td>
  332. <td>none</td>
  333. <td>The height of the timeline in pixels or as a percentage.
  334. When height is undefined or null, the height of the timeline is automatically
  335. adjusted to fit the contents.
  336. It is possible to set a maximum height using option <code>maxHeight</code>
  337. to prevent the timeline from getting too high in case of automatically
  338. calculated height.
  339. </td>
  340. </tr>
  341. <tr>
  342. <td>margin.axis</td>
  343. <td>Number</td>
  344. <td>20</td>
  345. <td>The minimal margin in pixels between items and the time axis.</td>
  346. </tr>
  347. <tr>
  348. <td>margin.item</td>
  349. <td>Number</td>
  350. <td>10</td>
  351. <td>The minimal margin in pixels between items.</td>
  352. </tr>
  353. <tr>
  354. <td>max</td>
  355. <td>Date | Number | String</td>
  356. <td>none</td>
  357. <td>Set a maximum Date for the visible range.
  358. It will not be possible to move beyond this maximum.
  359. </td>
  360. </tr>
  361. <tr>
  362. <td>maxHeight</td>
  363. <td>Number</td>
  364. <td>none</td>
  365. <td>Specifies a maximum height for the Timeline in pixels.
  366. </td>
  367. </tr>
  368. <tr>
  369. <td>min</td>
  370. <td>Date | Number | String</td>
  371. <td>none</td>
  372. <td>Set a minimum Date for the visible range.
  373. It will not be possible to move beyond this minimum.
  374. </td>
  375. </tr>
  376. <tr>
  377. <td>onAdd</td>
  378. <td>Function</td>
  379. <td>none</td>
  380. <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>.
  381. </td>
  382. </tr>
  383. <tr>
  384. <td>onUpdate</td>
  385. <td>Function</td>
  386. <td>none</td>
  387. <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>.
  388. </td>
  389. </tr>
  390. <tr>
  391. <td>onMove</td>
  392. <td>Function</td>
  393. <td>none</td>
  394. <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>.
  395. </td>
  396. </tr>
  397. <tr>
  398. <td>onRemove</td>
  399. <td>Function</td>
  400. <td>none</td>
  401. <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>.
  402. </td>
  403. </tr>
  404. <tr>
  405. <td>order</td>
  406. <td>Function</td>
  407. <td>none</td>
  408. <td>Provide a custom sort function to order the items. The order of the
  409. items is determining the way they are stacked. The function
  410. order is called with two parameters, both of type
  411. `vis.components.items.Item`.
  412. </td>
  413. </tr>
  414. <tr>
  415. <td>orientation</td>
  416. <td>String</td>
  417. <td>'bottom'</td>
  418. <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>
  419. </tr>
  420. <tr>
  421. <td>padding</td>
  422. <td>Number</td>
  423. <td>5</td>
  424. <td>The padding of items, needed to correctly calculate the size
  425. of item ranges. Must correspond with the css of items, for example when setting <code>options.padding=10</code>, corresponding css is:
  426. <pre class="prettyprint lang-css">
  427. .vis.timeline .item {
  428. padding: 10px;
  429. }</pre>
  430. </td>
  431. </tr>
  432. <tr>
  433. <td>selectable</td>
  434. <td>Boolean</td>
  435. <td>true</td>
  436. <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>
  437. </tr>
  438. <tr>
  439. <td>showCurrentTime</td>
  440. <td>boolean</td>
  441. <td>false</td>
  442. <td>Show a vertical bar at the current time.</td>
  443. </tr>
  444. <tr>
  445. <td>showCustomTime</td>
  446. <td>boolean</td>
  447. <td>false</td>
  448. <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>
  449. </tr>
  450. <tr>
  451. <tr>
  452. <td>showMajorLabels</td>
  453. <td>boolean</td>
  454. <td>true</td>
  455. <td>By default, the timeline shows both minor and major date labels on the
  456. time axis.
  457. For example the minor labels show minutes and the major labels show hours.
  458. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  459. are shown.</td>
  460. </tr>
  461. <tr>
  462. <td>showMinorLabels</td>
  463. <td>boolean</td>
  464. <td>true</td>
  465. <td>By default, the timeline shows both minor and major date labels on the
  466. time axis.
  467. For example the minor labels show minutes and the major labels show hours.
  468. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  469. are shown. When both <code>showMajorLabels</code> and
  470. <code>showMinorLabels</code> are false, no horizontal axis will be
  471. visible.</td>
  472. </tr>
  473. <tr>
  474. <td>start</td>
  475. <td>Date | Number | String</td>
  476. <td>none</td>
  477. <td>The initial start date for the axis of the timeline.
  478. If not provided, the earliest date present in the events is taken as start date.</td>
  479. </tr>
  480. <tr>
  481. <td>type</td>
  482. <td>String</td>
  483. <td>'box'</td>
  484. <td>Specifies the type for the timeline items. Choose from 'dot' or 'point'.
  485. Note that individual items can override this global type.
  486. </td>
  487. </tr>
  488. <tr>
  489. <td>width</td>
  490. <td>String</td>
  491. <td>'100%'</td>
  492. <td>The width of the timeline in pixels or as a percentage.</td>
  493. </tr>
  494. <tr>
  495. <td>zoomMax</td>
  496. <td>Number</td>
  497. <td>315360000000000</td>
  498. <td>Set a maximum zoom interval for the visible range in milliseconds.
  499. It will not be possible to zoom out further than this maximum.
  500. Default value equals about 10000 years.
  501. </td>
  502. </tr>
  503. <tr>
  504. <td>zoomMin</td>
  505. <td>Number</td>
  506. <td>10</td>
  507. <td>Set a minimum zoom interval for the visible range in milliseconds.
  508. It will not be possible to zoom in further than this minimum.
  509. </td>
  510. </tr>
  511. </table>
  512. <h2 id="Methods">Methods</h2>
  513. <p>
  514. The Timeline supports the following methods.
  515. </p>
  516. <table>
  517. <tr>
  518. <th>Method</th>
  519. <th>Return Type</th>
  520. <th>Description</th>
  521. </tr>
  522. <tr>
  523. <td>getCustomTime()</td>
  524. <td>Date</td>
  525. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  526. </td>
  527. </tr>
  528. <tr>
  529. <td>setCustomTime(time)</td>
  530. <td>none</td>
  531. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  532. </td>
  533. </tr>
  534. <tr>
  535. <td>getSelection()</td>
  536. <td>Number[]</td>
  537. <td>Get an array with the ids of the currently selected items.</td>
  538. </tr>
  539. <tr>
  540. <td>getWindow()</td>
  541. <td>Object</td>
  542. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  543. </tr>
  544. <tr>
  545. <td>on(event, callback)</td>
  546. <td>none</td>
  547. <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>
  548. </tr>
  549. <tr>
  550. <td>off(event, callback)</td>
  551. <td>none</td>
  552. <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>
  553. </tr>
  554. <tr>
  555. <td>setGroups(groups)</td>
  556. <td>none</td>
  557. <td>Set a data set with groups for the Timeline.
  558. <code>groups</code> can be an Array with Objects,
  559. a DataSet, or a DataView. For each of the groups, the items of the
  560. timeline are filtered on the property <code>group</code>, which
  561. must correspond with the id of the group.
  562. </td>
  563. </tr>
  564. <tr>
  565. <td>setItems(items)</td>
  566. <td>none</td>
  567. <td>Set a data set with items for the Timeline.
  568. <code>items</code> can be an Array with Objects,
  569. a DataSet, or a DataView.
  570. </td>
  571. </tr>
  572. <tr>
  573. <td>setOptions(options)</td>
  574. <td>none</td>
  575. <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.
  576. </td>
  577. </tr>
  578. <tr>
  579. <td>setSelection([ids])</td>
  580. <td>none</td>
  581. <td>Select or deselect items. Currently selected items will be unselected.
  582. </td>
  583. </tr>
  584. <tr>
  585. <td>setWindow(start, end)</td>
  586. <td>none</td>
  587. <td>Set the current visible window. The parameters <code>start</code> and <code>end</code> can be a <code>Date</code>, <code>Number</code>, or <code>String</code>. If the parameter value of <code>start</code> or <code>end</code> is null, the parameter will be left unchanged.</td>
  588. </tr>
  589. </table>
  590. <h2 id="Events">Events</h2>
  591. <p>
  592. Timeline fires events when changing the visible window by dragging, when
  593. selecting items, and when dragging the custom time bar.
  594. </p>
  595. <p>
  596. Here an example on how to listen for a <code>select</code> event.
  597. </p>
  598. <pre class="prettyprint lang-js">
  599. timeline.on('select', function (properties) {
  600. alert('selected items: ' + properties.nodes);
  601. });
  602. </pre>
  603. <p>
  604. A listener can be removed via the function <code>off</code>:
  605. </p>
  606. <pre class="prettyprint lang-js">
  607. function onSelect (properties) {
  608. alert('selected items: ' + properties.nodes);
  609. }
  610. // add event listener
  611. timeline.on('select', onSelect);
  612. // do stuff...
  613. // remove event listener
  614. timeline.off('select', onSelect);
  615. </pre>
  616. <p>
  617. The following events are available.
  618. </p>
  619. <table>
  620. <colgroup>
  621. <col style="width: 20%;">
  622. <col style="width: 40%;">
  623. <col style="width: 40%;">
  624. </colgroup>
  625. <tr>
  626. <th>name</th>
  627. <th>Description</th>
  628. <th>Properties</th>
  629. </tr>
  630. <tr>
  631. <td>rangechange</td>
  632. <td>Fired repeatedly when the user is dragging the timeline window.
  633. </td>
  634. <td>
  635. <ul>
  636. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  637. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  638. </ul>
  639. </td>
  640. </tr>
  641. <tr>
  642. <td>rangechanged</td>
  643. <td>Fired once after the user has dragged the timeline window.
  644. </td>
  645. <td>
  646. <ul>
  647. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  648. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  649. </ul>
  650. </td>
  651. </tr>
  652. <tr>
  653. <td>select</td>
  654. <td>Fired after the user selects or deselects items by tapping or holding them.
  655. Not fired when the method <code>setSelection</code>is executed.
  656. </td>
  657. <td>
  658. <ul>
  659. <li><code>items</code>: an array with the ids of the selected items</li>
  660. </ul>
  661. </td>
  662. </tr>
  663. <tr>
  664. <td>timechange</td>
  665. <td>Fired repeatedly when the user is dragging the custom time bar.
  666. Only available when the custom time bar is enabled.
  667. </td>
  668. <td>
  669. <ul>
  670. <li><code>time</code> (Date): the current time.</li>
  671. </ul>
  672. </td>
  673. </tr>
  674. <tr>
  675. <td>timechanged</td>
  676. <td>Fired once after the user has dragged the custom time bar.
  677. Only available when the custom time bar is enabled.
  678. </td>
  679. <td>
  680. <ul>
  681. <li><code>time</code> (Date): the current time.</li>
  682. </ul>
  683. </td>
  684. </tr>
  685. </table>
  686. <h2 id="Editing_Items">Editing Items</h2>
  687. <p>
  688. 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.
  689. </p>
  690. <p>
  691. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  692. </p>
  693. <ul>
  694. <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>
  695. <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>
  696. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  697. <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>
  698. </ul>
  699. <p>
  700. Each of the callbacks is invoked with two arguments:
  701. </p>
  702. <ul>
  703. <li><code>item</code>: the item being manipulated</li>
  704. <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>
  705. </ul>
  706. <p>
  707. Example code:
  708. </p>
  709. <pre class="prettyprint lang-js">var options = {
  710. onUpdate: function (item, callback) {
  711. item.content = prompt('Edit items text:', item.content);
  712. if (item.content != null) {
  713. callback(item); // send back adjusted item
  714. }
  715. else {
  716. callback(null); // cancel updating the item
  717. }
  718. }
  719. }
  720. </pre>
  721. A full example is available here: <a href="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
  722. <h2 id="Styles">Styles</h2>
  723. <p>
  724. All parts of the Timeline have a class name and a default css style.
  725. The styles can be overwritten, which enables full customization of the layout
  726. of the Timeline.
  727. </p>
  728. <p>For example, to change the border and background color of all items, include the
  729. following code inside the head of your html code or in a separate stylesheet.</p>
  730. <pre class="prettyprint lang-html">&lt;style&gt;
  731. .vis.timeline .item {
  732. border-color: orange;
  733. background-color: yellow;
  734. }
  735. &lt;/style&gt;
  736. </pre>
  737. <h2 id="Data_Policy">Data Policy</h2>
  738. <p>
  739. All code and data is processed and rendered in the browser.
  740. No data is sent to any server.
  741. </p>
  742. </div>
  743. </body>
  744. </html>