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.

111 lines
3.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Graph 3D camera position</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. td {font: 10pt arial}
  8. </style>
  9. <script type="text/javascript" src="../../dist/vis.js"></script>
  10. <script type="text/javascript">
  11. var data = null;
  12. var graph = null;
  13. function custom(x, y) {
  14. return (Math.sin(x/50) * Math.cos(y/50) * 50 + 50);
  15. }
  16. // callback function, called when the camera position has changed
  17. function oncamerapositionchange() {
  18. // adjust the values of startDate and endDate
  19. var pos = graph.getCameraPosition();
  20. document.getElementById('horizontal').value = parseFloat(pos.horizontal.toFixed(3));
  21. document.getElementById('vertical').value = parseFloat(pos.vertical.toFixed(3));
  22. document.getElementById('distance').value = parseFloat(pos.distance.toFixed(3));
  23. }
  24. // set the camera position
  25. function setcameraposition() {
  26. var horizontal = parseFloat(document.getElementById('horizontal').value);
  27. var vertical = parseFloat(document.getElementById('vertical').value);
  28. var distance = parseFloat(document.getElementById('distance').value);
  29. var pos = {
  30. "horizontal": horizontal,
  31. "vertical":vertical,
  32. "distance":distance};
  33. graph.setCameraPosition(pos);
  34. // retrieve the camera position again, to get the applied values
  35. oncamerapositionchange();
  36. }
  37. // Called when the Visualization API is loaded.
  38. function drawVisualization() {
  39. // Create and populate a data table.
  40. var data = new vis.DataSet({});
  41. // create some nice looking data with sin/cos
  42. var steps = 50; // number of datapoints will be steps*steps
  43. var axisMax = 314;
  44. var axisStep = axisMax / steps;
  45. for (var x = 0; x < axisMax; x+=axisStep) {
  46. for (var y = 0; y < axisMax; y+=axisStep) {
  47. var value = custom(x,y);
  48. data.add([
  49. {x:x,y:y,z:value,t:0,style:value}
  50. ]);
  51. }
  52. }
  53. // specify options
  54. var options = {
  55. width: "600px",
  56. height: "600px",
  57. style: "surface",
  58. showPerspective: true,
  59. showGrid: true,
  60. showShadow: false,
  61. keepAspectRatio: true,
  62. verticalRatio: 0.5
  63. };
  64. // Instantiate our graph object.
  65. graph = new vis.Graph3d(document.getElementById('mygraph'));
  66. // Draw our graph with the created data and options
  67. graph.draw(data, options);
  68. graph.on("camerapositionchange", oncamerapositionchange);
  69. //graph.redraw();
  70. }
  71. </script>
  72. </head>
  73. <body onload="drawVisualization()">
  74. <h1>Graph 3d camera position</h1>
  75. <table>
  76. <tr>
  77. <td>Horizontal angle (0 to 2*pi)</td>
  78. <td><input type="text" id="horizontal" value="1.0"></td>
  79. </tr>
  80. <tr>
  81. <td>Vertical angle (0 to 0.5*pi)</td>
  82. <td><input type="text" id="vertical" value="0.5"></td>
  83. </tr>
  84. <tr>
  85. <td>Distance (0.71 to 5.0)</td>
  86. <td><input type="text" id="distance" value="1.7"></td>
  87. </tr>
  88. <tr>
  89. <td></td>
  90. <td><input type="button" value="Set" onclick="setcameraposition();"></td>
  91. </tr>
  92. </table>
  93. <div id="mygraph"></div>
  94. <div id="info"></div>
  95. </body>
  96. </html>