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.

118 lines
3.3 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph 3D tooltips</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. div#info {
  8. width : 600px;
  9. text-align: center;
  10. margin-top: 2em;
  11. font-size : 1.2em;
  12. }
  13. </style>
  14. <script type="text/javascript" src="../../dist/vis.js"></script>
  15. <script type="text/javascript">
  16. var data = null;
  17. var graph = null;
  18. function custom(x, y) {
  19. return (-Math.sin(x/Math.PI) * Math.cos(y/Math.PI) * 10 + 10);
  20. }
  21. // Called when the Visualization API is loaded.
  22. function drawVisualization() {
  23. var style = document.getElementById('style').value;
  24. var withValue = ['bar-color', 'bar-size', 'dot-size', 'dot-color'].indexOf(style) != -1;
  25. // Create and populate a data table.
  26. data = new vis.DataSet();
  27. var extra_content = [
  28. 'Arbitrary information',
  29. 'You can access data from the point source object',
  30. 'Tooltip example content',
  31. ];
  32. // create some nice looking data with sin/cos
  33. var steps = 5; // number of datapoints will be steps*steps
  34. var axisMax = 10;
  35. var axisStep = axisMax / steps;
  36. for (var x = 0; x <= axisMax; x+=axisStep) {
  37. for (var y = 0; y <= axisMax; y+=axisStep) {
  38. var z = custom(x,y);
  39. if (withValue) {
  40. var value = (y - x);
  41. data.add({x:x, y:y, z: z, style:value, extra: extra_content[(x*y) % extra_content.length]});
  42. }
  43. else {
  44. data.add({x:x, y:y, z: z, extra: extra_content[(x*y) % extra_content.length]});
  45. }
  46. }
  47. }
  48. // specify options
  49. var options = {
  50. width: '600px',
  51. height: '600px',
  52. style: style,
  53. showPerspective: true,
  54. showLegend: true,
  55. showGrid: true,
  56. showShadow: false,
  57. // Option tooltip can be true, false, or a function returning a string with HTML contents
  58. //tooltip: true,
  59. tooltip: function (point) {
  60. // parameter point contains properties x, y, z, and data
  61. // data is the original object passed to the point constructor
  62. return 'value: <b>' + point.z + '</b><br>' + point.data.extra;
  63. },
  64. keepAspectRatio: true,
  65. verticalRatio: 0.5
  66. };
  67. var camera = graph ? graph.getCameraPosition() : null;
  68. // create our graph
  69. var container = document.getElementById('mygraph');
  70. graph = new vis.Graph3d(container, data, options);
  71. if (camera) graph.setCameraPosition(camera); // restore camera position
  72. document.getElementById('style').onchange = drawVisualization;
  73. }
  74. </script>
  75. <script src="../googleAnalytics.js"></script>
  76. </head>
  77. <body onload="drawVisualization()">
  78. <p>
  79. <label for="style"> Style:
  80. <select id="style">
  81. <option value="bar">bar</option>
  82. <option value="bar-color">bar-color</option>
  83. <option value="bar-size">bar-size</option>
  84. <option value="dot">dot</option>
  85. <option value="dot-line">dot-line</option>
  86. <option value="dot-color">dot-color</option>
  87. <option value="dot-size">dot-size</option>
  88. <option value="grid">grid</option>
  89. <option value="line">line</option>
  90. <option value="surface">surface</option>
  91. </select>
  92. </label>
  93. </p>
  94. <div id="mygraph"></div>
  95. <div id="info">Hover the mouse cursor over the graph to see tooltips.</div>
  96. </body>
  97. </html>