vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1510 lines
60 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <meta name="description" content="">
  9. <meta name="author" content="">
  10. <title>vis.js - A dynamic, browser based visualization library.</title>
  11. <!-- Bootstrap core CSS -->
  12. <link href="../css/bootstrap.css" rel="stylesheet">
  13. <!-- Tipue vendor css -->
  14. <link href="../css/tipuesearch.css" rel="stylesheet">
  15. <link href="../css/style.css" rel="stylesheet">
  16. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  17. <!--[if lt IE 9]>
  18. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  19. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  20. <![endif]-->
  21. <link href="../css/prettify.css" type="text/css" rel="stylesheet"/>
  22. <script type="text/javascript" src="../js/googleAnalytics.js"></script>
  23. <script type="text/javascript" src="../js/prettify/prettify.js"></script>
  24. <script src="../js/smooth-scroll.min.js"></script>
  25. <script language="JavaScript">
  26. smoothScroll.init();
  27. </script>
  28. <style>
  29. tr.subHeader {
  30. font-weight: bold;
  31. font-style: italic;
  32. }
  33. tr.subHeader td {
  34. padding-top: 30px;
  35. }
  36. td.midMethods {
  37. width: 150px;
  38. background-color: #ffffff;
  39. border: 1px solid #dddddd;
  40. }
  41. tr.visible td {
  42. padding: 10px;
  43. }
  44. h2 {
  45. margin-top:50px;
  46. }
  47. td.greenField {
  48. background-color: #b8e030;
  49. }
  50. </style>
  51. <script>
  52. function toggleGettingStarted(aThis) {
  53. var gettingStartedDiv = document.getElementById('gettingStarted');
  54. if (aThis.innerHTML.indexOf("Show") !== -1) {
  55. gettingStartedDiv.className = '';
  56. aThis.innerHTML = 'Hide the getting started again.';
  57. }
  58. else {
  59. gettingStartedDiv.className = 'hidden';
  60. aThis.innerHTML = 'Show the getting started!';
  61. }
  62. }
  63. </script>
  64. <script type="text/javascript" src="../js/toggleTable.js"></script>
  65. </head>
  66. <body onload="prettyPrint();">
  67. <div class="navbar-wrapper">
  68. <div class="container">
  69. <nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  70. <div class="container">
  71. <div class="navbar-header">
  72. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
  73. aria-expanded="false" aria-controls="navbar">
  74. <span class="sr-only">Toggle navigation</span>
  75. <span class="icon-bar"></span>
  76. <span class="icon-bar"></span>
  77. <span class="icon-bar"></span>
  78. </button>
  79. <a class="navbar-brand hidden-sm" href="./index.html">vis.js</a>
  80. </div>
  81. <div id="navbar" class="navbar-collapse collapse">
  82. <ul class="nav navbar-nav">
  83. <li><a href="http://www.visjs.org/index.html#modules">Modules</a></li>
  84. <li><a href="http://www.visjs.org/blog.html">Blog</a></li>
  85. <li><a href="http://www.visjs.org/index.html#download_install">Download</a></li>
  86. <li><a href="http://www.visjs.org/showcase/index.html">Showcase</a></li>
  87. <li><a href="http://www.visjs.org/index.html#contribute">Contribute</a></li>
  88. <li><a href="http://www.visjs.org/index.html#licenses">License</a></li>
  89. </ul>
  90. <form class="navbar-form navbar-right" role="search">
  91. <input name="q" id="tipue_search_input" autocomplete="off" type="text" class="form-control" placeholder="Enter keywords">
  92. <button type="submit" class="btn btn-default">Go!</button>
  93. </form>
  94. <div id="search-results-wrapper" class="panel panel-default">
  95. <div class="panel-body">
  96. <div id="tipue_search_content"></div>
  97. </div>
  98. </div>
  99. <div id="keyword-info" class="panel panel-success">
  100. <div class="panel-body">
  101. Found <span id="keyword-count"></span> results. Click <a id="keyword-jumper-button" href="">here</a> to jump to the first keyword occurence!
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </nav>
  107. </div>
  108. </div>
  109. <a href="https://github.com/almende/vis" class="hidden-xs hidden-sm hidden-md"><img
  110. style="position: absolute; top: 0; right: 0; border: 0;"
  111. src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
  112. alt="Fork me on GitHub"
  113. data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
  114. <div class="container full">
  115. <h1>Graph2d</h1>
  116. <p>
  117. Graph2d is an interactive visualization chart to draw data in a 2D graph.
  118. You can freely move and zoom in the graph by dragging and scrolling in the
  119. window.
  120. </p>
  121. <p>
  122. Graph2d uses HTML DOM and SVG for rendering. This allows for flexible
  123. customization using css styling.
  124. </p>
  125. <h2 id="Contents">Contents</h2>
  126. <ul>
  127. <li><a href="#Data_Format">Data Format</a>
  128. <ul>
  129. <li><a href="#items">Items</a></li>
  130. <li><a href="#groups">Groups</a></li>
  131. </ul>
  132. </li>
  133. <li><a href="#Configuration_Options">Configuration Options</a>
  134. <ul>
  135. <li><a href="#graph2dOptions">Graph2d options</a></li>
  136. <li><a href="#timelineOptions">Timeline options</a></li>
  137. </ul>
  138. </li>
  139. <li><a href="#Methods">Methods</a></li>
  140. <li><a href="#Events">Events</a></li>
  141. <li><a href="#Localization">Localization</a></li>
  142. <li><a href="#Time_zone">Time zone</a></li>
  143. <li><a href="#Styles">Styles</a></li>
  144. </ul>
  145. <a class="btn btn-primary" role="button" onclick="toggleGettingStarted(this)">Show the getting started!</a>
  146. <div id="gettingStarted" class="hidden">
  147. <h3>Creating a Graph2d</h3>
  148. <p>
  149. The following code shows how to create a Graph2d and provide it with data.
  150. More examples can be found in the <a href="../../examples">examples</a> directory.</p>
  151. <pre class="prettyprint lang-html options">
  152. &lt;!DOCTYPE HTML&gt;
  153. &lt;html&gt;
  154. &lt;head&gt;
  155. &lt;title&gt;Graph2d or Basic Example&lt;/title&gt;
  156. &lt;style type="text/css"&gt;
  157. body, html {
  158. font-family: sans-serif;
  159. }
  160. &lt;/style&gt;
  161. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  162. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  163. &lt;/head&gt;
  164. &lt;body&gt;
  165. &lt;div id="visualization"&gt;&lt;/div&gt;
  166. &lt;script type="text/javascript"&gt;
  167. var container = document.getElementById('visualization');
  168. var items = [
  169. {x: '2014-06-11', y: 10},
  170. {x: '2014-06-12', y: 25},
  171. {x: '2014-06-13', y: 30},
  172. {x: '2014-06-14', y: 10},
  173. {x: '2014-06-15', y: 15},
  174. {x: '2014-06-16', y: 30}
  175. ];
  176. var dataset = new vis.DataSet(items);
  177. var options = {
  178. start: '2014-06-10',
  179. end: '2014-06-18'
  180. };
  181. var Graph2d = new vis.Graph2d(container, dataset, options);
  182. &lt;/script&gt;
  183. &lt;/body&gt;
  184. &lt;/html&gt;
  185. </pre>
  186. <p><a href="http://visjs.org/examples/graph2d/01_basic.html" target="_blank">The result of the code above will be the basic example which is shown here.</a></p>
  187. <h2 id="Loading">Loading</h2>
  188. <p>
  189. The class name of the Graph2d is <code>vis.Graph2d</code>.
  190. When constructing a Graph2d, an HTML DOM container must be provided to attach
  191. the graph to. Optionally, data an options can be provided.
  192. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  193. section <a href="#Data_Format">Data Format</a>.
  194. Options is a name-value map in the JSON format. The available options
  195. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  196. Groups is a vis <code>DataSet</code> containing groups. The available options and the method of construction
  197. are described in section <a href="#Data_Format">Data Format</a>.
  198. </p>
  199. <pre class="prettyprint lang-js options">var graph = new vis.Graph2d(container [, data] [, groups] [, options]);</pre>
  200. For backwards compatibility, groups and options can be interchanged.
  201. <p>
  202. Data, options and groups can be set or changed later on using the functions
  203. <code>Graph2d.setItems(data)</code>, <code>Graph2d.setOptions(options)</code> and <code>Graph2d.setGroups(groups)</code>.
  204. </p>
  205. <br>
  206. </div>
  207. <br>
  208. <br>
  209. <h2 id="Data_Format">Data Format</h2>
  210. <p>
  211. Graph2d can load data from an <code>Array</code>, a <code>DataSet</code> (offering 2 way data binding), or a <code>DataView</code> (offering one way data binding).
  212. Objects are added to this DataSet by using the <code>add()</code> function.
  213. <p>
  214. Graph2d can be provided with two types of data:
  215. </p>
  216. <ul>
  217. <li><a href="#items">Items</a> containing a set of points to be displayed.</li>
  218. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  219. together. All items belonging to a group will be drawn as a single graph.</li>
  220. </ul>
  221. <h3 id="items">Items</h3>
  222. <pre class="prettyprint lang-js options">
  223. var items = [
  224. {x: '2014-06-13', y: 30, group: 0},
  225. {x: '2014-06-14', y: 10, group: 0},
  226. {x: '2014-06-15', y: 15, group: 1},
  227. {x: '2014-06-16', y: 30, group: 1},
  228. {x: '2014-06-17', y: 10, group: 1},
  229. {x: '2014-06-18', y: 15, group: 1}
  230. ];
  231. </pre>
  232. <table class="properties">
  233. <tr>
  234. <th>Name</th>
  235. <th>Type</th>
  236. <th>Required</th>
  237. <th>Description</th>
  238. </tr>
  239. <tr>
  240. <td>x</td>
  241. <td>Date</td>
  242. <td>yes</td>
  243. <td>Location on the x-axis.</td>
  244. </tr>
  245. <tr>
  246. <td>y</td>
  247. <td>Number</td>
  248. <td>yes</td>
  249. <td>Location on the y-axis.</td>
  250. </tr>
  251. <tr>
  252. <td>group</td>
  253. <td>Number or string</td>
  254. <td>no</td>
  255. <td>The ID of the group this point belongs to.</td>
  256. </tr>
  257. <tr>
  258. <td>label</td>
  259. <td>Object</td>
  260. <td>no</td>
  261. <td>A label object which will be displayed near to the item. A label object has one requirement - a <b> content </b> property. In addition you can set the <b> xOffset, yOffset and className </b> for further appearance customisations </td>
  262. </tr>
  263. </table>
  264. <h3 id="groups">Groups</h3>
  265. <p>
  266. Like the items, groups are regular JavaScript Arrays and Objects.
  267. Using groups, items can be grouped together.
  268. Items are filtered per group, and displayed as individual graphs. Groups can contain the properties <code>id</code>,
  269. <code>content</code>, <code>className</code> (optional) and <code>options</code> (optional).
  270. </p>
  271. <p>
  272. Groups can be applied to a timeline using the method <code>setGroups</code>.
  273. A table with groups can be created like:
  274. </p>
  275. <pre class="prettyprint lang-js options">
  276. var groups = new vis.DataSet();
  277. groups.add({
  278. id: 1,
  279. content: 'Group 1',
  280. // Optional: a field 'visible'
  281. // Optional: a field 'className'
  282. // Optional: options
  283. })
  284. groups.add({
  285. // more groups...
  286. });
  287. </pre>
  288. <p>
  289. Groups can have the following properties:
  290. </p>
  291. <table class="properties">
  292. <tr>
  293. <th>Name</th>
  294. <th>Type</th>
  295. <th>Required</th>
  296. <th>Description</th>
  297. </tr>
  298. <tr>
  299. <td>id</td>
  300. <td>String or Number</td>
  301. <td>yes</td>
  302. <td>An id for the group. The group will display all items having a
  303. property <code>group</code> which matches the <code>id</code>
  304. of the group.</td>
  305. </tr>
  306. <tr>
  307. <td>content</td>
  308. <td>String</td>
  309. <td>yes</td>
  310. <td>The contents of the group. This can be plain text or html code.</td>
  311. </tr>
  312. <tr>
  313. <td>className</td>
  314. <td>String</td>
  315. <td>no</td>
  316. <td>This field is optional. A className can be used to give groups
  317. an individual css style.
  318. </td>
  319. </tr>
  320. <tr>
  321. <td>style</td>
  322. <td>String</td>
  323. <td>no</td>
  324. <td>This field is optional. A style can be used to give groups
  325. an individual css style, and any style tags specified in style will
  326. override the definition in the className style defined in css.
  327. </td>
  328. </tr>
  329. <tr>
  330. <td>options</td>
  331. <td>Object</td>
  332. <td>no</td>
  333. <td>This field is optional. The options can be used to give a group a specific draw style.
  334. Any options that are colored green in the Configuration Options can be used as options here.
  335. </tr>
  336. <tr>
  337. <td>visible</td>
  338. <td>Boolean</td>
  339. <td>no</td>
  340. <td>This field is optional. If false, this group will not be drawn. By default it is true.
  341. </tr>
  342. </table>
  343. <h2 id="Configuration_Options">Configuration Options</h2>
  344. <h3 id="graph2dOptions">Graph2d Options</h3>
  345. Options can be used to customize the Graph2d to your purposes. These options can be passed to the Graph2d object either in
  346. the constructor, or by the <code>setOptions</code> function.
  347. <pre class="prettyprint lang-js options">
  348. var options = {
  349. width: '100%',
  350. height: '400px',
  351. style: 'surface'
  352. };
  353. </pre>
  354. The options colored in green can also be used as options for the groups. All options are optional.
  355. <table class="options" id="g2dOptions">
  356. <tr>
  357. <th>Name</th>
  358. <th>Type</th>
  359. <th>Default</th>
  360. <th>Description</th>
  361. </tr>
  362. <tr>
  363. <td>defaultGroup</td>
  364. <td>String</td>
  365. <td>'default'</td>
  366. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  367. </tr>
  368. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','barChart', this);">
  369. <td class="greenField"><span parent="barChart" class="right-caret"></span> barChart</td>
  370. <td>Object</td>
  371. <td></td>
  372. <td>Define the properties of the barchart style.</td>
  373. </tr>
  374. <tr parent="barChart" class="hidden">
  375. <td class="greenField indent">barChart.align</td>
  376. <td>String</td>
  377. <td>'center'</td>
  378. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  379. </tr>
  380. <tr parent="barChart" class="hidden">
  381. <td class="greenField indent">barChart.sideBySide</td>
  382. <td>Boolean</td>
  383. <td>false</td>
  384. <td>If two datapoints of a barchart overlap, they are drawn over eachother by default. If sideBySide is set to true, they will be drawn side by side, within the same width as a single bar..
  385. See <a href="../../examples/graph2d/10_barsSideBySide.html">example 10</a> for more information.
  386. When using groups, see <a href="../../examples/graph2d/11_barsSideBySideGroups.html">example 11</a>.
  387. </td>
  388. </tr>
  389. <tr parent="barChart" class="hidden">
  390. <td class="greenField indent">barChart.width</td>
  391. <td>Number</td>
  392. <td>50</td>
  393. <td>The width of the bars.</td>
  394. </tr>
  395. <tr parent="barChart" class="hidden">
  396. <td class="greenField indent">barChart.minWidth</td>
  397. <td>Number</td>
  398. <td></td>
  399. <td>The minimum width of the bars in pixels: by default the bars get smaller while zooming out to prevent overlap, this value is the minimum width of the bar. Default behavior (when minWidth is not set) is 10% of the bar width.</td>
  400. </tr>
  401. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','dataAxis', this);">
  402. <td><span parent="dataAxis" class="right-caret"></span> dataAxis</td>
  403. <td>Object</td>
  404. <td></td>
  405. <td>Define the properties of the left and right dataAxis.</td>
  406. </tr>
  407. <tr parent="dataAxis" class="hidden">
  408. <td class="indent">dataAxis.alignZeros</td>
  409. <td>Boolean</td>
  410. <td>true</td>
  411. <td>When using multiple axis, the right one is slaved to the left one. If you need to ensure that the zero-lines are on the same
  412. height, you can turn this option on.</td>
  413. </tr>
  414. <tr parent="dataAxis" class="hidden">
  415. <td class="indent">dataAxis.icons</td>
  416. <td>Boolean</td>
  417. <td>false</td>
  418. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  419. </tr>
  420. <tr parent="dataAxis" class="hidden">
  421. <td class="indent2">dataAxis.left.format</td>
  422. <td>Function</td>
  423. <td></td>
  424. <td>Insert a custom function on how to format the label. The function will receive a numeric value and has to return a string. Default function is:
  425. <pre class="prettyprint lang-js">
  426. function (value) {
  427. return ''+value.toPrecision(3);
  428. }</pre>
  429. </td>
  430. </tr>
  431. <tr parent="dataAxis" class="hidden">
  432. <td class="indent2">dataAxis.left.range.min</td>
  433. <td>Number</td>
  434. <td>undefined</td>
  435. <td>Set the minimum value of the left y-Axis.</td>
  436. </tr>
  437. <tr parent="dataAxis" class="hidden">
  438. <td class="indent2">dataAxis.left.range.max</td>
  439. <td>Number</td>
  440. <td>undefined</td>
  441. <td>Set the maximum value of the left y-Axis.</td>
  442. </tr>
  443. <tr parent="dataAxis" class="hidden">
  444. <td class="indent2">dataAxis.left.title.style</td>
  445. <td>String</td>
  446. <td>undefined</td>
  447. <td>Set the title style for the left axis. This is a css string and it will override the attributes set in the class.</td>
  448. </tr>
  449. <tr parent="dataAxis" class="hidden">
  450. <td class="indent2">dataAxis.left.title.text</td>
  451. <td>String</td>
  452. <td>undefined</td>
  453. <td>Set the title for the left axis.</td>
  454. </tr>
  455. <tr parent="dataAxis" class="hidden">
  456. <td class="indent2">dataAxis.right.format</td>
  457. <td>Function</td>
  458. <td></td>
  459. <td>Same explaination as the left side.</td>
  460. </tr>
  461. <tr parent="dataAxis" class="hidden">
  462. <td class="indent2">dataAxis.right.range.min</td>
  463. <td>Number</td>
  464. <td>undefined</td>
  465. <td>Set the minimum value of the right y-Axis.</td>
  466. </tr>
  467. <tr parent="dataAxis" class="hidden">
  468. <td class="indent2">dataAxis.right.range.max</td>
  469. <td>Number</td>
  470. <td>undefined</td>
  471. <td>Set the maximum value of the right y-Axis.</td>
  472. </tr>
  473. <tr parent="dataAxis" class="hidden">
  474. <td class="indent2">dataAxis.right.title.style</td>
  475. <td>String</td>
  476. <td>undefined</td>
  477. <td>Set the title style for the right axis. This is a css string and it will override the attributes set in the class.</td>
  478. </tr>
  479. <tr parent="dataAxis" class="hidden">
  480. <td class="indent2">dataAxis.right.title.text</td>
  481. <td>String</td>
  482. <td>undefined</td>
  483. <td>Set the title for the right axis.</td>
  484. </tr>
  485. <tr parent="dataAxis" class="hidden">
  486. <td class="indent">dataAxis.showMinorLabels</td>
  487. <td>Boolean</td>
  488. <td>true</td>
  489. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  490. </tr>
  491. <tr parent="dataAxis" class="hidden">
  492. <td class="indent">dataAxis.showMajorLabels</td>
  493. <td>Boolean</td>
  494. <td>true</td>
  495. <td>Toggle the drawing of the major labels on the Y axis.</td>
  496. </tr>
  497. <tr parent="dataAxis" class="hidden">
  498. <td class="indent">dataAxis.visible</td>
  499. <td>Boolean</td>
  500. <td>true</td>
  501. <td>Show or hide the data axis.</td>
  502. </tr>
  503. <tr parent="dataAxis" class="hidden">
  504. <td class="indent">dataAxis.width</td>
  505. <td>Number or String</td>
  506. <td>'40px'</td>
  507. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  508. </tr>
  509. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','drawPoints', this);">
  510. <td class="greenField"><span parent="drawPoints" class="right-caret"></span> drawPoints</td>
  511. <td>Boolean, Object or Function</td>
  512. <td>true</td>
  513. <td>Defines rendering options for the datapoints.
  514. Three different types of objects can be assigned to this property. See <a href="../../examples/graph2d/19_labels.html">Example 19</a> for an illustration.<br />
  515. 1. <code>Boolean</code>: When true is provided every datapoint will be drawn, false otherwise.<br />
  516. <pre class="prettyprint lang-js">
  517. drawPoints: true // or false
  518. </pre>
  519. 2. <code>Object</code> (the 'rendering' options): If an object is provided it may contain following properties which all can be optional: <code>onRender</code>, <code>className</code><code>size</code> and/or <code>style</code>. For more information check the property's documentation.<br />
  520. <pre class="prettyprint lang-js">
  521. drawPoints: {
  522. size: 3,
  523. style: 'square'
  524. }
  525. </pre>
  526. 3. <code>Function</code>: If a function is provided it will be used as a callback. The function may return values from listing 1 or 2.<br />
  527. <pre class="prettyprint lang-js">
  528. drawPoints: function(item, group) {
  529. ...
  530. }
  531. </pre>
  532. If a rendering property from the rendering option object is missing, the missing property will be fetched from the group's option.
  533. <br />
  534. All of these three options can be defined within the drawPoints properties separately as well.
  535. </td>
  536. </tr>
  537. <tr parent="drawPoints" class="hidden">
  538. <td class="greenField indent">drawPoints.enabled</td>
  539. <td>Boolean</td>
  540. <td>true</td>
  541. <td>Toggles the drawing of the datapoints.</td>
  542. </tr>
  543. <tr parent="drawPoints" class="hidden">
  544. <td class="greenField indent">drawPoints.onRender</td>
  545. <td>function</td>
  546. <td>none</td>
  547. <td>Defines a render function for every datapoint.
  548. If a group has no <code>drawPoints.onRender</code> callback, the graph2d <code>drawPoints.onRender</code> callback will be used.
  549. If neither is defined, the datapoint will be rendered according to the group setting of <code>drawPoints.enabled</code>.
  550. This callback must return <code>true</code> if the datapoint should be rendered, otherwise <code>false</code>.
  551. <pre class="prettyprint lang-js">
  552. drawPoints: {
  553. enabled: true,
  554. onRender: function(item, group, graph2d) {
  555. // only renders items with labels
  556. return item.label != null;
  557. }
  558. }
  559. </pre>
  560. This callback may also return an object containing a <code>size</code> and <code>style</code> property, both are optional, e.g.:
  561. <pre class="prettyprint lang-js">
  562. onRender: function(item, group, graph2d) {
  563. if (item.label == null) {
  564. return false;
  565. }
  566. return {
  567. style: 'circle',
  568. size: 30
  569. };
  570. }
  571. </pre>
  572. The properties <code>className</code>, <code>style</code> and <code>size</code> returned from the callback will be used for rendering the datapoint.
  573. If a property is missing in the rendering option object, the missing property will be fetched from the group's option.
  574. </td>
  575. </tr>
  576. <tr parent="drawPoints" class="hidden">
  577. <td class="greenField indent">drawPoints.size</td>
  578. <td>Number</td>
  579. <td>6</td>
  580. <td>Determine the size at which the data points are drawn.</td>
  581. </tr>
  582. <tr parent="drawPoints" class="hidden">
  583. <td class="greenField indent">drawPoints.style</td>
  584. <td>String</td>
  585. <td>'square'</td>
  586. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  587. </tr>
  588. <tr>
  589. <td>graphHeight</td>
  590. <td>Number or String</td>
  591. <td>'400px'</td>
  592. <td>This is the height of the graph SVG canvas.
  593. If it is larger than the height of the outer frame, you can drag up and down
  594. the vertical direction as well as the usual horizontal direction.</td>
  595. </tr>
  596. <tr>
  597. <td>groups.visibility</td>
  598. <td>Object</td>
  599. <td></td>
  600. <td>You can use this to toggle the visibility of groups per graph2D instance. This is different from setting the visibility flag of the groups since
  601. this is not communicated across instances of graph2d. Take a look at <a href="../../examples/graph2d/14_toggleGroups.html">Example 14</a>
  602. for more explanation.
  603. </td>
  604. </tr>
  605. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','interpolation', this);">
  606. <td class="greenField"><span parent="interpolation" class="right-caret"></span> interpolation</td>
  607. <td>Boolean or Object</td>
  608. <td>true</td>
  609. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  610. </tr>
  611. <tr parent="interpolation" class="hidden">
  612. <td class="greenField indent">interpolation.enabled</td>
  613. <td>Boolean</td>
  614. <td>true</td>
  615. <td>Toggle the interpolation.</td>
  616. </tr>
  617. <tr parent="interpolation" class="hidden">
  618. <td class="greenField indent">interpolation.parametrization</td>
  619. <td>String</td>
  620. <td>'centripetal'</td>
  621. <td>Define the type of parametrizaion for the catmullRom interpolation. <a href="../../examples/graph2d/06_interpolation.html">Example 6</a> shows the different parametrizations. The options are 'centripetal' (best results), 'chordal' and 'uniform'. Uniform is the computationally cheapest variant.
  622. If interpolation is disabled, linear interpolation is used.</td>
  623. </tr>
  624. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','legend', this);">
  625. <td><span parent="legend" class="right-caret"></span> legend</td>
  626. <td>Boolean or Object</td>
  627. <td>false</td>
  628. <td>Toggle the legend with the default settings.</td>
  629. </tr>
  630. <tr parent="legend" class="hidden">
  631. <td class="indent">legend.enabled</td>
  632. <td>Boolean</td>
  633. <td>false</td>
  634. <td>Toggle the legend.</td>
  635. </tr>
  636. <tr parent="legend" class="hidden">
  637. <td class="indent">legend.icons</td>
  638. <td>Boolean</td>
  639. <td>true</td>
  640. <td>Show automatically generated icons on the legend.</td>
  641. </tr>
  642. <tr parent="legend" class="hidden">
  643. <td class="indent2">legend.left.visible</td>
  644. <td>Boolean</td>
  645. <td>true</td>
  646. <td>Both axis, left and right, have a corresponding legend. This toggles the visibility of the legend that is coupled with the left axis.</td>
  647. </tr>
  648. <tr parent="legend" class="hidden">
  649. <td class="indent2">legend.left.position</td>
  650. <td>String</td>
  651. <td>'top-left'</td>
  652. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  653. </tr>
  654. <tr parent="legend" class="hidden">
  655. <td class="indent2">legend.right.visible</td>
  656. <td>Boolean</td>
  657. <td>true</td>
  658. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  659. </tr>
  660. <tr parent="legend" class="hidden">
  661. <td class="indent2">legend.right.position</td>
  662. <td>String</td>
  663. <td>'top-right'</td>
  664. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  665. </tr>
  666. <tr>
  667. <td>moment</td>
  668. <td>function</td>
  669. <td>vis.moment</td>
  670. <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>
  671. </tr>
  672. <tr>
  673. <td class="greenField">sampling</td>
  674. <td>Boolean</td>
  675. <td>true</td>
  676. <td>If sampling is enabled, Graph2d will automatically determine the amount of points per pixel.
  677. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  678. </tr>
  679. <tr>
  680. <td class="greenField">sort</td>
  681. <td>Boolean</td>
  682. <td>true</td>
  683. <td>This determines if the items are sorted automatically.
  684. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  685. </tr>
  686. <tr>
  687. <td>stack</td>
  688. <td>Boolean</td>
  689. <td>true</td>
  690. <td>If stack is enabled, the graphs will be stacked upon each-other when applicable. A group can opt-out of stacking through the "excludeFromStacking" option.</td>
  691. </tr>
  692. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','shaded', this);">
  693. <td class="greenField"><span parent="shaded" class="right-caret"></span> shaded</td>
  694. <td>Boolean or Object</td>
  695. <td>false</td>
  696. <td>Toggle a shaded area with the default settings.</td>
  697. </tr>
  698. <tr parent="shaded" class="hidden">
  699. <td class="greenField indent">shaded.enabled</td>
  700. <td>Boolean</td>
  701. <td>false</td>
  702. <td>This toggles the shading.</td>
  703. </tr>
  704. <tr parent="shaded" class="hidden">
  705. <td class="greenField indent">shaded.orientation</td>
  706. <td>String</td>
  707. <td>'bottom'</td>
  708. <td>This determines if the shaded area is at the bottom or at the top of the curve, or always towards the zero-axis of the graph.
  709. The options are 'zero', 'bottom', 'top', or the special case of 'group'. If group is chosen, the option groupId is required.
  710. See <a href="../../examples/graph2d/20_shading.html">Example 20</a> what these options look like.
  711. </td>
  712. </tr>
  713. <tr parent="shaded" class="hidden">
  714. <td class="greenField indent">shaded.groupId</td>
  715. <td>String</td>
  716. <td>undefined</td>
  717. <td>The id of the group which should be used as the other shading limit.
  718. </td>
  719. </tr>
  720. <tr parent="shaded" class="hidden">
  721. <td class="greenField indent">shaded.style</td>
  722. <td>String</td>
  723. <td>undefined</td>
  724. <td>Set the style for the shading. This is a css string and it will override the attributes set in the class.</td>
  725. </tr>
  726. <tr parent="shaded" class="hidden">
  727. <td class="greenField indent">style</td>
  728. <td>String</td>
  729. <td>'line'</td>
  730. <td>This allows the user to define if this should be a linegraph, barchart or pointcloud. The options are: 'line', 'bar', 'points'.</td>
  731. </tr>
  732. <tr>
  733. <td class="greenField">yAxisOrientation</td>
  734. <td>String</td>
  735. <td>'left'</td>
  736. <td>This defines with which axis, left or right, the graph is coupled. <a href="../../examples/graph2d/05_bothAxis.html">Example 5</a> shows groups with different Y axis. If no groups are coupled
  737. with an axis, it will not be shown.</td>
  738. </tr>
  739. <tr>
  740. <td class="greenField">excludeFromLegend</td>
  741. <td>Boolean</td>
  742. <td>false</td>
  743. <td>Group option only. Excludes the group from being listed in the legend.</td>
  744. </tr>
  745. <tr>
  746. <td class="greenField">excludeFromStacking</td>
  747. <td>Boolean</td>
  748. <td>false</td>
  749. <td>Group option only. Excludes the group from being included in the stacking.</td>
  750. </tr>
  751. </table>
  752. <h3 id="timelineOptions">Timeline Options</h3>
  753. <p>
  754. Graph2d is built upon the framework of the timeline. These options from the timeline can be used with graph2D.
  755. All options are optional.
  756. </p>
  757. <table class="options" id="optionTable">
  758. <tr>
  759. <th>Name</th>
  760. <th>Type</th>
  761. <th>Default</th>
  762. <th>Description</th>
  763. </tr>
  764. <tr>
  765. <td>autoResize</td>
  766. <td>Boolean</td>
  767. <td>true</td>
  768. <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>
  769. </tr>
  770. <tr>
  771. <td>configure</td>
  772. <td>boolean or function</td>
  773. <td><code>false</code></td>
  774. <td>When true, a configurator is loaded where all configuration options of the Graph2d can be changed live.
  775. 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:
  776. <pre class="prettyprint lang-js">
  777. function (option, path) {
  778. return option === 'format' || path.indexOf('format') !== -1;
  779. }</pre>
  780. </td>
  781. </tr>
  782. <tr>
  783. <td>clickToUse</td>
  784. <td>Boolean</td>
  785. <td>false</td>
  786. <td>When a Graph2d is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  787. When active, a blue shadow border is displayed around the Graph2d. The Graph2d is set active by clicking on it, and is changed to inactive again by clicking outside the Graph2d or by pressing the ESC key.</td>
  788. </tr>
  789. <tr>
  790. <td>end</td>
  791. <td>Date or Number or String</td>
  792. <td>none</td>
  793. <td>The initial end date for the axis of the timeline.
  794. If not provided, the latest date present in the items set is taken as
  795. end date.</td>
  796. </tr>
  797. <tr>
  798. <td>format</td>
  799. <td>Object</td>
  800. <td>none</td>
  801. <td>
  802. Apply custom date formatting of the labels on the time axis. The default value of <code>format</code> is:
  803. <pre class="prettyprint lang-js">{
  804. minorLabels: {
  805. millisecond:'SSS',
  806. second: 's',
  807. minute: 'HH:mm',
  808. hour: 'HH:mm',
  809. weekday: 'ddd D',
  810. day: 'D',
  811. month: 'MMM',
  812. year: 'YYYY'
  813. },
  814. majorLabels: {
  815. millisecond:'HH:mm:ss',
  816. second: 'D MMMM HH:mm',
  817. minute: 'ddd D MMMM',
  818. hour: 'ddd D MMMM',
  819. weekday: 'MMMM YYYY',
  820. day: 'MMMM YYYY',
  821. month: 'YYYY',
  822. year: ''
  823. }
  824. }</pre>
  825. For values which not provided in the customized <code>options.format</code>, the default values will be used.
  826. All available formatting syntax is described in the <a href="http://momentjs.com/docs/#/displaying/format/">docs of moment.js</a>.
  827. </td>
  828. </tr>
  829. <tr>
  830. <td>height</td>
  831. <td>Number or String</td>
  832. <td>none</td>
  833. <td>The height of the timeline in pixels or as a percentage.
  834. When height is undefined or null, the height of the timeline is automatically
  835. adjusted to fit the contents.
  836. It is possible to set a maximum height using option <code>maxHeight</code>
  837. to prevent the timeline from getting too high in case of automatically
  838. calculated height.
  839. </td>
  840. </tr>
  841. <tr>
  842. <td>hiddenDates</td>
  843. <td>Object</td>
  844. <td>none</td>
  845. <td>This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
  846. <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.
  847. 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
  848. and set repeat to weekly.
  849. </td>
  850. </tr>
  851. <tr>
  852. <td>locale</td>
  853. <td>String</td>
  854. <td>none</td>
  855. <td>Select a locale for the Graph2d. See section <a href="#Localization">Localization</a> for more information.</td>
  856. </tr>
  857. <tr>
  858. <td>locales</td>
  859. <td>Object</td>
  860. <td>none</td>
  861. <td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
  862. </tr>
  863. <tr>
  864. <td>max</td>
  865. <td>Date or Number or String</td>
  866. <td>none</td>
  867. <td>Set a maximum Date for the visible range.
  868. It will not be possible to move beyond this maximum.
  869. </td>
  870. </tr>
  871. <tr>
  872. <td>maxHeight</td>
  873. <td>Number or String</td>
  874. <td>none</td>
  875. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  876. </tr>
  877. <tr>
  878. <td>maxMinorChars</td>
  879. <td>number</td>
  880. <td>7</td>
  881. <td>
  882. Specifies the maximum number of characters that should fit in minor grid labels.
  883. If larger, less and wider grids will be drawn.
  884. </td>
  885. </tr>
  886. <tr>
  887. <td>min</td>
  888. <td>Date or Number or String</td>
  889. <td>none</td>
  890. <td>Set a minimum Date for the visible range.
  891. It will not be possible to move beyond this minimum.
  892. </td>
  893. </tr>
  894. <tr>
  895. <td>minHeight</td>
  896. <td>Number or String</td>
  897. <td>none</td>
  898. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  899. </tr>
  900. <tr>
  901. <td>moveable</td>
  902. <td>boolean</td>
  903. <td><code>true</code></td>
  904. <td>
  905. Specifies whether the Timeline can be moved and zoomed by dragging the window.
  906. See also option <code>zoomable</code>.
  907. </td>
  908. </tr>
  909. <tr>
  910. <td>orientation</td>
  911. <td>String</td>
  912. <td>'bottom'</td>
  913. <td>Orientation of the timeline: '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>
  914. </tr>
  915. <tr>
  916. <td>showCurrentTime</td>
  917. <td>Boolean</td>
  918. <td>true</td>
  919. <td>Show a vertical bar at the current time.</td>
  920. </tr>
  921. <tr>
  922. <td>showCustomTime</td>
  923. <td>Boolean</td>
  924. <td>false</td>
  925. <td>Show a vertical bar displaying a custom time. This line can be dragged by the user. The custom time can be utilized to show a state in the past or in the future. When the custom time bar is dragged by the user, the event <code>timechange</code> is fired repeatedly. After the bar is dragged, the event <code>timechanged</code> is fired once.</td>
  926. </tr>
  927. <tr>
  928. <td>showMajorLabels</td>
  929. <td>Boolean</td>
  930. <td>true</td>
  931. <td>By default, the timeline shows both minor and major date labels on the
  932. time axis.
  933. For example the minor labels show minutes and the major labels show hours.
  934. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  935. are shown.</td>
  936. </tr>
  937. <tr>
  938. <td>showMinorLabels</td>
  939. <td>Boolean</td>
  940. <td>true</td>
  941. <td>By default, the timeline shows both minor and major date labels on the
  942. time axis.
  943. For example the minor labels show minutes and the major labels show hours.
  944. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  945. are shown. When both <code>showMajorLabels</code> and
  946. <code>showMinorLabels</code> are false, no horizontal axis will be
  947. visible.</td>
  948. </tr>
  949. <tr>
  950. <td>start</td>
  951. <td>Date or Number or String</td>
  952. <td>none</td>
  953. <td>The initial start date for the axis of the timeline.
  954. If not provided, the earliest date present in the events is taken as start date.</td>
  955. </tr>
  956. <tr class='toggle collapsible' onclick="toggleTable('optionTable','timeAxis', this);">
  957. <td><span parent="timeAxis" class="right-caret"></span> timeAxis</td>
  958. <td>Object</td>
  959. <td><code>Object</code></td>
  960. <td>Specify a fixed scale and step size for the time axis.</td>
  961. </tr>
  962. <tr parent="timeAxis" class="hidden">
  963. <td class="indent">timeAxis.scale</td>
  964. <td>String</td>
  965. <td>none</td>
  966. <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:
  967. <pre class="prettyprint lang-js options">var options = {
  968. timeAxis: {scale: 'minute', step: 5}
  969. }</pre>
  970. </td>
  971. </tr>
  972. <tr parent="timeAxis" class="hidden">
  973. <td class="indent">timeAxis.step</td>
  974. <td>number</td>
  975. <td><code>1</code></td>
  976. <td>
  977. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  978. Choose for example 1, 2, 5, or 10.</td>
  979. </tr>
  980. <tr>
  981. <td>width</td>
  982. <td>String</td>
  983. <td>'100%'</td>
  984. <td>The width of the timeline in pixels or as a percentage.</td>
  985. </tr>
  986. <tr>
  987. <td>zoomable</td>
  988. <td>boolean</td>
  989. <td><code>true</code></td>
  990. <td>
  991. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  992. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  993. </td>
  994. </tr>
  995. <tr>
  996. <td>zoomKey</td>
  997. <td>String</td>
  998. <td><code>''</code></td>
  999. <td>Specifies whether the Timeline is only zoomed when an additional key is down.
  1000. Available values are '' (does not apply), 'altKey', 'ctrlKey', or 'metaKey'.
  1001. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  1002. </td>
  1003. </tr>
  1004. <tr>
  1005. <td>zoomMax</td>
  1006. <td>Number</td>
  1007. <td>315360000000000</td>
  1008. <td>Set a maximum zoom interval for the visible range in milliseconds.
  1009. It will not be possible to zoom out further than this maximum.
  1010. Default value equals about 10000 years.
  1011. </td>
  1012. </tr>
  1013. <tr>
  1014. <td>zoomMin</td>
  1015. <td>Number</td>
  1016. <td>10</td>
  1017. <td>Set a minimum zoom interval for the visible range in milliseconds.
  1018. It will not be possible to zoom in further than this minimum.
  1019. </td>
  1020. </tr>
  1021. </table>
  1022. <h2 id="Methods">Methods</h2>
  1023. <p>
  1024. The Graph2d supports the following methods.
  1025. </p>
  1026. <table class="methods">
  1027. <tr>
  1028. <th>Method</th>
  1029. <th>Return Type</th>
  1030. <th>Description</th>
  1031. </tr>
  1032. <tr>
  1033. <td>destroy()</td>
  1034. <td>none</td>
  1035. <td>Destroy the Graph2d. The Graph2d is removed from memory. all DOM elements and event listeners are cleaned up.
  1036. </td>
  1037. </tr>
  1038. <tr>
  1039. <td>fit()</td>
  1040. <td>none</td>
  1041. <td>Adjust the visible window such that it fits all items.
  1042. </td>
  1043. </tr>
  1044. <tr>
  1045. <td>getCurrentTime()</td>
  1046. <td>Date</td>
  1047. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  1048. </td>
  1049. </tr>
  1050. <tr>
  1051. <td>getCustomTime()</td>
  1052. <td>Date</td>
  1053. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  1054. </td>
  1055. </tr>
  1056. <tr>
  1057. <td>getDataRange()</td>
  1058. <td>Object</td>
  1059. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  1060. </tr>
  1061. <tr id="getEventProperties">
  1062. <td>getEventProperties(event)</td>
  1063. <td>Object</td>
  1064. <td>
  1065. Returns an Object with relevant properties from an event:
  1066. <ul>
  1067. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  1068. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  1069. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  1070. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  1071. <li><code>time</code> (Date): Date of the clicked event.</li>
  1072. <li><code>value</code> (Number[]): The data value of the click event. The array contains one value when there is one data axis visible, and two values when there are two visible data axes.</li>
  1073. <li><code>what</code> (String or null): name of the clicked thing: <code>background</code>, <code>axis</code>, <code>dat-axis</code>, <code>custom-time</code>, or <code>current-time</code>, <code>legend</code>.</li>
  1074. <li><code>event</code> (Object): the original click event.</li>
  1075. </ul>
  1076. </td>
  1077. </tr>
  1078. <tr>
  1079. <td>getLegend(groupId, iconWidth, iconHeight)</td>
  1080. <td>SVGelement, String, String</td>
  1081. <td>Returns an object containing an SVG element with the icon of the group (size determined by iconWidth and iconHeight), the label of the group (content) and the yAxisOrientation of the group (left or right).
  1082. </td>
  1083. </tr>
  1084. <tr>
  1085. <td>getWindow()</td>
  1086. <td>Object</td>
  1087. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  1088. </tr>
  1089. <tr>
  1090. <td>isGroupVisible(groupId)</td>
  1091. <td>Boolean</td>
  1092. <td>This checks if the visible option of the supplied group (by ID) is true or false.
  1093. </td>
  1094. </tr>
  1095. <tr>
  1096. <td>moveTo(time [, options])</td>
  1097. <td>none</td>
  1098. <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:
  1099. <ul>
  1100. <li><code>animate: boolean or number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms.</li>
  1101. </ul>
  1102. </td>
  1103. </tr>
  1104. <tr>
  1105. <td>on(event, callback)</td>
  1106. <td>none</td>
  1107. <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>
  1108. </tr>
  1109. <tr>
  1110. <td>off(event, callback)</td>
  1111. <td>none</td>
  1112. <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>
  1113. </tr>
  1114. <tr>
  1115. <td>redraw()</td>
  1116. <td>none</td>
  1117. <td>Force a redraw of the Graph2d. Can be useful to manually redraw when option autoResize=false.
  1118. </td>
  1119. </tr>
  1120. <tr>
  1121. <td>setCurrentTime(time)</td>
  1122. <td>none</td>
  1123. <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.
  1124. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  1125. Only applicable when option <code>showCurrentTime</code> is true.</td>
  1126. </tr>
  1127. <tr>
  1128. <td>setCustomTime(time)</td>
  1129. <td>none</td>
  1130. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  1131. </td>
  1132. </tr>
  1133. <tr>
  1134. <td>setGroups(groups)</td>
  1135. <td>none</td>
  1136. <td>Set a data set with groups for the Graph2d.
  1137. <code>groups</code> can be an Array with Objects,
  1138. a DataSet, or a DataView. For each of the groups, the items of the
  1139. Graph2d are filtered on the property <code>group</code>, which
  1140. must correspond with the id of the group.
  1141. </td>
  1142. </tr>
  1143. <tr>
  1144. <td>setItems(items)</td>
  1145. <td>none</td>
  1146. <td>Set a data set with items for the Graph2d.
  1147. <code>items</code> can be an Array with Objects,
  1148. a DataSet, or a DataView.
  1149. </td>
  1150. </tr>
  1151. <tr>
  1152. <td>setOptions(options)</td>
  1153. <td>none</td>
  1154. <td>Set or update options. It is possible to change any option of the Graph2d at any time. You can for example switch orientation on the fly.
  1155. </td>
  1156. </tr>
  1157. <tr>
  1158. <td>setWindow(start, end)</td>
  1159. <td>none</td>
  1160. <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.</td>
  1161. </tr>
  1162. </table>
  1163. <h2 id="Events">Events</h2>
  1164. <p>
  1165. Graph2d fires events when changing the visible window by dragging, when
  1166. selecting items, and when dragging the custom time bar.
  1167. </p>
  1168. <p>
  1169. Here an example on how to listen for a <code>rangeChanged</code> event. A listener can be removed via the function <code>off</code>:
  1170. </p>
  1171. <pre class="prettyprint lang-js">
  1172. function onChange (properties) {
  1173. alert('changed!');
  1174. }
  1175. // add event listener
  1176. Graph2d.on('rangechanged', onChange);
  1177. // do stuff...
  1178. // remove event listener
  1179. Graph2d.off('rangechanged', onChange);
  1180. </pre>
  1181. <p>
  1182. The following events are available.
  1183. </p>
  1184. <table class="events">
  1185. <tr>
  1186. <th>Name</th>
  1187. <th>Properties</th>
  1188. <th>Description</th>
  1189. </tr>
  1190. <tr>
  1191. <td>currentTimeTick</td>
  1192. <td>Fired when the current time bar redraws. The rate depends on the zoom level.</td>
  1193. </tr>
  1194. <tr>
  1195. <td>click</td>
  1196. <td>
  1197. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1198. </td>
  1199. <td>Fired when clicked inside the Graph2d.
  1200. </td>
  1201. </tr>
  1202. <tr>
  1203. <td>contextmenu</td>
  1204. <td>
  1205. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1206. </td>
  1207. <td>Fired when right-clicked inside the Graph2d. Note that in order to prevent the context menu from showing up, default behavior of the event must be stopped:
  1208. <pre class="prettyprint lang-js options">graph2d.on('contextmenu', function (props) {
  1209. alert('Right click!');
  1210. props.event.preventDefault();
  1211. });
  1212. </pre>
  1213. </td>
  1214. </tr>
  1215. <tr>
  1216. <td>doubleClick</td>
  1217. <td>
  1218. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1219. </td>
  1220. <td>Fired when double clicked inside the Graph2d.
  1221. </td>
  1222. </tr>
  1223. <tr>
  1224. <td>changed</td>
  1225. <td>
  1226. Has no properties.
  1227. </td>
  1228. <td>Fired once after each graph redraw.
  1229. </td>
  1230. </tr>
  1231. <tr>
  1232. <td>rangechange</td>
  1233. <td>
  1234. <ul>
  1235. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1236. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1237. </ul>
  1238. </td>
  1239. <td>Fired repeatedly when the user is dragging the Graph2d window.
  1240. </td>
  1241. </tr>
  1242. <tr>
  1243. <td>rangechanged</td>
  1244. <td>
  1245. <ul>
  1246. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1247. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1248. </ul>
  1249. </td>
  1250. <td>Fired once after the user has dragged the Graph2d window.
  1251. </td>
  1252. </tr>
  1253. <tr>
  1254. <td>timechange</td>
  1255. <td>
  1256. <ul>
  1257. <li><code>time</code> (Date): the current time.</li>
  1258. </ul>
  1259. </td>
  1260. <td>Fired repeatedly when the user is dragging the custom time bar.
  1261. Only available when the custom time bar is enabled.
  1262. </td>
  1263. </tr>
  1264. <tr>
  1265. <td>timechanged</td>
  1266. <td>
  1267. <ul>
  1268. <li><code>time</code> (Date): the current time.</li>
  1269. </ul>
  1270. </td>
  1271. <td>Fired once after the user has dragged the custom time bar.
  1272. Only available when the custom time bar is enabled.
  1273. </td>
  1274. </tr>
  1275. </table>
  1276. <h2 id="Localization">Localization</h2>
  1277. <p>
  1278. Graph2d can be localized. For localization, Graph2d 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.
  1279. </p>
  1280. <p>
  1281. To set a locale for the Graph2d, specify the option <code>locale</code>:
  1282. </p>
  1283. <pre class="prettyprint lang-js">var options = {
  1284. locale: 'nl'
  1285. };
  1286. </pre>
  1287. <h3>Create a new locale</h3>
  1288. To load a locale into the Graph2d not supported by default, one can add a new locale to the option <code>locales</code>:
  1289. <pre class="prettyprint lang-js">var options = {
  1290. locales: {
  1291. // create a new locale
  1292. mylocale: {
  1293. current: 'current',
  1294. time: 'time',
  1295. }
  1296. },
  1297. // use the new locale
  1298. locale: 'mylocale'
  1299. };
  1300. </pre>
  1301. <h3 id="available-locales">Available locales</h3>
  1302. Graph2d comes with support for the following locales:
  1303. <table>
  1304. <tr><td>Language</td><td>Code</td></tr>
  1305. <tr>
  1306. <td>English</td>
  1307. <td>
  1308. <code>en</code><br>
  1309. <code>en_EN</code><br>
  1310. <code>en_US</code>
  1311. </td>
  1312. </tr>
  1313. <tr>
  1314. <td>Dutch</td>
  1315. <td>
  1316. <code>nl</code><br>
  1317. <code>nl_NL</code><br>
  1318. <code>nl_BE</code>
  1319. </td>
  1320. </tr>
  1321. </table>
  1322. <h2 id="Time_zone">Time zone</h2>
  1323. <p>
  1324. By default, the Timeline displays time in local time. To display a Timeline in an other 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>.
  1325. </p>
  1326. <p>
  1327. Examples:
  1328. </p>
  1329. <pre class="prettyprint lang-js">// display in UTC
  1330. var options = {
  1331. moment: function(date) {
  1332. return vis.moment(date).utc();
  1333. }
  1334. };
  1335. // display in UTC +08:00
  1336. var options = {
  1337. moment: function(date) {
  1338. return vis.moment(date).utcOffset('+08:00');
  1339. }
  1340. };
  1341. </pre>
  1342. <h2 id="Styles">Styles</h2>
  1343. <p>
  1344. All parts of the Graph2d have a class name and a default css style just like the Graph2d.
  1345. The styles can be overwritten, which enables full customization of the layout
  1346. of the Graph2d.
  1347. </p>
  1348. <p>
  1349. Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  1350. as well, along with defining your own classes to style the graphs! <a href="../../examples/graph2d/04_rightAxis.html">Example 4</a> and
  1351. <a href="../../examples/graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  1352. </p>
  1353. </div>
  1354. <!-- Bootstrap core JavaScript
  1355. ================================================== -->
  1356. <!-- Placed at the end of the document so the pages load faster -->
  1357. <script src="../js/jquery.min.js"></script>
  1358. <script src="../js/bootstrap.min.js"></script>
  1359. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  1360. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  1361. <!-- jquery extensions -->
  1362. <script src="../js/jquery.highlight.js"></script>
  1363. <script src="../js/jquery.url.min.js"></script>
  1364. <!-- Tipue vendor js -->
  1365. <script src="../js/tipuesearch.config.js"></script>
  1366. <script src="../js/tipuesearch.js"></script>
  1367. <!-- controller -->
  1368. <script src="../js/main.js"></script>