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.

1510 lines
52 KiB

10 years ago
10 years ago
10 years ago
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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></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>selectable</td>
  635. <td>Boolean</td>
  636. <td>true</td>
  637. <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>
  638. </tr>
  639. <tr>
  640. <td>showCurrentTime</td>
  641. <td>boolean</td>
  642. <td>true</td>
  643. <td>Show a vertical bar at the current time.</td>
  644. </tr>
  645. <tr>
  646. <tr>
  647. <td>showMajorLabels</td>
  648. <td>boolean</td>
  649. <td>true</td>
  650. <td>By default, the timeline shows both minor and major date labels on the
  651. time axis.
  652. For example the minor labels show minutes and the major labels show hours.
  653. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  654. are shown.</td>
  655. </tr>
  656. <tr>
  657. <td>showMinorLabels</td>
  658. <td>boolean</td>
  659. <td>true</td>
  660. <td>By default, the timeline shows both minor and major date labels on the
  661. time axis.
  662. For example the minor labels show minutes and the major labels show hours.
  663. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  664. are shown. When both <code>showMajorLabels</code> and
  665. <code>showMinorLabels</code> are false, no horizontal axis will be
  666. visible.</td>
  667. </tr>
  668. <tr>
  669. <td>stack</td>
  670. <td>Boolean</td>
  671. <td>true</td>
  672. <td>If true (default), items will be stacked on top of each other such that they do not overlap.</td>
  673. </tr>
  674. <tr>
  675. <td>snap</td>
  676. <td>function | null</td>
  677. <td>function</td>
  678. <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:
  679. <pre class="prettyprint lang-js">function snap(date: Date, scale: string, step: number) : Date | number</pre>
  680. 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.
  681. </td>
  682. </tr>
  683. <tr>
  684. <td>start</td>
  685. <td>Date | Number | String | Moment</td>
  686. <td>none</td>
  687. <td>The initial start date for the axis of the timeline.
  688. If not provided, the earliest date present in the events is taken as start date.</td>
  689. </tr>
  690. <tr>
  691. <td>template</td>
  692. <td>Function</td>
  693. <td>none</td>
  694. <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>
  695. </tr>
  696. <tr>
  697. <td>timeAxis.scale</td>
  698. <td>string</td>
  699. <td>none</td>
  700. <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:
  701. <pre class="prettyprint lang-js">var options = {
  702. timeAxis: {scale: 'minute', step: 5}
  703. }</pre>
  704. </td>
  705. </tr>
  706. <tr>
  707. <td>timeAxis.step</td>
  708. <td>number</td>
  709. <td>1</td>
  710. <td>
  711. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  712. Choose for example 1, 2, 5, or 10.</td>
  713. </tr>
  714. <tr>
  715. <td>type</td>
  716. <td>String</td>
  717. <td>none</td>
  718. <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.
  719. </td>
  720. </tr>
  721. <tr>
  722. <td>width</td>
  723. <td>String</td>
  724. <td>'100%'</td>
  725. <td>The width of the timeline in pixels or as a percentage.</td>
  726. </tr>
  727. <tr>
  728. <td>zoomable</td>
  729. <td>Boolean</td>
  730. <td>true</td>
  731. <td>
  732. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  733. Only applicable when option <code>moveable</code> is set <code>true</code>.
  734. </td>
  735. </tr>
  736. <tr>
  737. <td>zoomMax</td>
  738. <td>Number</td>
  739. <td>315360000000000</td>
  740. <td>Set a maximum zoom interval for the visible range in milliseconds.
  741. It will not be possible to zoom out further than this maximum.
  742. Default value equals about 10000 years.
  743. </td>
  744. </tr>
  745. <tr>
  746. <td>zoomMin</td>
  747. <td>Number</td>
  748. <td>10</td>
  749. <td>Set a minimum zoom interval for the visible range in milliseconds.
  750. It will not be possible to zoom in further than this minimum.
  751. </td>
  752. </tr>
  753. </table>
  754. <h2 id="Methods">Methods</h2>
  755. <p>
  756. The Timeline supports the following methods.
  757. </p>
  758. <table>
  759. <tr>
  760. <th>Method</th>
  761. <th>Return Type</th>
  762. <th>Description</th>
  763. </tr>
  764. <tr>
  765. <td>addCustomTime([time] [, id])</td>
  766. <td>Number | String</td>
  767. <td>
  768. Add new vertical bar representing a custom time that can be dragged by the user.
  769. Parameter <code>time</code> can be a Date, Number, or String, and is <code>new Date()</code> by default.
  770. Parameter <code>id</code> can be Number or String and is <code>undefined</code> by default.<br>
  771. Returns id of the created bar.
  772. </td>
  773. </tr>
  774. <tr>
  775. <td>destroy()</td>
  776. <td>none</td>
  777. <td>Destroy the Timeline. The timeline is removed from memory. all DOM elements and event listeners are cleaned up.
  778. </td>
  779. </tr>
  780. <tr>
  781. <td>fit([options])</td>
  782. <td>none</td>
  783. <td>Adjust the visible window such that it fits all items. See also function <code>focus(id)</code>.
  784. Available options:
  785. <ul>
  786. <li><code>animation: boolean | {duration: number, easingFunction: string}</code><br>If true (default) or an Object, the range is animated smoothly to the new window. An object can be provided to specify duration and easing function. Default duration is 500 ms, and default easing function is <code>'easeInOutQuad'</code>. Available easing functions: <code>"linear"</code>, <code>"easeInQuad"</code>, <code>"easeOutQuad"</code>, <code>"easeInOutQuad"</code>, <code>"easeInCubic"</code>, <code>"easeOutCubic"</code>, <code>"easeInOutCubic"</code>, <code>"easeInQuart"</code>, <code>"easeOutQuart"</code>, <code>"easeInOutQuart"</code>, <code>"easeInQuint"</code>, <code>"easeOutQuint"</code>, <code>"easeInOutQuint"</code>.
  787. </li>
  788. </ul>
  789. </td>
  790. </tr>
  791. <tr>
  792. <td>focus(id | ids [, options])</td>
  793. <td>none</td>
  794. <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:
  795. <ul>
  796. <li><code>animation: boolean | {duration: number, easingFunction: string}</code><br>If true (default) or an Object, the range is animated smoothly to the new window. An object can be provided to specify duration and easing function. Default duration is 500 ms, and default easing function is <code>'easeInOutQuad'</code>. Available easing functions: <code>"linear"</code>, <code>"easeInQuad"</code>, <code>"easeOutQuad"</code>, <code>"easeInOutQuad"</code>, <code>"easeInCubic"</code>, <code>"easeOutCubic"</code>, <code>"easeInOutCubic"</code>, <code>"easeInQuart"</code>, <code>"easeOutQuart"</code>, <code>"easeInOutQuart"</code>, <code>"easeInQuint"</code>, <code>"easeOutQuint"</code>, <code>"easeInOutQuint"</code>.</li>
  797. </ul>
  798. </td>
  799. </tr>
  800. <tr>
  801. <td>getCurrentTime()</td>
  802. <td>Date</td>
  803. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  804. </td>
  805. </tr>
  806. <tr>
  807. <td>getCustomTime([id])</td>
  808. <td>Date</td>
  809. <td>Retrieve the custom time from the custom time bar with given id. Id is <code>undefined</code> by default.
  810. </td>
  811. </tr>
  812. <tr id="getEventProperties">
  813. <td>getEventProperties(event)</td>
  814. <td>Object</td>
  815. <td>
  816. Returns an Object with relevant properties from an event:
  817. <ul>
  818. <li><code>group</code> (Number | null): the id of the clicked group.</li>
  819. <li><code>item</code> (Number | null): the id of the clicked item.</li>
  820. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  821. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  822. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  823. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  824. <li><code>time</code> (Date): Date of the clicked event.</li>
  825. <li><code>snappedTime</code> (Date): Date of the clicked event, snapped to a nice value.</li>
  826. <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>
  827. <li><code>event</code> (Object): the original click event.</li>
  828. </ul>
  829. </td>
  830. </tr>
  831. <tr>
  832. <td>getSelection()</td>
  833. <td>Number[]</td>
  834. <td>Get an array with the ids of the currently selected items.</td>
  835. </tr>
  836. <tr>
  837. <td>getVisibleItems()</td>
  838. <td>Number[]</td>
  839. <td>Get an array with the ids of the currently visible items.</td>
  840. </tr>
  841. <tr>
  842. <td>getWindow()</td>
  843. <td>Object</td>
  844. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  845. </tr>
  846. <tr>
  847. <td>moveTo(time [, options])</td>
  848. <td>none</td>
  849. <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:
  850. <ul>
  851. <li><code>animation: boolean | {duration: number, easingFunction: string}</code><br>If true (default) or an Object, the range is animated smoothly to the new window. An object can be provided to specify duration and easing function. Default duration is 500 ms, and default easing function is <code>'easeInOutQuad'</code>. Available easing functions: <code>"linear"</code>, <code>"easeInQuad"</code>, <code>"easeOutQuad"</code>, <code>"easeInOutQuad"</code>, <code>"easeInCubic"</code>, <code>"easeOutCubic"</code>, <code>"easeInOutCubic"</code>, <code>"easeInQuart"</code>, <code>"easeOutQuart"</code>, <code>"easeInOutQuart"</code>, <code>"easeInQuint"</code>, <code>"easeOutQuint"</code>, <code>"easeInOutQuint"</code>.</li>
  852. </ul>
  853. </td>
  854. </tr>
  855. <tr>
  856. <td>on(event, callback)</td>
  857. <td>none</td>
  858. <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>
  859. </tr>
  860. <tr>
  861. <td>off(event, callback)</td>
  862. <td>none</td>
  863. <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>
  864. </tr>
  865. <tr>
  866. <td>redraw()</td>
  867. <td>none</td>
  868. <td>Force a redraw of the Timeline. The size of all items will be recalculated.
  869. Can be useful to manually redraw when option <code>autoResize=false</code> and the window
  870. has been resized, or when the items CSS has been changed.
  871. </td>
  872. </tr>
  873. <tr>
  874. <td>removeCustomTime(id)</td>
  875. <td>none</td>
  876. <td>
  877. 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.
  878. </td>
  879. </tr>
  880. <tr>
  881. <td>setCurrentTime(time)</td>
  882. <td>none</td>
  883. <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.
  884. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  885. Only applicable when option <code>showCurrentTime</code> is true.</td>
  886. </tr>
  887. <tr>
  888. <td>setCustomTime(time [, id])</td>
  889. <td>none</td>
  890. <td>Adjust the time of a custom time bar.
  891. Parameter <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  892. Parameter <code>id</code> is the idof the custom time bar, and is <code>undefined</code> by default.
  893. </td>
  894. </tr>
  895. <tr>
  896. <td>setData({<br>&nbsp;&nbsp;groups: groups,<br>&nbsp;&nbsp;items: items<br>})</td>
  897. <td>none</td>
  898. <td>Set both groups and items at once. Both properties are optional. This is a convenience method for individually calling both <code>setItems(items)</code> and <code>setGroups(groups)</code>.
  899. Both <code>items</code> and <code>groups</code> can be an Array with Objects,
  900. a DataSet, or a DataView. For each of the groups, the items of the
  901. timeline are filtered on the property <code>group</code>, which
  902. must correspond with the id of the group.
  903. </td>
  904. </tr>
  905. <tr>
  906. <td>setGroups(groups)</td>
  907. <td>none</td>
  908. <td>Set a data set with groups for the Timeline.
  909. <code>groups</code> can be an Array with Objects,
  910. a DataSet, or a DataView. For each of the groups, the items of the
  911. timeline are filtered on the property <code>group</code>, which
  912. must correspond with the id of the group.
  913. </td>
  914. </tr>
  915. <tr>
  916. <td>setItems(items)</td>
  917. <td>none</td>
  918. <td>Set a data set with items for the Timeline.
  919. <code>items</code> can be an Array with Objects,
  920. a DataSet, or a DataView.
  921. </td>
  922. </tr>
  923. <tr>
  924. <td>setOptions(options)</td>
  925. <td>none</td>
  926. <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.
  927. </td>
  928. </tr>
  929. <tr>
  930. <td>setSelection(id | ids [, options])</td>
  931. <td>none</td>
  932. <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:
  933. <ul>
  934. <li><code>focus: boolean</code><br>If true, focus will be set to the selected item(s)</li>
  935. <li><code>animation: boolean | {duration: number, easingFunction: string}</code><br>If true (default) or an Object, the range is animated smoothly to the new window. An object can be provided to specify duration and easing function. Default duration is 500 ms, and default easing function is <code>'easeInOutQuad'</code>. Only applicable when option focus is true. Available easing functions: <code>"linear"</code>, <code>"easeInQuad"</code>, <code>"easeOutQuad"</code>, <code>"easeInOutQuad"</code>, <code>"easeInCubic"</code>, <code>"easeOutCubic"</code>, <code>"easeInOutCubic"</code>, <code>"easeInQuart"</code>, <code>"easeOutQuart"</code>, <code>"easeInOutQuart"</code>, <code>"easeInQuint"</code>, <code>"easeOutQuint"</code>, <code>"easeInOutQuint"</code>.</li>
  936. </ul>
  937. </td>
  938. </tr>
  939. <tr>
  940. <td>setWindow(start, end [, options])</td>
  941. <td>none</td>
  942. <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:
  943. <ul>
  944. <li><code>animation: boolean | {duration: number, easingFunction: string}</code><br>If true (default) or an Object, the range is animated smoothly to the new window. An object can be provided to specify duration and easing function. Default duration is 500 ms, and default easing function is <code>'easeInOutQuad'</code>. Available easing functions: <code>"linear"</code>, <code>"easeInQuad"</code>, <code>"easeOutQuad"</code>, <code>"easeInOutQuad"</code>, <code>"easeInCubic"</code>, <code>"easeOutCubic"</code>, <code>"easeInOutCubic"</code>, <code>"easeInQuart"</code>, <code>"easeOutQuart"</code>, <code>"easeInOutQuart"</code>, <code>"easeInQuint"</code>, <code>"easeOutQuint"</code>, <code>"easeInOutQuint"</code>.</li>
  945. </ul>
  946. </td>
  947. </tr>
  948. </table>
  949. <h2 id="Events">Events</h2>
  950. <p>
  951. Timeline fires events when changing the visible window by dragging, when
  952. selecting items, and when dragging the custom time bar.
  953. </p>
  954. <p>
  955. Here an example on how to listen for a <code>select</code> event.
  956. </p>
  957. <pre class="prettyprint lang-js">
  958. timeline.on('select', function (properties) {
  959. alert('selected items: ' + properties.nodes);
  960. });
  961. </pre>
  962. <p>
  963. A listener can be removed via the function <code>off</code>:
  964. </p>
  965. <pre class="prettyprint lang-js">
  966. function onSelect (properties) {
  967. alert('selected items: ' + properties.nodes);
  968. }
  969. // add event listener
  970. timeline.on('select', onSelect);
  971. // do stuff...
  972. // remove event listener
  973. timeline.off('select', onSelect);
  974. </pre>
  975. <p>
  976. The following events are available.
  977. </p>
  978. <table>
  979. <colgroup>
  980. <col style="width: 20%;">
  981. <col style="width: 40%;">
  982. <col style="width: 40%;">
  983. </colgroup>
  984. <tr>
  985. <th>name</th>
  986. <th>Description</th>
  987. <th>Properties</th>
  988. </tr>
  989. <tr>
  990. <td>click</td>
  991. <td>Fired when clicked inside the Timeline.
  992. </td>
  993. <td>
  994. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  995. </td>
  996. </tr>
  997. <tr>
  998. <td>contextmenu</td>
  999. <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:
  1000. <pre class="prettyprint lang-js">timeline.on('contextmenu', function (props) {
  1001. alert('Right click!');
  1002. props.event.preventDefault();
  1003. });
  1004. </pre>
  1005. </td>
  1006. <td>
  1007. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1008. </td>
  1009. </tr>
  1010. <tr>
  1011. <td>doubleClick</td>
  1012. <td>Fired when double clicked inside the Timeline.
  1013. </td>
  1014. <td>
  1015. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1016. </td>
  1017. </tr>
  1018. <tr>
  1019. <td>rangechange</td>
  1020. <td>Fired repeatedly when the timeline window is being changed.
  1021. </td>
  1022. <td>
  1023. <ul>
  1024. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1025. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1026. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1027. </ul>
  1028. </td>
  1029. </tr>
  1030. <tr>
  1031. <td>rangechanged</td>
  1032. <td>Fired once after the timeline window has been changed.
  1033. </td>
  1034. <td>
  1035. <ul>
  1036. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1037. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1038. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1039. </ul>
  1040. </td>
  1041. </tr>
  1042. <tr>
  1043. <td>select</td>
  1044. <td>Fired after the user selects or deselects items by tapping or holding them.
  1045. When a use taps an already selected item, the select event is fired again.
  1046. Not fired when the method <code>setSelection</code>is executed.
  1047. </td>
  1048. <td>
  1049. <ul>
  1050. <li><code>items</code>: an array with the ids of the selected items</li>
  1051. </ul>
  1052. </td>
  1053. </tr>
  1054. <tr>
  1055. <td>timechange</td>
  1056. <td>Fired repeatedly when the user is dragging the custom time bar.
  1057. Only available when the custom time bar is enabled.
  1058. </td>
  1059. <td>
  1060. <ul>
  1061. <li><code>id</code> (Number | String): custom time bar id.</li>
  1062. <li><code>time</code> (Date): the custom time.</li>
  1063. </ul>
  1064. </td>
  1065. </tr>
  1066. <tr>
  1067. <td>timechanged</td>
  1068. <td>Fired once after the user has dragged the custom time bar.
  1069. Only available when the custom time bar is enabled.
  1070. </td>
  1071. <td>
  1072. <ul>
  1073. <li><code>id</code> (Number | String): custom time bar id.</li>
  1074. <li><code>time</code> (Date): the custom time.</li>
  1075. </ul>
  1076. </td>
  1077. </tr>
  1078. </table>
  1079. <h2 id="Editing_Items">Editing Items</h2>
  1080. <p>
  1081. When the Timeline is configured to be editable (both options <code>selectable</code> and <code>editable</code> are <code>true</code>), the user can:
  1082. </p>
  1083. <ul>
  1084. <li>Select an item by clicking it, and use ctrl+click to or shift+click to select multiple items</li>
  1085. <li>Move selected items by dragging them.</li>
  1086. <li>Create a new item by double tapping on an empty space.</li>
  1087. <li>Create a new range item by dragging on an empty space with the ctrl key down.</li>
  1088. <li>Update an item by double tapping it.</li>
  1089. <li>Delete a selected item by clicking the delete button on the top right.</li>
  1090. </ul>
  1091. <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>
  1092. <pre class="prettyprint lang-js">// enable or disable all manipulation actions
  1093. var options = {
  1094. editable: true // true or false
  1095. };
  1096. // enable or disable individual manipulation actions
  1097. var options = {
  1098. editable: {
  1099. add: true, // add new items by double tapping
  1100. updateTime: true, // drag items horizontally
  1101. updateGroup: true, // drag items from one group to another
  1102. remove: true // delete an item by tapping the delete button top right
  1103. }
  1104. };</pre>
  1105. <p>
  1106. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  1107. </p>
  1108. <ul>
  1109. <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>
  1110. <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>
  1111. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  1112. <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>
  1113. <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>
  1114. </ul>
  1115. <p>
  1116. Each of the callbacks is invoked with two arguments:
  1117. </p>
  1118. <ul>
  1119. <li><code>item</code>: the item being manipulated</li>
  1120. <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>
  1121. </ul>
  1122. <p>
  1123. Example code:
  1124. </p>
  1125. <pre class="prettyprint lang-js">var options = {
  1126. onUpdate: function (item, callback) {
  1127. item.content = prompt('Edit items text:', item.content);
  1128. if (item.content != null) {
  1129. callback(item); // send back adjusted item
  1130. }
  1131. else {
  1132. callback(null); // cancel updating the item
  1133. }
  1134. }
  1135. };
  1136. </pre>
  1137. A full example is available here: <a href="../../examples/timeline/08_manipulation_callbacks.html">08_edit_items.html</a>.
  1138. <h2 id="Templates">Templates</h2>
  1139. <p>
  1140. 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:
  1141. </p>
  1142. <pre class="prettyprint lang-js">var options = {
  1143. template: function (item) {
  1144. var html = ... // generate HTML markup for this item
  1145. return html;
  1146. }
  1147. };
  1148. </pre>
  1149. <h3>Create HTML manually</h3>
  1150. The HTML for an item can be created manually:
  1151. <pre class="prettyprint lang-js">var options = {
  1152. template: function (item) {
  1153. return '&lt;h1&gt;' + item.header + '&lt;/h1&gt;&lt;p&gt;' + item.description + '&lt;/p&gt;';
  1154. }
  1155. };
  1156. </pre>
  1157. <h3>Using a template engine</h3>
  1158. Using <a href="http://handlebarsjs.com/">handlebars</a>, one can write the template in HTML:
  1159. <pre class="prettyprint lang-html">
  1160. &lt;script id="item-template" type="text/x-handlebars-template"&gt;
  1161. &lt;h1&gt;{{header}}&lt;/h1&gt;
  1162. &lt;p&gt;{{description}}&lt;/p&gt;
  1163. &lt;/script&gt;
  1164. </pre>
  1165. Compile the template:
  1166. <pre class="prettyprint lang-js">
  1167. var source = document.getElementById('item-template').innerHTML;
  1168. var template = Handlebars.compile(source);
  1169. </pre>
  1170. And then specify the template in the Timeline options
  1171. <pre class="prettyprint lang-js">var options = {
  1172. template: template
  1173. };
  1174. </pre>
  1175. <h3>Multiple templates</h3>
  1176. In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property:
  1177. <pre class="prettyprint lang-js">
  1178. var templates = {
  1179. template1: Handlebars.compile(...),
  1180. template2: Handlebars.compile(...),
  1181. template2: Handlebars.compile(...),
  1182. ...
  1183. };
  1184. var options = {
  1185. template: function (item) {
  1186. var template = templates[item.template]; // choose the right template
  1187. return template(item); // execute the template
  1188. }
  1189. };
  1190. </pre>
  1191. Now the items can be extended with a property <code>template</code>, specifying which template to use for the item.
  1192. <h2 id="Localization">Localization</h2>
  1193. <p>
  1194. 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.
  1195. </p>
  1196. <p>
  1197. To set a locale for the Timeline, specify the option <code>locale</code>:
  1198. </p>
  1199. <pre class="prettyprint lang-js">var options = {
  1200. locale: 'nl'
  1201. };
  1202. </pre>
  1203. <h3>Create a new locale</h3>
  1204. To load a locale into the Timeline not supported by default, one can add a new locale to the option <code>locales</code>:
  1205. <pre class="prettyprint lang-js">var options = {
  1206. locales: {
  1207. // create a new locale (text strings should be replaced with localized strings)
  1208. mylocale: {
  1209. current: 'current',
  1210. time: 'time',
  1211. }
  1212. },
  1213. // use the new locale
  1214. locale: 'mylocale'
  1215. };
  1216. </pre>
  1217. <h3 id="available-locales">Available locales</h3>
  1218. <p>
  1219. Timeline comes with support for the following locales:
  1220. </p>
  1221. <table>
  1222. <tr><th>Language</th><th>Code</th></tr>
  1223. <tr>
  1224. <td>English</td>
  1225. <td>
  1226. <code>en</code><br>
  1227. <code>en_EN</code><br>
  1228. <code>en_US</code>
  1229. </td>
  1230. </tr>
  1231. <tr>
  1232. <td>Dutch</td>
  1233. <td>
  1234. <code>nl</code><br>
  1235. <code>nl_NL</code><br>
  1236. <code>nl_BE</code>
  1237. </td>
  1238. </tr>
  1239. </table>
  1240. <h2 id="Styles">Styles</h2>
  1241. <p>
  1242. All parts of the Timeline have a class name and a default css style.
  1243. The styles can be overwritten, which enables full customization of the layout
  1244. of the Timeline.
  1245. </p>
  1246. <p>For example, to change the border and background color of all items, include the
  1247. following code inside the head of your html code or in a separate stylesheet.</p>
  1248. <pre class="prettyprint lang-html">&lt;style&gt;
  1249. .vis-item {
  1250. border-color: orange;
  1251. background-color: yellow;
  1252. }
  1253. &lt;/style&gt;
  1254. </pre>
  1255. <h3 id="Grid_Backgrounds">Grid Backgrounds</h3>
  1256. <p>
  1257. The background grid of the time axis can be styled, for example to highlight
  1258. weekends or to create grids with an alternating white/lightgray background.
  1259. </p>
  1260. <p>
  1261. Depending on the zoom level, the grids get certain css classes attached.
  1262. The following classes are available:
  1263. </p>
  1264. <table>
  1265. <tr>
  1266. <th>Description</th><th>values</th>
  1267. </tr>
  1268. <tr>
  1269. <td>Alternating columns</td><td><code>even</code>, <code>odd</code></td>
  1270. </tr>
  1271. <tr>
  1272. <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>
  1273. </tr>
  1274. <tr>
  1275. <td>Hours</td><td><code>h0</code>, <code>h1</code>, ..., <code>h23</code></td>
  1276. </tr>
  1277. <tr>
  1278. <td>Grouped hours</td><td><code>h0-h4</code> to <code>h20-h24</code></td>
  1279. </tr>
  1280. <tr>
  1281. <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>
  1282. </tr>
  1283. <tr>
  1284. <td>Days</td><td><code>date1</code>, <code>date2</code>, ..., <code>date31</code></td>
  1285. </tr>
  1286. <tr>
  1287. <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>
  1288. </tr>
  1289. <tr>
  1290. <td>Years</td><td><code>year2014</code>, <code>year2015</code>, ...</td>
  1291. </tr>
  1292. </table>
  1293. <p>Examples:</p>
  1294. <pre class="prettyprint lang-html">&lt;style&gt;
  1295. /* alternating column backgrounds */
  1296. .vis-time-axis .grid.odd {
  1297. background: #f5f5f5;
  1298. }
  1299. /* gray background in weekends, white text color */
  1300. .vis-time-axis .vis-grid.saturday,
  1301. .vis-time-axis .vis-grid.sunday {
  1302. background: gray;
  1303. }
  1304. .vis-time-axis .vis-text.saturday,
  1305. .vis-time-axis .vis-text.sunday {
  1306. color: white;
  1307. }
  1308. &lt;/style&gt;
  1309. </pre>
  1310. <h2 id="Data_Policy">Data Policy</h2>
  1311. <p>
  1312. All code and data is processed and rendered in the browser.
  1313. No data is sent to any server.
  1314. </p>
  1315. </div>
  1316. </body>
  1317. </html>