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.

1535 lines
50 KiB

10 years ago
  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="#Templates">Templates</a></li>
  40. <li><a href="#Localization">Localization</a></li>
  41. <li><a href="#Styles">Styles</a></li>
  42. <li><a href="#Data_Policy">Data Policy</a></li>
  43. </ul>
  44. <h2 id="Example">Example</h2>
  45. <p>
  46. The following code shows how to create a Timeline and provide it with data.
  47. More examples can be found in the <a href="../examples">examples</a> directory.
  48. </p>
  49. <pre class="prettyprint lang-html">&lt;!DOCTYPE HTML&gt;
  50. &lt;html&gt;
  51. &lt;head&gt;
  52. &lt;title&gt;Timeline | Basic demo&lt;/title&gt;
  53. &lt;style type="text/css"&gt;
  54. body, html {
  55. font-family: sans-serif;
  56. }
  57. &lt;/style&gt;
  58. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  59. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  60. &lt;/head&gt;
  61. &lt;body&gt;
  62. &lt;div id="visualization"&gt;&lt;/div&gt;
  63. &lt;script type="text/javascript"&gt;
  64. // DOM element where the Timeline will be attached
  65. var container = document.getElementById('visualization');
  66. // Create a DataSet (allows two way data-binding)
  67. var items = new vis.DataSet([
  68. {id: 1, content: 'item 1', start: '2013-04-20'},
  69. {id: 2, content: 'item 2', start: '2013-04-14'},
  70. {id: 3, content: 'item 3', start: '2013-04-18'},
  71. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  72. {id: 5, content: 'item 5', start: '2013-04-25'},
  73. {id: 6, content: 'item 6', start: '2013-04-27'}
  74. ]);
  75. // Configuration for the Timeline
  76. var options = {};
  77. // Create a Timeline
  78. var timeline = new vis.Timeline(container, items, options);
  79. &lt;/script&gt;
  80. &lt;/body&gt;
  81. &lt;/html&gt;
  82. </pre>
  83. <h2 id="Loading">Loading</h2>
  84. <p>
  85. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  86. in a subfolder of your project. Include the libraries script and css files in the
  87. head of your html code:
  88. </p>
  89. <pre class="prettyprint lang-html">
  90. &lt;script src="vis/dist/vis.js"&gt;&lt;/script&gt;
  91. &lt;link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  92. </pre>
  93. The constructor of the Timeline is <code>vis.Timeline</code>
  94. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, options);</pre>
  95. or when using groups:
  96. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, groups, options);</pre>
  97. The constructor accepts four parameters:
  98. <ul>
  99. <li>
  100. <code>container</code> is the DOM element in which to create the timeline.
  101. </li>
  102. <li>
  103. <code>items</code> is an Array containing items. The properties of an
  104. item are described in section <a href="#Data_Format">Data Format, items</a>.
  105. </li><li>
  106. <code>groups</code> is an Array containing groups. The properties of a
  107. group are described in section <a href="#groups">Data Format, groups</a>.
  108. </li>
  109. <li>
  110. <code>options</code> is an optional Object containing a name-value map
  111. with options. Options can also be set using the method
  112. <code>setOptions</code>.
  113. </li>
  114. </ul>
  115. <h2 id="Data_Format">Data Format</h2>
  116. <p>
  117. The timeline can be provided with two types of data:
  118. </p>
  119. <ul>
  120. <li><a href="#items">Items</a> containing a set of items to be displayed in time.</li>
  121. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  122. together.</li>
  123. </ul>
  124. <h3 id="items">Items</h3>
  125. <p>
  126. The Timeline uses regular Arrays and Objects as data format.
  127. Data items can contain the properties <code>start</code>,
  128. <code>end</code> (optional), <code>content</code>,
  129. <code>group</code> (optional), <code>className</code> (optional),
  130. and <code>style</code> (optional).
  131. </p>
  132. <p>
  133. A table is constructed as:
  134. </p>
  135. <pre class="prettyprint lang-js">
  136. var items = [
  137. {
  138. start: new Date(2010, 7, 15),
  139. end: new Date(2010, 8, 2), // end is optional
  140. content: 'Trajectory A'
  141. // Optional: fields 'id', 'type', 'group', 'className', 'style'
  142. }
  143. // more items...
  144. ]);
  145. </pre>
  146. <p>
  147. The item properties are defined as:
  148. </p>
  149. <table>
  150. <tr>
  151. <th>Name</th>
  152. <th>Type</th>
  153. <th>Required</th>
  154. <th>Description</th>
  155. </tr>
  156. <tr>
  157. <td>className</td>
  158. <td>String</td>
  159. <td>no</td>
  160. <td>This field is optional. A className can be used to give items
  161. an individual css style. For example, when an item has className
  162. 'red', one can define a css style like:
  163. <pre class="prettyprint lang-css">
  164. .vis.timeline .red {
  165. color: white;
  166. background-color: red;
  167. border-color: darkred;
  168. }</pre>
  169. More details on how to style items can be found in the section
  170. <a href="#Styles">Styles</a>.
  171. </td>
  172. </tr>
  173. <tr>
  174. <td>content</td>
  175. <td>String</td>
  176. <td>yes</td>
  177. <td>The contents of the item. This can be plain text or html code.</td>
  178. </tr>
  179. <tr>
  180. <td>end</td>
  181. <td>Date | number | string | Moment</td>
  182. <td>no</td>
  183. <td>The end date of the item. The end date is optional, and can be left <code>null</code>.
  184. If end date is provided, the item is displayed as a range.
  185. If not, the item is displayed as a box.</td>
  186. </tr>
  187. <tr>
  188. <td>group</td>
  189. <td>any type</td>
  190. <td>no</td>
  191. <td>This field is optional. When the group column is provided,
  192. all items with the same group are placed on one line.
  193. A vertical axis is displayed showing the groups.
  194. Grouping items can be useful for example when showing availability of multiple
  195. people, rooms, or other resources next to each other.<br>
  196. </td>
  197. </tr>
  198. <tr>
  199. <td>id</td>
  200. <td>String | Number</td>
  201. <td>no</td>
  202. <td>An id for the item. Using an id is not required but highly
  203. recommended. An id is needed when dynamically adding, updating,
  204. and removing items in a DataSet.</td>
  205. </tr>
  206. <tr>
  207. <td>start</td>
  208. <td>Date | number | string | Moment</td>
  209. <td>yes</td>
  210. <td>The start date of the item, for example <code>new Date(2010,9,23)</code>.</td>
  211. </tr>
  212. <tr>
  213. <td>style</td>
  214. <td>String</td>
  215. <td>no</td>
  216. <td>
  217. A css text string to apply custom styling for an individual item, for
  218. example <code>"color: red; background-color: pink;"</code>.
  219. </td>
  220. </tr>
  221. <tr>
  222. <td>subgroup</td>
  223. <td>String | Number</td>
  224. <td>none</td>
  225. <td>The id of a subgroup.
  226. Groups all items within a group per subgroup, and positions them on the
  227. same height instead of staking them on top of each other. can be ordered
  228. by specifying the option <code>subgroupOrder</code> of a group.
  229. </td>
  230. </tr>
  231. <tr>
  232. <td>title</td>
  233. <td>String</td>
  234. <td>none</td>
  235. <td>Add a title for the item, displayed when holding the mouse on the item.
  236. The title can only contain plain text.
  237. </td>
  238. </tr>
  239. <tr>
  240. <td>type</td>
  241. <td>String</td>
  242. <td>'box'</td>
  243. <td>The type of the item. Can be 'box' (default), 'point', 'range', or 'background'.
  244. Types 'box' and 'point' need a start date, the types 'range' and 'background' needs both a start and end date.
  245. </td>
  246. </tr>
  247. </table>
  248. <h3 id="groups">Groups</h3>
  249. <p>
  250. Like the items, groups are regular JavaScript Arrays and Objects.
  251. Using groups, items can be grouped together.
  252. Items are filtered per group, and displayed as
  253. Group items can contain the properties <code>id</code>,
  254. <code>content</code>, and <code>className</code> (optional).
  255. </p>
  256. <p>
  257. Groups can be applied to a timeline using the method <code>setGroups</code> or supplied in the constructor.
  258. A table with groups can be created like:
  259. </p>
  260. <pre class="prettyprint lang-js">
  261. var groups = [
  262. {
  263. id: 1,
  264. content: 'Group 1'
  265. // Optional: a field 'className', 'style'
  266. }
  267. // more groups...
  268. ]);
  269. </pre>
  270. <p>
  271. Groups can have the following properties:
  272. </p>
  273. <table>
  274. <tr>
  275. <th>Name</th>
  276. <th>Type</th>
  277. <th>Required</th>
  278. <th>Description</th>
  279. </tr>
  280. <tr>
  281. <td>className</td>
  282. <td>String</td>
  283. <td>no</td>
  284. <td>This field is optional. A className can be used to give groups
  285. an individual css style. For example, when a group has className
  286. 'red', one can define a css style
  287. <code>
  288. .red {
  289. color: red;
  290. }
  291. </code>.
  292. More details on how to style groups can be found in the section
  293. <a href="#Styles">Styles</a>.
  294. </td>
  295. </tr>
  296. <tr>
  297. <td>content</td>
  298. <td>String</td>
  299. <td>yes</td>
  300. <td>The contents of the group. This can be plain text or html code.</td>
  301. </tr>
  302. <tr>
  303. <td>id</td>
  304. <td>String | Number</td>
  305. <td>yes</td>
  306. <td>An id for the group. The group will display all items having a
  307. property <code>group</code> which matches the <code>id</code>
  308. of the group.</td>
  309. </tr>
  310. <tr>
  311. <td>style</td>
  312. <td>String</td>
  313. <td>no</td>
  314. <td>
  315. A css text string to apply custom styling for an individual group label, for
  316. example <code>"color: red; background-color: pink;"</code>.
  317. </td>
  318. </tr>
  319. <tr>
  320. <td>subgroupOrder</td>
  321. <td>String | Function</td>
  322. <td>none</td>
  323. <td>Order the subgroups by a field name or custom sort function.
  324. By default, groups are ordered by first-come, first-show.
  325. </td>
  326. </tr>
  327. <tr>
  328. <td>title</td>
  329. <td>String</td>
  330. <td>none</td>
  331. <td>A title for the group, displayed when holding the mouse on the groups label.
  332. The title can only contain plain text.
  333. </td>
  334. </tr>
  335. </table>
  336. <h2 id="Configuration_Options">Configuration Options</h2>
  337. <p>
  338. Options can be used to customize the timeline.
  339. Options are defined as a JSON object. All options are optional.
  340. </p>
  341. <pre class="prettyprint lang-js">
  342. var options = {
  343. width: '100%',
  344. height: '30px',
  345. margin: {
  346. item: 20
  347. }
  348. };
  349. </pre>
  350. <p>
  351. The following options are available.
  352. </p>
  353. <table>
  354. <tr>
  355. <th>Name</th>
  356. <th>Type</th>
  357. <th>Default</th>
  358. <th>Description</th>
  359. </tr>
  360. <tr>
  361. <td>align</td>
  362. <td>String</td>
  363. <td>"center"</td>
  364. <td>Alignment of items with type 'box', 'range', and 'background'. Available values are 'auto' (default), 'center', 'left', or 'right'. For 'box' items, the 'auto' alignment is 'center'. For 'range' items, the auto alignment is dynamic: positioned left and shifted such that the contents is always visible on screen.</td>
  365. </tr>
  366. <tr>
  367. <td>autoResize</td>
  368. <td>boolean</td>
  369. <td>true</td>
  370. <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>
  371. </tr>
  372. <tr>
  373. <td>clickToUse</td>
  374. <td>boolean</td>
  375. <td>false</td>
  376. <td>When a Timeline is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  377. 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>
  378. </tr>
  379. <tr>
  380. <td>dataAttributes</td>
  381. <td>Array[String] | 'all'</td>
  382. <td>false</td>
  383. <td>An array of fields optionally defined on the timeline items that will be appended as <code>data-</code> attributes to the DOM element of the items.<br>
  384. If value is <code>'all'</code> then each field defined on the timeline item will become a <code>data-</code> attribute.</td>
  385. </tr>
  386. <tr>
  387. <td>editable</td>
  388. <td>Boolean | Object</td>
  389. <td>false</td>
  390. <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.
  391. See section <a href="#Editing_Items">Editing Items</a> for a detailed explanation.
  392. </td>
  393. </tr>
  394. <tr>
  395. <td>editable.add</td>
  396. <td>Boolean</td>
  397. <td>false</td>
  398. <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>
  399. </tr>
  400. <tr>
  401. <td>editable.remove</td>
  402. <td>Boolean</td>
  403. <td>false</td>
  404. <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>
  405. </tr>
  406. <tr>
  407. <td>editable.updateGroup</td>
  408. <td>Boolean</td>
  409. <td>false</td>
  410. <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>
  411. </tr>
  412. <tr>
  413. <td>editable.updateTime</td>
  414. <td>Boolean</td>
  415. <td>false</td>
  416. <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>
  417. </tr>
  418. <tr>
  419. <td>end</td>
  420. <td>Date | Number | String | Moment</td>
  421. <td>none</td>
  422. <td>The initial end date for the axis of the timeline.
  423. If not provided, the latest date present in the items set is taken as
  424. end date.</td>
  425. </tr>
  426. <tr>
  427. <td>format</td>
  428. <td>Object</td>
  429. <td>none</td>
  430. <td>
  431. Apply custom date formatting of the labels on the time axis. The default value of <code>format</code> is:
  432. <pre class="prettyprint lang-js">{
  433. minorLabels: {
  434. millisecond:'SSS',
  435. second: 's',
  436. minute: 'HH:mm',
  437. hour: 'HH:mm',
  438. weekday: 'ddd D',
  439. day: 'D',
  440. month: 'MMM',
  441. year: 'YYYY'
  442. },
  443. majorLabels: {
  444. millisecond:'HH:mm:ss',
  445. second: 'D MMMM HH:mm',
  446. minute: 'ddd D MMMM',
  447. hour: 'ddd D MMMM',
  448. weekday: 'MMMM YYYY',
  449. day: 'MMMM YYYY',
  450. month: 'YYYY',
  451. year: ''
  452. }
  453. }</pre>
  454. For values which not provided in the customized <code>options.format</code>, the default values will be used.
  455. All available formatting syntax is described in the <a href="http://momentjs.com/docs/#/displaying/format/">docs of moment.js</a>.
  456. </td>
  457. </tr>
  458. <tr>
  459. <td>groupOrder</td>
  460. <td>String | Function</td>
  461. <td>none</td>
  462. <td>Order the groups by a field name or custom sort function.
  463. By default, groups are not ordered.
  464. </td>
  465. </tr>
  466. <tr>
  467. <td>height</td>
  468. <td>Number | String</td>
  469. <td>none</td>
  470. <td>The height of the timeline in pixels or as a percentage.
  471. When height is undefined or null, the height of the timeline is automatically
  472. adjusted to fit the contents.
  473. It is possible to set a maximum height using option <code>maxHeight</code>
  474. to prevent the timeline from getting too high in case of automatically
  475. calculated height.
  476. </td>
  477. </tr>
  478. <tr>
  479. <td>hiddenDates</td>
  480. <td>Object</td>
  481. <td>none</td>
  482. <td>This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
  483. <code>{start: '2014-03-21 00:00:00', end: '2014-03-28 00:00:00', [repeat:'daily']}</code> or as an Array of these objects. The repeat argument is optional.
  484. The possible values are (case-sensitive): <code>daily, weekly, monthly, yearly</code>. To hide a weekend, pick any Saturday as start and the following Monday as end
  485. and set repeat to weekly.
  486. </td>
  487. </tr>
  488. <tr>
  489. <td>locale</td>
  490. <td>String</td>
  491. <td>none</td>
  492. <td>Select a locale for the Timeline. See section <a href="#Localization">Localization</a> for more information.</td>
  493. </tr>
  494. <tr>
  495. <td>locales</td>
  496. <td>Object</td>
  497. <td>none</td>
  498. <td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
  499. </tr>
  500. <tr>
  501. <td>margin</td>
  502. <td>Number | Object</td>
  503. <td>Object</td>
  504. <td>When a number, applies the margin to <code>margin.axis</code>, <code>margin.item.horizontal</code>, and <code>margin.item.vertical</code>.</td>
  505. </tr>
  506. <tr>
  507. <td>margin.axis</td>
  508. <td>Number</td>
  509. <td>20</td>
  510. <td>The minimal margin in pixels between items and the time axis.</td>
  511. </tr>
  512. <tr>
  513. <td>margin.item</td>
  514. <td>Number</td>
  515. <td>10</td>
  516. <td>The minimal margin in pixels between items in both horizontal and vertical direction.</td>
  517. </tr>
  518. <tr>
  519. <td>margin.item.horizontal</td>
  520. <td>Number</td>
  521. <td>10</td>
  522. <td>The minimal horizontal margin in pixels between items.</td>
  523. </tr>
  524. <tr>
  525. <td>margin.item.vertical</td>
  526. <td>Number</td>
  527. <td>10</td>
  528. <td>The minimal vertical margin in pixels between items.</td>
  529. </tr>
  530. <tr>
  531. <td>max</td>
  532. <td>Date | Number | String | Moment</td>
  533. <td>none</td>
  534. <td>Set a maximum Date for the visible range.
  535. It will not be possible to move beyond this maximum.
  536. </td>
  537. </tr>
  538. <tr>
  539. <td>maxHeight</td>
  540. <td>Number | String</td>
  541. <td>none</td>
  542. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  543. </tr>
  544. <tr>
  545. <td>min</td>
  546. <td>Date | Number | String | Moment</td>
  547. <td>none</td>
  548. <td>Set a minimum Date for the visible range.
  549. It will not be possible to move beyond this minimum.
  550. </td>
  551. </tr>
  552. <tr>
  553. <td>minHeight</td>
  554. <td>Number | String</td>
  555. <td>none</td>
  556. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  557. </tr>
  558. <tr>
  559. <td>moveable</td>
  560. <td>Boolean</td>
  561. <td>true</td>
  562. <td>
  563. Specifies whether the Timeline can be moved and zoomed by dragging the window.
  564. See also option <code>zoomable</code>.
  565. </td>
  566. </tr>
  567. <tr>
  568. <td>onAdd</td>
  569. <td>Function</td>
  570. <td>none</td>
  571. <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>.
  572. </td>
  573. </tr>
  574. <tr>
  575. <td>onUpdate</td>
  576. <td>Function</td>
  577. <td>none</td>
  578. <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>.
  579. </td>
  580. </tr>
  581. <tr>
  582. <td>onMove</td>
  583. <td>Function</td>
  584. <td>none</td>
  585. <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>.
  586. </td>
  587. </tr>
  588. <tr>
  589. <td>onMoving</td>
  590. <td>Function</td>
  591. <td>none</td>
  592. <td>Callback function triggered repeatedly when an item is being moved. 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>.
  593. </td>
  594. </tr>
  595. <tr>
  596. <td>onRemove</td>
  597. <td>Function</td>
  598. <td>none</td>
  599. <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>.
  600. </td>
  601. </tr>
  602. <tr>
  603. <td>order</td>
  604. <td>Function</td>
  605. <td>none</td>
  606. <td>
  607. <p>Provide a custom sort function to order the items. The order of the
  608. items is determining the way they are stacked. The function
  609. order is called with two arguments containing the data of two items to be
  610. compared.
  611. </p>
  612. <p style="font-style: italic">WARNING: Use with caution. Custom ordering is not suitable for large amounts of items. On load, the Timeline will render all items once to determine their width and height. Keep the number of items in this configuration limited to a maximum of a few hundred items.</p>
  613. </td>
  614. </tr>
  615. <tr>
  616. <td>orientation</td>
  617. <td>String | Object</td>
  618. <td>'bottom'</td>
  619. <td>Orientation of the timelines axis and items. When orientation is a string, the value is applied to both items and axis. Can be 'top', 'bottom' (default), or 'both'.</td>
  620. </tr>
  621. <tr>
  622. <td>orientation.axis</td>
  623. <td>String</td>
  624. <td>'bottom'</td>
  625. <td>Orientation of the timeline axis: 'top', 'bottom' (default), or 'both'. If orientation is 'bottom', the time axis is drawn at the bottom. When 'top', the axis is drawn on top. When 'both', two axes are drawn, both on top and at the bottom.</td>
  626. </tr>
  627. <tr>
  628. <td>orientation.item</td>
  629. <td>String</td>
  630. <td>'bottom'</td>
  631. <td>Orientation of the timeline items: 'top' or 'bottom' (default). Determines whether items are aligned to the top or bottom of the Timeline.</td>
  632. </tr>
  633. <tr>
  634. <td>padding</td>
  635. <td>Number</td>
  636. <td>5</td>
  637. <td>The padding of items, needed to correctly calculate the size
  638. of item ranges. Must correspond with the css of items, for example when setting <code>options.padding=10</code>, corresponding css is:
  639. <pre class="prettyprint lang-css">
  640. .vis.timeline .item {
  641. padding: 10px;
  642. }</pre>
  643. </td>
  644. </tr>
  645. <tr>
  646. <td>selectable</td>
  647. <td>Boolean</td>
  648. <td>true</td>
  649. <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>
  650. </tr>
  651. <tr>
  652. <td>showCurrentTime</td>
  653. <td>boolean</td>
  654. <td>true</td>
  655. <td>Show a vertical bar at the current time.</td>
  656. </tr>
  657. <tr>
  658. <td>showCustomTime</td>
  659. <td>boolean</td>
  660. <td>false</td>
  661. <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>
  662. </tr>
  663. <tr>
  664. <tr>
  665. <td>showMajorLabels</td>
  666. <td>boolean</td>
  667. <td>true</td>
  668. <td>By default, the timeline shows both minor and major date labels on the
  669. time axis.
  670. For example the minor labels show minutes and the major labels show hours.
  671. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  672. are shown.</td>
  673. </tr>
  674. <tr>
  675. <td>showMinorLabels</td>
  676. <td>boolean</td>
  677. <td>true</td>
  678. <td>By default, the timeline shows both minor and major date labels on the
  679. time axis.
  680. For example the minor labels show minutes and the major labels show hours.
  681. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  682. are shown. When both <code>showMajorLabels</code> and
  683. <code>showMinorLabels</code> are false, no horizontal axis will be
  684. visible.</td>
  685. </tr>
  686. <tr>
  687. <td>stack</td>
  688. <td>Boolean</td>
  689. <td>true</td>
  690. <td>If true (default), items will be stacked on top of each other such that they do not overlap.</td>
  691. </tr>
  692. <tr>
  693. <td>snap</td>
  694. <td>function | null</td>
  695. <td>function</td>
  696. <td>When moving items on the Timeline, they will be snapped to nice dates like full hours or days, depending on the current scale. The <code>snap</code> function can be replaced with a custom function, or can be set to <code>null</code> to disable snapping. The signature of the snap function is:
  697. <pre class="prettyprint lang-js">function snap(date: Date, scale: string, step: number) : Date | number</pre>
  698. The parameter <code>scale</code> can be can be 'millisecond', 'second', 'minute', 'hour', 'weekday, 'day, 'month, or 'year'. The parameter <code>step</code> is a number like 1, 2, 4, 5.
  699. </td>
  700. </tr>
  701. <tr>
  702. <td>start</td>
  703. <td>Date | Number | String | Moment</td>
  704. <td>none</td>
  705. <td>The initial start date for the axis of the timeline.
  706. If not provided, the earliest date present in the events is taken as start date.</td>
  707. </tr>
  708. <tr>
  709. <td>template</td>
  710. <td>Function</td>
  711. <td>none</td>
  712. <td>A template function used to generate the contents of the items. The function is called by the Timeline with an items data as argument, and must return HTML code as result. When the option template is specified, the items do not need to have a field <code>content</code>. See section <a href="#Templates">Templates</a> for a detailed explanation.</td>
  713. </tr>
  714. <tr>
  715. <td>timeAxis.scale</td>
  716. <td>string</td>
  717. <td>none</td>
  718. <td>Set a fixed scale for the time axis of the Timeline. Choose from <code>'millisecond'</code>, <code>'second'</code>, <code>'minute'</code>, <code>'hour'</code>, <code>'weekday'</code>, <code>'day'</code>, <code>'month'</code>, <code>'year'</code>. Example usage:
  719. <pre class="prettyprint lang-js">var options = {
  720. timeAxis: {scale: 'minute', step: 5}
  721. }</pre>
  722. </td>
  723. </tr>
  724. <tr>
  725. <td>timeAxis.step</td>
  726. <td>number</td>
  727. <td>1</td>
  728. <td>
  729. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  730. Choose for example 1, 2, 5, or 10.</td>
  731. </tr>
  732. <tr>
  733. <td>type</td>
  734. <td>String</td>
  735. <td>none</td>
  736. <td>Specifies the default type for the timeline items. Choose from 'box', 'point', 'range', and 'background'. 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. Items of type 'background' are not editable.
  737. </td>
  738. </tr>
  739. <tr>
  740. <td>width</td>
  741. <td>String</td>
  742. <td>'100%'</td>
  743. <td>The width of the timeline in pixels or as a percentage.</td>
  744. </tr>
  745. <tr>
  746. <td>zoomable</td>
  747. <td>Boolean</td>
  748. <td>true</td>
  749. <td>
  750. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  751. Only applicable when option <code>moveable</code> is set <code>true</code>.
  752. </td>
  753. </tr>
  754. <tr>
  755. <td>zoomMax</td>
  756. <td>Number</td>
  757. <td>315360000000000</td>
  758. <td>Set a maximum zoom interval for the visible range in milliseconds.
  759. It will not be possible to zoom out further than this maximum.
  760. Default value equals about 10000 years.
  761. </td>
  762. </tr>
  763. <tr>
  764. <td>zoomMin</td>
  765. <td>Number</td>
  766. <td>10</td>
  767. <td>Set a minimum zoom interval for the visible range in milliseconds.
  768. It will not be possible to zoom in further than this minimum.
  769. </td>
  770. </tr>
  771. </table>
  772. <h2 id="Methods">Methods</h2>
  773. <p>
  774. The Timeline supports the following methods.
  775. </p>
  776. <table>
  777. <tr>
  778. <th>Method</th>
  779. <th>Return Type</th>
  780. <th>Description</th>
  781. </tr>
  782. <tr>
  783. <td>addCustomTime(time[, id])</td>
  784. <td>Number | String</td>
  785. <td>
  786. Only applicable when the option showCustomTime is true.<br>
  787. Add new vertical bar representing custom time that can be dragged by the user. Parameter <code>time</code> can be a Date, Number, or String. Parameter <code>id</code> can be Number or String. If <code>id</code> is provided, it will be used as ID for the new vertical bar, otherwise the ID will be auto generated.<br>
  788. Returns ID of the newly created bar.
  789. </td>
  790. </tr>
  791. <tr>
  792. <td>clear([what])</td>
  793. <td>none</td>
  794. <td>
  795. Clear the Timeline. An object can be passed specifying which sections to clear: items, groups,
  796. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  797. <pre class="prettyprint lang-js">timeline.clear(); // clear items, groups, and options
  798. timeline.clear({options: true}); // clear options only
  799. </pre>
  800. </td>
  801. </tr>
  802. <tr>
  803. <td>destroy()</td>
  804. <td>none</td>
  805. <td>Destroy the Timeline. The timeline is removed from memory. all DOM elements and event listeners are cleaned up.
  806. </td>
  807. </tr>
  808. <tr>
  809. <td>fit([options])</td>
  810. <td>none</td>
  811. <td>Adjust the visible window such that it fits all items. See also function <code>focus(id)</code>.
  812. Available options:
  813. <ul>
  814. <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>
  815. </ul>
  816. </td>
  817. </tr>
  818. <tr>
  819. <td>focus(id | ids [, options])</td>
  820. <td>none</td>
  821. <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:
  822. <ul>
  823. <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>
  824. </ul>
  825. </td>
  826. </tr>
  827. <tr>
  828. <td>getCurrentTime()</td>
  829. <td>Date</td>
  830. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  831. </td>
  832. </tr>
  833. <tr>
  834. <td>getCustomTime([id])</td>
  835. <td>Date</td>
  836. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true. If parameter <code>id</code> is provided, time of the custom time bar under that ID is returned.
  837. </td>
  838. </tr>
  839. <tr id="getEventProperties">
  840. <td>getEventProperties(event)</td>
  841. <td>Object</td>
  842. <td>
  843. Returns an Object with relevant properties from an event:
  844. <ul>
  845. <li><code>group</code> (Number | null): the id of the clicked group.</li>
  846. <li><code>item</code> (Number | null): the id of the clicked item.</li>
  847. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  848. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  849. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  850. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  851. <li><code>time</code> (Date): Date of the clicked event.</li>
  852. <li><code>snappedTime</code> (Date): Date of the clicked event, snapped to a nice value.</li>
  853. <li><code>what</code> (String | null): name of the clicked thing: <code>item</code>, <code>background</code>, <code>axis</code>, <code>group-label</code>, <code>custom-time</code>, or <code>current-time</code>.</li>
  854. <li><code>event</code> (Object): the original click event.</li>
  855. </ul>
  856. </td>
  857. </tr>
  858. <tr>
  859. <td>getSelection()</td>
  860. <td>Number[]</td>
  861. <td>Get an array with the ids of the currently selected items.</td>
  862. </tr>
  863. <tr>
  864. <td>getVisibleItems()</td>
  865. <td>Number[]</td>
  866. <td>Get an array with the ids of the currently visible items.</td>
  867. </tr>
  868. <tr>
  869. <td>getWindow()</td>
  870. <td>Object</td>
  871. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  872. </tr>
  873. <tr>
  874. <td>moveTo(time [, options])</td>
  875. <td>none</td>
  876. <td>Move the window such that given time is centered on screen. Parameter <code>time</code> can be a <code>Date</code>, <code>Number</code>, or <code>String</code>. Available options:
  877. <ul>
  878. <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>
  879. </ul>
  880. </td>
  881. </tr>
  882. <tr>
  883. <td>on(event, callback)</td>
  884. <td>none</td>
  885. <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>
  886. </tr>
  887. <tr>
  888. <td>off(event, callback)</td>
  889. <td>none</td>
  890. <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>
  891. </tr>
  892. <tr>
  893. <td>redraw()</td>
  894. <td>none</td>
  895. <td>Force a redraw of the Timeline. The size of all items will be recalculated.
  896. Can be useful to manually redraw when option <code>autoResize=false</code> and the window
  897. has been resized, or when the items CSS has been changed.
  898. </td>
  899. </tr>
  900. <tr>
  901. <td>removeCustomTime(id)</td>
  902. <td>none</td>
  903. <td>
  904. Remove vertical bars previously added to the timeline via <code>addCustomTime</code> method. Parameter <code>id</code> is the ID of the custom vertical bar returned by <code>addCustomTime</code> method.
  905. </td>
  906. </tr>
  907. <tr>
  908. <td>setCurrentTime(time)</td>
  909. <td>none</td>
  910. <td>Set a current time. This can be used for example to ensure that a client's time is synchronized with a shared server time.
  911. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  912. Only applicable when option <code>showCurrentTime</code> is true.</td>
  913. </tr>
  914. <tr>
  915. <td>setCustomTime(time [, id])</td>
  916. <td>none</td>
  917. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. Parameter <code>time</code> can be a Date object, numeric timestamp, or ISO date string. Parameter <code>id</code> represents ID of the custom time bar, provided by <code>addCustomTime</code> method and can be a Number or String.
  918. </td>
  919. </tr>
  920. <tr>
  921. <td>setGroups(groups)</td>
  922. <td>none</td>
  923. <td>Set a data set with groups for the Timeline.
  924. <code>groups</code> can be an Array with Objects,
  925. a DataSet, or a DataView. For each of the groups, the items of the
  926. timeline are filtered on the property <code>group</code>, which
  927. must correspond with the id of the group.
  928. </td>
  929. </tr>
  930. <tr>
  931. <td>setItems(items)</td>
  932. <td>none</td>
  933. <td>Set a data set with items for the Timeline.
  934. <code>items</code> can be an Array with Objects,
  935. a DataSet, or a DataView.
  936. </td>
  937. </tr>
  938. <tr>
  939. <td>setOptions(options)</td>
  940. <td>none</td>
  941. <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.
  942. </td>
  943. </tr>
  944. <tr>
  945. <td>setSelection(id | ids [, options])</td>
  946. <td>none</td>
  947. <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:
  948. <ul>
  949. <li><code>focus: boolean</code><br>If true, focus will be set to the selected item(s)</li>
  950. <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>
  951. </ul>
  952. </td>
  953. </tr>
  954. <tr>
  955. <td>setWindow(start, end [, options])</td>
  956. <td>none</td>
  957. <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:
  958. <ul>
  959. <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>
  960. </ul>
  961. </td>
  962. </tr>
  963. </table>
  964. <h2 id="Events">Events</h2>
  965. <p>
  966. Timeline fires events when changing the visible window by dragging, when
  967. selecting items, and when dragging the custom time bar.
  968. </p>
  969. <p>
  970. Here an example on how to listen for a <code>select</code> event.
  971. </p>
  972. <pre class="prettyprint lang-js">
  973. timeline.on('select', function (properties) {
  974. alert('selected items: ' + properties.nodes);
  975. });
  976. </pre>
  977. <p>
  978. A listener can be removed via the function <code>off</code>:
  979. </p>
  980. <pre class="prettyprint lang-js">
  981. function onSelect (properties) {
  982. alert('selected items: ' + properties.nodes);
  983. }
  984. // add event listener
  985. timeline.on('select', onSelect);
  986. // do stuff...
  987. // remove event listener
  988. timeline.off('select', onSelect);
  989. </pre>
  990. <p>
  991. The following events are available.
  992. </p>
  993. <table>
  994. <colgroup>
  995. <col style="width: 20%;">
  996. <col style="width: 40%;">
  997. <col style="width: 40%;">
  998. </colgroup>
  999. <tr>
  1000. <th>name</th>
  1001. <th>Description</th>
  1002. <th>Properties</th>
  1003. </tr>
  1004. <tr>
  1005. <td>click</td>
  1006. <td>Fired when clicked inside the Timeline.
  1007. </td>
  1008. <td>
  1009. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1010. </td>
  1011. </tr>
  1012. <tr>
  1013. <td>contextmenu</td>
  1014. <td>Fired when right-clicked inside the Timeline. Note that in order to prevent the context menu from showing up, default behavior of the event must be stopped:
  1015. <pre class="prettyprint lang-js">timeline.on('contextmenu', function (props) {
  1016. alert('Right click!');
  1017. props.event.preventDefault();
  1018. });
  1019. </pre>
  1020. </td>
  1021. <td>
  1022. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1023. </td>
  1024. </tr>
  1025. <tr>
  1026. <td>doubleClick</td>
  1027. <td>Fired when double clicked inside the Timeline.
  1028. </td>
  1029. <td>
  1030. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1031. </td>
  1032. </tr>
  1033. <tr>
  1034. <td>finishedRedraw</td>
  1035. <td>Fired after a redraw is complete. When moving the timeline around, this could be fired frequently.
  1036. </td>
  1037. <td>
  1038. none.
  1039. </td>
  1040. </tr>
  1041. <tr>
  1042. <td>rangechange</td>
  1043. <td>Fired repeatedly when the timeline window is being changed.
  1044. </td>
  1045. <td>
  1046. <ul>
  1047. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1048. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1049. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1050. </ul>
  1051. </td>
  1052. </tr>
  1053. <tr>
  1054. <td>rangechanged</td>
  1055. <td>Fired once after the timeline window has been changed.
  1056. </td>
  1057. <td>
  1058. <ul>
  1059. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1060. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1061. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1062. </ul>
  1063. </td>
  1064. </tr>
  1065. <tr>
  1066. <td>select</td>
  1067. <td>Fired after the user selects or deselects items by tapping or holding them.
  1068. When a use taps an already selected item, the select event is fired again.
  1069. Not fired when the method <code>setSelection</code>is executed.
  1070. </td>
  1071. <td>
  1072. <ul>
  1073. <li><code>items</code>: an array with the ids of the selected items</li>
  1074. </ul>
  1075. </td>
  1076. </tr>
  1077. <tr>
  1078. <td>timechange</td>
  1079. <td>Fired repeatedly when the user is dragging the custom time bar.
  1080. Only available when the custom time bar is enabled.
  1081. </td>
  1082. <td>
  1083. <ul>
  1084. <li><code>id</code> (Number | String): Vertical bar ID.</li>
  1085. <li><code>time</code> (Date): the current time.</li>
  1086. </ul>
  1087. </td>
  1088. </tr>
  1089. <tr>
  1090. <td>timechanged</td>
  1091. <td>Fired once after the user has dragged the custom time bar.
  1092. Only available when the custom time bar is enabled.
  1093. </td>
  1094. <td>
  1095. <ul>
  1096. <li><code>id</code> (Number | String): Vertical bar ID.</li>
  1097. <li><code>time</code> (Date): the current time.</li>
  1098. </ul>
  1099. </td>
  1100. </tr>
  1101. </table>
  1102. <h2 id="Editing_Items">Editing Items</h2>
  1103. <p>
  1104. When the Timeline is configured to be editable (both options <code>selectable</code> and <code>editable</code> are <code>true</code>), the user can:
  1105. </p>
  1106. <ul>
  1107. <li>Select an item by clicking it, and use ctrl+click to or shift+click to select multiple items</li>
  1108. <li>Move selected items by dragging them.</li>
  1109. <li>Create a new item by double tapping on an empty space.</li>
  1110. <li>Create a new range item by dragging on an empty space with the ctrl key down.</li>
  1111. <li>Update an item by double tapping it.</li>
  1112. <li>Delete a selected item by clicking the delete button on the top right.</li>
  1113. </ul>
  1114. <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>
  1115. <pre class="prettyprint lang-js">// enable or disable all manipulation actions
  1116. var options = {
  1117. editable: true // true or false
  1118. };
  1119. // enable or disable individual manipulation actions
  1120. var options = {
  1121. editable: {
  1122. add: true, // add new items by double tapping
  1123. updateTime: true, // drag items horizontally
  1124. updateGroup: true, // drag items from one group to another
  1125. remove: true // delete an item by tapping the delete button top right
  1126. }
  1127. };</pre>
  1128. <p>
  1129. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  1130. </p>
  1131. <ul>
  1132. <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>
  1133. <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>
  1134. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  1135. <li><code>onMoving(item, callback)</code> Fired repeatedly while an item is being moved (dragged). Can be used to adjust the items start, end, and/or group to allowed regions.</li>
  1136. <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>
  1137. </ul>
  1138. <p>
  1139. Each of the callbacks is invoked with two arguments:
  1140. </p>
  1141. <ul>
  1142. <li><code>item</code>: the item being manipulated</li>
  1143. <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>
  1144. </ul>
  1145. <p>
  1146. Example code:
  1147. </p>
  1148. <pre class="prettyprint lang-js">var options = {
  1149. onUpdate: function (item, callback) {
  1150. item.content = prompt('Edit items text:', item.content);
  1151. if (item.content != null) {
  1152. callback(item); // send back adjusted item
  1153. }
  1154. else {
  1155. callback(null); // cancel updating the item
  1156. }
  1157. }
  1158. };
  1159. </pre>
  1160. A full example is available here: <a href="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
  1161. <h2 id="Templates">Templates</h2>
  1162. <p>
  1163. Timeline supports templates to format item contents. Any template engine (such as <a href="http://handlebarsjs.com/">handlebars</a> or <a href="http://mustache.github.io/">mustache</a>) can be used, and one can also manually build HTML. In the options, one can provide a template handler. This handler is a function accepting an items data as argument, and outputs formatted HTML:
  1164. </p>
  1165. <pre class="prettyprint lang-js">var options = {
  1166. template: function (item) {
  1167. var html = ... // generate HTML markup for this item
  1168. return html;
  1169. }
  1170. };
  1171. </pre>
  1172. <h3>Create HTML manually</h3>
  1173. The HTML for an item can be created manually:
  1174. <pre class="prettyprint lang-js">var options = {
  1175. template: function (item) {
  1176. return '&lt;h1&gt;' + item.header + '&lt;/h1&gt;&lt;p&gt;' + item.description + '&lt;/p&gt;';
  1177. }
  1178. };
  1179. </pre>
  1180. <h3>Using a template engine</h3>
  1181. Using <a href="http://handlebarsjs.com/">handlebars</a>, one can write the template in HTML:
  1182. <pre class="prettyprint lang-html">
  1183. &lt;script id="item-template" type="text/x-handlebars-template"&gt;
  1184. &lt;h1&gt;{{header}}&lt;/h1&gt;
  1185. &lt;p&gt;{{description}}&lt;/p&gt;
  1186. &lt;/script&gt;
  1187. </pre>
  1188. Compile the template:
  1189. <pre class="prettyprint lang-js">
  1190. var source = document.getElementById('item-template').innerHTML;
  1191. var template = Handlebars.compile(source);
  1192. </pre>
  1193. And then specify the template in the Timeline options
  1194. <pre class="prettyprint lang-js">var options = {
  1195. template: template
  1196. };
  1197. </pre>
  1198. <h3>Multiple templates</h3>
  1199. In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property:
  1200. <pre class="prettyprint lang-js">
  1201. var templates = {
  1202. template1: Handlebars.compile(...),
  1203. template2: Handlebars.compile(...),
  1204. template2: Handlebars.compile(...),
  1205. ...
  1206. };
  1207. var options = {
  1208. template: function (item) {
  1209. var template = templates[item.template]; // choose the right template
  1210. return template(item); // execute the template
  1211. }
  1212. };
  1213. </pre>
  1214. Now the items can be extended with a property <code>template</code>, specifying which template to use for the item.
  1215. <h2 id="Localization">Localization</h2>
  1216. <p>
  1217. 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.
  1218. </p>
  1219. <p>
  1220. To set a locale for the Timeline, specify the option <code>locale</code>:
  1221. </p>
  1222. <pre class="prettyprint lang-js">var options = {
  1223. locale: 'nl'
  1224. };
  1225. </pre>
  1226. <h3>Create a new locale</h3>
  1227. To load a locale into the Timeline not supported by default, one can add a new locale to the option <code>locales</code>:
  1228. <pre class="prettyprint lang-js">var options = {
  1229. locales: {
  1230. // create a new locale (text strings should be replaced with localized strings)
  1231. mylocale: {
  1232. current: 'current',
  1233. time: 'time',
  1234. }
  1235. },
  1236. // use the new locale
  1237. locale: 'mylocale'
  1238. };
  1239. </pre>
  1240. <h3 id="available-locales">Available locales</h3>
  1241. <p>
  1242. Timeline comes with support for the following locales:
  1243. </p>
  1244. <table>
  1245. <tr><th>Language</th><th>Code</th></tr>
  1246. <tr>
  1247. <td>English</td>
  1248. <td>
  1249. <code>en</code><br>
  1250. <code>en_EN</code><br>
  1251. <code>en_US</code>
  1252. </td>
  1253. </tr>
  1254. <tr>
  1255. <td>Dutch</td>
  1256. <td>
  1257. <code>nl</code><br>
  1258. <code>nl_NL</code><br>
  1259. <code>nl_BE</code>
  1260. </td>
  1261. </tr>
  1262. </table>
  1263. <h2 id="Styles">Styles</h2>
  1264. <p>
  1265. All parts of the Timeline have a class name and a default css style.
  1266. The styles can be overwritten, which enables full customization of the layout
  1267. of the Timeline.
  1268. </p>
  1269. <p>For example, to change the border and background color of all items, include the
  1270. following code inside the head of your html code or in a separate stylesheet.</p>
  1271. <pre class="prettyprint lang-html">&lt;style&gt;
  1272. .vis.timeline .item {
  1273. border-color: orange;
  1274. background-color: yellow;
  1275. }
  1276. &lt;/style&gt;
  1277. </pre>
  1278. <h3 id="Grid_Backgrounds">Grid Backgrounds</h3>
  1279. <p>
  1280. The background grid of the time axis can be styled, for example to highlight
  1281. weekends or to create grids with an alternating white/lightgray background.
  1282. </p>
  1283. <p>
  1284. Depending on the zoom level, the grids get certain css classes attached.
  1285. The following classes are available:
  1286. </p>
  1287. <table>
  1288. <tr>
  1289. <th>Description</th><th>values</th>
  1290. </tr>
  1291. <tr>
  1292. <td>Alternating columns</td><td><code>even</code>, <code>odd</code></td>
  1293. </tr>
  1294. <tr>
  1295. <td>Current date</td><td><code>today</code>, <code>tomorrow</code>, <code>yesterday</code>, <code>current-week</code>, <code>current-month</code>, <code>current-year</code></td>
  1296. </tr>
  1297. <tr>
  1298. <td>Hours</td><td><code>0h</code>, <code>1h</code>, ..., <code>23h</code></td>
  1299. </tr>
  1300. <tr>
  1301. <td>Grouped hours</td><td><code>0-4h</code> to <code>20-24h</code></td>
  1302. </tr>
  1303. <tr>
  1304. <td>Weekday</td><td><code>monday</code>, <code>tuesday</code>, <code>wednesday</code>, <code>thursday</code>, <code>friday</code>, <code>saturday</code>, <code>sunday</code></td>
  1305. </tr>
  1306. <tr>
  1307. <td>Days</td><td><code>date1</code>, <code>date2</code>, ..., <code>date31</code></td>
  1308. </tr>
  1309. <tr>
  1310. <td>Months</td><td><code>januari</code>, <code>februari</code>, <code>march</code>, <code>april</code>, <code>may</code>, <code>june</code>, <code>july</code>, <code>august</code>, <code>september</code>, <code>october</code>, <code>november</code>, <code>december</code></td>
  1311. </tr>
  1312. <tr>
  1313. <td>Years</td><td><code>year2014</code>, <code>year2015</code>, ...</td>
  1314. </tr>
  1315. </table>
  1316. <p>Examples:</p>
  1317. <pre class="prettyprint lang-html">&lt;style&gt;
  1318. /* alternating column backgrounds */
  1319. .vis.timeline .timeaxis .grid.odd {
  1320. background: #f5f5f5;
  1321. }
  1322. /* gray background in weekends, white text color */
  1323. .vis.timeline .timeaxis .grid.saturday,
  1324. .vis.timeline .timeaxis .grid.sunday {
  1325. background: gray;
  1326. }
  1327. .vis.timeline .timeaxis .text.saturday,
  1328. .vis.timeline .timeaxis .text.sunday {
  1329. color: white;
  1330. }
  1331. &lt;/style&gt;
  1332. </pre>
  1333. <h2 id="Data_Policy">Data Policy</h2>
  1334. <p>
  1335. All code and data is processed and rendered in the browser.
  1336. No data is sent to any server.
  1337. </p>
  1338. </div>
  1339. </body>
  1340. </html>