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.

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