From ca43052c92cd63ac522ca12c0fa3a40df268cd1a Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 13 Dec 2009 00:20:49 -0800 Subject: [PATCH] apply patches from mark swanson --- dygraph-canvas.js | 98 +++++++++++++++++++++++++++++++------------------------ dygraph.js | 12 +++++-- 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 11affc2..70ec659 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -38,12 +38,14 @@ DygraphLayout.prototype.evaluate = function() { DygraphLayout.prototype._evaluateLimits = function() { this.minxval = this.maxxval = null; for (var name in this.datasets) { - var series = this.datasets[name]; - var x1 = series[0][0]; - if (!this.minxval || x1 < this.minxval) this.minxval = x1; - - var x2 = series[series.length - 1][0]; - if (!this.maxxval || x2 > this.maxxval) this.maxxval = x2; + if (this.datasets.hasOwnProperty(name)) { + var series = this.datasets[name]; + var x1 = series[0][0]; + if (!this.minxval || x1 < this.minxval) this.minxval = x1; + + var x2 = series[series.length - 1][0]; + if (!this.maxxval || x2 > this.maxxval) this.maxxval = x2; + } } this.xrange = this.maxxval - this.minxval; this.xscale = (this.xrange != 0 ? 1/this.xrange : 1.0); @@ -58,28 +60,30 @@ DygraphLayout.prototype._evaluateLineCharts = function() { // add all the rects this.points = new Array(); for (var setName in this.datasets) { - var dataset = this.datasets[setName]; - for (var j = 0; j < dataset.length; j++) { - var item = dataset[j]; - var point = { - x: ((parseFloat(item[0]) - this.minxval) * this.xscale), - y: 1.0 - ((parseFloat(item[1]) - this.minyval) * this.yscale), - xval: parseFloat(item[0]), - yval: parseFloat(item[1]), - name: setName - }; - - // limit the x, y values so they do not overdraw - if (point.y <= 0.0) { - point.y = 0.0; - } - if (point.y >= 1.0) { - point.y = 1.0; - } - if ((point.x >= 0.0) && (point.x <= 1.0)) { - this.points.push(point); - } - } + if (this.datasets.hasOwnProperty(setName)) { + var dataset = this.datasets[setName]; + for (var j = 0; j < dataset.length; j++) { + var item = dataset[j]; + var point = { + x: ((parseFloat(item[0]) - this.minxval) * this.xscale), + y: 1.0 - ((parseFloat(item[1]) - this.minyval) * this.yscale), + xval: parseFloat(item[0]), + yval: parseFloat(item[1]), + name: setName + }; + + // limit the x, y values so they do not overdraw + if (point.y <= 0.0) { + point.y = 0.0; + } + if (point.y >= 1.0) { + point.y = 1.0; + } + if ((point.x >= 0.0) && (point.x <= 1.0)) { + this.points.push(point); + } + } + } } }; @@ -117,19 +121,21 @@ DygraphLayout.prototype.evaluateWithError = function() { // Copy over the error terms var i = 0; // index in this.points for (var setName in this.datasets) { - var j = 0; - var dataset = this.datasets[setName]; - for (var j = 0; j < dataset.length; j++, i++) { - var item = dataset[j]; - var xv = parseFloat(item[0]); - var yv = parseFloat(item[1]); - - if (xv == this.points[i].xval && - yv == this.points[i].yval) { - this.points[i].errorMinus = parseFloat(item[2]); - this.points[i].errorPlus = parseFloat(item[3]); - } - } + if (this.datasets.hasOwnProperty(setName)) { + var j = 0; + var dataset = this.datasets[setName]; + for (var j = 0; j < dataset.length; j++, i++) { + var item = dataset[j]; + var xv = parseFloat(item[0]); + var yv = parseFloat(item[1]); + + if (xv == this.points[i].xval && + yv == this.points[i].yval) { + this.points[i].errorMinus = parseFloat(item[2]); + this.points[i].errorPlus = parseFloat(item[3]); + } + } + } } }; @@ -322,7 +328,9 @@ DygraphCanvasRenderer.prototype._renderAxis = function() { var makeDiv = function(txt) { var div = document.createElement("div"); for (var name in labelStyle) { - div.style[name] = labelStyle[name]; + if (labelStyle.hasOwnProperty(name)) { + div.style[name] = labelStyle[name]; + } } div.appendChild(document.createTextNode(txt)); return div; @@ -437,7 +445,11 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var errorBars = this.layout.options.errorBars; var setNames = []; - for (var name in this.layout.datasets) setNames.push(name); + for (var name in this.layout.datasets) { + if (this.layout.datasets.hasOwnProperty(name)) { + setNames.push(name); + } + } var setCount = setNames.length; //Update Points diff --git a/dygraph.js b/dygraph.js index 4fc2fdc..690cb8b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -451,7 +451,9 @@ Dygraph.prototype.createStatusMessage_ = function(){ Dygraph.update(messagestyle, this.attr_('labelsDivStyles')); var div = document.createElement("div"); for (var name in messagestyle) { - div.style[name] = messagestyle[name]; + if (messagestyle.hasOwnProperty(name)) { + div.style[name] = messagestyle[name]; + } } this.graphDiv.appendChild(div); this.attrs_.labelsDiv = div; @@ -476,7 +478,9 @@ Dygraph.prototype.createRollInterface_ = function() { roller.size = "2"; roller.value = this.rollPeriod_; for (var name in textAttr) { - roller.style[name] = textAttr[name]; + if (textAttr.hasOwnProperty(name)) { + roller.style[name] = textAttr[name]; + } } var pa = this.graphDiv; @@ -1607,7 +1611,9 @@ Dygraph.prototype.parseDataTable_ = function(data) { Dygraph.update = function (self, o) { if (typeof(o) != 'undefined' && o !== null) { for (var k in o) { - self[k] = o[k]; + if (o.hasOwnProperty(k)) { + self[k] = o[k]; + } } } return self; -- 2.7.4