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 */
19 * @extends Dygraph.DataHandlers.BarsHandler
21 Dygraph
.DataHandlers
.CustomBarsHandler
= function() {
24 var CustomBarsHandler
= Dygraph
.DataHandlers
.CustomBarsHandler
;
25 CustomBarsHandler
.prototype = new Dygraph
.DataHandlers
.BarsHandler();
28 CustomBarsHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
29 // TODO(danvk): pre-allocate series here.
32 var logScale
= options
.get('logscale');
33 for ( var j
= 0; j
< rawData
.length
; j
++) {
35 point
= rawData
[j
][i
];
36 if (logScale
&& point
!== null) {
37 // On the log scale, points less than zero do not exist.
38 // This will create a gap in the chart.
39 if (point
[0] <= 0 || point
[1] <= 0 || point
[2] <= 0) {
43 // Extract to the unified data format.
46 if (y
!== null && !isNaN(y
)) {
47 series
.push([ x
, y
, [ point
[0], point
[2] ] ]);
49 series
.push([ x
, y
, [ y
, y
] ]);
52 series
.push([ x
, null, [ null, null ] ]);
59 CustomBarsHandler
.prototype.rollingAverage
=
60 function(originalData
, rollPeriod
, options
) {
61 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
63 var y
, low
, high
, mid
,count
, i
, extremes
;
69 for (i
= 0; i
< originalData
.length
; i
++) {
70 y
= originalData
[i
][1];
71 extremes
= originalData
[i
][2];
72 rollingData
[i
] = originalData
[i
];
74 if (y
!== null && !isNaN(y
)) {
80 if (i
- rollPeriod
>= 0) {
81 var prev
= originalData
[i
- rollPeriod
];
82 if (prev
[1] !== null && !isNaN(prev
[1])) {
94 1.0 * high
/ count
] ];
96 rollingData
[i
] = [ originalData
[i
][0], null, [ null, null ] ];