3 * Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
8 * @fileoverview DataHandler implementation for the custom bars option.
9 * @author David Eberlein (david.eberlein@ch.sauter-bc.com)
13 /*global Dygraph:false */
16 var CustomBarsHandler
= Dygraph
.DataHandler();
17 CustomBarsHandler
.prototype = Dygraph
.DataHandlers
.createHandler("bars");
18 Dygraph
.DataHandlers
.registerHandler("bars-custom", CustomBarsHandler
);
20 CustomBarsHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
21 // TODO(danvk): pre-allocate series here.
24 var logScale
= options
.get('logscale');
25 for ( var j
= 0; j
< rawData
.length
; j
++) {
27 point
= rawData
[j
][i
];
28 if (logScale
&& point
!== null) {
29 // On the log scale, points less than zero do not exist.
30 // This will create a gap in the chart.
31 if (point
[0] <= 0 || point
[1] <= 0 || point
[2] <= 0) {
35 // Extract to the unified data format.
38 if (y
!== null && !isNaN(y
)) {
39 series
.push([ x
, y
, [ point
[0], point
[2] ] ]);
41 series
.push([ x
, y
, [ y
, y
] ]);
44 series
.push([ x
, null, [ null, null ] ]);
50 CustomBarsHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
52 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
54 var y
, low
, high
, mid
,count
, i
, extremes
;
60 for (i
= 0; i
< originalData
.length
; i
++) {
61 y
= originalData
[i
][1];
62 extremes
= originalData
[i
][2];
63 rollingData
[i
] = originalData
[i
];
65 if (y
!== null && !isNaN(y
)) {
71 if (i
- rollPeriod
>= 0) {
72 var prev
= originalData
[i
- rollPeriod
];
73 if (prev
[1] !== null && !isNaN(prev
[1])) {
85 1.0 * high
/ count
] ];
87 rollingData
[i
] = [ originalData
[i
][0], null, [ null, null ] ];