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.

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