X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=datahandler%2Fbars-custom.js;h=37255e567cad8be36ad6b0797c3115be0e698e1e;hb=a67b72369a6b7be63873258068082c139958e5dc;hp=e77d7463b5a0ba09ab4b937771524a30f9deeff5;hpb=a49c164ae4b251553a87517ef7d1dc57f3f2ad4c;p=dygraphs.git diff --git a/datahandler/bars-custom.js b/datahandler/bars-custom.js index e77d746..37255e5 100644 --- a/datahandler/bars-custom.js +++ b/datahandler/bars-custom.js @@ -10,84 +10,87 @@ */ (function() { - /*global Dygraph:false */ - "use strict"; - var CustomBarsHandler = Dygraph.DataHandler(); - CustomBarsHandler.prototype = Dygraph.DataHandlers.createHandler("bars"); - Dygraph.DataHandlers.registerHandler("bars-custom", CustomBarsHandler); - // customBars - CustomBarsHandler.prototype.extractSeries = function(rawData, i, options) { - // TODO(danvk): pre-allocate series here. - var series = []; - var x, y, point; - var logScale = options.get('logscale'); - for ( var j = 0; j < rawData.length; j++) { - x = rawData[j][0]; - point = rawData[j][i]; - if (logScale && point !== null) { - // On the log scale, points less than zero do not exist. - // This will create a gap in the chart. - if (point[0] <= 0 || point[1] <= 0 || point[2] <= 0) { - point = null; - } +/*global Dygraph:false */ +"use strict"; + +Dygraph.DataHandlers.CustomBarsHandler = Dygraph.DataHandler(); +var CustomBarsHandler = Dygraph.DataHandlers.CustomBarsHandler; +CustomBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler(); + +// customBars +CustomBarsHandler.prototype.extractSeries = function(rawData, i, options) { + // TODO(danvk): pre-allocate series here. + var series = []; + var x, y, point; + var logScale = options.get('logscale'); + for ( var j = 0; j < rawData.length; j++) { + x = rawData[j][0]; + point = rawData[j][i]; + if (logScale && point !== null) { + // On the log scale, points less than zero do not exist. + // This will create a gap in the chart. + if (point[0] <= 0 || point[1] <= 0 || point[2] <= 0) { + point = null; } - // Extract to the unified data format. - if (point !== null) { - y = point[1]; - if (y !== null && !isNaN(y)) { - series.push([ x, y, [ point[0], point[2] ] ]); - } else { - series.push([ x, y, [ y, y ] ]); - } + } + // Extract to the unified data format. + if (point !== null) { + y = point[1]; + if (y !== null && !isNaN(y)) { + series.push([ x, y, [ point[0], point[2] ] ]); } else { - series.push([ x, null, [ null, null ] ]); + series.push([ x, y, [ y, y ] ]); } + } else { + series.push([ x, null, [ null, null ] ]); } - return series; - }; + } + return series; +}; - CustomBarsHandler.prototype.rollingAverage = function(originalData, rollPeriod, - options) { - rollPeriod = Math.min(rollPeriod, originalData.length); - var rollingData = []; - var y, low, high, mid,count, i, extremes; +CustomBarsHandler.prototype.rollingAverage = function(originalData, rollPeriod, + options) { + rollPeriod = Math.min(rollPeriod, originalData.length); + var rollingData = []; + var y, low, high, mid,count, i, extremes; - low = 0; - mid = 0; - high = 0; - count = 0; - for (i = 0; i < originalData.length; i++) { - y = originalData[i][1]; - extremes = originalData[i][2]; - rollingData[i] = originalData[i]; + low = 0; + mid = 0; + high = 0; + count = 0; + for (i = 0; i < originalData.length; i++) { + y = originalData[i][1]; + extremes = originalData[i][2]; + rollingData[i] = originalData[i]; - if (y !== null && !isNaN(y)) { - low += extremes[0]; - mid += y; - high += extremes[1]; - count += 1; - } - if (i - rollPeriod >= 0) { - var prev = originalData[i - rollPeriod]; - if (prev[1] !== null && !isNaN(prev[1])) { - low -= prev[2][0]; - mid -= prev[1]; - high -= prev[2][1]; - count -= 1; - } - } - if (count) { - rollingData[i] = [ - originalData[i][0], - 1.0 * mid / count, - [ 1.0 * low / count, - 1.0 * high / count ] ]; - } else { - rollingData[i] = [ originalData[i][0], null, [ null, null ] ]; + if (y !== null && !isNaN(y)) { + low += extremes[0]; + mid += y; + high += extremes[1]; + count += 1; + } + if (i - rollPeriod >= 0) { + var prev = originalData[i - rollPeriod]; + if (prev[1] !== null && !isNaN(prev[1])) { + low -= prev[2][0]; + mid -= prev[1]; + high -= prev[2][1]; + count -= 1; } } + if (count) { + rollingData[i] = [ + originalData[i][0], + 1.0 * mid / count, + [ 1.0 * low / count, + 1.0 * high / count ] ]; + } else { + rollingData[i] = [ originalData[i][0], null, [ null, null ] ]; + } + } + + return rollingData; +}; - return rollingData; - }; })();