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.

132 lines
3.7 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: function (point) {
  59. // parameter point contains properties x, y, z, and data
  60. // data is the original object passed to the point constructor
  61. return 'value: <b>' + point.z + '</b><br>' + point.data.extra;
  62. },
  63. // Tooltip default styling can be overridden
  64. tooltipStyle: {
  65. content: {
  66. background : 'rgba(255, 255, 255, 0.7)',
  67. padding : '10px',
  68. borderRadius : '10px'
  69. },
  70. line: {
  71. borderLeft : '1px dotted rgba(0, 0, 0, 0.5)'
  72. },
  73. dot: {
  74. border : '5px solid rgba(0, 0, 0, 0.5)'
  75. }
  76. },
  77. keepAspectRatio: true,
  78. verticalRatio: 0.5
  79. };
  80. var camera = graph ? graph.getCameraPosition() : null;
  81. // create our graph
  82. var container = document.getElementById('mygraph');
  83. graph = new vis.Graph3d(container, data, options);
  84. if (camera) graph.setCameraPosition(camera); // restore camera position
  85. document.getElementById('style').onchange = drawVisualization;
  86. }
  87. </script>
  88. </head>
  89. <body onload="drawVisualization()">
  90. <p>
  91. <label for="style"> Style:
  92. <select id="style">
  93. <option value="bar">bar</option>
  94. <option value="bar-color">bar-color</option>
  95. <option value="bar-size">bar-size</option>
  96. <option value="dot">dot</option>
  97. <option value="dot-line">dot-line</option>
  98. <option value="dot-color">dot-color</option>
  99. <option value="dot-size">dot-size</option>
  100. <option value="grid">grid</option>
  101. <option value="line">line</option>
  102. <option value="surface">surface</option>
  103. </select>
  104. </label>
  105. </p>
  106. <div id="mygraph"></div>
  107. <div id="info">Hover the mouse cursor over the graph to see tooltips.</div>
  108. </body>
  109. </html>