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.

858 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), 'point', 'range', or 'rangeoverflow'.
  173. Types 'box' and 'point' need a start date, and types 'range' and 'rangeoverflow' need both a start and end date. Types 'range' and rangeoverflow are equal, except that overflowing text in 'range' is hidden, while visible in '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 'box', 'point', 'range', and 'rangeoverflow'. Note that individual items can override this global type.
  485. </td>
  486. </tr>
  487. <tr>
  488. <td>width</td>
  489. <td>String</td>
  490. <td>'100%'</td>
  491. <td>The width of the timeline in pixels or as a percentage.</td>
  492. </tr>
  493. <tr>
  494. <td>zoomMax</td>
  495. <td>Number</td>
  496. <td>315360000000000</td>
  497. <td>Set a maximum zoom interval for the visible range in milliseconds.
  498. It will not be possible to zoom out further than this maximum.
  499. Default value equals about 10000 years.
  500. </td>
  501. </tr>
  502. <tr>
  503. <td>zoomMin</td>
  504. <td>Number</td>
  505. <td>10</td>
  506. <td>Set a minimum zoom interval for the visible range in milliseconds.
  507. It will not be possible to zoom in further than this minimum.
  508. </td>
  509. </tr>
  510. </table>
  511. <h2 id="Methods">Methods</h2>
  512. <p>
  513. The Timeline supports the following methods.
  514. </p>
  515. <table>
  516. <tr>
  517. <th>Method</th>
  518. <th>Return Type</th>
  519. <th>Description</th>
  520. </tr>
  521. <tr>
  522. <td>getCustomTime()</td>
  523. <td>Date</td>
  524. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  525. </td>
  526. </tr>
  527. <tr>
  528. <td>setCustomTime(time)</td>
  529. <td>none</td>
  530. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  531. </td>
  532. </tr>
  533. <tr>
  534. <td>getSelection()</td>
  535. <td>Number[]</td>
  536. <td>Get an array with the ids of the currently selected items.</td>
  537. </tr>
  538. <tr>
  539. <td>getWindow()</td>
  540. <td>Object</td>
  541. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  542. </tr>
  543. <tr>
  544. <td>on(event, callback)</td>
  545. <td>none</td>
  546. <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>
  547. </tr>
  548. <tr>
  549. <td>off(event, callback)</td>
  550. <td>none</td>
  551. <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>
  552. </tr>
  553. <tr>
  554. <td>setGroups(groups)</td>
  555. <td>none</td>
  556. <td>Set a data set with groups for the Timeline.
  557. <code>groups</code> can be an Array with Objects,
  558. a DataSet, or a DataView. For each of the groups, the items of the
  559. timeline are filtered on the property <code>group</code>, which
  560. must correspond with the id of the group.
  561. </td>
  562. </tr>
  563. <tr>
  564. <td>setItems(items)</td>
  565. <td>none</td>
  566. <td>Set a data set with items for the Timeline.
  567. <code>items</code> can be an Array with Objects,
  568. a DataSet, or a DataView.
  569. </td>
  570. </tr>
  571. <tr>
  572. <td>setOptions(options)</td>
  573. <td>none</td>
  574. <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.
  575. </td>
  576. </tr>
  577. <tr>
  578. <td>setSelection([ids])</td>
  579. <td>none</td>
  580. <td>Select or deselect items. Currently selected items will be unselected.
  581. </td>
  582. </tr>
  583. <tr>
  584. <td>setWindow(start, end)</td>
  585. <td>none</td>
  586. <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>
  587. </tr>
  588. </table>
  589. <h2 id="Events">Events</h2>
  590. <p>
  591. Timeline fires events when changing the visible window by dragging, when
  592. selecting items, and when dragging the custom time bar.
  593. </p>
  594. <p>
  595. Here an example on how to listen for a <code>select</code> event.
  596. </p>
  597. <pre class="prettyprint lang-js">
  598. timeline.on('select', function (properties) {
  599. alert('selected items: ' + properties.nodes);
  600. });
  601. </pre>
  602. <p>
  603. A listener can be removed via the function <code>off</code>:
  604. </p>
  605. <pre class="prettyprint lang-js">
  606. function onSelect (properties) {
  607. alert('selected items: ' + properties.nodes);
  608. }
  609. // add event listener
  610. timeline.on('select', onSelect);
  611. // do stuff...
  612. // remove event listener
  613. timeline.off('select', onSelect);
  614. </pre>
  615. <p>
  616. The following events are available.
  617. </p>
  618. <table>
  619. <colgroup>
  620. <col style="width: 20%;">
  621. <col style="width: 40%;">
  622. <col style="width: 40%;">
  623. </colgroup>
  624. <tr>
  625. <th>name</th>
  626. <th>Description</th>
  627. <th>Properties</th>
  628. </tr>
  629. <tr>
  630. <td>rangechange</td>
  631. <td>Fired repeatedly when the user is dragging the timeline window.
  632. </td>
  633. <td>
  634. <ul>
  635. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  636. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  637. </ul>
  638. </td>
  639. </tr>
  640. <tr>
  641. <td>rangechanged</td>
  642. <td>Fired once after the user has dragged the timeline window.
  643. </td>
  644. <td>
  645. <ul>
  646. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  647. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  648. </ul>
  649. </td>
  650. </tr>
  651. <tr>
  652. <td>select</td>
  653. <td>Fired after the user selects or deselects items by tapping or holding them.
  654. Not fired when the method <code>setSelection</code>is executed.
  655. </td>
  656. <td>
  657. <ul>
  658. <li><code>items</code>: an array with the ids of the selected items</li>
  659. </ul>
  660. </td>
  661. </tr>
  662. <tr>
  663. <td>timechange</td>
  664. <td>Fired repeatedly when the user is dragging the custom time bar.
  665. Only available when the custom time bar is enabled.
  666. </td>
  667. <td>
  668. <ul>
  669. <li><code>time</code> (Date): the current time.</li>
  670. </ul>
  671. </td>
  672. </tr>
  673. <tr>
  674. <td>timechanged</td>
  675. <td>Fired once after the user has dragged the custom time bar.
  676. Only available when the custom time bar is enabled.
  677. </td>
  678. <td>
  679. <ul>
  680. <li><code>time</code> (Date): the current time.</li>
  681. </ul>
  682. </td>
  683. </tr>
  684. </table>
  685. <h2 id="Editing_Items">Editing Items</h2>
  686. <p>
  687. 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.
  688. </p>
  689. <p>
  690. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  691. </p>
  692. <ul>
  693. <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>
  694. <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>
  695. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  696. <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>
  697. </ul>
  698. <p>
  699. Each of the callbacks is invoked with two arguments:
  700. </p>
  701. <ul>
  702. <li><code>item</code>: the item being manipulated</li>
  703. <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>
  704. </ul>
  705. <p>
  706. Example code:
  707. </p>
  708. <pre class="prettyprint lang-js">var options = {
  709. onUpdate: function (item, callback) {
  710. item.content = prompt('Edit items text:', item.content);
  711. if (item.content != null) {
  712. callback(item); // send back adjusted item
  713. }
  714. else {
  715. callback(null); // cancel updating the item
  716. }
  717. }
  718. }
  719. </pre>
  720. A full example is available here: <a href="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
  721. <h2 id="Styles">Styles</h2>
  722. <p>
  723. All parts of the Timeline have a class name and a default css style.
  724. The styles can be overwritten, which enables full customization of the layout
  725. of the Timeline.
  726. </p>
  727. <p>For example, to change the border and background color of all items, include the
  728. following code inside the head of your html code or in a separate stylesheet.</p>
  729. <pre class="prettyprint lang-html">&lt;style&gt;
  730. .vis.timeline .item {
  731. border-color: orange;
  732. background-color: yellow;
  733. }
  734. &lt;/style&gt;
  735. </pre>
  736. <h2 id="Data_Policy">Data Policy</h2>
  737. <p>
  738. All code and data is processed and rendered in the browser.
  739. No data is sent to any server.
  740. </p>
  741. </div>
  742. </body>
  743. </html>