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)
14 /*global Dygraph:false */
17 Dygraph
.DataHandlers
.CustomBarsHandler
= Dygraph
.DataHandler();
18 var CustomBarsHandler
= Dygraph
.DataHandlers
.CustomBarsHandler
;
19 CustomBarsHandler
.prototype = new Dygraph
.DataHandlers
.BarsHandler();
22 CustomBarsHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
23 // TODO(danvk): pre-allocate series here.
26 var logScale
= options
.get('logscale');
27 for ( var j
= 0; j
< rawData
.length
; j
++) {
29 point
= rawData
[j
][i
];
30 if (logScale
&& point
!== null) {
31 // On the log scale, points less than zero do not exist.
32 // This will create a gap in the chart.
33 if (point
[0] <= 0 || point
[1] <= 0 || point
[2] <= 0) {
37 // Extract to the unified data format.
40 if (y
!== null && !isNaN(y
)) {
41 series
.push([ x
, y
, [ point
[0], point
[2] ] ]);
43 series
.push([ x
, y
, [ y
, y
] ]);
46 series
.push([ x
, null, [ null, null ] ]);
52 CustomBarsHandler
.prototype.rollingAverage
= function(originalData
, rollPeriod
,
54 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
56 var y
, low
, high
, mid
,count
, i
, extremes
;
62 for (i
= 0; i
< originalData
.length
; i
++) {
63 y
= originalData
[i
][1];
64 extremes
= originalData
[i
][2];
65 rollingData
[i
] = originalData
[i
];
67 if (y
!== null && !isNaN(y
)) {
73 if (i
- rollPeriod
>= 0) {
74 var prev
= originalData
[i
- rollPeriod
];
75 if (prev
[1] !== null && !isNaN(prev
[1])) {
87 1.0 * high
/ count
] ];
89 rollingData
[i
] = [ originalData
[i
][0], null, [ null, null ] ];