6e6697f8b4f3f8eed35faf5c07248c9b0907e525
3 * Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
8 * @fileoverview DataHandler default implementation used for simple line charts.
9 * @author David Eberlein (david.eberlein@ch.sauter-bc.com)
14 /*global Dygraph:false */
17 Dygraph
.DataHandlers
.DefaultHandler
= Dygraph
.DataHandler();
18 var DefaultHandler
= Dygraph
.DataHandlers
.DefaultHandler
;
20 DefaultHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
21 // TODO(danvk): pre-allocate series here.
23 var logScale
= options
.get('logscale');
24 for ( var j
= 0; j
< rawData
.length
; j
++) {
25 var x
= rawData
[j
][0];
26 var point
= rawData
[j
][i
];
28 // On the log scale, points less than zero do not exist.
29 // This will create a gap in the chart.
34 series
.push([ x
, point
]);
39 DefaultHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
41 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
44 var i
, j
, y
, sum
, num_ok
;
45 // Calculate the rolling average for the first rollPeriod - 1 points
47 // there is not enough data to roll over the full number of points
48 if (rollPeriod
== 1) {
51 for (i
= 0; i
< originalData
.length
; i
++) {
54 for (j
= Math
.max(0, i
- rollPeriod
+ 1); j
< i
+ 1; j
++) {
55 y
= originalData
[j
][1];
56 if (y
=== null || isNaN(y
))
59 sum
+= originalData
[j
][1];
62 rollingData
[i
] = [ originalData
[i
][0], sum
/ num_ok
];
64 rollingData
[i
] = [ originalData
[i
][0], null ];
71 DefaultHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
,
73 var minY
= null, maxY
= null, y
;
74 var firstIdx
= 0, lastIdx
= series
.length
- 1;
76 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
78 if (y
=== null || isNaN(y
))
80 if (maxY
=== null || y
> maxY
) {
83 if (minY
=== null || y
< minY
) {
87 return [ minY
, maxY
];