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