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)
14 /*global Dygraph:false */
15 /*global DygraphLayout:false */
18 import DygraphDataHandler from
'./datahandler';
19 import DygraphLayout from
'../dygraph-layout';
23 * @extends {Dygraph.DataHandler}
25 var BarsHandler
= function() {
26 DygraphDataHandler
.call(this);
28 BarsHandler
.prototype = new DygraphDataHandler();
30 // TODO(danvk): figure out why the jsdoc has to be copy/pasted from superclass
.
31 // (I get closure compiler errors if this isn't here.)
34 * @param {!Array.<Array>} rawData The raw data passed into dygraphs where
35 * rawData[i] = [x,ySeries1,...,ySeriesN].
36 * @param {!number} seriesIndex Index of the series to extract. All other
37 * series should be ignored.
38 * @param {!DygraphOptions} options Dygraph options.
39 * @return {Array.<[!number,?number,?]>} The series in the unified data format
40 * where series[i] = [x,y,{extras}].
42 BarsHandler
.prototype.extractSeries
= function(rawData
, seriesIndex
, options
) {
43 // Not implemented here must be extended
48 * @param {!Array.<[!number,?number,?]>} series The series in the unified
49 * data format where series[i] = [x,y,{extras}].
50 * @param {!number} rollPeriod The number of points over which to average the data
51 * @param {!DygraphOptions} options The dygraph options.
52 * TODO(danvk): be more specific than "Array" here.
53 * @return {!Array.<[!number,?number,?]>} the rolled series.
55 BarsHandler
.prototype.rollingAverage
=
56 function(series
, rollPeriod
, options
) {
57 // Not implemented here, must be extended.
61 BarsHandler
.prototype.onPointsCreated_
= function(series
, points
) {
62 for (var i
= 0; i
< series
.length
; ++i
) {
64 var point
= points
[i
];
67 point
.yval_minus
= DygraphDataHandler
.parseFloat(item
[2][0]);
68 point
.yval_plus
= DygraphDataHandler
.parseFloat(item
[2][1]);
73 BarsHandler
.prototype.getExtremeYValues
= function(series
, dateWindow
, options
) {
74 var minY
= null, maxY
= null, y
;
77 var lastIdx
= series
.length
- 1;
79 for ( var j
= firstIdx
; j
<= lastIdx
; j
++) {
81 if (y
=== null || isNaN(y
)) continue;
83 var low
= series
[j
][2][0];
84 var high
= series
[j
][2][1];
86 if (low
> y
) low
= y
; // this can happen with custom bars,
87 if (high
< y
) high
= y
; // e.g. in tests/custom-bars
.html
89 if (maxY
=== null || high
> maxY
) maxY
= high
;
90 if (minY
=== null || low
< minY
) minY
= low
;
93 return [ minY
, maxY
];
97 BarsHandler
.prototype.onLineEvaluated
= function(points
, axis
, logscale
) {
99 for (var j
= 0; j
< points
.length
; j
++) {
100 // Copy over the error terms
102 point
.y_top
= DygraphLayout
.calcYNormal_(axis
, point
.yval_minus
, logscale
);
103 point
.y_bottom
= DygraphLayout
.calcYNormal_(axis
, point
.yval_plus
, logscale
);
107 export default BarsHandler
;