d4e94d189486d54e0718d0ae4d3a9507ddc4ec8c
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)
12 /*global Dygraph:false */
15 import BarsHandler from
'./bars';
19 * @extends Dygraph.DataHandlers.BarsHandler
21 var CustomBarsHandler
= function() {
24 CustomBarsHandler
.prototype = new BarsHandler();
27 CustomBarsHandler
.prototype.extractSeries
= function(rawData
, i
, options
) {
28 // TODO(danvk): pre-allocate series here.
31 var logScale
= options
.get('logscale');
32 for ( var j
= 0; j
< rawData
.length
; j
++) {
34 point
= rawData
[j
][i
];
35 if (logScale
&& point
!== null) {
36 // On the log scale, points less than zero do not exist.
37 // This will create a gap in the chart.
38 if (point
[0] <= 0 || point
[1] <= 0 || point
[2] <= 0) {
42 // Extract to the unified data format.
45 if (y
!== null && !isNaN(y
)) {
46 series
.push([ x
, y
, [ point
[0], point
[2] ] ]);
48 series
.push([ x
, y
, [ y
, y
] ]);
51 series
.push([ x
, null, [ null, null ] ]);
58 CustomBarsHandler
.prototype.rollingAverage
=
59 function(originalData
, rollPeriod
, options
) {
60 rollPeriod
= Math
.min(rollPeriod
, originalData
.length
);
62 var y
, low
, high
, mid
,count
, i
, extremes
;
68 for (i
= 0; i
< originalData
.length
; i
++) {
69 y
= originalData
[i
][1];
70 extremes
= originalData
[i
][2];
71 rollingData
[i
] = originalData
[i
];
73 if (y
!== null && !isNaN(y
)) {
79 if (i
- rollPeriod
>= 0) {
80 var prev
= originalData
[i
- rollPeriod
];
81 if (prev
[1] !== null && !isNaN(prev
[1])) {
93 1.0 * high
/ count
] ];
95 rollingData
[i
] = [ originalData
[i
][0], null, [ null, null ] ];
102 export default CustomBarsHandler
;