X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=datahandler%2Fdatahandler.js;h=2b637b569c00291bf0cc3113d6c7192fe111d5b5;hb=60edb3ae4e1d7655e3a48fe6fa56d0cf0fd8a686;hp=b9eb67c2f65658da037666d827170bfce96111b8;hpb=749281f855678908181d622157ceee12fa0f8349;p=dygraphs.git diff --git a/datahandler/datahandler.js b/datahandler/datahandler.js index b9eb67c..2b637b5 100644 --- a/datahandler/datahandler.js +++ b/datahandler/datahandler.js @@ -123,11 +123,11 @@ handler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) { for ( var i = 0; i < series.length; ++i) { var item = series[i]; var yraw = item[1]; - var yval = yraw === null ? null : Dygraph.parseFloat(yraw); + var yval = yraw === null ? null : handler.parseFloat(yraw); var point = { x : NaN, y : NaN, - xval : Dygraph.parseFloat(item[0]), + xval : handler.parseFloat(item[0]), yval : yval, name : setName, // TODO(danvk): is this really necessary? idx : i + boundaryIdStart @@ -161,7 +161,6 @@ handler.prototype.onPointsCreated_ = function(series, points) { * data format where series[i] = [x,y,{extras}]. * @param {!number} rollPeriod The number of points over which to average the data * @param {!DygraphOptions} options The dygraph options. - * TODO(danvk): be more specific than "Array" here. * @return {!Array.<[!number,?number,?]>} the rolled series. */ handler.prototype.rollingAverage = function(series, rollPeriod, options) { @@ -250,4 +249,21 @@ handler.prototype.getIndexesInWindow_ = function(series, dateWindow) { } }; +/** + * Optimized replacement for parseFloat, which was way too slow when almost + * all values were type number, with few edge cases, none of which were strings. + * @param {?number} val + * @return {number} + * @protected + */ +handler.parseFloat = function(val) { + // parseFloat(null) is NaN + if (val === null) { + return NaN; + } + + // Assume it's a number or NaN. If it's something else, I'll be shocked. + return val; +}; + })();