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.

108 lines
3.1 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
  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. 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. // create our graph
  65. var container = document.getElementById('mygraph');
  66. graph = new vis.Graph3d(container, data, options);
  67. graph.on("cameraPositionChange", onCameraPositionChange);
  68. }
  69. </script>
  70. </head>
  71. <body onload="drawVisualization()">
  72. <h1>Graph 3d camera position</h1>
  73. <table>
  74. <tr>
  75. <td>Horizontal angle (0 to 2*pi)</td>
  76. <td><input type="text" id="horizontal" value="1.0"></td>
  77. </tr>
  78. <tr>
  79. <td>Vertical angle (0 to 0.5*pi)</td>
  80. <td><input type="text" id="vertical" value="0.5"></td>
  81. </tr>
  82. <tr>
  83. <td>Distance (0.71 to 5.0)</td>
  84. <td><input type="text" id="distance" value="1.7"></td>
  85. </tr>
  86. <tr>
  87. <td></td>
  88. <td><input type="button" value="Set" onclick="setCameraPosition();"></td>
  89. </tr>
  90. </table>
  91. <div id="mygraph"></div>
  92. <div id="info"></div>
  93. </body>
  94. </html>