1 | <!DOCTYPE HTML>
|
2 | <html>
|
3 | <head>
|
4 | <title>Graph2d | Interpolation</title>
|
5 | <link href="../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
|
6 | <style type="text/css">
|
7 | body, html {
|
8 | font-family: sans-serif;
|
9 | }
|
10 | </style>
|
11 |
|
12 | <script src="../../dist/vis-timeline-graph2d.min.js"></script>
|
13 |
|
14 | </head>
|
15 | <body>
|
16 | <h2>Graph2d | Interpolation</h2>
|
17 | <div style="width:700px; font-size:14px; text-align: justify;">
|
18 | 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>.
|
19 | The user can configure these per group, or globally. In this example we show all 4 possiblities. The differences are in the parametrization of
|
20 | the curves. The options are <code>uniform</code>, <code>chordal</code> and <code>centripetal</code>. Alternatively you can disable the Catmull-Rom interpolation and
|
21 | 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.
|
22 | <br /><br />
|
23 | 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
|
24 | 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
|
25 | 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 ″On the parametrization of Catmull-Rom Curves″</a>.
|
26 | </div>
|
27 | <br />
|
28 | <div id="visualization"></div>
|
29 |
|
30 | <script type="text/javascript">
|
31 |
|
32 | var names = ['centripetal', 'chordal', 'uniform', 'disabled'];
|
33 | var groups = new vis.DataSet();
|
34 | groups.add({
|
35 | id: 0,
|
36 | content: names[0],
|
37 | options: {
|
38 | drawPoints: false,
|
39 | interpolation: {
|
40 | parametrization: 'centripetal'
|
41 | }
|
42 | }});
|
43 |
|
44 | groups.add({
|
45 | id: 1,
|
46 | content: names[1],
|
47 | options: {
|
48 | drawPoints: false,
|
49 | interpolation: {
|
50 | parametrization: 'chordal'
|
51 | }
|
52 | }});
|
53 |
|
54 | groups.add({
|
55 | id: 2,
|
56 | content: names[2],
|
57 | options: {
|
58 | drawPoints: false,
|
59 | interpolation: {
|
60 | parametrization: 'uniform'
|
61 | }
|
62 | }
|
63 | });
|
64 |
|
65 | groups.add({
|
66 | id: 3,
|
67 | content: names[3],
|
68 | options: {
|
69 | drawPoints: { style: 'circle' },
|
70 | interpolation: false
|
71 | }});
|
72 |
|
73 | var container = document.getElementById('visualization');
|
74 | var dataset = new vis.DataSet();
|
75 | for (var i = 0; i < names.length; i++) {
|
76 | dataset.add( [
|
77 | {x: '2014-06-12', y: 0 , group: i},
|
78 | {x: '2014-06-13', y: 40, group: i},
|
79 | {x: '2014-06-14', y: 10, group: i},
|
80 | {x: '2014-06-15', y: 15, group: i},
|
81 | {x: '2014-06-15', y: 30, group: i},
|
82 | {x: '2014-06-17', y: 10, group: i},
|
83 | {x: '2014-06-18', y: 15, group: i},
|
84 | {x: '2014-06-19', y: 52, group: i},
|
85 | {x: '2014-06-20', y: 10, group: i},
|
86 | {x: '2014-06-21', y: 20, group: i}
|
87 | ]);
|
88 | }
|
89 |
|
90 | var options = {
|
91 | drawPoints: false,
|
92 | dataAxis: {visible: false},
|
93 | legend: true,
|
94 | start: '2014-06-11',
|
95 | end: '2014-06-22'
|
96 | };
|
97 | var graph2d = new vis.Graph2d(container, dataset, groups, options);
|
98 |
|
99 | </script>
|
100 | </body>
|
101 | </html> |
\ | No newline at end of file |