X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=datahandler%2Fdefault.js;h=e42b92bb83715d3b38e8bd431ffc726acb9e5f89;hb=fb2b89c8d082b2bd83b5e809d343254e388adb4c;hp=79adcb56bd73651aeb202131688a3f7923569dcd;hpb=a49c164ae4b251553a87517ef7d1dc57f3f2ad4c;p=dygraphs.git diff --git a/datahandler/default.js b/datahandler/default.js index 79adcb5..e42b92b 100644 --- a/datahandler/default.js +++ b/datahandler/default.js @@ -10,79 +10,91 @@ */ (function() { - /*global Dygraph:false */ - "use strict"; - var DefaultHandler = Dygraph.DataHandler(); - Dygraph.DataHandlers.registerHandler("default", DefaultHandler); +/*global Dygraph:false */ +"use strict"; - DefaultHandler.prototype.extractSeries = function(rawData, i, options) { - // TODO(danvk): pre-allocate series here. - var series = []; - var logScale = options.get('logscale'); - for ( var j = 0; j < rawData.length; j++) { - var x = rawData[j][0]; - var point = rawData[j][i]; - if (logScale) { - // On the log scale, points less than zero do not exist. - // This will create a gap in the chart. - if (point <= 0) { - point = null; - } +/** + * @constructor + * @extends Dygraph.DataHandler + */ +Dygraph.DataHandlers.DefaultHandler = function() { +}; + +var DefaultHandler = Dygraph.DataHandlers.DefaultHandler; +DefaultHandler.prototype = new Dygraph.DataHandler(); + +/** @inheritDoc */ +DefaultHandler.prototype.extractSeries = function(rawData, i, options) { + // TODO(danvk): pre-allocate series here. + var series = []; + var logScale = options.get('logscale'); + for ( var j = 0; j < rawData.length; j++) { + var x = rawData[j][0]; + var point = rawData[j][i]; + if (logScale) { + // On the log scale, points less than zero do not exist. + // This will create a gap in the chart. + if (point <= 0) { + point = null; } - series.push([ x, point ]); } - return series; - }; + series.push([ x, point ]); + } + return series; +}; - DefaultHandler.prototype.rollingAverage = function(originalData, rollPeriod, - options) { - rollPeriod = Math.min(rollPeriod, originalData.length); - var rollingData = []; +/** @inheritDoc */ +DefaultHandler.prototype.rollingAverage = function(originalData, rollPeriod, + options) { + rollPeriod = Math.min(rollPeriod, originalData.length); + var rollingData = []; - var i, j, y, sum, num_ok; - // Calculate the rolling average for the first rollPeriod - 1 points - // where - // there is not enough data to roll over the full number of points - if (rollPeriod == 1) { - return originalData; + var i, j, y, sum, num_ok; + // Calculate the rolling average for the first rollPeriod - 1 points + // where + // there is not enough data to roll over the full number of points + if (rollPeriod == 1) { + return originalData; + } + for (i = 0; i < originalData.length; i++) { + sum = 0; + num_ok = 0; + for (j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) { + y = originalData[j][1]; + if (y === null || isNaN(y)) + continue; + num_ok++; + sum += originalData[j][1]; } - for (i = 0; i < originalData.length; i++) { - sum = 0; - num_ok = 0; - for (j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) { - y = originalData[j][1]; - if (y === null || isNaN(y)) - continue; - num_ok++; - sum += originalData[j][1]; - } - if (num_ok) { - rollingData[i] = [ originalData[i][0], sum / num_ok ]; - } else { - rollingData[i] = [ originalData[i][0], null ]; - } + if (num_ok) { + rollingData[i] = [ originalData[i][0], sum / num_ok ]; + } else { + rollingData[i] = [ originalData[i][0], null ]; } + } - return rollingData; - }; + return rollingData; +}; - DefaultHandler.prototype.getExtremeYValues = function(series, dateWindow, - options) { - var minY = null, maxY = null, y; - var firstIdx = 0, lastIdx = series.length - 1; +/** @inheritDoc */ +DefaultHandler.prototype.getExtremeYValues = function(series, dateWindow, + options) { + var minY = null, maxY = null, y; + var firstIdx = 0, lastIdx = series.length - 1; - for ( var j = firstIdx; j <= lastIdx; j++) { - y = series[j][1]; - if (y === null || isNaN(y)) - continue; - if (maxY === null || y > maxY) { - maxY = y; - } - if (minY === null || y < minY) { - minY = y; - } + for ( var j = firstIdx; j <= lastIdx; j++) { + y = series[j][1]; + if (y === null || isNaN(y)) + continue; + if (maxY === null || y > maxY) { + maxY = y; + } + if (minY === null || y < minY) { + minY = y; } - return [ minY, maxY ]; - }; + } + return [ minY, maxY ]; +}; + })();