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.

649 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
  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>yBarWidth</td>
  381. <td>number</td>
  382. <td>none</td>
  383. <td>The width of bars in y direction. By default, the width is equal to the distance
  384. between the data points, such that bars adjoin each other.
  385. Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td>
  386. </tr>
  387. <tr>
  388. <td>yCenter</td>
  389. <td>string</td>
  390. <td>'45%'</td>
  391. <td>The vertical center position of the graph, as a percentage or in
  392. pixels.</td>
  393. </tr>
  394. <tr>
  395. <td>yMax</td>
  396. <td>number</td>
  397. <td>none</td>
  398. <td>The maximum value for the y-axis.</td>
  399. </tr>
  400. <tr>
  401. <td>yMin</td>
  402. <td>number</td>
  403. <td>none</td>
  404. <td>The minimum value for the y-axis.</td>
  405. </tr>
  406. <tr>
  407. <td>yStep</td>
  408. <td>number</td>
  409. <td>none</td>
  410. <td>Step size for the grid on the y-axis.</td>
  411. </tr>
  412. <tr>
  413. <td>zMin</td>
  414. <td>number</td>
  415. <td>none</td>
  416. <td>The minimum value for the z-axis.</td>
  417. </tr>
  418. <tr>
  419. <td>zMax</td>
  420. <td>number</td>
  421. <td>none</td>
  422. <td>The maximum value for the z-axis.</td>
  423. </tr>
  424. <tr>
  425. <td>zStep</td>
  426. <td>number</td>
  427. <td>none</td>
  428. <td>Step size for the grid on the z-axis.</td>
  429. </tr>
  430. <tr>
  431. <td>xLabel</td>
  432. <td>String</td>
  433. <td>x</td>
  434. <td>Label on the X axis.</td>
  435. </tr>
  436. <tr>
  437. <td>yLabel</td>
  438. <td>String</td>
  439. <td>y</td>
  440. <td>Label on the Y axis.</td>
  441. </tr>
  442. <tr>
  443. <td>zLabel</td>
  444. <td>String</td>
  445. <td>z</td>
  446. <td>Label on the Z axis.</td>
  447. </tr>
  448. <tr>
  449. <td>filterLabel</td>
  450. <td>String</td>
  451. <td>time</td>
  452. <td>Label for the filter column.</td>
  453. </tr>
  454. <tr>
  455. <td>legendLabel</td>
  456. <td>String</td>
  457. <td>value</td>
  458. <td>Label for the style description.</td>
  459. </tr>
  460. </table>
  461. <h2 id="Methods">Methods</h2>
  462. <p>
  463. Graph3d supports the following methods.
  464. </p>
  465. <table>
  466. <tr>
  467. <th>Method</th>
  468. <th>Return Type</th>
  469. <th>Description</th>
  470. </tr>
  471. <tr>
  472. <td>animationStart()</td>
  473. <td>none</td>
  474. <td>Start playing the animation.
  475. Only applicable when animation data is available.</td>
  476. </tr>
  477. <tr>
  478. <td>animationStop()</td>
  479. <td>none</td>
  480. <td>Stop playing the animation.
  481. Only applicable when animation data is available.</td>
  482. </tr>
  483. <tr>
  484. <td>getCameraPosition()</td>
  485. <td>An object with parameters <code>horizontal</code>,
  486. <code>vertical</code> and <code>distance</code></td>
  487. <td>Returns an object with parameters <code>horizontal</code>,
  488. <code>vertical</code> and <code>distance</code>,
  489. which each one of them is a number, representing the rotation and position
  490. of the camera.</td>
  491. </tr>
  492. <tr>
  493. <td>redraw()</td>
  494. <td>none</td>
  495. <td>Redraw the graph. Useful after the camera position is changed externally,
  496. when data is changed, or when the layout of the webpage changed.</td>
  497. </tr>
  498. <tr>
  499. <td>setData(data)</td>
  500. <td>none</td>
  501. <td>Replace the data in the Graph3d.</td>
  502. </tr>
  503. <tr>
  504. <td>setOptions(options)</td>
  505. <td>none</td>
  506. <td>Update options of Graph3d.
  507. The provided options will be merged with current options.</td>
  508. </tr>
  509. <tr>
  510. <td>setSize(width, height)</td>
  511. <td>none</td>
  512. <td>Parameters <code>width</code> and <code>height</code> are strings,
  513. containing a new size for the graph. Size can be provided in pixels
  514. or in percentages.</td>
  515. </tr>
  516. <tr>
  517. <td>setCameraPosition (pos)</td>
  518. <td>{horizontal:&nbsp;1.0, vertical:&nbsp;0.5, distance:&nbsp;1.7}</td>
  519. <td>Set the rotation and position of the camera. Parameter <code>pos</code>
  520. is an object which contains three parameters: <code>horizontal</code>,
  521. <code>vertical</code>, and <code>distance</code>.
  522. Parameter <code>horizontal</code> is a value in radians and can have any
  523. value (but normally in the range of 0 and 2*Pi).
  524. Parameter <code>vertical</code> is a value in radians between 0 and 0.5*Pi.
  525. Parameter <code>distance</code> is the (normalized) distance from the
  526. camera to the center of the graph, in the range of 0.71 to 5.0. A
  527. larger distance puts the graph further away, making it smaller.
  528. All parameters are optional.
  529. </td>
  530. </tr>
  531. </table>
  532. <h2 id="Events">Events</h2>
  533. <p>
  534. Graph3d fires events after the camera position has been changed.
  535. The event can be catched by creating a listener.
  536. Here an example on how to catch a <code>cameraPositionChange</code> event.
  537. </p>
  538. <pre class="prettyprint lang-js">
  539. function onCameraPositionChange(event) {
  540. alert('The camera position changed to:\n' +
  541. 'Horizontal: ' + event.horizontal + '\n' +
  542. 'Vertical: ' + event.vertical + '\n' +
  543. 'Distance: ' + event.distance);
  544. }
  545. // assuming var graph3d = new vis.Graph3d(document.getElementById('mygraph'));
  546. graph3d.on('cameraPositionChange', onCameraPositionChange);
  547. </pre>
  548. <p>
  549. The following events are available.
  550. </p>
  551. <table>
  552. <col width="10%">
  553. <col width="60%">
  554. <col width="30%">
  555. <tr>
  556. <th>name</th>
  557. <th>Description</th>
  558. <th>Properties</th>
  559. </tr>
  560. <tr>
  561. <td>cameraPositionChange</td>
  562. <td>The camera position changed. Fired after the user modified the camera position
  563. by moving (dragging) the graph, or by zooming (scrolling),
  564. but not after a call to <code>setCameraPosition</code> method.
  565. The new camera position can be retrieved by calling the method
  566. <code>getCameraPosition</code>.</td>
  567. <td>
  568. <ul>
  569. <li><code>horizontal</code>: Number. The horizontal angle of the camera.</li>
  570. <li><code>vertical</code>: Number. The vertical angle of the camera.</li>
  571. <li><code>distance</code>: Number. The distance of the camera to the center of the graph.</li>
  572. </ul>
  573. </td>
  574. </tr>
  575. </table>
  576. <h2 id="Data_Policy">Data Policy</h2>
  577. <p>
  578. All code and data are processed and rendered in the browser. No data is sent to any server.
  579. </p>
  580. </div>
  581. </body>
  582. </html>