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.

100 lines
3.6 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Interpolation</title>
  5. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  6. <style type="text/css">
  7. body, html {
  8. font-family: sans-serif;
  9. }
  10. </style>
  11. <script src="../../dist/vis.js"></script>
  12. </head>
  13. <body>
  14. <h2>Graph2D | Interpolation</h2>
  15. <div style="width:700px; font-size:14px; text-align: justify;">
  16. The Graph2D makes use of <a href="http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline" target="_blank">Catmull-Rom spline interpolation</a>.
  17. The user can configure these per group, or globally. In this example we show all 4 possiblities. The differences are in the parametrization of
  18. the curves. The options are <code>uniform</code>, <code>chordal</code> and <code>centripetal</code>. Alternatively you can disable the Catmull-Rom interpolation and
  19. a linear interpolation will be used. The <code>centripetal</code> parametrization produces the best result (no self intersection, yet follows the line closely) and is therefore the default setting.
  20. <br /><br />
  21. For both the <code>centripetal</code> and <code>chordal</code> parametrization, the distances between the points have to be calculated and this makes these methods computationally intensive
  22. if there are very many points. The <code>uniform</code> parametrization still has to do transformations, though it does not have to calculate the distance between point. Finally, the
  23. linear interpolation is the fastest method. For more on the Catmull-Rom method, <a href="http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf" target="_blank">C. Yuksel et al. have an interesting paper titled &Prime;On the parametrization of Catmull-Rom Curves&Prime;</a>.
  24. </div>
  25. <br />
  26. <div id="visualization"></div>
  27. <script type="text/javascript">
  28. // create a dataSet with groups
  29. var names = ['centripetal', 'chordal', 'uniform', 'disabled'];
  30. var groups = new vis.DataSet();
  31. groups.add({
  32. id: 0,
  33. content: names[0],
  34. options: {
  35. drawPoints: false,
  36. catmullRom: {
  37. parametrization: 'centripetal'
  38. }
  39. }});
  40. groups.add({
  41. id: 1,
  42. content: names[1],
  43. options: {
  44. drawPoints: false,
  45. catmullRom: {
  46. parametrization: 'chordal'
  47. }
  48. }});
  49. groups.add({
  50. id: 2,
  51. content: names[2],
  52. options: {
  53. drawPoints: false,
  54. catmullRom: {
  55. parametrization: 'uniform'
  56. }
  57. }
  58. });
  59. groups.add({
  60. id: 3,
  61. content: names[3],
  62. options: {
  63. drawPoints: { style: 'circle' },
  64. catmullRom: false
  65. }});
  66. var container = document.getElementById('visualization');
  67. var dataset = new vis.DataSet();
  68. for (var i = 0; i < names.length; i++) {
  69. dataset.add( [
  70. {x: '2014-06-12', y: 0 , group: i},
  71. {x: '2014-06-13', y: 40, group: i},
  72. {x: '2014-06-14', y: 10, group: i},
  73. {x: '2014-06-15', y: 15, group: i},
  74. {x: '2014-06-15', y: 30, group: i},
  75. {x: '2014-06-17', y: 10, group: i},
  76. {x: '2014-06-18', y: 15, group: i},
  77. {x: '2014-06-19', y: 52, group: i},
  78. {x: '2014-06-20', y: 10, group: i},
  79. {x: '2014-06-21', y: 20, group: i}
  80. ]);
  81. }
  82. var options = {
  83. dataPoints: false,
  84. dataAxis: {visible: false},
  85. legend: true,
  86. start: '2014-06-11',
  87. end: '2014-06-22'
  88. };
  89. var graph2d = new vis.Graph2d(container, dataset, options, groups);
  90. </script>
  91. </body>
  92. </html>