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.

121 lines
3.5 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
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph 3D styles</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. </style>
  8. <script type="text/javascript" src="../../dist/vis.js"></script>
  9. <script type="text/javascript">
  10. var data = null;
  11. var graph = null;
  12. function custom(x, y) {
  13. return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10);
  14. }
  15. // Called when the Visualization API is loaded.
  16. function drawVisualization() {
  17. var style = document.getElementById('style').value;
  18. var showPerspective = document.getElementById('perspective').checked;
  19. var xBarWidth = parseFloat(document.getElementById('xBarWidth').value) || undefined;
  20. var yBarWidth = parseFloat(document.getElementById('yBarWidth').value) || undefined;
  21. var withValue = ['bar-color', 'bar-size', 'dot-size', 'dot-color'].indexOf(style) != -1;
  22. // Create and populate a data table.
  23. data = [];
  24. // create some nice looking data with sin/cos
  25. var steps = 5; // number of datapoints will be steps*steps
  26. var axisMax = 10;
  27. var axisStep = axisMax / steps;
  28. for (var x = 0; x <= axisMax; x+=axisStep) {
  29. for (var y = 0; y <= axisMax; y+=axisStep) {
  30. var z = custom(x,y);
  31. if (withValue) {
  32. var value = (y - x);
  33. data.push({x:x, y:y, z: z, style:value});
  34. }
  35. else {
  36. data.push({x:x, y:y, z: z});
  37. }
  38. }
  39. }
  40. // specify options
  41. var options = {
  42. width: '600px',
  43. height: '600px',
  44. style: style,
  45. xBarWidth: xBarWidth,
  46. yBarWidth: yBarWidth,
  47. showPerspective: showPerspective,
  48. showGrid: true,
  49. showShadow: false,
  50. keepAspectRatio: true,
  51. verticalRatio: 0.5
  52. };
  53. var camera = graph ? graph.getCameraPosition() : null;
  54. // create our graph
  55. var container = document.getElementById('mygraph');
  56. graph = new vis.Graph3d(container, data, options);
  57. if (camera) graph.setCameraPosition(camera); // restore camera position
  58. document.getElementById('style').onchange = drawVisualization;
  59. document.getElementById('perspective').onchange = drawVisualization;
  60. document.getElementById('xBarWidth').onchange = drawVisualization;
  61. document.getElementById('yBarWidth').onchange = drawVisualization;
  62. }
  63. </script>
  64. <script src="../googleAnalytics.js"></script>
  65. </head>
  66. <body onload="drawVisualization()">
  67. <p>
  68. <label for="style"> Style:
  69. <select id="style">
  70. <option value="bar">bar</option>
  71. <option value="bar-color">bar-color</option>
  72. <option value="bar-size">bar-size</option>
  73. <option value="dot">dot</option>
  74. <option value="dot-line">dot-line</option>
  75. <option value="dot-color">dot-color</option>
  76. <option value="dot-size">dot-size</option>
  77. <option value="grid">grid</option>
  78. <option value="line">line</option>
  79. <option value="surface">surface</option>
  80. </select>
  81. </label>
  82. </p>
  83. <p>
  84. <label for="perspective">
  85. <input type="checkbox" id="perspective" checked> Show perspective
  86. </label>
  87. </p>
  88. <p>
  89. <label for="xBarWidth"> Bar width X:
  90. <input type="text" id="xBarWidth" value="" style="width:50px;"> (only applicable for styles "bar" and "bar-color")
  91. </label>
  92. </p>
  93. <p>
  94. <label for="yBarWidth"> Bar width Y:
  95. <input type="text" id="yBarWidth" value="" style="width:50px;"> (only applicable for styles "bar" and "bar-color")
  96. </label>
  97. </p>
  98. <div id="mygraph"></div>
  99. <div id="info"></div>
  100. </body>
  101. </html>