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.

1122 lines
34 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. <p>
  21. Timeline uses regular HTML DOM to render the timeline and items put on the
  22. timeline. This allows for flexible customization using css styling.
  23. </p>
  24. <h2 id="Contents">Contents</h2>
  25. <ul>
  26. <li><a href="#Overview">Overview</a></li>
  27. <li><a href="#Example">Example</a></li>
  28. <li><a href="#Loading">Loading</a></li>
  29. <li><a href="#Data_Format">Data Format</a>
  30. <ul>
  31. <li><a href="#items">Items</a></li>
  32. <li><a href="#groups">Groups</a></li>
  33. </ul>
  34. </li>
  35. <li><a href="#Configuration_Options">Configuration Options</a></li>
  36. <li><a href="#Methods">Methods</a></li>
  37. <li><a href="#Events">Events</a></li>
  38. <li><a href="#Editing_Items">Editing Items</a></li>
  39. <li><a href="#Localization">Localization</a></li>
  40. <li><a href="#Styles">Styles</a></li>
  41. <li><a href="#Data_Policy">Data Policy</a></li>
  42. </ul>
  43. <h2 id="Example">Example</h2>
  44. <p>
  45. The following code shows how to create a Timeline and provide it with data.
  46. More examples can be found in the <a href="../examples">examples</a> directory.
  47. </p>
  48. <pre class="prettyprint lang-html">&lt;!DOCTYPE HTML&gt;
  49. &lt;html&gt;
  50. &lt;head&gt;
  51. &lt;title&gt;Timeline | Basic demo&lt;/title&gt;
  52. &lt;style type="text/css"&gt;
  53. body, html {
  54. font-family: sans-serif;
  55. }
  56. &lt;/style&gt;
  57. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  58. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  59. &lt;/head&gt;
  60. &lt;body&gt;
  61. &lt;div id="visualization"&gt;&lt;/div&gt;
  62. &lt;script type="text/javascript"&gt;
  63. // DOM element where the Timeline will be attached
  64. var container = document.getElementById('visualization');
  65. // Create a DataSet (allows two way data-binding)
  66. var items = new vis.DataSet([
  67. {id: 1, content: 'item 1', start: '2013-04-20'},
  68. {id: 2, content: 'item 2', start: '2013-04-14'},
  69. {id: 3, content: 'item 3', start: '2013-04-18'},
  70. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  71. {id: 5, content: 'item 5', start: '2013-04-25'},
  72. {id: 6, content: 'item 6', start: '2013-04-27'}
  73. ]);
  74. // Configuration for the Timeline
  75. var options = {};
  76. // Create a Timeline
  77. var timeline = new vis.Timeline(container, items, options);
  78. &lt;/script&gt;
  79. &lt;/body&gt;
  80. &lt;/html&gt;
  81. </pre>
  82. <h2 id="Loading">Loading</h2>
  83. <p>
  84. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  85. in a subfolder of your project. Include the libraries script and css files in the
  86. head of your html code:
  87. </p>
  88. <pre class="prettyprint lang-html">
  89. &lt;script src="vis/dist/vis.js"&gt;&lt;/script&gt;
  90. &lt;link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  91. </pre>
  92. The constructor of the Timeline is <code>vis.Timeline</code>
  93. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, options);</pre>
  94. The constructor accepts three parameters:
  95. <ul>
  96. <li>
  97. <code>container</code> is the DOM element in which to create the timeline.
  98. </li>
  99. <li>
  100. <code>items</code> is an Array containing items. The properties of an
  101. item are described in section <a href="#Data_Format">Data Format</a>.
  102. </li>
  103. <li>
  104. <code>options</code> is an optional Object containing a name-value map
  105. with options. Options can also be set using the method
  106. <code>setOptions</code>.
  107. </li>
  108. </ul>
  109. <h2 id="Data_Format">Data Format</h2>
  110. <p>
  111. The timeline can be provided with two types of data:
  112. </p>
  113. <ul>
  114. <li><a href="#items">Items</a> containing a set of items to be displayed in time.</li>
  115. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  116. together.</li>
  117. </ul>
  118. <h3 id="items">Items</h3>
  119. <p>
  120. The Timeline uses regular Arrays and Objects as data format.
  121. Data items can contain the properties <code>start</code>,
  122. <code>end</code> (optional), <code>content</code>,
  123. <code>group</code> (optional), and <code>className</code> (optional).
  124. </p>
  125. <p>
  126. A table is constructed as:
  127. </p>
  128. <pre class="prettyprint lang-js">
  129. var items = [
  130. {
  131. start: new Date(2010, 7, 15),
  132. end: new Date(2010, 8, 2), // end is optional
  133. content: 'Trajectory A'
  134. // Optional: fields 'id', 'type', 'group', 'className'
  135. }
  136. // more items...
  137. ]);
  138. </pre>
  139. <p>
  140. The item properties are defined as:
  141. </p>
  142. <table>
  143. <tr>
  144. <th>Name</th>
  145. <th>Type</th>
  146. <th>Required</th>
  147. <th>Description</th>
  148. </tr>
  149. <tr>
  150. <td>className</td>
  151. <td>String</td>
  152. <td>no</td>
  153. <td>This field is optional. A className can be used to give items
  154. an individual css style. For example, when an item has className
  155. 'red', one can define a css style like:
  156. <pre class="prettyprint lang-css">
  157. .vis.timeline .red {
  158. color: white;
  159. background-color: red;
  160. border-color: darkred;
  161. }</pre>
  162. More details on how to style items can be found in the section
  163. <a href="#Styles">Styles</a>.
  164. </td>
  165. </tr>
  166. <tr>
  167. <td>content</td>
  168. <td>String</td>
  169. <td>yes</td>
  170. <td>The contents of the item. This can be plain text or html code.</td>
  171. </tr>
  172. <tr>
  173. <td>end</td>
  174. <td>Date</td>
  175. <td>no</td>
  176. <td>The end date of the item. The end date is optional, and can be left <code>null</code>.
  177. If end date is provided, the item is displayed as a range.
  178. If not, the item is displayed as a box.</td>
  179. </tr>
  180. <tr>
  181. <td>group</td>
  182. <td>any type</td>
  183. <td>no</td>
  184. <td>This field is optional. When the group column is provided,
  185. all items with the same group are placed on one line.
  186. A vertical axis is displayed showing the groups.
  187. Grouping items can be useful for example when showing availability of multiple
  188. people, rooms, or other resources next to each other.<br>
  189. </td>
  190. </tr>
  191. <tr>
  192. <td>id</td>
  193. <td>String | Number</td>
  194. <td>no</td>
  195. <td>An id for the item. Using an id is not required but highly
  196. recommended. An id is needed when dynamically adding, updating,
  197. and removing items in a DataSet.</td>
  198. </tr>
  199. <tr>
  200. <td>start</td>
  201. <td>Date</td>
  202. <td>yes</td>
  203. <td>The start date of the item, for example <code>new Date(2010,9,23)</code>.</td>
  204. </tr>
  205. <tr>
  206. <td>title</td>
  207. <td>String</td>
  208. <td>none</td>
  209. <td>Add a title for the item, displayed when holding the mouse on the item.
  210. The title can only contain plain text.
  211. </td>
  212. </tr>
  213. <tr>
  214. <td>type</td>
  215. <td>String</td>
  216. <td>'box'</td>
  217. <td>The type of the item. Can be 'box' (default), 'point', or 'range'.
  218. Types 'box' and 'point' need a start date, and type 'range' needs both a start and end date.
  219. </td>
  220. </tr>
  221. </table>
  222. <h3 id="groups">Groups</h3>
  223. <p>
  224. Like the items, groups are regular JavaScript Arrays and Objects.
  225. Using groups, items can be grouped together.
  226. Items are filtered per group, and displayed as
  227. Group items can contain the properties <code>id</code>,
  228. <code>content</code>, and <code>className</code> (optional).
  229. </p>
  230. <p>
  231. Groups can be applied to a timeline using the method <code>setGroups</code>.
  232. A table with groups can be created like:
  233. </p>
  234. <pre class="prettyprint lang-js">
  235. var groups = [
  236. {
  237. id: 1,
  238. content: 'Group 1'
  239. // Optional: a field 'className'
  240. }
  241. // more groups...
  242. ]);
  243. </pre>
  244. <p>
  245. Groups can have the following properties:
  246. </p>
  247. <table>
  248. <tr>
  249. <th>Name</th>
  250. <th>Type</th>
  251. <th>Required</th>
  252. <th>Description</th>
  253. </tr>
  254. <tr>
  255. <td>className</td>
  256. <td>String</td>
  257. <td>no</td>
  258. <td>This field is optional. A className can be used to give groups
  259. an individual css style. For example, when a group has className
  260. 'red', one can define a css style
  261. <code>
  262. .red {
  263. color: red;
  264. }
  265. </code>.
  266. More details on how to style groups can be found in the section
  267. <a href="#Styles">Styles</a>.
  268. </td>
  269. </tr>
  270. <tr>
  271. <td>content</td>
  272. <td>String</td>
  273. <td>yes</td>
  274. <td>The contents of the group. This can be plain text or html code.</td>
  275. </tr>
  276. <tr>
  277. <td>id</td>
  278. <td>String | Number</td>
  279. <td>yes</td>
  280. <td>An id for the group. The group will display all items having a
  281. property <code>group</code> which matches the <code>id</code>
  282. of the group.</td>
  283. </tr>
  284. <tr>
  285. <td>title</td>
  286. <td>String</td>
  287. <td>none</td>
  288. <td>A title for the group, displayed when holding the mouse the groups label.
  289. The title can only contain plain text.
  290. </td>
  291. </tr>
  292. </table>
  293. <h2 id="Configuration_Options">Configuration Options</h2>
  294. <p>
  295. Options can be used to customize the timeline.
  296. Options are defined as a JSON object. All options are optional.
  297. </p>
  298. <pre class="prettyprint lang-js">
  299. var options = {
  300. width: '100%',
  301. height: '30px',
  302. margin: {
  303. item: 20
  304. }
  305. };
  306. </pre>
  307. <p>
  308. The following options are available.
  309. </p>
  310. <table>
  311. <tr>
  312. <th>Name</th>
  313. <th>Type</th>
  314. <th>Default</th>
  315. <th>Description</th>
  316. </tr>
  317. <tr>
  318. <td>align</td>
  319. <td>String</td>
  320. <td>"center"</td>
  321. <td>Alignment of items with type 'box'. Available values are
  322. 'center' (default), 'left', or 'right').</td>
  323. </tr>
  324. <tr>
  325. <td>autoResize</td>
  326. <td>boolean</td>
  327. <td>true</td>
  328. <td>If true, the Timeline will automatically detect when its container is resized, and redraw itself accordingly. If false, the Timeline can be forced to repaint after its container has been resized using the function <code>redraw()</code>.</td>
  329. </tr>
  330. <tr>
  331. <td>clickToUse</td>
  332. <td>boolean</td>
  333. <td>false</td>
  334. <td>When a Timeline is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  335. When active, a blue shadow border is displayed around the Timeline. The Timeline is set active by clicking on it, and is changed to inactive again by clicking outside the Timeline or by pressing the ESC key.</td>
  336. </tr>
  337. <tr>
  338. <td>editable</td>
  339. <td>Boolean | Object</td>
  340. <td>false</td>
  341. <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.
  342. See section <a href="#Editing_Items">Editing Items</a> for a detailed explanation.
  343. </td>
  344. </tr>
  345. <tr>
  346. <td>editable.add</td>
  347. <td>Boolean</td>
  348. <td>false</td>
  349. <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>
  350. </tr>
  351. <tr>
  352. <td>editable.remove</td>
  353. <td>Boolean</td>
  354. <td>false</td>
  355. <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>
  356. </tr>
  357. <tr>
  358. <td>editable.updateGroup</td>
  359. <td>Boolean</td>
  360. <td>false</td>
  361. <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>
  362. </tr>
  363. <tr>
  364. <td>editable.updateTime</td>
  365. <td>Boolean</td>
  366. <td>false</td>
  367. <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>
  368. </tr>
  369. <tr>
  370. <td>end</td>
  371. <td>Date | Number | String</td>
  372. <td>none</td>
  373. <td>The initial end date for the axis of the timeline.
  374. If not provided, the latest date present in the items set is taken as
  375. end date.</td>
  376. </tr>
  377. <tr>
  378. <td>groupOrder</td>
  379. <td>String | Function</td>
  380. <td>none</td>
  381. <td>Order the groups by a field name or custom sort function.
  382. By default, groups are not ordered.
  383. </td>
  384. </tr>
  385. <tr>
  386. <td>height</td>
  387. <td>Number | String</td>
  388. <td>none</td>
  389. <td>The height of the timeline in pixels or as a percentage.
  390. When height is undefined or null, the height of the timeline is automatically
  391. adjusted to fit the contents.
  392. It is possible to set a maximum height using option <code>maxHeight</code>
  393. to prevent the timeline from getting too high in case of automatically
  394. calculated height.
  395. </td>
  396. </tr>
  397. <tr>
  398. <td>locale</td>
  399. <td>String</td>
  400. <td>none</td>
  401. <td>Select a locale for the Timeline. See section <a href="#Localization">Localization</a> for more information.</td>
  402. </tr>
  403. <tr>
  404. <td>locales</td>
  405. <td>Object</td>
  406. <td>none</td>
  407. <td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
  408. </tr>
  409. <tr>
  410. <td>margin.axis</td>
  411. <td>Number</td>
  412. <td>20</td>
  413. <td>The minimal margin in pixels between items and the time axis.</td>
  414. </tr>
  415. <tr>
  416. <td>margin.item</td>
  417. <td>Number</td>
  418. <td>10</td>
  419. <td>The minimal margin in pixels between items in both horizontal and vertical direction.</td>
  420. </tr>
  421. <tr>
  422. <td>margin.item.horizontal</td>
  423. <td>Number</td>
  424. <td>10</td>
  425. <td>The minimal horizontal margin in pixels between items.</td>
  426. </tr>
  427. <tr>
  428. <td>margin.item.vertical</td>
  429. <td>Number</td>
  430. <td>10</td>
  431. <td>The minimal vertical margin in pixels between items.</td>
  432. </tr>
  433. <tr>
  434. <td>max</td>
  435. <td>Date | Number | String</td>
  436. <td>none</td>
  437. <td>Set a maximum Date for the visible range.
  438. It will not be possible to move beyond this maximum.
  439. </td>
  440. </tr>
  441. <tr>
  442. <td>maxHeight</td>
  443. <td>Number | String</td>
  444. <td>none</td>
  445. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  446. </tr>
  447. <tr>
  448. <td>min</td>
  449. <td>Date | Number | String</td>
  450. <td>none</td>
  451. <td>Set a minimum Date for the visible range.
  452. It will not be possible to move beyond this minimum.
  453. </td>
  454. </tr>
  455. <tr>
  456. <td>minHeight</td>
  457. <td>Number | String</td>
  458. <td>none</td>
  459. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  460. </tr>
  461. <tr>
  462. <td>moveable</td>
  463. <td>Boolean</td>
  464. <td>true</td>
  465. <td>
  466. Specifies whether the Timeline can be moved and zoomed by dragging the window.
  467. See also option <code>zoomable</code>.
  468. </td>
  469. </tr>
  470. <tr>
  471. <td>onAdd</td>
  472. <td>Function</td>
  473. <td>none</td>
  474. <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>.
  475. </td>
  476. </tr>
  477. <tr>
  478. <td>onUpdate</td>
  479. <td>Function</td>
  480. <td>none</td>
  481. <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>.
  482. </td>
  483. </tr>
  484. <tr>
  485. <td>onMove</td>
  486. <td>Function</td>
  487. <td>none</td>
  488. <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>.
  489. </td>
  490. </tr>
  491. <tr>
  492. <td>onRemove</td>
  493. <td>Function</td>
  494. <td>none</td>
  495. <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>.
  496. </td>
  497. </tr>
  498. <!-- TODO: cleanup option order
  499. <tr>
  500. <td>order</td>
  501. <td>Function</td>
  502. <td>none</td>
  503. <td>Provide a custom sort function to order the items. The order of the
  504. items is determining the way they are stacked. The function
  505. order is called with two parameters, both of type
  506. `vis.components.items.Item`.
  507. </td>
  508. </tr>
  509. -->
  510. <tr>
  511. <td>orientation</td>
  512. <td>String</td>
  513. <td>'bottom'</td>
  514. <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>
  515. </tr>
  516. <tr>
  517. <td>padding</td>
  518. <td>Number</td>
  519. <td>5</td>
  520. <td>The padding of items, needed to correctly calculate the size
  521. of item ranges. Must correspond with the css of items, for example when setting <code>options.padding=10</code>, corresponding css is:
  522. <pre class="prettyprint lang-css">
  523. .vis.timeline .item {
  524. padding: 10px;
  525. }</pre>
  526. </td>
  527. </tr>
  528. <tr>
  529. <td>selectable</td>
  530. <td>Boolean</td>
  531. <td>true</td>
  532. <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>
  533. </tr>
  534. <tr>
  535. <td>showCurrentTime</td>
  536. <td>boolean</td>
  537. <td>true</td>
  538. <td>Show a vertical bar at the current time.</td>
  539. </tr>
  540. <tr>
  541. <td>showCustomTime</td>
  542. <td>boolean</td>
  543. <td>false</td>
  544. <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>
  545. </tr>
  546. <tr>
  547. <tr>
  548. <td>showMajorLabels</td>
  549. <td>boolean</td>
  550. <td>true</td>
  551. <td>By default, the timeline shows both minor and major date labels on the
  552. time axis.
  553. For example the minor labels show minutes and the major labels show hours.
  554. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  555. are shown.</td>
  556. </tr>
  557. <tr>
  558. <td>showMinorLabels</td>
  559. <td>boolean</td>
  560. <td>true</td>
  561. <td>By default, the timeline shows both minor and major date labels on the
  562. time axis.
  563. For example the minor labels show minutes and the major labels show hours.
  564. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  565. are shown. When both <code>showMajorLabels</code> and
  566. <code>showMinorLabels</code> are false, no horizontal axis will be
  567. visible.</td>
  568. </tr>
  569. <tr>
  570. <td>stack</td>
  571. <td>Boolean</td>
  572. <td>true</td>
  573. <td>If true (default), items will be stacked on top of each other such that they do not overlap.</td>
  574. </tr>
  575. <tr>
  576. <td>start</td>
  577. <td>Date | Number | String</td>
  578. <td>none</td>
  579. <td>The initial start date for the axis of the timeline.
  580. If not provided, the earliest date present in the events is taken as start date.</td>
  581. </tr>
  582. <tr>
  583. <td>type</td>
  584. <td>String</td>
  585. <td>none</td>
  586. <td>Specifies the default type for the timeline items. Choose from 'box', 'point', and 'range'. Note that individual items can override this default type. If undefined, the Timeline will auto detect the type from the items data: if a start and end date is available, a 'range' will be created, and else, a 'box' is created.
  587. </td>
  588. </tr>
  589. <tr>
  590. <td>width</td>
  591. <td>String</td>
  592. <td>'100%'</td>
  593. <td>The width of the timeline in pixels or as a percentage.</td>
  594. </tr>
  595. <tr>
  596. <td>zoomable</td>
  597. <td>Boolean</td>
  598. <td>true</td>
  599. <td>
  600. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  601. Only applicable when option <code>moveable</code> is set <code>true</code>.
  602. </td>
  603. </tr>
  604. <tr>
  605. <td>zoomMax</td>
  606. <td>Number</td>
  607. <td>315360000000000</td>
  608. <td>Set a maximum zoom interval for the visible range in milliseconds.
  609. It will not be possible to zoom out further than this maximum.
  610. Default value equals about 10000 years.
  611. </td>
  612. </tr>
  613. <tr>
  614. <td>zoomMin</td>
  615. <td>Number</td>
  616. <td>10</td>
  617. <td>Set a minimum zoom interval for the visible range in milliseconds.
  618. It will not be possible to zoom in further than this minimum.
  619. </td>
  620. </tr>
  621. </table>
  622. <h2 id="Methods">Methods</h2>
  623. <p>
  624. The Timeline supports the following methods.
  625. </p>
  626. <table>
  627. <tr>
  628. <th>Method</th>
  629. <th>Return Type</th>
  630. <th>Description</th>
  631. </tr>
  632. <tr>
  633. <td>clear([what])</td>
  634. <td>none</td>
  635. <td>
  636. Clear the Timeline. An object can be passed specifying which sections to clear: items, groups,
  637. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  638. <pre class="prettyprint lang-js">timeline.clear(); // clear items, groups, and options
  639. timeline.clear({options: true}); // clear options only
  640. </pre>
  641. </td>
  642. </tr>
  643. <tr>
  644. <td>destroy()</td>
  645. <td>none</td>
  646. <td>Destroy the Timeline. The timeline is removed from memory. all DOM elements and event listeners are cleaned up.
  647. </td>
  648. </tr>
  649. <tr>
  650. <td>fit([options])</td>
  651. <td>none</td>
  652. <td>Adjust the visible window such that it fits all items. See also function <code>focus(id)</code>.
  653. Available options:
  654. <ul>
  655. <li><code>animate: boolean | number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms.</li>
  656. </ul>
  657. </td>
  658. </tr>
  659. <tr>
  660. <td>focus(id | ids [, options])</td>
  661. <td>none</td>
  662. <td>Adjust the visible window such that the selected item (or multiple items) are centered on screen. See also function <code>fit()</code>. Available options:
  663. <ul>
  664. <li><code>animate: boolean | number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms.</li>
  665. </ul>
  666. </td>
  667. </tr>
  668. <tr>
  669. <td>getCustomTime()</td>
  670. <td>Date</td>
  671. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  672. </td>
  673. </tr>
  674. <tr>
  675. <td>setCustomTime(time)</td>
  676. <td>none</td>
  677. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  678. </td>
  679. </tr>
  680. <tr>
  681. <td>getSelection()</td>
  682. <td>Number[]</td>
  683. <td>Get an array with the ids of the currently selected items.</td>
  684. </tr>
  685. <tr>
  686. <td>getVisibleItems()</td>
  687. <td>Number[]</td>
  688. <td>Get an array with the ids of the currently visible items.</td>
  689. </tr>
  690. <tr>
  691. <td>getWindow()</td>
  692. <td>Object</td>
  693. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  694. </tr>
  695. <tr>
  696. <td>on(event, callback)</td>
  697. <td>none</td>
  698. <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>
  699. </tr>
  700. <tr>
  701. <td>off(event, callback)</td>
  702. <td>none</td>
  703. <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>
  704. </tr>
  705. <tr>
  706. <td>redraw()</td>
  707. <td>none</td>
  708. <td>Force a redraw of the Timeline. Can be useful to manually redraw when option autoResize=false.
  709. </td>
  710. </tr>
  711. <tr>
  712. <td>setGroups(groups)</td>
  713. <td>none</td>
  714. <td>Set a data set with groups for the Timeline.
  715. <code>groups</code> can be an Array with Objects,
  716. a DataSet, or a DataView. For each of the groups, the items of the
  717. timeline are filtered on the property <code>group</code>, which
  718. must correspond with the id of the group.
  719. </td>
  720. </tr>
  721. <tr>
  722. <td>setItems(items)</td>
  723. <td>none</td>
  724. <td>Set a data set with items for the Timeline.
  725. <code>items</code> can be an Array with Objects,
  726. a DataSet, or a DataView.
  727. </td>
  728. </tr>
  729. <tr>
  730. <td>setOptions(options)</td>
  731. <td>none</td>
  732. <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.
  733. </td>
  734. </tr>
  735. <tr>
  736. <td>setSelection(id | ids [, options])</td>
  737. <td>none</td>
  738. <td>Select one or multiple items by their id. The currently selected items will be unselected. To unselect all selected items, call `setSelection([])`. Available options:
  739. <ul>
  740. <li><code>focus: boolean</code><br>If true, focus will be set to the selected item(s)</li>
  741. <li><code>animate: boolean | number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms. Only applicable when option focus is true.</li>
  742. </ul>
  743. </td>
  744. </tr>
  745. <tr>
  746. <td>setWindow(start, end [, options])</td>
  747. <td>none</td>
  748. <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. Available options:
  749. <ul>
  750. <li><code>animate: boolean | number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms.</li>
  751. </ul>
  752. </td>
  753. </tr>
  754. </table>
  755. <h2 id="Events">Events</h2>
  756. <p>
  757. Timeline fires events when changing the visible window by dragging, when
  758. selecting items, and when dragging the custom time bar.
  759. </p>
  760. <p>
  761. Here an example on how to listen for a <code>select</code> event.
  762. </p>
  763. <pre class="prettyprint lang-js">
  764. timeline.on('select', function (properties) {
  765. alert('selected items: ' + properties.nodes);
  766. });
  767. </pre>
  768. <p>
  769. A listener can be removed via the function <code>off</code>:
  770. </p>
  771. <pre class="prettyprint lang-js">
  772. function onSelect (properties) {
  773. alert('selected items: ' + properties.nodes);
  774. }
  775. // add event listener
  776. timeline.on('select', onSelect);
  777. // do stuff...
  778. // remove event listener
  779. timeline.off('select', onSelect);
  780. </pre>
  781. <p>
  782. The following events are available.
  783. </p>
  784. <table>
  785. <colgroup>
  786. <col style="width: 20%;">
  787. <col style="width: 40%;">
  788. <col style="width: 40%;">
  789. </colgroup>
  790. <tr>
  791. <th>name</th>
  792. <th>Description</th>
  793. <th>Properties</th>
  794. </tr>
  795. <tr>
  796. <td>rangechange</td>
  797. <td>Fired repeatedly when the user is dragging the timeline window.
  798. </td>
  799. <td>
  800. <ul>
  801. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  802. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  803. </ul>
  804. </td>
  805. </tr>
  806. <tr>
  807. <td>rangechanged</td>
  808. <td>Fired once after the user has dragged the timeline window.
  809. </td>
  810. <td>
  811. <ul>
  812. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  813. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  814. </ul>
  815. </td>
  816. </tr>
  817. <tr>
  818. <td>select</td>
  819. <td>Fired after the user selects or deselects items by tapping or holding them.
  820. When a use taps an already selected item, the select event is fired again.
  821. Not fired when the method <code>setSelection</code>is executed.
  822. </td>
  823. <td>
  824. <ul>
  825. <li><code>items</code>: an array with the ids of the selected items</li>
  826. </ul>
  827. </td>
  828. </tr>
  829. <tr>
  830. <td>timechange</td>
  831. <td>Fired repeatedly when the user is dragging the custom time bar.
  832. Only available when the custom time bar is enabled.
  833. </td>
  834. <td>
  835. <ul>
  836. <li><code>time</code> (Date): the current time.</li>
  837. </ul>
  838. </td>
  839. </tr>
  840. <tr>
  841. <td>timechanged</td>
  842. <td>Fired once after the user has dragged the custom time bar.
  843. Only available when the custom time bar is enabled.
  844. </td>
  845. <td>
  846. <ul>
  847. <li><code>time</code> (Date): the current time.</li>
  848. </ul>
  849. </td>
  850. </tr>
  851. </table>
  852. <h2 id="Editing_Items">Editing Items</h2>
  853. <p>
  854. 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.
  855. </p>
  856. <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>
  857. <pre class="prettyprint lang-js">// enable or disable all manipulation actions
  858. var options = {
  859. editable: true // true or false
  860. };
  861. // enable or disable individual manipulation actions
  862. var options = {
  863. editable: {
  864. add: true, // add new items by double tapping
  865. updateTime: true, // drag items horizontally
  866. updateGroup: true, // drag items from one group to another
  867. remove: true // delete an item by tapping the delete button top right
  868. }
  869. };</pre>
  870. <p>
  871. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  872. </p>
  873. <ul>
  874. <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>
  875. <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>
  876. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  877. <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>
  878. </ul>
  879. <p>
  880. Each of the callbacks is invoked with two arguments:
  881. </p>
  882. <ul>
  883. <li><code>item</code>: the item being manipulated</li>
  884. <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. Parameter `item` typically contains fields `content`, `start`, and optionally `end`. The type of `start` and `end` is determined by the DataSet type configuration and is `Date` by default. When invoked as <code>callback(null)</code>, the action will be cancelled.</li>
  885. </ul>
  886. <p>
  887. Example code:
  888. </p>
  889. <pre class="prettyprint lang-js">var options = {
  890. onUpdate: function (item, callback) {
  891. item.content = prompt('Edit items text:', item.content);
  892. if (item.content != null) {
  893. callback(item); // send back adjusted item
  894. }
  895. else {
  896. callback(null); // cancel updating the item
  897. }
  898. }
  899. };
  900. </pre>
  901. A full example is available here: <a href="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
  902. <h2 id="Localization">Localization</h2>
  903. <p>
  904. Timeline can be localized. For localization, Timeline depends largely on the localization of <a href="http://momentjs.com">moment.js</a>. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales.
  905. </p>
  906. <p>
  907. To set a locale for the Timeline, specify the option <code>locale</code>:
  908. </p>
  909. <pre class="prettyprint lang-js">var options = {
  910. locale: 'nl'
  911. };
  912. </pre>
  913. <h3>Create a new locale</h3>
  914. To load a locale into the Timeline not supported by default, one can add a new locale to the option <code>locales</code>:
  915. <pre class="prettyprint lang-js">var options = {
  916. locales: {
  917. // create a new locale (text strings should be replaced with localized strings)
  918. mylocale: {
  919. current: 'current',
  920. time: 'time',
  921. }
  922. },
  923. // use the new locale
  924. locale: 'mylocale'
  925. };
  926. </pre>
  927. <h3 id="available-locales">Available locales</h3>
  928. <p>
  929. Timeline comes with support for the following locales:
  930. </p>
  931. <table>
  932. <tr><th>Language</th><th>Code</th></tr>
  933. <tr>
  934. <td>English</td>
  935. <td>
  936. <code>en</code><br>
  937. <code>en_EN</code><br>
  938. <code>en_US</code>
  939. </td>
  940. </tr>
  941. <tr>
  942. <td>Dutch</td>
  943. <td>
  944. <code>nl</code><br>
  945. <code>nl_NL</code><br>
  946. <code>nl_BE</code>
  947. </td>
  948. </tr>
  949. </table>
  950. <h2 id="Styles">Styles</h2>
  951. <p>
  952. All parts of the Timeline have a class name and a default css style.
  953. The styles can be overwritten, which enables full customization of the layout
  954. of the Timeline.
  955. </p>
  956. <p>For example, to change the border and background color of all items, include the
  957. following code inside the head of your html code or in a separate stylesheet.</p>
  958. <pre class="prettyprint lang-html">&lt;style&gt;
  959. .vis.timeline .item {
  960. border-color: orange;
  961. background-color: yellow;
  962. }
  963. &lt;/style&gt;
  964. </pre>
  965. <h2 id="Data_Policy">Data Policy</h2>
  966. <p>
  967. All code and data is processed and rendered in the browser.
  968. No data is sent to any server.
  969. </p>
  970. </div>
  971. </body>
  972. </html>