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.

90 lines
2.9 KiB

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 animation moving dots</title>
  5. <style>
  6. body {font: 10pt arial;}
  7. </style>
  8. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  9. <script type="text/javascript" src="../graph3d.js"></script>
  10. <script type="text/javascript">
  11. var data = null;
  12. var graph = null;
  13. google.load("visualization", "1");
  14. // Set callback to run when API is loaded
  15. google.setOnLoadCallback(drawVisualization);
  16. // Called when the Visualization API is loaded.
  17. function drawVisualization() {
  18. // create the data table.
  19. data = new google.visualization.DataTable();
  20. data.addColumn('number', 'x');
  21. data.addColumn('number', 'y');
  22. data.addColumn('number', 'z');
  23. data.addColumn('number', 'color value');
  24. data.addColumn('number', 'time');
  25. // create some shortcuts to math functions
  26. var sin = Math.sin;
  27. var cos = Math.cos;
  28. var pi = Math.PI;
  29. // create the animation data
  30. var tmax = 2.0 * pi;
  31. var tstep = tmax / 75;
  32. var dotCount = 1; // set this to 1, 2, 3, 4, ...
  33. for (var t = 0; t < tmax; t += tstep) {
  34. var tgroup = parseFloat(t.toFixed(2));
  35. var value = t;
  36. // a dot in the center
  37. data.addRow([0, 0, 0, value, tgroup]);
  38. // one or multiple dots moving around the center
  39. for (var dot = 0; dot < dotCount; dot++) {
  40. var tdot = t + 2*pi * dot / dotCount;
  41. data.addRow([sin(tdot), cos(tdot), sin(tdot), value, tgroup]);
  42. data.addRow([sin(tdot), -cos(tdot), sin(tdot + tmax*1/2), value, tgroup]);
  43. }
  44. }
  45. // specify options
  46. var options = {
  47. width: "600px",
  48. height: "600px",
  49. style: "dot-color",
  50. showPerspective: true,
  51. showGrid: true,
  52. keepAspectRatio: true,
  53. verticalRatio: 1.0,
  54. animationInterval: 35, // milliseconds
  55. animationPreload: false,
  56. animationAutoStart: true,
  57. cameraPosition:
  58. {
  59. horizontal: 2.7,
  60. vertical: 0.0,
  61. distance: 1.65
  62. }
  63. };
  64. // Instantiate our graph object.
  65. graph = new links.Graph3d(document.getElementById('mygraph'));
  66. // Draw our graph with the created data and options
  67. graph.draw(data, options);
  68. }
  69. </script>
  70. </head>
  71. <body>
  72. <div id="mygraph"></div>
  73. <div id="info"></div>
  74. </body>
  75. </html>