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.

1495 lines
59 KiB

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