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.

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