Add jsdoc to setVisibility.
[dygraphs.git] / datahandler / bars.js
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() {
15
16 /*global Dygraph:false */
17 /*global DygraphLayout:false */
18 "use strict";
19
20 Dygraph.DataHandlers.BarsHandler = Dygraph.DataHandler();
21 var BarsHandler = Dygraph.DataHandlers.BarsHandler;
22
23 // errorBars
24 BarsHandler.prototype.extractSeries = function(rawData, i, options) {
25 // Not implemented here must be extended
26 };
27
28 BarsHandler.prototype.rollingAverage =
29 function(originalData, rollPeriod, options) {
30 // Not implemented here, must be extended.
31 };
32
33 BarsHandler.prototype.onPointsCreated_ = function(series, points) {
34 for (var i = 0; i < series.length; ++i) {
35 var item = series[i];
36 var point = points[i];
37 point.y_top = NaN;
38 point.y_bottom = NaN;
39 point.yval_minus = DygraphLayout.parseFloat_(item[2][0]);
40 point.yval_plus = DygraphLayout.parseFloat_(item[2][1]);
41 }
42 };
43
44 BarsHandler.prototype.getExtremeYValues = function(series, dateWindow, options) {
45 var minY = null, maxY = null, y;
46
47 var firstIdx = 0;
48 var lastIdx = series.length - 1;
49
50 for ( var j = firstIdx; j <= lastIdx; j++) {
51 y = series[j][1];
52 if (y === null || isNaN(y)) continue;
53
54 var low = series[j][2][0];
55 var high = series[j][2][1];
56
57 if (low > y) low = y; // this can happen with custom bars,
58 if (high < y) high = y; // e.g. in tests/custom-bars.html
59
60 if (maxY === null || high > maxY) maxY = high;
61 if (minY === null || low < minY) minY = low;
62 }
63
64 return [ minY, maxY ];
65 };
66
67 BarsHandler.prototype.onLineEvaluated = function(points, axis, logscale) {
68 var point;
69 for (var j = 0; j < points.length; j++) {
70 // Copy over the error terms
71 point = points[j];
72 point.y_top = DygraphLayout._calcYNormal(axis, point.yval_minus, logscale);
73 point.y_bottom = DygraphLayout._calcYNormal(axis, point.yval_plus, logscale);
74 }
75 };
76
77 })();