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 */
19 * @extends Dygraph.DataHandler
21 Dygraph
.DataHandlers
.DefaultHandler
= function() {
24 var DefaultHandler
= Dygraph
.DataHandlers
.DefaultHandler
;
25 DefaultHandler
.prototype = new Dygraph
.DataHandler();
28 DefaultHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
29 // TODO(danvk): pre-allocate series here.
31 var logScale
= options
.get('logscale');
32 for ( var j
= 0; j
< rawData
.length
; j
++) {
33 var x
= rawData
[j
][0];
34 var point
= rawData
[j
][i
];
36 // On the log scale, points less than zero do not exist.
37 // This will create a gap in the chart.
42 series
.push([ x
, point
]);
48 DefaultHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
50 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
53 var i
, j
, y
, sum
, num_ok
;
54 // Calculate the rolling average for the first rollPeriod - 1 points
56 // there is not enough data to roll over the full number of points
57 if (rollPeriod
== 1) {
60 for (i
= 0; i
< originalData
.length
; i
++) {
63 for (j
= Math
.max(0, i
- rollPeriod
+ 1); j
< i
+ 1; j
++) {
64 y
= originalData
[j
][1];
65 if (y
=== null || isNaN(y
))
68 sum
+= originalData
[j
][1];
71 rollingData
[i
] = [ originalData
[i
][0], sum
/ num_ok
];
73 rollingData
[i
] = [ originalData
[i
][0], null ];
81 DefaultHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
,
83 var minY
= null, maxY
= null, y
;
84 var firstIdx
= 0, lastIdx
= series
.length
- 1;
86 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
88 if (y
=== null || isNaN(y
))
90 if (maxY
=== null || y
> maxY
) {
93 if (minY
=== null || y
< minY
) {
97 return [ minY
, maxY
];