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.

673 lines
18 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
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="js/prettify/prettify.js"></script>
  7. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></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>zValueLabel</td>
  448. <td>function</td>
  449. <td>none</td>
  450. <td>A function for custom formatting of the labels along the z-axis,
  451. for example <code>function (z) {return (z * 100) + '%'}</code>.
  452. </td>
  453. </tr>
  454. <tr>
  455. <td>xLabel</td>
  456. <td>String</td>
  457. <td>x</td>
  458. <td>Label on the X axis.</td>
  459. </tr>
  460. <tr>
  461. <td>yLabel</td>
  462. <td>String</td>
  463. <td>y</td>
  464. <td>Label on the Y axis.</td>
  465. </tr>
  466. <tr>
  467. <td>zLabel</td>
  468. <td>String</td>
  469. <td>z</td>
  470. <td>Label on the Z axis.</td>
  471. </tr>
  472. <tr>
  473. <td>filterLabel</td>
  474. <td>String</td>
  475. <td>time</td>
  476. <td>Label for the filter column.</td>
  477. </tr>
  478. <tr>
  479. <td>legendLabel</td>
  480. <td>String</td>
  481. <td>value</td>
  482. <td>Label for the style description.</td>
  483. </tr>
  484. </table>
  485. <h2 id="Methods">Methods</h2>
  486. <p>
  487. Graph3d supports the following methods.
  488. </p>
  489. <table>
  490. <tr>
  491. <th>Method</th>
  492. <th>Return Type</th>
  493. <th>Description</th>
  494. </tr>
  495. <tr>
  496. <td>animationStart()</td>
  497. <td>none</td>
  498. <td>Start playing the animation.
  499. Only applicable when animation data is available.</td>
  500. </tr>
  501. <tr>
  502. <td>animationStop()</td>
  503. <td>none</td>
  504. <td>Stop playing the animation.
  505. Only applicable when animation data is available.</td>
  506. </tr>
  507. <tr>
  508. <td>getCameraPosition()</td>
  509. <td>An object with parameters <code>horizontal</code>,
  510. <code>vertical</code> and <code>distance</code></td>
  511. <td>Returns an object with parameters <code>horizontal</code>,
  512. <code>vertical</code> and <code>distance</code>,
  513. which each one of them is a number, representing the rotation and position
  514. of the camera.</td>
  515. </tr>
  516. <tr>
  517. <td>redraw()</td>
  518. <td>none</td>
  519. <td>Redraw the graph. Useful after the camera position is changed externally,
  520. when data is changed, or when the layout of the webpage changed.</td>
  521. </tr>
  522. <tr>
  523. <td>setData(data)</td>
  524. <td>none</td>
  525. <td>Replace the data in the Graph3d.</td>
  526. </tr>
  527. <tr>
  528. <td>setOptions(options)</td>
  529. <td>none</td>
  530. <td>Update options of Graph3d.
  531. The provided options will be merged with current options.</td>
  532. </tr>
  533. <tr>
  534. <td>setSize(width, height)</td>
  535. <td>none</td>
  536. <td>Parameters <code>width</code> and <code>height</code> are strings,
  537. containing a new size for the graph. Size can be provided in pixels
  538. or in percentages.</td>
  539. </tr>
  540. <tr>
  541. <td>setCameraPosition (pos)</td>
  542. <td>{horizontal:&nbsp;1.0, vertical:&nbsp;0.5, distance:&nbsp;1.7}</td>
  543. <td>Set the rotation and position of the camera. Parameter <code>pos</code>
  544. is an object which contains three parameters: <code>horizontal</code>,
  545. <code>vertical</code>, and <code>distance</code>.
  546. Parameter <code>horizontal</code> is a value in radians and can have any
  547. value (but normally in the range of 0 and 2*Pi).
  548. Parameter <code>vertical</code> is a value in radians between 0 and 0.5*Pi.
  549. Parameter <code>distance</code> is the (normalized) distance from the
  550. camera to the center of the graph, in the range of 0.71 to 5.0. A
  551. larger distance puts the graph further away, making it smaller.
  552. All parameters are optional.
  553. </td>
  554. </tr>
  555. </table>
  556. <h2 id="Events">Events</h2>
  557. <p>
  558. Graph3d fires events after the camera position has been changed.
  559. The event can be catched by creating a listener.
  560. Here an example on how to catch a <code>cameraPositionChange</code> event.
  561. </p>
  562. <pre class="prettyprint lang-js">
  563. function onCameraPositionChange(event) {
  564. alert('The camera position changed to:\n' +
  565. 'Horizontal: ' + event.horizontal + '\n' +
  566. 'Vertical: ' + event.vertical + '\n' +
  567. 'Distance: ' + event.distance);
  568. }
  569. // assuming var graph3d = new vis.Graph3d(document.getElementById('mygraph'));
  570. graph3d.on('cameraPositionChange', onCameraPositionChange);
  571. </pre>
  572. <p>
  573. The following events are available.
  574. </p>
  575. <table>
  576. <col width="10%">
  577. <col width="60%">
  578. <col width="30%">
  579. <tr>
  580. <th>name</th>
  581. <th>Description</th>
  582. <th>Properties</th>
  583. </tr>
  584. <tr>
  585. <td>cameraPositionChange</td>
  586. <td>The camera position changed. Fired after the user modified the camera position
  587. by moving (dragging) the graph, or by zooming (scrolling),
  588. but not after a call to <code>setCameraPosition</code> method.
  589. The new camera position can be retrieved by calling the method
  590. <code>getCameraPosition</code>.</td>
  591. <td>
  592. <ul>
  593. <li><code>horizontal</code>: Number. The horizontal angle of the camera.</li>
  594. <li><code>vertical</code>: Number. The vertical angle of the camera.</li>
  595. <li><code>distance</code>: Number. The distance of the camera to the center of the graph.</li>
  596. </ul>
  597. </td>
  598. </tr>
  599. </table>
  600. <h2 id="Data_Policy">Data Policy</h2>
  601. <p>
  602. All code and data are processed and rendered in the browser. No data is sent to any server.
  603. </p>
  604. </div>
  605. </body>
  606. </html>