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.

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