Test labelsKMB{B,G2} with values < 1
[dygraphs.git] / src / datahandler / bars.js
CommitLineData
a49c164a
DE
1/**
2 * @license
3 * Copyright 2013 David Eberlein (david.eberlein@ch.sauter-bc.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
5 */
6
7/**
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)
12 */
13
14(function() {
3ea41d86
DV
15
16/*global Dygraph:false */
17/*global DygraphLayout:false */
18"use strict";
19
749281f8
DV
20/**
21 * @constructor
22 * @extends {Dygraph.DataHandler}
23 */
24Dygraph.DataHandlers.BarsHandler = function() {
25 Dygraph.DataHandler.call(this);
26};
27Dygraph.DataHandlers.BarsHandler.prototype = new Dygraph.DataHandler();
28
29// alias for the rest of the implementation
3ea41d86
DV
30var BarsHandler = Dygraph.DataHandlers.BarsHandler;
31
749281f8
DV
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.)
34/**
35 * @override
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}].
43 */
44BarsHandler.prototype.extractSeries = function(rawData, seriesIndex, options) {
3ea41d86
DV
45 // Not implemented here must be extended
46};
47
749281f8
DV
48/**
49 * @override
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.
56 */
3ea41d86 57BarsHandler.prototype.rollingAverage =
749281f8 58 function(series, rollPeriod, options) {
3ea41d86
DV
59 // Not implemented here, must be extended.
60};
61
749281f8 62/** @inheritDoc */
3ea41d86
DV
63BarsHandler.prototype.onPointsCreated_ = function(series, points) {
64 for (var i = 0; i < series.length; ++i) {
65 var item = series[i];
66 var point = points[i];
67 point.y_top = NaN;
68 point.y_bottom = NaN;
66c95356
DV
69 point.yval_minus = Dygraph.DataHandler.parseFloat(item[2][0]);
70 point.yval_plus = Dygraph.DataHandler.parseFloat(item[2][1]);
3ea41d86
DV
71 }
72};
73
749281f8 74/** @inheritDoc */
3ea41d86
DV
75BarsHandler.prototype.getExtremeYValues = function(series, dateWindow, options) {
76 var minY = null, maxY = null, y;
77
78 var firstIdx = 0;
79 var lastIdx = series.length - 1;
80
81 for ( var j = firstIdx; j <= lastIdx; j++) {
82 y = series[j][1];
83 if (y === null || isNaN(y)) continue;
84
85 var low = series[j][2][0];
86 var high = series[j][2][1];
87
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
90
91 if (maxY === null || high > maxY) maxY = high;
92 if (minY === null || low < minY) minY = low;
93 }
94
95 return [ minY, maxY ];
96};
97
749281f8 98/** @inheritDoc */
3ea41d86
DV
99BarsHandler.prototype.onLineEvaluated = function(points, axis, logscale) {
100 var point;
101 for (var j = 0; j < points.length; j++) {
102 // Copy over the error terms
103 point = points[j];
749281f8
DV
104 point.y_top = DygraphLayout.calcYNormal_(axis, point.yval_minus, logscale);
105 point.y_bottom = DygraphLayout.calcYNormal_(axis, point.yval_plus, logscale);
3ea41d86
DV
106 }
107};
108
a49c164a 109})();