3 * Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
8 * @fileoverview DataHandler base implementation for the "bar"
9 * data formats. This implementation must be extended and the
10 * extractSeries and rollingAverage must be implemented.
11 * @author David Eberlein (david.eberlein@ch.sauter-bc.com)
16 /*global Dygraph:false */
17 /*global DygraphLayout:false */
22 * @extends {Dygraph.DataHandler}
24 Dygraph
.DataHandlers
.BarsHandler
= function() {
25 Dygraph
.DataHandler
.call(this);
27 Dygraph
.DataHandlers
.BarsHandler
.prototype = new Dygraph
.DataHandler();
29 // alias for the rest of the implementation
30 var BarsHandler
= Dygraph
.DataHandlers
.BarsHandler
;
32 // TODO(danvk): figure out why the jsdoc has to be copy/pasted from superclass
.
33 // (I get closure compiler errors if this isn't here.)
36 * @param {!Array.<Array>} rawData The raw data passed into dygraphs where
37 * rawData[i] = [x,ySeries1,...,ySeriesN].
38 * @param {!number} seriesIndex Index of the series to extract. All other
39 * series should be ignored.
40 * @param {!DygraphOptions} options Dygraph options.
41 * @return {Array.<[!number,?number,?]>} The series in the unified data format
42 * where series[i] = [x,y,{extras}].
44 BarsHandler
.prototype.extractSeries
= function(rawData
, seriesIndex
, options
) {
45 // Not implemented here must be extended
50 * @param {!Array.<[!number,?number,?]>} series The series in the unified
51 * data format where series[i] = [x,y,{extras}].
52 * @param {!number} rollPeriod The number of points over which to average the data
53 * @param {!DygraphOptions} options The dygraph options.
54 * TODO(danvk): be more specific than "Array" here.
55 * @return {!Array.<[!number,?number,?]>} the rolled series.
57 BarsHandler
.prototype.rollingAverage
=
58 function(series
, rollPeriod
, options
) {
59 // Not implemented here, must be extended.
63 BarsHandler
.prototype.onPointsCreated_
= function(series
, points
) {
64 for (var i
= 0; i
< series
.length
; ++i
) {
66 var point
= points
[i
];
69 point
.yval_minus
= Dygraph
.DataHandler
.parseFloat(item
[2][0]);
70 point
.yval_plus
= Dygraph
.DataHandler
.parseFloat(item
[2][1]);
75 BarsHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
, options
) {
76 var minY
= null, maxY
= null, y
;
79 var lastIdx
= series
.length
- 1;
81 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
83 if (y
=== null || isNaN(y
)) continue;
85 var low
= series
[j
][2][0];
86 var high
= series
[j
][2][1];
88 if (low
> y
) low
= y
; // this can happen with custom bars,
89 if (high
< y
) high
= y
; // e.g. in tests/custom-bars
.html
91 if (maxY
=== null || high
> maxY
) maxY
= high
;
92 if (minY
=== null || low
< minY
) minY
= low
;
95 return [ minY
, maxY
];
99 BarsHandler
.prototype.onLineEvaluated
= function(points
, axis
, logscale
) {
101 for (var j
= 0; j
< points
.length
; j
++) {
102 // Copy over the error terms
104 point
.y_top
= DygraphLayout
.calcYNormal_(axis
, point
.yval_minus
, logscale
);
105 point
.y_bottom
= DygraphLayout
.calcYNormal_(axis
, point
.yval_plus
, logscale
);