From: Dan Vanderkam Date: Wed, 29 Sep 2010 16:48:47 +0000 (+0200) Subject: change to an implementation based on set names X-Git-Tag: v1.0.0~645 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=227b93cc36500fbab1edab16880f1aa696f8a408;p=dygraphs.git change to an implementation based on set names --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 20e1f8b..3b2ffa7 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -754,16 +754,15 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { for (var i = 0; i < setCount; i++) { var setName = setNames[i]; - var setIdx = this.dygraph_.indexFromSetName(setName); var color = this.colors[setName]; - var strokeWidth = this.dygraph_.attr_("strokeWidth", setIdx); + var strokeWidth = this.dygraph_.attr_("strokeWidth", setName); // setup graphics context context.save(); var point = this.layout.points[0]; - var pointSize = this.dygraph_.attr_("pointSize", setIdx); + var pointSize = this.dygraph_.attr_("pointSize", setName); var prevX = null, prevY = null; - var drawPoints = this.dygraph_.attr_("drawPoints", setIdx); + var drawPoints = this.dygraph_.attr_("drawPoints", setName); var points = this.layout.points; for (var j = 0; j < points.length; j++) { var point = points[j]; diff --git a/dygraph.js b/dygraph.js index 929a9ea..2574d4b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -240,12 +240,12 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.start_(); }; -Dygraph.prototype.attr_ = function(name, series) { - if (series && - typeof(this.user_attrs_[series]) != 'undefined' && - this.user_attrs_[series] != null && - typeof(this.user_attrs_[series][name]) != 'undefined') { - return this.user_attrs_[series][name]; +Dygraph.prototype.attr_ = function(name, seriesName) { + if (seriesName && + typeof(this.user_attrs_[seriesName]) != 'undefined' && + this.user_attrs_[seriesName] != null && + typeof(this.user_attrs_[seriesName][name]) != 'undefined') { + return this.user_attrs_[seriesName][name]; } else if (typeof(this.user_attrs_[name]) != 'undefined') { return this.user_attrs_[name]; } else if (typeof(this.attrs_[name]) != 'undefined') { @@ -1026,9 +1026,9 @@ Dygraph.prototype.updateSelection_ = function() { if (this.previousVerticalX_ >= 0) { // Determine the maximum highlight circle size. var maxCircleSize = 0; - var num_series = this.attr_('labels').length; - for (var i = 1; i < num_series; i++) { - var r = this.attr_('highlightCircleSize', i); + var labels = this.attr_('labels'); + for (var i = 1; i < labels.length; i++) { + var r = this.attr_('highlightCircleSize', labels[i]); if (r > maxCircleSize) maxCircleSize = r; } var px = this.previousVerticalX_; @@ -1069,8 +1069,8 @@ Dygraph.prototype.updateSelection_ = function() { ctx.save(); for (var i = 0; i < this.selPoints_.length; i++) { if (!isOK(this.selPoints_[i].canvasy)) continue; - var setIdx = this.indexFromSetName(this.selPoints_[i].name); - var circleSize = this.attr_('highlightCircleSize', setIdx); + var circleSize = + this.attr_('highlightCircleSize', this.selPoints_[i].name); ctx.beginPath(); ctx.fillStyle = this.plotter_.colors[this.selPoints_[i].name]; ctx.arc(canvasx, this.selPoints_[i].canvasy, circleSize, diff --git a/tests/linear-regression-addseries.html b/tests/linear-regression-addseries.html index 530cea3..4445f47 100644 --- a/tests/linear-regression-addseries.html +++ b/tests/linear-regression-addseries.html @@ -88,16 +88,16 @@ for (var i = 0; i < labels.length; i++) { new_labels.push(labels[i]); if (i) new_colors.push(orig_colors[i - 1]); - new_opts[new_colors.length] = null; if (coeffs[i]) { // Darken the series by 50% to generate its regression. - new_labels.push(labels[i] + " Regression"); + var label = labels[i] + " Regression"; + new_labels.push(label); var c = new RGBColor(orig_colors[i - 1]); c.r = Math.floor(255 - 0.5 * (255 - c.r)); c.g = Math.floor(255 - 0.5 * (255 - c.g)); c.b = Math.floor(255 - 0.5 * (255 - c.b)); new_colors.push(c.toHex()); - new_opts[new_colors.length] = { + new_opts[label] = { drawPoints: false, strokeWidth: 1.0 }; diff --git a/tests/per-series.html b/tests/per-series.html index 8ac90df..7b98dea 100644 --- a/tests/per-series.html +++ b/tests/per-series.html @@ -33,18 +33,18 @@ }, { strokeWidth: 2, - 1: { + 'parabola': { strokeWidth: 0.0, drawPoints: true, pointSize: 4, highlightCircleSize: 6 }, - 2: { + 'line': { strokeWidth: 1.0, drawPoints: true, pointSize: 1.5 }, - 3: { + 'sine wave': { strokeWidth: 3, highlightCircleSize: 10 }