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.

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