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.

665 lines
17 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <html>
  2. <head>
  3. <title>vis.js | graph3d documentation</title>
  4. <link href='css/prettify.css' type='text/css' rel='stylesheet'>
  5. <link href='css/style.css' type='text/css' rel='stylesheet'>
  6. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <div id="container">
  10. <h1>Graph3d documentation</h1>
  11. <h2 id="Overview">Overview</h2>
  12. <p>
  13. Graph3d is an interactive visualization chart to draw data in a three dimensional
  14. graph. You can freely move and zoom in the graph by dragging and scrolling in the
  15. window. Graph3d also supports animation of a graph.
  16. </p>
  17. <p>
  18. Graph3d uses <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Canvas">HTML canvas</a>
  19. to render graphs, and can render up to a few thousands of data points smoothly.
  20. </p>
  21. <h2 id="Contents">Contents</h2>
  22. <ul>
  23. <li><a href="#Overview">Overview</a></li>
  24. <li><a href="#Loading">Loading</a></li>
  25. <li><a href="#Data_Format">Data Format</a></li>
  26. <li><a href="#Configuration_Options">Configuration Options</a></li>
  27. <li><a href="#Methods">Methods</a></li>
  28. <li><a href="#Events">Events</a></li>
  29. <li><a href="#Data_Policy">Data Policy</a></li>
  30. </ul>
  31. <h2 id="Example">Example</h2>
  32. <p>
  33. The following code shows how to create a Graph3d and provide it with data.
  34. More examples can be found in the <a href="../examples">examples</a> directory.
  35. </p>
  36. <pre class="prettyprint lang-html">
  37. &lt;!DOCTYPE HTML&gt;
  38. &lt;html&gt;
  39. &lt;head&gt;
  40. &lt;title&gt;Graph 3D demo&lt;/title&gt;
  41. &lt;style&gt;
  42. body {font: 10pt arial;}
  43. &lt;/style&gt;
  44. &lt;script type="text/javascript" src="../../dist/vis.js"&gt;&lt;/script&gt;
  45. &lt;script type="text/javascript"&gt;
  46. var data = null;
  47. var graph = null;
  48. function custom(x, y) {
  49. return (Math.sin(x/50) * Math.cos(y/50) * 50 + 50);
  50. }
  51. // Called when the Visualization API is loaded.
  52. function drawVisualization() {
  53. // Create and populate a data table.
  54. var data = new vis.DataSet();
  55. // create some nice looking data with sin/cos
  56. var steps = 50; // number of datapoints will be steps*steps
  57. var axisMax = 314;
  58. var axisStep = axisMax / steps;
  59. for (var x = 0; x &lt; axisMax; x+=axisStep) {
  60. for (var y = 0; y &lt; axisMax; y+=axisStep) {
  61. var value = custom(x, y);
  62. data.add({
  63. x: x,
  64. y: y,
  65. z: value,
  66. style: value
  67. });
  68. }
  69. }
  70. // specify options
  71. var options = {
  72. width: '600px',
  73. height: '600px',
  74. style: 'surface',
  75. showPerspective: true,
  76. showGrid: true,
  77. showShadow: false,
  78. keepAspectRatio: true,
  79. verticalRatio: 0.5
  80. };
  81. // create a graph3d
  82. var container = document.getElementById('mygraph');
  83. graph3d = new vis.Graph3d(container, data, options);
  84. }
  85. &lt;/script&gt;
  86. &lt;/head&gt;
  87. &lt;body onload="drawVisualization();"&gt;
  88. &lt;div id="mygraph"&gt;&lt;/div&gt;
  89. &lt;/body&gt;
  90. &lt;/html&gt;
  91. </pre>
  92. <h2 id="Loading">Loading</h2>
  93. <p>
  94. The class name of the Graph3d is <code>vis.Graph3d</code>.
  95. When constructing a Graph3d, an HTML DOM container must be provided to attach
  96. the graph to. Optionally, data an options can be provided.
  97. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  98. section <a href="#Data_Format">Data Format</a>.
  99. Options is a name-value map in the JSON format. The available options
  100. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  101. </p>
  102. <pre class="prettyprint lang-js">var graph = new vis.Graph3d(container [, data] [, options]);</pre>
  103. <p>
  104. Data and options can be set or changed later on using the functions
  105. <code>Graph3d.setData(data)</code> and <code>Graph3d.setOptions(options)</code>.
  106. </p>
  107. <h2 id="Data_Format">Data Format</h2>
  108. <p>
  109. Graph3d can load data from an <code>Array</code>, a <code>DataSet</code> or a <code>DataView</code>.
  110. JSON objects are added to this DataSet by using the <code>add()</code> function.
  111. Data points must have properties <code>x</code>, <code>y</code>, and <code>z</code>,
  112. and can optionally have a property <code>style</code> and <code>filter</code>.
  113. <h3>Definition</h3>
  114. <p>
  115. The DataSet JSON objects are defined as:
  116. </p>
  117. <table>
  118. <tr>
  119. <th>Name</th>
  120. <th>Type</th>
  121. <th>Required</th>
  122. <th>Description</th>
  123. </tr>
  124. <tr>
  125. <td>x</td>
  126. <td>number</td>
  127. <td>yes</td>
  128. <td>Location on the x-axis.</td>
  129. </tr>
  130. <tr>
  131. <td>y</td>
  132. <td>number</td>
  133. <td>yes</td>
  134. <td>Location on the y-axis.</td>
  135. </tr>
  136. <tr>
  137. <td>z</td>
  138. <td>number</td>
  139. <td>yes</td>
  140. <td>Location on the z-axis.</td>
  141. </tr>
  142. <tr>
  143. <td>style</td>
  144. <td>number</td>
  145. <td>no</td>
  146. <td>The data value, required for graph styles <code>dot-color</code> and
  147. <code>dot-size</code>.
  148. </td>
  149. </tr>
  150. <tr>
  151. <td>filter</td>
  152. <td>*</td>
  153. <td>no</td>
  154. <td>Filter values used for the animation.
  155. This column may have any type, such as a number, string, or Date.</td>
  156. </tr>
  157. </table>
  158. <h2 id="Configuration_Options">Configuration Options</h2>
  159. <p>
  160. Options can be used to customize the graph. Options are defined as a JSON object.
  161. All options are optional.
  162. </p>
  163. <pre class="prettyprint lang-js">
  164. var options = {
  165. width: '100%',
  166. height: '400px',
  167. style: 'surface'
  168. };
  169. </pre>
  170. <p>
  171. The following options are available.
  172. </p>
  173. <table>
  174. <tr>
  175. <th>Name</th>
  176. <th>Type</th>
  177. <th>Default</th>
  178. <th>Description</th>
  179. </tr>
  180. <tr>
  181. <td>animationInterval</td>
  182. <td>number</td>
  183. <td>1000</td>
  184. <td>The animation interval in milliseconds. This determines how fast
  185. the animation runs.</td>
  186. </tr>
  187. <tr>
  188. <td>animationPreload</td>
  189. <td>boolean</td>
  190. <td>false</td>
  191. <td>If false, the animation frames are loaded as soon as they are requested.
  192. if <code>animationPreload</code> is true, the graph will automatically load
  193. all frames in the background, resulting in a smoother animation as soon as
  194. all frames are loaded. The load progress is shown on screen.</td>
  195. </tr>
  196. <tr>
  197. <td>animationAutoStart</td>
  198. <td>boolean</td>
  199. <td>false</td>
  200. <td>If true, the animation starts playing automatically after the graph
  201. is created.</td>
  202. </tr>
  203. <tr>
  204. <td>backgroundColor</td>
  205. <td>string or Object</td>
  206. <td>'white'</td>
  207. <td>The background color for the main area of the chart.
  208. Can be either a simple HTML color string, for example: 'red' or '#00cc00',
  209. or an object with the following properties.</td>
  210. </tr>
  211. <tr>
  212. <td>backgroundColor.stroke</td>
  213. <td>string</td>
  214. <td>'gray'</td>
  215. <td>The color of the chart border, as an HTML color string.</td>
  216. </tr>
  217. <tr>
  218. <td>backgroundColor.strokeWidth</td>
  219. <td>number</td>
  220. <td>1</td>
  221. <td>The border width, in pixels.</td>
  222. </tr>
  223. <tr>
  224. <td>backgroundColor.fill</td>
  225. <td>string</td>
  226. <td>'white'</td>
  227. <td>The chart fill color, as an HTML color string.</td>
  228. </tr>
  229. <tr>
  230. <td>cameraPosition</td>
  231. <td>Object</td>
  232. <td>{horizontal:&nbsp;1.0, vertical:&nbsp;0.5, distance:&nbsp;1.7}</td>
  233. <td>Set the initial rotation and position of the camera.
  234. The object <code>cameraPosition</code> contains three parameters:
  235. <code>horizontal</code>, <code>vertical</code>, and <code>distance</code>.
  236. Parameter <code>horizontal</code> is a value in radians and can have any
  237. value (but normally in the range of 0 and 2*Pi).
  238. Parameter <code>vertical</code> is a value in radians between 0 and 0.5*Pi.
  239. Parameter <code>distance</code> is the (normalized) distance from the
  240. camera to the center of the graph, in the range of 0.71 to 5.0. A
  241. larger distance puts the graph further away, making it smaller.
  242. All parameters are optional.
  243. </tr>
  244. <tr>
  245. <td>height</td>
  246. <td>string</td>
  247. <td>'400px'</td>
  248. <td>The height of the graph in pixels or as a percentage.</td>
  249. </tr>
  250. <tr>
  251. <td>keepAspectRatio</td>
  252. <td>boolean</td>
  253. <td>true</td>
  254. <td>If <code>keepAspectRatio</code> is true, the x-axis and the y-axis
  255. keep their aspect ratio. If false, the axes are scaled such that they
  256. both have the same, maximum with.</td>
  257. </tr>
  258. <tr>
  259. <td>showAnimationControls</td>
  260. <td>boolean</td>
  261. <td>true</td>
  262. <td>If true, animation controls are created at the bottom of the Graph.
  263. The animation controls consists of buttons previous, start/stop, next,
  264. and a slider showing the current frame.
  265. Only applicable when the provided data contains an animation.</td>
  266. </tr>
  267. <tr>
  268. <td>showGrid</td>
  269. <td>boolean</td>
  270. <td>true</td>
  271. <td>If true, grid lines are draw in the x-y surface (the bottom of the 3d
  272. graph).</td>
  273. </tr>
  274. <tr>
  275. <td>showPerspective</td>
  276. <td>boolean</td>
  277. <td>true</td>
  278. <td>If true, the graph is drawn in perspective: points and lines which
  279. are further away are drawn smaller.
  280. Note that the graph currently does not support a gray colored bottom side
  281. when drawn in perspective.
  282. </td>
  283. </tr>
  284. <tr>
  285. <td>showShadow</td>
  286. <td>boolean</td>
  287. <td>false</td>
  288. <td>Show shadow on the graph.</td>
  289. </tr>
  290. <tr>
  291. <td>style</td>
  292. <td>string</td>
  293. <td>'dot'</td>
  294. <td>The style of the 3d graph. Available styles:
  295. <code>bar</code>,
  296. <code>bar-color</code>,
  297. <code>bar-size</code>,
  298. <code>dot</code>,
  299. <code>dot-line</code>,
  300. <code>dot-color</code>,
  301. <code>dot-size</code>,
  302. <code>line</code>,
  303. <code>grid</code>,
  304. or <code>surface</code></td>
  305. </tr>
  306. <tr>
  307. <td>tooltip</td>
  308. <td>boolean | function</td>
  309. <td>false</td>
  310. <td>Show a tooltip showing the values of the hovered data point.
  311. The contents of the tooltip can be customized by providing a callback
  312. function as <code>tooltip</code>. In this case the function is called
  313. with an object containing parameters <code>x</code>,
  314. <code>y</code>, and <code>z</code> argument,
  315. and must return a string which may contain HTML.
  316. </td>
  317. </tr>
  318. <tr>
  319. <td>valueMax</td>
  320. <td>number</td>
  321. <td>none</td>
  322. <td>The maximum value for the value-axis. Only available in combination
  323. with the styles <code>dot-color</code> and <code>dot-size</code>.</td>
  324. </tr>
  325. <tr>
  326. <td>valueMin</td>
  327. <td>number</td>
  328. <td>none</td>
  329. <td>The minimum value for the value-axis. Only available in combination
  330. with the styles <code>dot-color</code> and <code>dot-size</code>.</td>
  331. </tr>
  332. <tr>
  333. <td>verticalRatio</td>
  334. <td>number</td>
  335. <td>0.5</td>
  336. <td>A value between 0.1 and 1.0. This scales the vertical size of the graph
  337. When keepAspectRatio is set to false, and verticalRatio is set to 1.0,
  338. the graph will be a cube.</td>
  339. </tr>
  340. <tr>
  341. <td>width</td>
  342. <td>string</td>
  343. <td>'400px'</td>
  344. <td>The width of the graph in pixels or as a percentage.</td>
  345. </tr>
  346. <tr>
  347. <td>xBarWidth</td>
  348. <td>number</td>
  349. <td>none</td>
  350. <td>The width of bars in x direction. By default, the width is equal to the distance
  351. between the data points, such that bars adjoin each other.
  352. Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td>
  353. </tr>
  354. <tr>
  355. <td>xCenter</td>
  356. <td>string</td>
  357. <td>'55%'</td>
  358. <td>The horizontal center position of the graph, as a percentage or in
  359. pixels.</td>
  360. </tr>
  361. <tr>
  362. <td>xMax</td>
  363. <td>number</td>
  364. <td>none</td>
  365. <td>The maximum value for the x-axis.</td>
  366. </tr>
  367. <tr>
  368. <td>xMin</td>
  369. <td>number</td>
  370. <td>none</td>
  371. <td>The minimum value for the x-axis.</td>
  372. </tr>
  373. <tr>
  374. <td>xStep</td>
  375. <td>number</td>
  376. <td>none</td>
  377. <td>Step size for the grid on the x-axis.</td>
  378. </tr>
  379. <tr>
  380. <td>xValueLabel</td>
  381. <td>function</td>
  382. <td>none</td>
  383. <td>A function for custom formatting of the labels along the x-axis,
  384. for example <code>function (x) {return (x * 100) + '%'}</code>.
  385. </td>
  386. </tr>
  387. <tr>
  388. <td>yBarWidth</td>
  389. <td>number</td>
  390. <td>none</td>
  391. <td>The width of bars in y direction. By default, the width is equal to the distance
  392. between the data points, such that bars adjoin each other.
  393. Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td>
  394. </tr>
  395. <tr>
  396. <td>yCenter</td>
  397. <td>string</td>
  398. <td>'45%'</td>
  399. <td>The vertical center position of the graph, as a percentage or in
  400. pixels.</td>
  401. </tr>
  402. <tr>
  403. <td>yMax</td>
  404. <td>number</td>
  405. <td>none</td>
  406. <td>The maximum value for the y-axis.</td>
  407. </tr>
  408. <tr>
  409. <td>yMin</td>
  410. <td>number</td>
  411. <td>none</td>
  412. <td>The minimum value for the y-axis.</td>
  413. </tr>
  414. <tr>
  415. <td>yStep</td>
  416. <td>number</td>
  417. <td>none</td>
  418. <td>Step size for the grid on the y-axis.</td>
  419. </tr>
  420. <tr>
  421. <td>yValueLabel</td>
  422. <td>function</td>
  423. <td>none</td>
  424. <td>A function for custom formatting of the labels along the y-axis,
  425. for example <code>function (y) {return (y * 100) + '%'}</code>.
  426. </td>
  427. </tr>
  428. <tr>
  429. <td>zMin</td>
  430. <td>number</td>
  431. <td>none</td>
  432. <td>The minimum value for the z-axis.</td>
  433. </tr>
  434. <tr>
  435. <td>zMax</td>
  436. <td>number</td>
  437. <td>none</td>
  438. <td>The maximum value for the z-axis.</td>
  439. </tr>
  440. <tr>
  441. <td>zStep</td>
  442. <td>number</td>
  443. <td>none</td>
  444. <td>Step size for the grid on the z-axis.</td>
  445. </tr>
  446. <tr>
  447. <td>xLabel</td>
  448. <td>String</td>
  449. <td>x</td>
  450. <td>Label on the X axis.</td>
  451. </tr>
  452. <tr>
  453. <td>yLabel</td>
  454. <td>String</td>
  455. <td>y</td>
  456. <td>Label on the Y axis.</td>
  457. </tr>
  458. <tr>
  459. <td>zLabel</td>
  460. <td>String</td>
  461. <td>z</td>
  462. <td>Label on the Z axis.</td>
  463. </tr>
  464. <tr>
  465. <td>filterLabel</td>
  466. <td>String</td>
  467. <td>time</td>
  468. <td>Label for the filter column.</td>
  469. </tr>
  470. <tr>
  471. <td>legendLabel</td>
  472. <td>String</td>
  473. <td>value</td>
  474. <td>Label for the style description.</td>
  475. </tr>
  476. </table>
  477. <h2 id="Methods">Methods</h2>
  478. <p>
  479. Graph3d supports the following methods.
  480. </p>
  481. <table>
  482. <tr>
  483. <th>Method</th>
  484. <th>Return Type</th>
  485. <th>Description</th>
  486. </tr>
  487. <tr>
  488. <td>animationStart()</td>
  489. <td>none</td>
  490. <td>Start playing the animation.
  491. Only applicable when animation data is available.</td>
  492. </tr>
  493. <tr>
  494. <td>animationStop()</td>
  495. <td>none</td>
  496. <td>Stop playing the animation.
  497. Only applicable when animation data is available.</td>
  498. </tr>
  499. <tr>
  500. <td>getCameraPosition()</td>
  501. <td>An object with parameters <code>horizontal</code>,
  502. <code>vertical</code> and <code>distance</code></td>
  503. <td>Returns an object with parameters <code>horizontal</code>,
  504. <code>vertical</code> and <code>distance</code>,
  505. which each one of them is a number, representing the rotation and position
  506. of the camera.</td>
  507. </tr>
  508. <tr>
  509. <td>redraw()</td>
  510. <td>none</td>
  511. <td>Redraw the graph. Useful after the camera position is changed externally,
  512. when data is changed, or when the layout of the webpage changed.</td>
  513. </tr>
  514. <tr>
  515. <td>setData(data)</td>
  516. <td>none</td>
  517. <td>Replace the data in the Graph3d.</td>
  518. </tr>
  519. <tr>
  520. <td>setOptions(options)</td>
  521. <td>none</td>
  522. <td>Update options of Graph3d.
  523. The provided options will be merged with current options.</td>
  524. </tr>
  525. <tr>
  526. <td>setSize(width, height)</td>
  527. <td>none</td>
  528. <td>Parameters <code>width</code> and <code>height</code> are strings,
  529. containing a new size for the graph. Size can be provided in pixels
  530. or in percentages.</td>
  531. </tr>
  532. <tr>
  533. <td>setCameraPosition (pos)</td>
  534. <td>{horizontal:&nbsp;1.0, vertical:&nbsp;0.5, distance:&nbsp;1.7}</td>
  535. <td>Set the rotation and position of the camera. Parameter <code>pos</code>
  536. is an object which contains three parameters: <code>horizontal</code>,
  537. <code>vertical</code>, and <code>distance</code>.
  538. Parameter <code>horizontal</code> is a value in radians and can have any
  539. value (but normally in the range of 0 and 2*Pi).
  540. Parameter <code>vertical</code> is a value in radians between 0 and 0.5*Pi.
  541. Parameter <code>distance</code> is the (normalized) distance from the
  542. camera to the center of the graph, in the range of 0.71 to 5.0. A
  543. larger distance puts the graph further away, making it smaller.
  544. All parameters are optional.
  545. </td>
  546. </tr>
  547. </table>
  548. <h2 id="Events">Events</h2>
  549. <p>
  550. Graph3d fires events after the camera position has been changed.
  551. The event can be catched by creating a listener.
  552. Here an example on how to catch a <code>cameraPositionChange</code> event.
  553. </p>
  554. <pre class="prettyprint lang-js">
  555. function onCameraPositionChange(event) {
  556. alert('The camera position changed to:\n' +
  557. 'Horizontal: ' + event.horizontal + '\n' +
  558. 'Vertical: ' + event.vertical + '\n' +
  559. 'Distance: ' + event.distance);
  560. }
  561. // assuming var graph3d = new vis.Graph3d(document.getElementById('mygraph'));
  562. graph3d.on('cameraPositionChange', onCameraPositionChange);
  563. </pre>
  564. <p>
  565. The following events are available.
  566. </p>
  567. <table>
  568. <col width="10%">
  569. <col width="60%">
  570. <col width="30%">
  571. <tr>
  572. <th>name</th>
  573. <th>Description</th>
  574. <th>Properties</th>
  575. </tr>
  576. <tr>
  577. <td>cameraPositionChange</td>
  578. <td>The camera position changed. Fired after the user modified the camera position
  579. by moving (dragging) the graph, or by zooming (scrolling),
  580. but not after a call to <code>setCameraPosition</code> method.
  581. The new camera position can be retrieved by calling the method
  582. <code>getCameraPosition</code>.</td>
  583. <td>
  584. <ul>
  585. <li><code>horizontal</code>: Number. The horizontal angle of the camera.</li>
  586. <li><code>vertical</code>: Number. The vertical angle of the camera.</li>
  587. <li><code>distance</code>: Number. The distance of the camera to the center of the graph.</li>
  588. </ul>
  589. </td>
  590. </tr>
  591. </table>
  592. <h2 id="Data_Policy">Data Policy</h2>
  593. <p>
  594. All code and data are processed and rendered in the browser. No data is sent to any server.
  595. </p>
  596. </div>
  597. </body>
  598. </html>