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.

149 lines
5.4 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2D | Performance</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. span.label {
  11. width:150px;
  12. display:inline-block;
  13. }
  14. </style>
  15. <!-- note: moment.js must be loaded before vis.js, else vis.js uses its embedded version of moment.js -->
  16. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.3.1/moment.min.js"></script>
  17. <script src="../../dist/vis.js"></script>
  18. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  19. </head>
  20. <body>
  21. <h2>Graph2D | Performance</h2>
  22. <div style="width:700px; font-size:14px; text-align: justify;">
  23. This example is a test of the performance of the Graph2D. Select the amount of datapoints you want to plot and press draw.
  24. You can choose between the style of the points as well as the interpolation method. This can only be toggled with the buttons.
  25. The interpolation options may not look different for this dataset but you can see their effects clearly in example 7.
  26. <br /><br />
  27. Linear interpolation and no points are the settings that will render quickest. By default, graph2D will downsample when there are more
  28. than 1 point per pixel. This can be manually disabled at the cost of performance by using the <code>sampling</code> option.
  29. </div>
  30. <br />
  31. <p>
  32. <span class="label">Number of items:</span><input id="count" value="50000">
  33. <input id="draw" type="button" value="draw" style="width:200px;"> <span id="description"><b>Click the draw button to load the data!</b></span>
  34. <br />
  35. <span class="label">Interpolation method:</span><input id="interpolation" value="linear">
  36. <input id="toggleInterpolation" type="button" value="toggle Interpolation" style="width:200px;">
  37. <br />
  38. <span class="label">Points style:</span><input id="points" value="none">
  39. <input id="togglePoints" type="button" value="toggle Points" style="width:200px;">
  40. </p>
  41. <div id="visualization"></div>
  42. <script>
  43. var points = 'none';
  44. var interpolation = 'linear';
  45. function togglePoints() {
  46. var pointsOptions = {};
  47. var pointsField = document.getElementById("points");
  48. if (points == "none") {
  49. points = 'circle';
  50. pointsOptions = {drawPoints: {style: points}};
  51. }
  52. else if (points == "circle") {
  53. points = 'square';
  54. pointsOptions = {drawPoints: {style: points}};
  55. }
  56. else if (points == "square") {
  57. points = 'none';
  58. pointsOptions = {drawPoints: false};
  59. }
  60. pointsField.value = points;
  61. graph2d.setOptions(pointsOptions);
  62. }
  63. function toggleInterpolation() {
  64. var interpolationOptions = {};
  65. var interpolationField = document.getElementById("interpolation");
  66. if (interpolation == "linear") {
  67. interpolation = 'centripetal';
  68. interpolationOptions = {catmullRom: {parametrization: interpolation}};
  69. }
  70. else if (interpolation == "centripetal") {
  71. interpolation = 'chordal';
  72. interpolationOptions = {catmullRom: {parametrization: interpolation}};
  73. }
  74. else if (interpolation == "chordal") {
  75. interpolation = 'uniform';
  76. interpolationOptions = {catmullRom: {parametrization: interpolation}};
  77. }
  78. else if (interpolation == "uniform") {
  79. interpolation = 'linear';
  80. interpolationOptions = {catmullRom: false};
  81. }
  82. interpolationField.value = interpolation;
  83. graph2d.setOptions(interpolationOptions);
  84. }
  85. // create a dataset with items
  86. var now = moment().minutes(0).seconds(0).milliseconds(0);
  87. var dataset = new vis.DataSet({
  88. type: {start: 'ISODate', end: 'ISODate' }
  89. });
  90. var startPoint = now;
  91. var endPoint = now + 3600000 * 5000;
  92. // create data -- this is seperated into 3 functions so we can update the span.
  93. function createData() {
  94. var span = document.getElementById("description");
  95. span.innerHTML = 'Generating data... (just javascript, not vis.graph2D)...';
  96. setTimeout(generateData,10);
  97. }
  98. function generateData() {
  99. var count = parseInt(document.getElementById('count').value) || 100;
  100. var newData = [];
  101. var span = document.getElementById("description");
  102. var start = now;
  103. for (var i = 0; i < count; i++) {
  104. var yval = Math.sin(i/100) * Math.cos(i/50) * 50 + Math.sin(i/1000) * 50;
  105. newData.push({id: i, x: start + 3600000 * i, y: yval});
  106. }
  107. span.innerHTML = 'Loading data into Graph2D...';
  108. setTimeout(function() {loadDataIntoVis(newData);},10);
  109. }
  110. function loadDataIntoVis(newData) {
  111. var span = document.getElementById("description");
  112. dataset.clear();
  113. dataset.add(newData);
  114. span.innerHTML = 'Done!';
  115. }
  116. document.getElementById('draw').onclick = createData;
  117. document.getElementById('toggleInterpolation').onclick = toggleInterpolation;
  118. document.getElementById('togglePoints').onclick = togglePoints;
  119. var container = document.getElementById('visualization');
  120. var options = {
  121. sampling: true,
  122. drawPoints: {enabled:false, size:3},
  123. catmullRom: false,
  124. start: startPoint,
  125. end: endPoint
  126. };
  127. var graph2d = new vis.Graph2d(container, dataset, options);
  128. </script>
  129. </body>
  130. </html>