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.

2040 lines
82 KiB

9 years ago
  1. <!DOCTYPE html>
  2. <html lang="en"><head>
  3. <meta charset="utf-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="description" content="">
  7. <meta name="author" content="">
  8. <link rel="icon" HREF="favicon.ico">
  9. <title>timeline - vis.js - A dynamic, browser based visualization library.</title>
  10. <!-- Bootstrap core CSS -->
  11. <link href="../css/bootstrap.css" rel="stylesheet">
  12. <!-- Tipue vendor css -->
  13. <link href="../css/tipuesearch.css" rel="stylesheet">
  14. <link href="../css/style.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <link href="../css/prettify.css" type="text/css" rel="stylesheet"/>
  21. <script type="text/javascript" src="../js/googleAnalytics.js"></script>
  22. <script type="text/javascript" src="../js/prettify/prettify.js"></script>
  23. <script src="../js/smooth-scroll.min.js"></script>
  24. <script language="JavaScript">
  25. smoothScroll.init();
  26. </script>
  27. <!-- Tipue vendor css -->
  28. <link href="../css/tipuesearch.css" rel="stylesheet">
  29. <!-- Tipue vendor css -->
  30. <link href="../css/tipuesearch.css" rel="stylesheet">
  31. <script type="text/javascript" src="../js/toggleTable.js"></script>
  32. </head>
  33. <body onload="prettyPrint();">
  34. <div class="navbar-wrapper">
  35. <div class="container">
  36. <nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  37. <div class="container">
  38. <div class="navbar-header">
  39. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
  40. aria-expanded="false" aria-controls="navbar">
  41. <span class="sr-only">Toggle navigation</span>
  42. <span class="icon-bar"></span>
  43. <span class="icon-bar"></span>
  44. <span class="icon-bar"></span>
  45. </button>
  46. <a class="navbar-brand hidden-sm" href="./index.html">vis.js</a>
  47. </div>
  48. <div id="navbar" class="navbar-collapse collapse">
  49. <ul class="nav navbar-nav">
  50. <li><a href="http://www.visjs.org/index.html#modules">Modules</a></li>
  51. <li><a href="http://www.visjs.org/blog.html">Blog</a></li>
  52. <li><a href="http://www.visjs.org/index.html#download_install">Download</a></li>
  53. <li><a href="http://www.visjs.org/showcase/index.html">Showcase</a></li>
  54. <li><a href="http://www.visjs.org/index.html#contribute">Contribute</a></li>
  55. <li><a href="http://www.visjs.org/featureRequests.html">Feature requests</a></li>
  56. <li><a href="http://www.visjs.org/index.html#licenses">License</a></li>
  57. </ul>
  58. </div>
  59. </div>
  60. </nav>
  61. </div>
  62. </div>
  63. <a href="https://github.com/almende/vis" class="hidden-xs hidden-sm hidden-md"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
  64. <div class="container full">
  65. <h1>Timeline</h1>
  66. <h2 id="Overview">Overview</h2>
  67. <p>
  68. The Timeline is an interactive visualization chart to visualize data in time.
  69. The data items can take place on a single date, or have a start and end date (a range).
  70. You can freely move and zoom in the timeline by dragging and scrolling in the
  71. Timeline. Items can be created, edited, and deleted in the timeline.
  72. The time scale on the axis is adjusted automatically, and supports scales ranging
  73. from milliseconds to years.
  74. </p>
  75. <p>
  76. Timeline uses regular HTML DOM to render the timeline and items put on the
  77. timeline. This allows for flexible customization using css styling.
  78. </p>
  79. <h2 id="Contents">Contents</h2>
  80. <ul>
  81. <li><a href="#Overview">Overview</a></li>
  82. <li><a href="#Example">Example</a></li>
  83. <li><a href="#Loading">Loading</a></li>
  84. <li><a href="#Data_Format">Data Format</a>
  85. <ul>
  86. <li><a href="#items">Items</a></li>
  87. <li><a href="#groups">Groups</a></li>
  88. </ul>
  89. </li>
  90. <li><a href="#Configuration_Options">Configuration Options</a></li>
  91. <li><a href="#Methods">Methods</a></li>
  92. <li><a href="#Events">Events</a></li>
  93. <li><a href="#Editing_Items">Editing Items</a></li>
  94. <li><a href="#Templates">Templates</a></li>
  95. <li><a href="#Localization">Localization</a></li>
  96. <li><a href="#Time_zone">Time zone</a></li>
  97. <li><a href="#Styles">Styles</a></li>
  98. </ul>
  99. <h2 id="Example">Example</h2>
  100. <p>
  101. The following code shows how to create a Timeline and provide it with data.
  102. More examples can be found in the <a href="../../timeline_examples.html">timeline examples</a> page.
  103. </p>
  104. <pre class="prettyprint lang-html">&lt;!DOCTYPE HTML&gt;
  105. &lt;html&gt;
  106. &lt;head&gt;
  107. &lt;title&gt;Timeline | Basic demo&lt;/title&gt;
  108. &lt;style type="text/css"&gt;
  109. body, html {
  110. font-family: sans-serif;
  111. }
  112. &lt;/style&gt;
  113. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  114. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  115. &lt;/head&gt;
  116. &lt;body&gt;
  117. &lt;div id="visualization"&gt;&lt;/div&gt;
  118. &lt;script type="text/javascript"&gt;
  119. // DOM element where the Timeline will be attached
  120. var container = document.getElementById('visualization');
  121. // Create a DataSet (allows two way data-binding)
  122. var items = new vis.DataSet([
  123. {id: 1, content: 'item 1', start: '2013-04-20'},
  124. {id: 2, content: 'item 2', start: '2013-04-14'},
  125. {id: 3, content: 'item 3', start: '2013-04-18'},
  126. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  127. {id: 5, content: 'item 5', start: '2013-04-25'},
  128. {id: 6, content: 'item 6', start: '2013-04-27'}
  129. ]);
  130. // Configuration for the Timeline
  131. var options = {};
  132. // Create a Timeline
  133. var timeline = new vis.Timeline(container, items, options);
  134. &lt;/script&gt;
  135. &lt;/body&gt;
  136. &lt;/html&gt;
  137. </pre>
  138. <h2 id="Loading">Loading</h2>
  139. <p>
  140. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library
  141. in a subfolder of your project. Include the library's script and css files in the
  142. head of your html code:
  143. </p>
  144. <pre class="prettyprint lang-html">
  145. &lt;script src="vis/dist/vis.js"&gt;&lt;/script&gt;
  146. &lt;link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  147. </pre>
  148. The constructor of the Timeline is <code>vis.Timeline</code>
  149. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, options);</pre>
  150. or when using groups:
  151. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, groups, options);</pre>
  152. The constructor accepts four parameters:
  153. <ul>
  154. <li>
  155. <code>container</code> is the DOM element in which to create the timeline.
  156. </li>
  157. <li>
  158. <code>items</code> is an Array containing items. The properties of an
  159. item are described in section <a href="#Data_Format">Data Format, items</a>.
  160. </li><li>
  161. <code>groups</code> is an Array containing groups. The properties of a
  162. group are described in section <a href="#groups">Data Format, groups</a>.
  163. </li>
  164. <li>
  165. <code>options</code> is an optional Object containing a name-value map
  166. with options. Options can also be set using the method
  167. <code>setOptions</code>.
  168. </li>
  169. </ul>
  170. <h2 id="Data_Format">Data Format</h2>
  171. <p>
  172. The timeline can be provided with two types of data:
  173. </p>
  174. <ul>
  175. <li><a href="#items">Items</a> containing a set of items to be displayed in time.</li>
  176. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  177. together.</li>
  178. </ul>
  179. <h3 id="items">Items</h3>
  180. <p>
  181. For items, the Timeline accepts an Array, a DataSet (offering 2 way data binding),
  182. or a DataView (offering 1 way data binding).
  183. Items are regular objects and can contain the properties <code>start</code>,
  184. <code>end</code> (optional), <code>content</code>,
  185. <code>group</code> (optional), <code>className</code> (optional),
  186. <code>editable</code> (optional), and <code>style</code> (optional).
  187. </p>
  188. <p>
  189. A DataSet is constructed as:
  190. </p>
  191. <pre class="prettyprint lang-js">
  192. var items = new vis.DataSet([
  193. {
  194. start: new Date(2010, 7, 15),
  195. end: new Date(2010, 8, 2), // end is optional
  196. content: 'Trajectory A'
  197. // Optional: fields 'id', 'type', 'group', 'className', 'style'
  198. }
  199. // more items...
  200. ]);
  201. </pre>
  202. <p>
  203. The item properties are defined as:
  204. </p>
  205. <table class="properties" id="itemOptionTable">
  206. <tr>
  207. <th>Name</th>
  208. <th>Type</th>
  209. <th>Required</th>
  210. <th>Description</th>
  211. </tr>
  212. <tr>
  213. <td>className</td>
  214. <td>String</td>
  215. <td>no</td>
  216. <td>This field is optional. A className can be used to give items
  217. an individual css style. For example, when an item has className
  218. 'red', one can define a css style like:
  219. <pre class="prettyprint lang-css">
  220. .vis-item.red {
  221. color: white;
  222. background-color: red;
  223. border-color: darkred;
  224. }</pre>
  225. More details on how to style items can be found in the section
  226. <a href="#Styles">Styles</a>.
  227. </td>
  228. </tr>
  229. <tr>
  230. <td>content</td>
  231. <td>String</td>
  232. <td>yes</td>
  233. <td>The contents of the item. This can be plain text or html code.</td>
  234. </tr>
  235. <tr>
  236. <td>end</td>
  237. <td>Date or number or string or Moment</td>
  238. <td>no</td>
  239. <td>The end date of the item. The end date is optional, and can be left <code>null</code>.
  240. If end date is provided, the item is displayed as a range.
  241. If not, the item is displayed as a box.</td>
  242. </tr>
  243. <tr>
  244. <td>group</td>
  245. <td>any type</td>
  246. <td>no</td>
  247. <td>This field is optional. When the group column is provided,
  248. all items with the same group are placed on one line.
  249. A vertical axis is displayed showing the groups.
  250. Grouping items can be useful for example when showing availability of multiple
  251. people, rooms, or other resources next to each other.<br>
  252. </td>
  253. </tr>
  254. <tr>
  255. <td>id</td>
  256. <td>String or Number</td>
  257. <td>no</td>
  258. <td>An id for the item. Using an id is not required but highly
  259. recommended. An id is needed when dynamically adding, updating,
  260. and removing items in a DataSet.</td>
  261. </tr>
  262. <tr>
  263. <td>start</td>
  264. <td>Date or number or string or Moment</td>
  265. <td>yes</td>
  266. <td>The start date of the item, for example <code>new Date(2010,9,23)</code>.</td>
  267. </tr>
  268. <tr>
  269. <td>style</td>
  270. <td>String</td>
  271. <td>no</td>
  272. <td>
  273. A css text string to apply custom styling for an individual item, for
  274. example <code>"color: red; background-color: pink;"</code>.
  275. </td>
  276. </tr>
  277. <tr>
  278. <td>subgroup</td>
  279. <td>String or Number</td>
  280. <td>none</td>
  281. <td>The id of a subgroup.
  282. Groups all items within a group per subgroup, and positions them on the
  283. same height instead of staking them on top of each other. can be ordered
  284. by specifying the option <code>subgroupOrder</code> of a group.
  285. </td>
  286. </tr>
  287. <tr>
  288. <td>title</td>
  289. <td>String</td>
  290. <td>none</td>
  291. <td>Add a title for the item, displayed when holding the mouse on the item.
  292. The title can be an HTML element or a string containing plain text or HTML.
  293. </td>
  294. </tr>
  295. <tr>
  296. <td>type</td>
  297. <td>String</td>
  298. <td>no</td>
  299. <td>The type of the item. Can be 'box' (default), 'point', 'range', or 'background'.
  300. Types 'box' and 'point' need a start date, the types 'range' and 'background' needs both a start and end date.
  301. </td>
  302. </tr>
  303. <tr class='toggle collapsible' onclick="toggleTable('itemOptionTable', 'itemEditable', this);">
  304. <td><span parent="itemEditable" class="right-caret"></span> editable</td>
  305. <td>Boolean or Object</td>
  306. <td>no</td>
  307. <td>Override the editable option of the timeline for a specific item (assuming <code>timeline.editable.overrideItems</code> is false).</td>
  308. </tr>
  309. <tr parent="itemEditable" class="hidden">
  310. <td class="indent">editable.remove</td>
  311. <td>boolean</td>
  312. <td>no</td>
  313. <td>If true, item can be deleted by first selecting it, 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>
  314. </tr>
  315. <tr parent="itemEditable" class="hidden">
  316. <td class="indent">editable.updateGroup</td>
  317. <td>boolean</td>
  318. <td>no</td>
  319. <td>If true, item 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>
  320. </tr>
  321. <tr parent="itemEditable" class="hidden">
  322. <td class="indent">editable.updateTime</td>
  323. <td>boolean</td>
  324. <td>no</td>
  325. <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>
  326. </tr>
  327. </table>
  328. <h3 id="groups">Groups</h3>
  329. <p>
  330. For the items, groups can be an Array, a DataSet (offering 2 way data binding),
  331. or a DataView (offering 1 way data binding).
  332. Using groups, items can be grouped together.
  333. Items are filtered per group, and displayed as
  334. Group items can contain the properties <code>id</code>,
  335. <code>content</code>, and <code>className</code> (optional).
  336. </p>
  337. <p>
  338. Groups can be applied to a timeline using the method <code>setGroups</code> or supplied in the constructor.
  339. A table with groups can be created like:
  340. </p>
  341. <pre class="prettyprint lang-js">
  342. var groups = [
  343. {
  344. id: 1,
  345. content: 'Group 1'
  346. // Optional: a field 'className', 'style', 'order', [properties]
  347. }
  348. // more groups...
  349. ]);
  350. </pre>
  351. <p>
  352. Groups can have the following properties:
  353. </p>
  354. <table class="properties">
  355. <tr>
  356. <th>Name</th>
  357. <th>Type</th>
  358. <th>Required</th>
  359. <th>Description</th>
  360. </tr>
  361. <tr>
  362. <td>className</td>
  363. <td>String</td>
  364. <td>no</td>
  365. <td>This field is optional. A className can be used to give groups
  366. an individual css style. For example, when a group has className
  367. 'red', one can define a css style
  368. <code>
  369. .red {
  370. color: red;
  371. }
  372. </code>.
  373. More details on how to style groups can be found in the section
  374. <a href="#Styles">Styles</a>.
  375. </td>
  376. </tr>
  377. <tr>
  378. <td>content</td>
  379. <td>String or Element</td>
  380. <td>yes</td>
  381. <td>The contents of the group. This can be plain text, html code or an html element.</td>
  382. </tr>
  383. <tr>
  384. <td>id</td>
  385. <td>String or Number</td>
  386. <td>yes</td>
  387. <td>An id for the group. The group will display all items having a
  388. property <code>group</code> which matches the <code>id</code>
  389. of the group.</td>
  390. </tr>
  391. <tr>
  392. <td>style</td>
  393. <td>String</td>
  394. <td>no</td>
  395. <td>
  396. A css text string to apply custom styling for an individual group label, for
  397. example <code>"color: red; background-color: pink;"</code>.
  398. </td>
  399. </tr>
  400. <tr>
  401. <td>subgroupOrder</td>
  402. <td>String or Function</td>
  403. <td>none</td>
  404. <td>Order the subgroups by a field name or custom sort function.
  405. By default, groups are ordered by first-come, first-show.
  406. </td>
  407. </tr>
  408. <tr>
  409. <td>title</td>
  410. <td>String</td>
  411. <td>none</td>
  412. <td>A title for the group, displayed when holding the mouse on the groups label.
  413. The title can only contain plain text.
  414. </td>
  415. </tr>
  416. <tr>
  417. <td>visible</td>
  418. <td>Boolean</td>
  419. <td>no</td>
  420. <td>Provides a means to toggle the whether a group is displayed or not. Defaults to <code>true</code>.</td>
  421. </tr>
  422. <tr>
  423. <td>nestedGroups</td>
  424. <td>Array</td>
  425. <td>no</td>
  426. <td>Array of group ids nested in the group. Nested groups will appear under this nesting group.</td>
  427. </tr>
  428. <tr>
  429. <td>showNested</td>
  430. <td>Boolean</td>
  431. <td>no</td>
  432. <td>Assuming the group has nested groups, this will set the initial state of the group - shown or collapsed. The <code>showNested</code> is defaulted to <code>true</code>.</td>
  433. </tr>
  434. </table>
  435. <h2 id="Configuration_Options">Configuration Options</h2>
  436. <p>
  437. Options can be used to customize the timeline.
  438. Options are defined as a JSON object. All options are optional.
  439. </p>
  440. <pre class="prettyprint lang-js">
  441. var options = {
  442. width: '100%',
  443. height: '30px',
  444. margin: {
  445. item: 20
  446. }
  447. };
  448. </pre>
  449. <p>
  450. The following options are available.
  451. </p>
  452. <table class="options" id="optionTable">
  453. <tr>
  454. <th>Name</th>
  455. <th>Type</th>
  456. <th>Default</th>
  457. <th>Description</th>
  458. </tr>
  459. <tr>
  460. <td>align</td>
  461. <td>String</td>
  462. <td><code>'center'</code></td>
  463. <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>
  464. </tr>
  465. <tr>
  466. <td>autoResize</td>
  467. <td>boolean</td>
  468. <td><code>true</code></td>
  469. <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>
  470. </tr>
  471. <tr>
  472. <td>clickToUse</td>
  473. <td>boolean</td>
  474. <td><code>false</code></td>
  475. <td>When a Timeline is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  476. 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>
  477. </tr>
  478. <tr>
  479. <td>configure</td>
  480. <td>boolean or function</td>
  481. <td><code>false</code></td>
  482. <td>When true, a configurator is loaded where all configuration options of the Timeline can be changed live.
  483. The displayed options can be filtered by providing a filter function. This function is invoked with two arguments: the current <code>option</code> and the <code>path</code> (an Array) of the option within the options object. The option will be displayed when the filter function returns true. For example to only display format options:
  484. <pre class="prettyprint lang-js">
  485. function (option, path) {
  486. return option === 'format' || path.indexOf('format') !== -1;
  487. }</pre>
  488. </td>
  489. </tr>
  490. <tr>
  491. <td>dataAttributes</td>
  492. <td>string[] or 'all'</string></td>
  493. <td><code>false</code></td>
  494. <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>
  495. If value is <code>'all'</code> then each field defined on the timeline item will become a <code>data-</code> attribute.</td>
  496. </tr>
  497. <tr class='toggle collapsible' onclick="toggleTable('optionTable','editable', this);">
  498. <td><span parent="editable" class="right-caret"></span> editable</td>
  499. <td>boolean or Object</td>
  500. <td><code>false</code></td>
  501. <td>If true, the items in the timeline can be manipulated. Only applicable when option <code>selectable</code> is <code><code>true</code></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.
  502. See section <a href="#Editing_Items">Editing Items</a> for a detailed explanation.
  503. </td>
  504. </tr>
  505. <tr parent="editable" class="hidden">
  506. <td class="indent">editable.add</td>
  507. <td>boolean</td>
  508. <td><code>false</code></td>
  509. <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>
  510. </tr>
  511. <tr parent="editable" class="hidden">
  512. <td class="indent">editable.remove</td>
  513. <td>boolean</td>
  514. <td><code>false</code></td>
  515. <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>
  516. </tr>
  517. <tr parent="editable" class="hidden">
  518. <td class="indent">editable.updateGroup</td>
  519. <td>boolean</td>
  520. <td><code>false</code></td>
  521. <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>
  522. </tr>
  523. <tr parent="editable" class="hidden">
  524. <td class="indent">editable.updateTime</td>
  525. <td>boolean</td>
  526. <td><code>false</code></td>
  527. <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>
  528. </tr>
  529. <tr parent="editable" class="hidden">
  530. <td class="indent">editable.overrideItems</td>
  531. <td>boolean</td>
  532. <td><code>false</code></td>
  533. <td>If true, item specific editable properties are overridden by timeline settings</td>
  534. </tr>
  535. <tr>
  536. <td>end</td>
  537. <td>Date or Number or String or Moment</td>
  538. <td>none</td>
  539. <td>The initial end date for the axis of the timeline.
  540. If not provided, the latest date present in the items set is taken as
  541. end date.</td>
  542. </tr>
  543. <tr>
  544. <td>format</td>
  545. <td>Object or Function</td>
  546. <td>none</td>
  547. <td>
  548. Apply custom date formatting of the labels on the time axis. The default value of <code>format</code> is:
  549. <pre class="prettyprint lang-js">{
  550. minorLabels: {
  551. millisecond:'SSS',
  552. second: 's',
  553. minute: 'HH:mm',
  554. hour: 'HH:mm',
  555. weekday: 'ddd D',
  556. day: 'D',
  557. month: 'MMM',
  558. year: 'YYYY'
  559. },
  560. majorLabels: {
  561. millisecond:'HH:mm:ss',
  562. second: 'D MMMM HH:mm',
  563. minute: 'ddd D MMMM',
  564. hour: 'ddd D MMMM',
  565. weekday: 'MMMM YYYY',
  566. day: 'MMMM YYYY',
  567. month: 'YYYY',
  568. year: ''
  569. }
  570. }</pre>
  571. For values which not provided in the customized <code>options.format</code>, the default values will be used.
  572. All available formatting syntax is described in the <a href="http://momentjs.com/docs/#/displaying/format/">docs of moment.js</a>.
  573. <br>
  574. You can also use a function format for each label. The function accepts as arguments the date, scale and step in that order, and expects to return a string for the label.
  575. <pre class="prettyprint lang-js">function format({
  576. minorLabels: Function(date: Date, scale: Number, step: Number),
  577. majorLabels: Function(date: Date, scale: Number, step: Number)
  578. }</pre>
  579. </td>
  580. </tr>
  581. <tr class='toggle collapsible' onclick="toggleTable('optionTable','groupEditable', this);">
  582. <td><span parent="groupEditable" class="right-caret"></span> groupEditable</td>
  583. <td>boolean or Object</td>
  584. <td><code>false</code></td>
  585. <td>If true, the groups in the timeline can be manipulated. See also the callbacks <code>onAddGroup</code>, <code>onMoveGroup</code>, and <code>onRemoveGroup</code>. When <code>groupEditable</code> is an object, one can enable or disable individual manipulation actions.
  586. The editing of groups follows the same principles as for items, see section <a href="#Editing_Items">Editing Items</a> for a detailed explanation.
  587. </td>
  588. </tr>
  589. <tr parent="groupEditable" class="hidden">
  590. <td class="indent">groupEditable.add</td>
  591. <td>boolean</td>
  592. <td><code>false</code></td>
  593. <td>If true, new groups can be created in the Timeline. For now adding new groups is done by the user.</td>
  594. </tr>
  595. <tr parent="groupEditable" class="hidden">
  596. <td class="indent">groupEditable.remove</td>
  597. <td>boolean</td>
  598. <td><code>false</code></td>
  599. <td>If true, groups can be deleted. For now removing groups is done by the user.</td>
  600. </tr>
  601. <tr parent="groupEditable" class="hidden">
  602. <td class="indent">groupEditable.order</td>
  603. <td>boolean</td>
  604. <td><code>false</code></td>
  605. <td>If true, groups can be dragged to change their order. Only applicable when the Timeline has groups. For this option to work properly the groupOrder and groupOrderSwap options have to be set as well.</td>
  606. </tr>
  607. <tr>
  608. <td>groupOrder</td>
  609. <td>String or Function</td>
  610. <td>'order'</td>
  611. <td>Order the groups by a field name or custom sort function.
  612. By default, groups are ordered by a property <code>order</code> (if set).
  613. If no <code>order</code> properties are provided, the order will be undetermined.
  614. </td>
  615. </tr>
  616. <tr>
  617. <td>groupOrderSwap</td>
  618. <td>Function</td>
  619. <td>none</td>
  620. <td>Swaps the positions of two groups. If groups have a custom order (via <code>groupOrder</code>) and groups are configured to be reorderable (via <code>groupEditable.order</code>), the user has to provide a function that swaps the positions of two given groups.
  621. If this option is not set, the default implementation assumes that groups hold an attribute <code>order</code> which values are changed. The signature of the <code>groupOrderWap</code> function is:
  622. <pre class="prettyprint lang-js">function groupOrderSwap(fromGroup: Object, toGroup: Object, groups: DataSet)</pre>
  623. The first to arguments hold the groups of which the positions are to be swapped and the third argument holds the DataSet with all groups.
  624. </td>
  625. </tr>
  626. <tr>
  627. <td>groupTemplate</td>
  628. <td>function</td>
  629. <td>none</td>
  630. <td>A template function used to generate the contents of the groups. The function is called by the Timeline with a groups data as the first argument and the group element as the second, and must return HTML code, a string or a template as result. When the option groupTemplate is specified, the groups do not need to have a field <code>content</code>. See section <a href="#Templates">Templates</a> for a detailed explanation.</td>
  631. </tr>
  632. <tr>
  633. <td>height</td>
  634. <td>number or String</td>
  635. <td>none</td>
  636. <td>The height of the timeline in pixels or as a percentage.
  637. When height is undefined or null, the height of the timeline is automatically
  638. adjusted to fit the contents.
  639. It is possible to set a maximum height using option <code>maxHeight</code>
  640. to prevent the timeline from getting too high in case of automatically
  641. calculated height.
  642. </td>
  643. </tr>
  644. <tr>
  645. <td>hiddenDates</td>
  646. <td>Object</td>
  647. <td>none</td>
  648. <td>This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
  649. <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.
  650. 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
  651. and set repeat to weekly.
  652. </td>
  653. </tr>
  654. <tr>
  655. <td>horizontalScroll</td>
  656. <td>Boolean</td>
  657. <td>false</td>
  658. <td>This option allows you to scroll horizontally to move backwards and forwards in the time range.
  659. Only applicable when option <code>zoomCtrl</code> is defined or <code>zoomable</code> is <code>false</code>. Notice that defining this option as <code>true</code> will override <code>verticalScroll</code> scroll event but not eliminate the vertical scrollbar.
  660. </td>
  661. </tr>
  662. <tr>
  663. <td>itemsAlwaysDraggable</td>
  664. <td>boolean</td>
  665. <td><code>false</code></td>
  666. <td>If true, all items in the Timeline are draggable without being selected. If false, only the selected item(s) are draggable.</td>
  667. </tr>
  668. <tr>
  669. <td>locale</td>
  670. <td>String</td>
  671. <td>none</td>
  672. <td>Select a locale for the Timeline. See section <a href="#Localization">Localization</a> for more information.</td>
  673. </tr>
  674. <tr>
  675. <td>locales</td>
  676. <td>Object</td>
  677. <td>none</td>
  678. <td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
  679. </tr>
  680. <tr>
  681. <td>moment</td>
  682. <td>function</td>
  683. <td>vis.moment</td>
  684. <td>A constructor for creating a moment.js Date. Allows for applying a custom time zone. See section <a href="#Time_zone">Time zone</a> for more information.</td>
  685. </tr>
  686. <tr class='toggle collapsible' onclick="toggleTable('optionTable','margin', this);">
  687. <td><span parent="margin" class="right-caret"></span> margin</td>
  688. <td>number or Object</td>
  689. <td>Object</td>
  690. <td>When a number, applies the margin to <code>margin.axis</code>, <code>margin.item.horizontal</code>, and <code>margin.item.vertical</code>.</td>
  691. </tr>
  692. <tr parent="margin" class="hidden">
  693. <td class="indent">margin.axis</td>
  694. <td>number</td>
  695. <td><code>20</code></td>
  696. <td>The minimal margin in pixels between items and the time axis.</td>
  697. </tr>
  698. <tr parent="margin" class="hidden">
  699. <td class="indent">margin.item</td>
  700. <td>number</td>
  701. <td><code>10</code></td>
  702. <td>The minimal margin in pixels between items in both horizontal and vertical direction.</td>
  703. </tr>
  704. <tr parent="margin" class="hidden">
  705. <td class="indent2">margin.item.horizontal</td>
  706. <td>number</td>
  707. <td><code>10</code></td>
  708. <td>The minimal horizontal margin in pixels between items.</td>
  709. </tr>
  710. <tr parent="margin" class="hidden">
  711. <td class="indent2">margin.item.vertical</td>
  712. <td>number</td>
  713. <td><code>10</code></td>
  714. <td>The minimal vertical margin in pixels between items.</td>
  715. </tr>
  716. <tr>
  717. <td>max</td>
  718. <td>Date or Number or String or Moment</td>
  719. <td>none</td>
  720. <td>Set a maximum Date for the visible range.
  721. It will not be possible to move beyond this maximum.
  722. </td>
  723. </tr>
  724. <tr>
  725. <td>maxHeight</td>
  726. <td>number or String</td>
  727. <td>none</td>
  728. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  729. </tr>
  730. <tr>
  731. <td>maxMinorChars</td>
  732. <td>number</td>
  733. <td>7</td>
  734. <td>
  735. Specifies the maximum number of characters that should fit in minor grid labels.
  736. If larger, less and wider grids will be drawn.
  737. </td>
  738. </tr>
  739. <tr>
  740. <td>min</td>
  741. <td>Date or Number or String or Moment</td>
  742. <td>none</td>
  743. <td>Set a minimum Date for the visible range.
  744. It will not be possible to move beyond this minimum.
  745. </td>
  746. </tr>
  747. <tr>
  748. <td>minHeight</td>
  749. <td>number or String</td>
  750. <td>none</td>
  751. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  752. </tr>
  753. <tr>
  754. <td>moveable</td>
  755. <td>boolean</td>
  756. <td><code>true</code></td>
  757. <td>
  758. Specifies whether the Timeline can be moved and zoomed by dragging the window.
  759. See also option <code>zoomable</code>.
  760. </td>
  761. </tr>
  762. <tr>
  763. <td>multiselect</td>
  764. <td>boolean</td>
  765. <td><code>false</code></td>
  766. <td>
  767. If true, multiple items can be selected using ctrl+click, shift+click, or by holding items.
  768. Only applicable when option <code>selectable</code> is <code>true</code>.
  769. </td>
  770. </tr>
  771. <tr>
  772. <td style="font-size: 0.9em">multiselectPerGroup</td>
  773. <td>boolean</td>
  774. <td><code>false</code></td>
  775. <td>
  776. If true, selecting multiple items using shift+click will only select items residing in the same group as the <i>first</i> selected item.
  777. Only applicable when option <code>selectable</code> and <code>multiselect</code> are <code>true</code>.
  778. </td>
  779. </tr>
  780. <tr>
  781. <td>onAdd</td>
  782. <td>function</td>
  783. <td>none</td>
  784. <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><code>true</code></code>.
  785. </td>
  786. </tr>
  787. <tr>
  788. <td>onAddGroup</td>
  789. <td>function</td>
  790. <td>none</td>
  791. <td>Callback function triggered when a group is about to be added. The signature and semantics are the same as for <code>onAdd</code>.
  792. </td>
  793. </tr>
  794. <tr>
  795. <td>onUpdate</td>
  796. <td>function</td>
  797. <td>none</td>
  798. <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><code>true</code></code>.
  799. </td>
  800. </tr>
  801. <tr>
  802. <td>onMove</td>
  803. <td>function</td>
  804. <td>none</td>
  805. <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><code>true</code></code>.
  806. </td>
  807. </tr>
  808. <tr>
  809. <td>onMoveGroup</td>
  810. <td>function</td>
  811. <td>none</td>
  812. <td>Callback function triggered when a group has been moved: after the user has dragged the group to an other position. The signature and semantics are the same as for <code>onMove</code>.
  813. </td>
  814. </tr>
  815. <tr>
  816. <td>onMoving</td>
  817. <td>function</td>
  818. <td>none</td>
  819. <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><code>true</code></code>.
  820. </td>
  821. </tr>
  822. <tr>
  823. <td>onRemove</td>
  824. <td>function</td>
  825. <td>none</td>
  826. <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><code>true</code></code>.
  827. </td>
  828. </tr>
  829. <tr>
  830. <td>onRemoveGroup</td>
  831. <td>function</td>
  832. <td>none</td>
  833. <td>Callback function triggered when a group is about to be removed. The signature and semantics are the same as for <code>onRemove</code>.
  834. </td>
  835. </tr>
  836. <tr>
  837. <td>order</td>
  838. <td>function</td>
  839. <td>none</td>
  840. <td>
  841. <p>Provide a custom sort function to order the items. The order of the
  842. items is determining the way they are stacked. The function
  843. order is called with two arguments containing the data of two items to be
  844. compared.
  845. </p>
  846. <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>
  847. </td>
  848. </tr>
  849. <tr class='toggle collapsible' onclick="toggleTable('optionTable','orientation', this);">
  850. <td><span parent="orientation" class="right-caret"></span> orientation</td>
  851. <td>String or Object</td>
  852. <td><code>'bottom'</code></td>
  853. <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), 'both', or 'none'.</td>
  854. </tr>
  855. <tr parent="orientation" class="hidden">
  856. <td class="indent">orientation.axis</td>
  857. <td>String</td>
  858. <td><code>'bottom'</code></td>
  859. <td>Orientation of the timeline axis: 'top', 'bottom' (default), 'both', or 'none'. 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. In case of 'none', no axis is drawn at all.</td>
  860. </tr>
  861. <tr parent="orientation" class="hidden">
  862. <td class="indent">orientation.item</td>
  863. <td>String</td>
  864. <td><code>'bottom'</code></td>
  865. <td>Orientation of the timeline items: 'top' or 'bottom' (default). Determines whether items are aligned to the top or bottom of the Timeline.</td>
  866. </tr>
  867. <tr>
  868. <td>rollingMode</td>
  869. <td>boolean</td>
  870. <td><code>false</code></td>
  871. <td>If true, the timeline will initial in a rolling mode - the current time will always be centered. I the user drags the timeline, the timeline will go out of rolling mode and a toggle button will appear. Clicking that button will go back to rolling mode. Zooming in rolling mode will zoom in to the center without consideration of the mouse position.</td>
  872. </tr>
  873. <tr>
  874. <td>rtl</td>
  875. <td>boolean</td>
  876. <td><code>false</code></td>
  877. <td>If true, the timeline will be right-to-left. Note: you can achieve rtl timeline by defining a parent node with <code>dir="rtl"</code>. The timeline knows to take the nearest parent node direction and apply it. Notice that the timeline will prefer the <code>option.rtl</code> over any parent <code>dir="rtl"</code></td>
  878. </tr>
  879. <tr>
  880. <td>selectable</td>
  881. <td>boolean</td>
  882. <td><code>true</code></td>
  883. <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>
  884. </tr>
  885. <tr>
  886. <td>showCurrentTime</td>
  887. <td>boolean</td>
  888. <td><code>true</code></td>
  889. <td>Show a vertical bar at the current time.</td>
  890. </tr>
  891. <tr>
  892. <tr>
  893. <td>showMajorLabels</td>
  894. <td>boolean</td>
  895. <td><code>true</code></td>
  896. <td>By default, the timeline shows both minor and major date labels on the
  897. time axis.
  898. For example the minor labels show minutes and the major labels show hours.
  899. When <code>showMajorLabels</code> is <code><code>false</code></code>, no major labels
  900. are shown.</td>
  901. </tr>
  902. <tr>
  903. <td>showMinorLabels</td>
  904. <td>boolean</td>
  905. <td><code>true</code></td>
  906. <td>By default, the timeline shows both minor and major date labels on the
  907. time axis.
  908. For example the minor labels show minutes and the major labels show hours.
  909. When <code>showMinorLabels</code> is <code><code>false</code></code>, no minor labels
  910. are shown. When both <code>showMajorLabels</code> and
  911. <code>showMinorLabels</code> are false, no horizontal axis will be
  912. visible.</td>
  913. </tr>
  914. <tr>
  915. <td>stack</td>
  916. <td>boolean</td>
  917. <td><code>true</code></td>
  918. <td>If true (default), items will be stacked on top of each other such that they do not overlap.</td>
  919. </tr>
  920. <tr>
  921. <td>stackSubgroups</td>
  922. <td>boolean</td>
  923. <td><code>true</code></td>
  924. <td>If true (default), subgroups will be stacked on top of each other such that they do not overlap.</td>
  925. </tr>
  926. <tr>
  927. <td>snap</td>
  928. <td>function or null</td>
  929. <td>function</td>
  930. <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:
  931. <pre class="prettyprint lang-js">function snap(date: Date, scale: string, step: number) : Date or number</pre>
  932. 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.
  933. </td>
  934. </tr>
  935. <tr>
  936. <td>start</td>
  937. <td>Date or Number or String or Moment</td>
  938. <td>none</td>
  939. <td>The initial start date for the axis of the timeline.
  940. If not provided, the earliest date present in the events is taken as start date.</td>
  941. </tr>
  942. <tr>
  943. <td>template</td>
  944. <td>function</td>
  945. <td>none</td>
  946. <td>A template function used to generate the contents of the items. The function is called by the Timeline with an items' data as the first argument, the item element as the second argument and the edited data as the third argument, and must return HTML code, a string or a template 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>
  947. </tr>
  948. <tr>
  949. <td>visibleFrameTemplate</td>
  950. <td>function</td>
  951. <td>none</td>
  952. <td>A template function used to generate the visible frame of the items. The function is called by the Timeline with an items' data as the first argument and the item frame element as the second, and must return HTML code, a string or a template 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.
  953. This would be used as an additional way to add content that is constant in size with the visible frame of the item and does not get visibly hidden with the item's internal container: <code>vis-item-overflow</code> which is <code>overflow:hidden</code>.</td>
  954. </tr>
  955. <tr class='deprecated'>
  956. <td>throttleRedraw</td>
  957. <td>number</td>
  958. <td><code>0</code></td>
  959. <td>This option is <b>DEPRECATED</b> and no longer supported. It will be removed in the next MAJOR release.</td>
  960. </tr>
  961. <tr class='toggle collapsible' onclick="toggleTable('optionTable','timeAxis', this);">
  962. <td><span parent="timeAxis" class="right-caret"></span> timeAxis</td>
  963. <td>Object</td>
  964. <td><code>Object</code></td>
  965. <td>Specify a fixed scale and step size for the time axis.</td>
  966. </tr>
  967. <tr parent="timeAxis" class="hidden">
  968. <td class="indent">timeAxis.scale</td>
  969. <td>String</td>
  970. <td>none</td>
  971. <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:
  972. <pre class="prettyprint lang-js">var options = {
  973. timeAxis: {scale: 'minute', step: 5}
  974. }</pre>
  975. </td>
  976. </tr>
  977. <tr parent="timeAxis" class="hidden">
  978. <td class="indent">timeAxis.step</td>
  979. <td>number</td>
  980. <td><code>1</code></td>
  981. <td>
  982. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  983. Choose for example 1, 2, 5, or 10.</td>
  984. </tr>
  985. <tr>
  986. <td>type</td>
  987. <td>String</td>
  988. <td>none</td>
  989. <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.
  990. </td>
  991. </tr>
  992. <tr class='toggle collapsible' onclick="toggleTable('optionTable','tooltip', this);">
  993. <td><span parent="tooltip" class="right-caret"></span> tooltip</td>
  994. <td>Object</td>
  995. <td><code>Object</code></td>
  996. <td>Specify how the tooltip is positioned.</td>
  997. </tr>
  998. <tr parent="tooltip" class="hidden">
  999. <td class="indent">tooltip.followMouse</td>
  1000. <td>boolean</td>
  1001. <td><code>false</code></td>
  1002. <td>If true, tooltips will follow the mouse as they move around in the item.</td>
  1003. </tr>
  1004. <tr parent="tooltip" class="hidden">
  1005. <td class="indent">tooltip.overflowMethod</td>
  1006. <td>String</td>
  1007. <td><code>'flip'</code></td>
  1008. <td>
  1009. Set how the tooltip should act if it is about to overflow out of the timeline.<br />
  1010. Choose from <code>'cap'</code> and <code>'flip'</code>. <br />
  1011. If it is set to <code>'cap'</code>, the tooltip will just cap its position to inside to timeline. <br />
  1012. While if it is set to <code>'flip'</code>, the position of the tooltip will flip around the cursor so that a corner is at the cursor, and the rest of it is visible. <br />
  1013. </tr>
  1014. <tr class='toggle collapsible' onclick="toggleTable('optionTable','tooltipOnItemUpdateTime', this);">
  1015. <td><span parent="tooltipOnItemUpdateTime" class="right-caret"></span> tooltipOnItemUpdateTime</td>
  1016. <td>Object/Boolean</td>
  1017. <td><code>false</code></td>
  1018. <td>Show a tooltip on updating an item's time. Note: <code>editable.updateTime</code> must be <code>true</code></td>
  1019. </tr>
  1020. <tr parent="tooltipOnItemUpdateTime" class="hidden">
  1021. <td class="indent">template</td>
  1022. <td>Function</td>
  1023. <td>none</td>
  1024. <td>A template function used to generate the contents of the tooltip. The function is called by the Timeline with an item data as the first argument, and must return HTML code, a string or a template as result. See section <a href="#Templates">Templates</a> for a detailed explanation.
  1025. </td>
  1026. </tr>
  1027. <tr>
  1028. <td>verticalScroll</td>
  1029. <td>Boolean</td>
  1030. <td><code>false</code></td>
  1031. <td> Show a vertical scroll on the side of the group list and link it to the scroll event when zoom is not triggered. Notice that defining this option as <code>true</code> will NOT override <code>horizontalScroll</code>. The scroll event will be vertically ignored, but a vertical scrollbar will be visible
  1032. </td>
  1033. </tr>
  1034. <tr>
  1035. <td>width</td>
  1036. <td>String or Number</td>
  1037. <td><code>'100%'</code></td>
  1038. <td>The width of the timeline in pixels or as a percentage.</td>
  1039. </tr>
  1040. <tr>
  1041. <td>zoomable</td>
  1042. <td>boolean</td>
  1043. <td><code>true</code></td>
  1044. <td>
  1045. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  1046. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  1047. </td>
  1048. </tr>
  1049. <tr>
  1050. <td>zoomKey</td>
  1051. <td>String</td>
  1052. <td><code>''</code></td>
  1053. <td>Specifies whether the Timeline is only zoomed when an additional key is down.
  1054. Available values are '' (does not apply), 'altKey', 'ctrlKey', or 'metaKey'.
  1055. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  1056. </td>
  1057. </tr>
  1058. <tr>
  1059. <td>zoomMax</td>
  1060. <td>number</td>
  1061. <td><code>315360000000000</code></td>
  1062. <td>Set a maximum zoom interval for the visible range in milliseconds.
  1063. It will not be possible to zoom out further than this maximum.
  1064. Default value equals about 10000 years.
  1065. </td>
  1066. </tr>
  1067. <tr>
  1068. <td>zoomMin</td>
  1069. <td>number</td>
  1070. <td><code>10</code></td>
  1071. <td>Set a minimum zoom interval for the visible range in milliseconds.
  1072. It will not be possible to zoom in further than this minimum.
  1073. </td>
  1074. </tr>
  1075. </table>
  1076. <h2 id="Methods">Methods</h2>
  1077. <p>
  1078. The Timeline supports the following methods.
  1079. </p>
  1080. <table class="methods">
  1081. <tr>
  1082. <th>Method</th>
  1083. <th>Return&nbsp;Type</th>
  1084. <th>Description</th>
  1085. </tr>
  1086. <tr>
  1087. <td>addCustomTime([time] [, id])</td>
  1088. <td>number or String</td>
  1089. <td>
  1090. Add new vertical bar representing a custom time that can be dragged by the user.
  1091. Parameter <code>time</code> can be a Date, Number, or String, and is <code>new Date()</code> by default.
  1092. Parameter <code>id</code> can be Number or String and is <code>undefined</code> by default.
  1093. The <code>id</code>code> is added as CSS class name of the custom time bar, allowing to style multiple time bars differently.
  1094. The method returns id of the created bar.
  1095. </td>
  1096. </tr>
  1097. <tr>
  1098. <td>destroy()</td>
  1099. <td>none</td>
  1100. <td>Destroy the Timeline. The timeline is removed from memory. all DOM elements and event listeners are cleaned up.
  1101. </td>
  1102. </tr>
  1103. <tr>
  1104. <td>fit([options])</td>
  1105. <td>none</td>
  1106. <td>Adjust the visible window such that it fits all items. See also function <code>focus(id)</code>.
  1107. Available options:
  1108. <ul>
  1109. <li><code>animation: boolean or {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>.
  1110. </li>
  1111. </ul>
  1112. </td>
  1113. </tr>
  1114. <tr>
  1115. <td>focus(id or ids [, options])</td>
  1116. <td>none</td>
  1117. <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:
  1118. <ul>
  1119. <li><code>animation: boolean or {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>
  1120. </ul>
  1121. </td>
  1122. </tr>
  1123. <tr>
  1124. <td>getCurrentTime()</td>
  1125. <td>Date</td>
  1126. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  1127. </td>
  1128. </tr>
  1129. <tr>
  1130. <td>getCustomTime([id])</td>
  1131. <td>Date</td>
  1132. <td>Retrieve the custom time from the custom time bar with given id. Id is <code>undefined</code> by default.
  1133. </td>
  1134. </tr>
  1135. <tr id="getEventProperties">
  1136. <td>getEventProperties(event)</td>
  1137. <td>Object</td>
  1138. <td>
  1139. Returns an Object with relevant properties from an event:
  1140. <ul>
  1141. <li><code>group</code> (Number or null): the id of the clicked group.</li>
  1142. <li><code>item</code> (Number or null): the id of the clicked item.</li>
  1143. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  1144. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  1145. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  1146. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  1147. <li><code>time</code> (Date): Date of the clicked event.</li>
  1148. <li><code>snappedTime</code> (Date): Date of the clicked event, snapped to a nice value.</li>
  1149. <li><code>what</code> (String or 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>
  1150. <li><code>event</code> (Object): the original click event.</li>
  1151. </ul>
  1152. Example usage:
  1153. <pre class="prettyprint lang-js">
  1154. document.getElementById('myTimeline').onclick = function (event) {
  1155. var props = timeline.getEventProperties(event)
  1156. console.log(props);
  1157. }</pre>
  1158. </td>
  1159. </tr>
  1160. <tr>
  1161. <td>getItemRange()</td>
  1162. <td>Object</td>
  1163. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  1164. </tr>
  1165. <tr>
  1166. <td>getSelection()</td>
  1167. <td>number[]</td>
  1168. <td>Get an array with the ids of the currently selected items.</td>
  1169. </tr>
  1170. <tr>
  1171. <td>getVisibleItems()</td>
  1172. <td>number[]</td>
  1173. <td>Get an array with the ids of the currently visible items.</td>
  1174. </tr>
  1175. <tr>
  1176. <td>getWindow()</td>
  1177. <td>Object</td>
  1178. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  1179. </tr>
  1180. <tr>
  1181. <td>moveTo(time [, options])</td>
  1182. <td>none</td>
  1183. <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:
  1184. <ul>
  1185. <li><code>animation: boolean or {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>
  1186. </ul>
  1187. </td>
  1188. </tr>
  1189. <tr>
  1190. <td>on(event, callback)</td>
  1191. <td>none</td>
  1192. <td>Create an event listener. The callback function is invoked every time the event is triggered. Available events: <code>rangechange</code>, <code>rangechanged</code>, <code>select</code>, <code>itemover</code>, <code>itemout</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>
  1193. </tr>
  1194. <tr>
  1195. <td>off(event, callback)</td>
  1196. <td>none</td>
  1197. <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>
  1198. </tr>
  1199. <tr>
  1200. <td>redraw()</td>
  1201. <td>none</td>
  1202. <td>Force a redraw of the Timeline. The size of all items will be recalculated.
  1203. Can be useful to manually redraw when option <code>autoResize=false</code> and the window
  1204. has been resized, or when the items CSS has been changed.
  1205. </td>
  1206. </tr>
  1207. <tr>
  1208. <td>removeCustomTime(id)</td>
  1209. <td>none</td>
  1210. <td>
  1211. 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.
  1212. </td>
  1213. </tr>
  1214. <tr>
  1215. <td>setCurrentTime(time)</td>
  1216. <td>none</td>
  1217. <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.
  1218. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  1219. Only applicable when option <code>showCurrentTime</code> is true.</td>
  1220. </tr>
  1221. <tr>
  1222. <td>setCustomTime(time [, id])</td>
  1223. <td>none</td>
  1224. <td>Adjust the time of a custom time bar.
  1225. Parameter <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  1226. Parameter <code>id</code> is the id of the custom time bar, and is <code>undefined</code> by default.
  1227. </td>
  1228. </tr>
  1229. <tr>
  1230. <td>setCustomTimeTitle(title [, id])</td>
  1231. <td>none</td>
  1232. <td>Adjust the title attribute of a custom time bar.
  1233. Parameter <code>title</code> is the string or function to be set as title. Use empty string to hide the title completely.
  1234. Parameter <code>id</code> is the id of the custom time bar, and is <code>undefined</code> by default.
  1235. </td>
  1236. </tr>
  1237. <tr>
  1238. <td>setData({<br>&nbsp;&nbsp;groups: groups,<br>&nbsp;&nbsp;items: items<br>})</td>
  1239. <td>none</td>
  1240. <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>.
  1241. Both <code>items</code> and <code>groups</code> can be an Array with Objects,
  1242. a DataSet (offering 2 way data binding), or a DataView (offering 1 way data binding).
  1243. For each of the groups, the items of the timeline are filtered on the
  1244. property <code>group</code>, which must correspond with the id of the group.
  1245. </td>
  1246. </tr>
  1247. <tr>
  1248. <td>setGroups(groups)</td>
  1249. <td>none</td>
  1250. <td>Set a data set with groups for the Timeline.
  1251. <code>groups</code> can be an Array with Objects,
  1252. a DataSet (offering 2 way data binding), or a DataView (offering 1 way data binding).
  1253. For each of the groups, the items of the timeline are filtered on the
  1254. property <code>group</code>, which must correspond with the id of the group.
  1255. </td>
  1256. </tr>
  1257. <tr>
  1258. <td>setItems(items)</td>
  1259. <td>none</td>
  1260. <td>Set a data set with items for the Timeline.
  1261. <code>items</code> can be an Array with Objects,
  1262. a DataSet (offering 2 way data binding), or a DataView (offering 1 way data binding).
  1263. </td>
  1264. </tr>
  1265. <tr>
  1266. <td>setOptions(options)</td>
  1267. <td>none</td>
  1268. <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.
  1269. </td>
  1270. </tr>
  1271. <tr>
  1272. <td>setSelection(id or ids [, options])</td>
  1273. <td>none</td>
  1274. <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:
  1275. <ul>
  1276. <li><code>focus: boolean</code><br>If true, focus will be set to the selected item(s)</li>
  1277. <li><code>animation: boolean or {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>
  1278. </ul>
  1279. </td>
  1280. </tr>
  1281. <tr>
  1282. <td>setWindow(start, end [, options])</td>
  1283. <td>none</td>
  1284. <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:
  1285. <ul>
  1286. <li><code>animation: boolean or {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>
  1287. </ul>
  1288. </td>
  1289. </tr>
  1290. <tr>
  1291. <td>toggleRollingMode()</td>
  1292. <td>none</td>
  1293. <td>Toggle rollingMode.
  1294. </td>
  1295. </tr>
  1296. <tr>
  1297. <td>zoomIn(percentage [, options])</td>
  1298. <td>none</td>
  1299. <td>Zoom in the current visible window. The parameter <code>percentage</code> can be a <code>Number</code> and must be between 0 and 1. If the parameter value of <code>percentage</code> is null, the window will be left unchanged. Available options:
  1300. <ul>
  1301. <li><code>animation: boolean or {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>
  1302. </ul>
  1303. </td>
  1304. </tr>
  1305. <tr>
  1306. <td>zoomOut(percentage [, options])</td>
  1307. <td>none</td>
  1308. <td>Zoom out the current visible window. The parameter <code>percentage</code> can be a <code>Number</code> and must be between 0 and 1. If the parameter value of <code>percentage</code> is null, the window will be left unchanged. Available options:
  1309. <ul>
  1310. <li><code>animation: boolean or {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>
  1311. </ul>
  1312. </td>
  1313. </tr>
  1314. </table>
  1315. <h2 id="Events">Events</h2>
  1316. <p>
  1317. Timeline fires events when changing the visible window by dragging, when
  1318. selecting items, and when dragging the custom time bar.
  1319. </p>
  1320. <p>
  1321. Here an example on how to listen for a <code>select</code> event.
  1322. </p>
  1323. <pre class="prettyprint lang-js">
  1324. timeline.on('select', function (properties) {
  1325. alert('selected items: ' + properties.items);
  1326. });
  1327. </pre>
  1328. <p>
  1329. A listener can be removed via the function <code>off</code>:
  1330. </p>
  1331. <pre class="prettyprint lang-js">
  1332. function onSelect (properties) {
  1333. alert('selected items: ' + properties.items);
  1334. }
  1335. // add event listener
  1336. timeline.on('select', onSelect);
  1337. // do stuff...
  1338. // remove event listener
  1339. timeline.off('select', onSelect);
  1340. </pre>
  1341. <p>
  1342. The following events are available.
  1343. </p>
  1344. <table class="events">
  1345. <tr>
  1346. <th>Name</th>
  1347. <th>Properties</th>
  1348. <th>Description</th>
  1349. </tr>
  1350. <tr>
  1351. <td>currentTimeTick</td>
  1352. <td>Fired when the current time bar redraws. The rate depends on the zoom level.</td>
  1353. </tr>
  1354. <tr>
  1355. <td>click</td>
  1356. <td>
  1357. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1358. </td>
  1359. <td>Fired when clicked inside the Timeline.
  1360. </td>
  1361. </tr>
  1362. <tr>
  1363. <td>contextmenu</td>
  1364. <td>
  1365. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1366. </td>
  1367. <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:
  1368. <pre class="prettyprint lang-js">timeline.on('contextmenu', function (props) {
  1369. alert('Right click!');
  1370. props.event.preventDefault();
  1371. });
  1372. </pre>
  1373. </td>
  1374. </tr>
  1375. <tr>
  1376. <td>doubleClick</td>
  1377. <td>
  1378. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1379. </td>
  1380. <td>Fired when double clicked inside the Timeline.
  1381. </td>
  1382. </tr>
  1383. <tr>
  1384. <td>mouseOver</td>
  1385. <td>
  1386. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Timeline.getEventProperties(event)</code></a>.
  1387. </td>
  1388. <td>Fired when the mouse hovers over a timeline element.
  1389. </td>
  1390. </tr>
  1391. <tr>
  1392. <td>groupDragged</td>
  1393. <td>
  1394. Passes the id of the dragged group.
  1395. </td>
  1396. <td>Fired after the dragging of a group is finished.
  1397. </td>
  1398. </tr>
  1399. <tr>
  1400. <td>changed</td>
  1401. <td>
  1402. Has no properties.
  1403. </td>
  1404. <td>Fired once after each graph redraw.
  1405. </td>
  1406. </tr>
  1407. <tr>
  1408. <td>rangechange</td>
  1409. <td>
  1410. <ul>
  1411. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1412. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1413. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1414. <li><code>event</code> (Object): original event triggering the rangechange.</li>
  1415. </ul>
  1416. </td>
  1417. <td>Fired repeatedly when the timeline window is being changed.
  1418. </td>
  1419. </tr>
  1420. <tr>
  1421. <td>rangechanged</td>
  1422. <td>
  1423. <ul>
  1424. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1425. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1426. <li><code>byUser</code> (Boolean): change happened because of user drag/zoom.</li>
  1427. <li><code>event</code> (Object): original event triggering the rangechanged.</li>
  1428. </ul>
  1429. </td>
  1430. <td>Fired once after the timeline window has been changed.
  1431. </td>
  1432. </tr>
  1433. <tr>
  1434. <td>select</td>
  1435. <td>
  1436. <ul>
  1437. <li><code>items</code>: an array with the ids of the selected items</li>
  1438. <li><code>event</code>: the original click event</li>
  1439. </ul>
  1440. </td>
  1441. <td>Fired after the user selects or deselects items by tapping or holding them.
  1442. When a user taps an already selected item, the select event is fired again.
  1443. Not fired when the method <code>setSelection</code>is executed.
  1444. </td>
  1445. </tr>
  1446. <tr>
  1447. <td>itemover</td>
  1448. <td>
  1449. <ul>
  1450. <li><code>item</code>: hovered item id</li>
  1451. <li><code>event</code>: the original mouseover event</li>
  1452. </ul>
  1453. </td>
  1454. <td>Fired when the user moves the mouse over an item.</td>
  1455. </tr>
  1456. <tr>
  1457. <td>itemout</td>
  1458. <td>
  1459. <ul>
  1460. <li><code>item</code>: hovered item id</li>
  1461. <li><code>event</code>: the original mouseout event</li>
  1462. </ul>
  1463. </td>
  1464. <td>Fired when the user moves the mouse out of an item.</td>
  1465. </tr>
  1466. <tr>
  1467. <td>timechange</td>
  1468. <td>
  1469. <ul>
  1470. <li><code>id</code> (Number or String): custom time bar id.</li>
  1471. <li><code>time</code> (Date): the custom time.</li>
  1472. <li><code>event</code> (Object): original event triggering the timechange.</li>
  1473. </ul>
  1474. </td>
  1475. <td>Fired repeatedly when the user is dragging the custom time bar.
  1476. Only available when the custom time bar is enabled.
  1477. </td>
  1478. </tr>
  1479. <tr>
  1480. <td>timechanged</td>
  1481. <td>
  1482. <ul>
  1483. <li><code>id</code> (Number or String): custom time bar id.</li>
  1484. <li><code>time</code> (Date): the custom time.</li>
  1485. <li><code>event</code> (Object): original event triggering the timechanged.</li>
  1486. </ul>
  1487. </td>
  1488. <td>Fired once after the user has dragged the custom time bar.
  1489. Only available when the custom time bar is enabled.
  1490. </td>
  1491. </tr>
  1492. </table>
  1493. <h2 id="Editing_Items">Editing Items</h2>
  1494. <p>
  1495. When the Timeline is configured to be editable (both options <code>selectable</code> and <code>editable</code> are <code><code>true</code></code>), the user can:
  1496. </p>
  1497. <ul>
  1498. <li>Select an item by clicking it, and use ctrl+click to or shift+click to select multiple items (when <code>multiselect: true</code>).</li>
  1499. <li>Move selected items by dragging them.</li>
  1500. <li>Create a new item by double tapping on an empty space.</li>
  1501. <li>Create a new range item by dragging on an empty space with the ctrl key down.</li>
  1502. <li>Update an item by double tapping it.</li>
  1503. <li>Delete a selected item by clicking the delete button on the top right.</li>
  1504. </ul>
  1505. <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>
  1506. <pre class="prettyprint lang-js">// enable or disable all manipulation actions
  1507. var options = {
  1508. editable: true // true or false
  1509. };
  1510. // enable or disable individual manipulation actions
  1511. var options = {
  1512. editable: {
  1513. add: true, // add new items by double tapping
  1514. updateTime: true, // drag items horizontally
  1515. updateGroup: true, // drag items from one group to another
  1516. remove: true, // delete an item by tapping the delete button top right
  1517. overrideItems: false // allow these options to override item.editable
  1518. }
  1519. };</pre>
  1520. <p>
  1521. Editing can be enabled/disabled for specific items. Setting the property <code>editable</code> to <code>true</code> or <code>false</code> on a data item will override the timeline option except when <code>timeline.editable.overrideItems</code> is set to <code>true</code>.
  1522. </p>
  1523. <pre class="prettyprint lang-js">
  1524. var items = new vis.DataSet([
  1525. {id: 1, content: 'read-only item', start: '2013-04-20', editable: false},
  1526. {id: 2, content: 'editable item', start: '2013-04-14'}
  1527. ]);
  1528. </pre>
  1529. <p>
  1530. Individual manipulation actions (<code>updateTime</code>, <code>updateGroup</code> and <code>remove</code>) can also be set on individual items. If any of the item-level
  1531. actions are specified (and <code>overrideItems</code> is not <code>false</code>) then that takes precedence over the settings at the timeline level. Current behavior is
  1532. that if any of the item-level actions are not specified, those items get <code>undefined</code> value (rather than inheriting from the timeline level). This may change
  1533. in future major releases, and code that specifies all item level values will handle major release changes better. That is, instead of using
  1534. <code>editable: {updateTime : true}</code>, use <code>editable: {updateTime : true, updateGroup: false, remove: false}</code>.
  1535. </p>
  1536. <p>
  1537. One can specify callback functions to validate changes made by the user. There are a number of callback functions for this purpose:
  1538. </p>
  1539. <ul>
  1540. <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>
  1541. <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>
  1542. <li><code>onMove(item, callback)</code> Fired when an item has been moved. If not implemented, the move action will be accepted.</li>
  1543. <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>
  1544. <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>
  1545. </ul>
  1546. <p>
  1547. Each of the callbacks is invoked with two arguments:
  1548. </p>
  1549. <ul>
  1550. <li><code>item</code>: the item being manipulated</li>
  1551. <li><code>callback</code>: a callback function which must be invoked to report back. The callback must be invoked as <code>callback(item)</code> or <code>callback(null)</code>.
  1552. Here, <code>item</code> can contain changes to the passed item. Parameter <code>item</code> typically contains fields `content`, `start`, and optionally `end`. The type of `start`
  1553. 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>
  1554. </ul>
  1555. <p>
  1556. Example code:
  1557. </p>
  1558. <pre class="prettyprint lang-js">var options = {
  1559. onUpdate: function (item, callback) {
  1560. item.content = prompt('Edit items text:', item.content);
  1561. if (item.content != null) {
  1562. callback(item); // send back adjusted item
  1563. }
  1564. else {
  1565. callback(null); // cancel updating the item
  1566. }
  1567. }
  1568. };
  1569. </pre>
  1570. A full example is available here: <a href="../../examples/timeline/editing/editingItemsCallbacks.html">editingItemsCallbacks.html</a>.
  1571. <h2 id="Templates">Templates</h2>
  1572. <p>
  1573. 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 item's data as the first argument, the item element as the second argument and the edited data as the third argument, and outputs formatted HTML:
  1574. </p>
  1575. <pre class="prettyprint lang-js">var options = {
  1576. template: function (item, element, data) {
  1577. var html = ... // generate HTML markup for this item
  1578. return html;
  1579. }
  1580. };
  1581. </pre>
  1582. <h3>Create HTML manually</h3>
  1583. The HTML for an item can be created manually:
  1584. <pre class="prettyprint lang-js">var options = {
  1585. template: function (item, element, data) {
  1586. return '&lt;h1&gt;' + item.header + data.moving?' '+ data.start:'' + '&lt;/h1&gt;&lt;p&gt;' + item.description + '&lt;/p&gt;';
  1587. },
  1588. onMoving: function (item, callback) {
  1589. item.moving = true;
  1590. }
  1591. };
  1592. </pre>
  1593. <h3>Using a template engine</h3>
  1594. Using <a href="http://handlebarsjs.com/">handlebars</a>, one can write the template in HTML:
  1595. <pre class="prettyprint lang-html">
  1596. &lt;script id="item-template" type="text/x-handlebars-template"&gt;
  1597. &lt;h1&gt;{{header}}&lt;/h1&gt;
  1598. &lt;p&gt;{{description}}&lt;/p&gt;
  1599. &lt;/script&gt;
  1600. </pre>
  1601. Compile the template:
  1602. <pre class="prettyprint lang-js">
  1603. var source = document.getElementById('item-template').innerHTML;
  1604. var template = Handlebars.compile(source);
  1605. </pre>
  1606. And then specify the template in the Timeline options
  1607. <pre class="prettyprint lang-js">var options = {
  1608. template: template
  1609. };
  1610. </pre>
  1611. <h3>React templates</h3>
  1612. You can use a React component for the templates by rendering them to the templates' element directly:
  1613. <pre class="prettyprint lang-js">
  1614. template: function (item, element, data) {
  1615. return ReactDOM.render(&lt;b&gt;{item.content}&lt;/b&gt;, element);
  1616. },
  1617. </pre>
  1618. <h3>Multiple templates</h3>
  1619. In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property:
  1620. <pre class="prettyprint lang-js">
  1621. var templates = {
  1622. template1: Handlebars.compile(...),
  1623. template2: Handlebars.compile(...),
  1624. template2: Handlebars.compile(...),
  1625. ...
  1626. };
  1627. var options = {
  1628. template: function (item, element, data) {
  1629. var template = templates[item.template]; // choose the right template
  1630. return template(item); // execute the template
  1631. }
  1632. };
  1633. </pre>
  1634. Now the items can be extended with a property <code>template</code>, specifying which template to use for the item.
  1635. <h2 id="Localization">Localization</h2>
  1636. <p>
  1637. 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.
  1638. </p>
  1639. <p>
  1640. To set a locale for the Timeline, specify the option <code>locale</code>:
  1641. </p>
  1642. <pre class="prettyprint lang-js">var options = {
  1643. locale: 'nl'
  1644. };
  1645. </pre>
  1646. <h3>Create a new locale</h3>
  1647. To load a locale (that is not supported by default) into the Timeline, one can add a new locale to the option <code>locales</code>:
  1648. <pre class="prettyprint lang-js">var options = {
  1649. locales: {
  1650. // create a new locale (text strings should be replaced with localized strings)
  1651. mylocale: {
  1652. current: 'current',
  1653. time: 'time',
  1654. }
  1655. },
  1656. // use the new locale
  1657. locale: 'mylocale'
  1658. };
  1659. </pre>
  1660. <h3 id="available-locales">Available locales</h3>
  1661. <p>
  1662. Timeline comes with support for the following locales:
  1663. </p>
  1664. <table>
  1665. <tr>
  1666. <th>Language</th>
  1667. <th>Code</th>
  1668. </tr>
  1669. <tr>
  1670. <td>English</td>
  1671. <td>
  1672. <code>en</code><br>
  1673. <code>en_EN</code><br>
  1674. <code>en_US</code>
  1675. </td>
  1676. </tr>
  1677. <tr>
  1678. <td>Italian</td>
  1679. <td>
  1680. <code>it</code><br>
  1681. <code>it_IT</code><br>
  1682. <code>it_CH</code>
  1683. </td>
  1684. </tr>
  1685. <tr>
  1686. <td>Dutch</td>
  1687. <td>
  1688. <code>nl</code><br>
  1689. <code>nl_NL</code><br>
  1690. <code>nl_BE</code>
  1691. </td>
  1692. </tr>
  1693. <tr>
  1694. <td>German</td>
  1695. <td>
  1696. <code>de</code><br>
  1697. <code>de_DE</code><br>
  1698. </td>
  1699. </tr>
  1700. </table>
  1701. <h2 id="Time_zone">Time zone</h2>
  1702. <p>
  1703. By default, the Timeline displays time in local time. To display a Timeline in another time zone or in UTC, the date constructor can be overloaded via the configuration option <code>moment</code>, which by default is the constructor function of moment.js. More information about UTC with moment.js can be found in the docs: <a href="http://momentjs.com/docs/#/parsing/utc/">http://momentjs.com/docs/#/parsing/utc/</a>.
  1704. </p>
  1705. <p>
  1706. Examples:
  1707. </p>
  1708. <pre class="prettyprint lang-js">// display in UTC
  1709. var options = {
  1710. moment: function(date) {
  1711. return vis.moment(date).utc();
  1712. }
  1713. };
  1714. // display in UTC +08:00
  1715. var options = {
  1716. moment: function(date) {
  1717. return vis.moment(date).utcOffset('+08:00');
  1718. }
  1719. };
  1720. </pre>
  1721. <h2 id="Styles">Styles</h2>
  1722. <p>
  1723. All parts of the Timeline have a class name and a default css style.
  1724. The styles can be overwritten, which enables full customization of the layout
  1725. of the Timeline.
  1726. </p>
  1727. <p>For example, to change the border and background color of all items, include the
  1728. following code inside the head of your html code or in a separate stylesheet.</p>
  1729. <pre class="prettyprint lang-html">&lt;style&gt;
  1730. .vis-item {
  1731. border-color: orange;
  1732. background-color: yellow;
  1733. }
  1734. &lt;/style&gt;
  1735. </pre>
  1736. <h3 id="Grid_Backgrounds">Grid Backgrounds</h3>
  1737. <p>
  1738. The background grid of the time axis can be styled, for example to highlight
  1739. weekends or to create grids with an alternating white/lightgray background.
  1740. </p>
  1741. <p>
  1742. Depending on the zoom level, the grids get certain css classes attached.
  1743. The following classes are available:
  1744. </p>
  1745. <table class="styles">
  1746. <tr>
  1747. <th>Description</th><th>Values</th>
  1748. </tr>
  1749. <tr>
  1750. <td>Alternating columns</td><td><code>vis-even</code>, <code>vis-odd</code></td>
  1751. </tr>
  1752. <tr>
  1753. <td>Current date</td><td><code>vis-today</code>, <code>vis-tomorrow</code>, <code>vis-yesterday</code>, <code>vis-current-week</code>, <code>vis-current-month</code>, <code>vis-current-year</code></td>
  1754. </tr>
  1755. <tr>
  1756. <td>Hours</td><td><code>vis-h0</code>, <code>vis-h1</code>, ..., <code>vis-h23</code></td>
  1757. </tr>
  1758. <tr>
  1759. <td>Grouped hours</td><td><code>vis-h0-h4</code> to <code>vis-h20-h24</code></td>
  1760. </tr>
  1761. <tr>
  1762. <td>Weekday</td><td><code>vis-monday</code>, <code>vis-tuesday</code>, <code>vis-wednesday</code>, <code>vis-thursday</code>, <code>vis-friday</code>, <code>vis-saturday</code>, <code>vis-sunday</code></td>
  1763. </tr>
  1764. <tr>
  1765. <td>Days</td><td><code>vis-day1</code>, <code>vis-day2</code>, ..., <code>vis-day31</code></td>
  1766. </tr>
  1767. <tr>
  1768. <td>Months</td><td><code>vis-january</code>, <code>vis-february</code>, <code>vis-march</code>, <code>vis-april</code>, <code>vis-may</code>, <code>vis-june</code>, <code>vis-july</code>, <code>vis-august</code>, <code>vis-september</code>, <code>vis-october</code>, <code>vis-november</code>, <code>vis-december</code></td>
  1769. </tr>
  1770. <tr>
  1771. <td>Years</td><td><code>vis-year2014</code>, <code>vis-year2015</code>, ...</td>
  1772. </tr>
  1773. </table>
  1774. <p>Examples:</p>
  1775. <pre class="prettyprint lang-html">&lt;style&gt;
  1776. /* alternating column backgrounds */
  1777. .vis-time-axis .grid.vis-odd {
  1778. background: #f5f5f5;
  1779. }
  1780. /* gray background in weekends, white text color */
  1781. .vis-time-axis .vis-grid.vis-saturday,
  1782. .vis-time-axis .vis-grid.vis-sunday {
  1783. background: gray;
  1784. }
  1785. .vis-time-axis .vis-text.vis-saturday,
  1786. .vis-time-axis .vis-text.vis-sunday {
  1787. color: white;
  1788. }
  1789. &lt;/style&gt;
  1790. </pre>
  1791. </div>
  1792. <!-- Bootstrap core JavaScript
  1793. ================================================== -->
  1794. <!-- Placed at the end of the document so the pages load faster -->
  1795. <script src="../js/jquery.min.js"></script>
  1796. <script src="../js/bootstrap.min.js"></script>
  1797. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  1798. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  1799. <!-- jquery extensions -->
  1800. <script src="../js/jquery.highlight.js"></script>
  1801. <script src="../js/jquery.url.min.js"></script>
  1802. <!-- Tipue vendor js -->
  1803. <script src="../js/tipuesearch.config.js"></script>
  1804. <script src="../js/tipuesearch.js"></script>
  1805. <!-- controller -->
  1806. <script src="../js/main.js"></script>