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
4.0 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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></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. interpolation: {
  37. parametrization: 'centripetal'
  38. }
  39. }});
  40. groups.add({
  41. id: 1,
  42. content: names[1],
  43. options: {
  44. drawPoints: false,
  45. interpolation: {
  46. parametrization: 'chordal'
  47. }
  48. }});
  49. groups.add({
  50. id: 2,
  51. content: names[2],
  52. options: {
  53. drawPoints: false,
  54. interpolation: {
  55. parametrization: 'uniform'
  56. }
  57. }
  58. });
  59. groups.add({
  60. id: 3,
  61. content: names[3],
  62. options: {
  63. drawPoints: { style: 'circle' },
  64. interpolation: 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. drawPoints: 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, groups, options);
  90. </script>
  91. </body>
  92. </html>