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.

1587 lines
62 KiB

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