5ddf67c4a41d8c852fb9916ba5d37f7501d850b8
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)
12 /*global Dygraph:false */
15 import DygraphDataHandler from
'./datahandler';
19 * @extends Dygraph.DataHandler
21 var DefaultHandler
= function() {
24 DefaultHandler
.prototype = new DygraphDataHandler();
27 DefaultHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
28 // TODO(danvk): pre-allocate series here.
30 var logScale
= options
.get('logscale');
31 for ( var j
= 0; j
< rawData
.length
; j
++) {
32 var x
= rawData
[j
][0];
33 var point
= rawData
[j
][i
];
35 // On the log scale, points less than zero do not exist.
36 // This will create a gap in the chart.
41 series
.push([ x
, point
]);
47 DefaultHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
49 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
52 var i
, j
, y
, sum
, num_ok
;
53 // Calculate the rolling average for the first rollPeriod - 1 points
55 // there is not enough data to roll over the full number of points
56 if (rollPeriod
== 1) {
59 for (i
= 0; i
< originalData
.length
; i
++) {
62 for (j
= Math
.max(0, i
- rollPeriod
+ 1); j
< i
+ 1; j
++) {
63 y
= originalData
[j
][1];
64 if (y
=== null || isNaN(y
))
67 sum
+= originalData
[j
][1];
70 rollingData
[i
] = [ originalData
[i
][0], sum
/ num_ok
];
72 rollingData
[i
] = [ originalData
[i
][0], null ];
80 DefaultHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
,
82 var minY
= null, maxY
= null, y
;
83 var firstIdx
= 0, lastIdx
= series
.length
- 1;
85 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
87 if (y
=== null || isNaN(y
))
89 if (maxY
=== null || y
> maxY
) {
92 if (minY
=== null || y
< minY
) {
96 return [ minY
, maxY
];
99 export default DefaultHandler
;