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.

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