|
1 /* Support for flat 1D data series. |
|
2 |
|
3 A 1D flat data series is a data series in the form of a regular 1D array. The |
|
4 main reason for using a flat data series is that it performs better, consumes |
|
5 less memory and generates less garbage collection than the regular flot format. |
|
6 |
|
7 Example: |
|
8 |
|
9 plot.setData([[[0,0], [1,1], [2,2], [3,3]]]); // regular flot format |
|
10 plot.setData([{flatdata: true, data: [0, 1, 2, 3]}]); // flatdata format |
|
11 |
|
12 Set series.flatdata to true to enable this plugin. |
|
13 |
|
14 You can use series.start to specify the starting index of the series (default is 0) |
|
15 You can use series.step to specify the interval between consecutive indexes of the series (default is 1) |
|
16 */ |
|
17 |
|
18 /* global jQuery*/ |
|
19 |
|
20 (function ($) { |
|
21 'use strict'; |
|
22 |
|
23 function process1DRawData(plot, series, data, datapoints) { |
|
24 if (series.flatdata === true) { |
|
25 var start = series.start || 0; |
|
26 var step = typeof series.step === 'number' ? series.step : 1; |
|
27 datapoints.pointsize = 2; |
|
28 for (var i = 0, j = 0; i < data.length; i++, j += 2) { |
|
29 datapoints.points[j] = start + (i * step); |
|
30 datapoints.points[j + 1] = data[i]; |
|
31 } |
|
32 if (datapoints.points !== undefined) { |
|
33 datapoints.points.length = data.length * 2; |
|
34 } else { |
|
35 datapoints.points = []; |
|
36 } |
|
37 } |
|
38 } |
|
39 |
|
40 $.plot.plugins.push({ |
|
41 init: function(plot) { |
|
42 plot.hooks.processRawData.push(process1DRawData); |
|
43 }, |
|
44 name: 'flatdata', |
|
45 version: '0.0.2' |
|
46 }); |
|
47 })(jQuery); |