79adcb56bd73651aeb202131688a3f7923569dcd
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)
13 /*global Dygraph:false */
16 var DefaultHandler
= Dygraph
.DataHandler();
17 Dygraph
.DataHandlers
.registerHandler("default", DefaultHandler
);
19 DefaultHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
20 // TODO(danvk): pre-allocate series here.
22 var logScale
= options
.get('logscale');
23 for ( var j
= 0; j
< rawData
.length
; j
++) {
24 var x
= rawData
[j
][0];
25 var point
= rawData
[j
][i
];
27 // On the log scale, points less than zero do not exist.
28 // This will create a gap in the chart.
33 series
.push([ x
, point
]);
38 DefaultHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
40 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
43 var i
, j
, y
, sum
, num_ok
;
44 // Calculate the rolling average for the first rollPeriod - 1 points
46 // there is not enough data to roll over the full number of points
47 if (rollPeriod
== 1) {
50 for (i
= 0; i
< originalData
.length
; i
++) {
53 for (j
= Math
.max(0, i
- rollPeriod
+ 1); j
< i
+ 1; j
++) {
54 y
= originalData
[j
][1];
55 if (y
=== null || isNaN(y
))
58 sum
+= originalData
[j
][1];
61 rollingData
[i
] = [ originalData
[i
][0], sum
/ num_ok
];
63 rollingData
[i
] = [ originalData
[i
][0], null ];
70 DefaultHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
,
72 var minY
= null, maxY
= null, y
;
73 var firstIdx
= 0, lastIdx
= series
.length
- 1;
75 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
77 if (y
=== null || isNaN(y
))
79 if (maxY
=== null || y
> maxY
) {
82 if (minY
=== null || y
< minY
) {
86 return [ minY
, maxY
];