From: Dan Vanderkam Date: Wed, 29 Sep 2010 16:38:33 +0000 (+0200) Subject: update both linear regression tests; support null as per-series value X-Git-Tag: v1.0.0~646 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=de0445fc1b969ab85a3d985dbd1e6747f3ddac0b;p=dygraphs.git update both linear regression tests; support null as per-series value --- diff --git a/dygraph.js b/dygraph.js index 56f9319..929a9ea 100644 --- a/dygraph.js +++ b/dygraph.js @@ -243,6 +243,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { 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]; } else if (typeof(this.user_attrs_[name]) != 'undefined') { diff --git a/tests/linear-regression-addseries.html b/tests/linear-regression-addseries.html index 3aa0632..530cea3 100644 --- a/tests/linear-regression-addseries.html +++ b/tests/linear-regression-addseries.html @@ -37,6 +37,7 @@ { labels: labels, drawPoints: true, + strokeWidth: 0.0, drawCallback: function(g, is_initial) { if (!is_initial) return; var c = g.getColors(); @@ -83,9 +84,11 @@ // Generate a new data set with the regression lines. var new_labels = []; var new_colors = []; + var new_opts = {}; 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"); @@ -94,6 +97,10 @@ 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] = { + drawPoints: false, + strokeWidth: 1.0 + }; } } @@ -108,49 +115,16 @@ } } - // TODO(danvk): set colors intelligently. - - g.updateOptions({ - file: new_data, - labels: new_labels, - colors: new_colors - }); + new_opts.file = new_data; + new_opts.labels = new_labels; + new_opts.colors = new_colors; + g.updateOptions(new_opts); } function clearLines() { for (var i = 0; i < coeffs.length; i++) coeffs[i] = null; updateChart(); } - - // function drawLines(ctx, area, layout) { - // if (typeof(g) == 'undefined') return; // won't be set on the initial draw. - - // var range = g.xAxisRange(); - // for (var i = 0; i < coeffs.length; i++) { - // if (!coeffs[i]) continue; - // var a = coeffs[i][1]; - // var b = coeffs[i][0]; - - // var x1 = range[0]; - // var y1 = a * x1 + b; - // var x2 = range[1]; - // var y2 = a * x2 + b; - - // var p1 = g.toDomCoords(x1, y1); - // var p2 = g.toDomCoords(x2, y2); - - // var color = g.getColors()[i - 1]; - // ctx.save(); - // ctx.strokeStyle = color; - // ctx.lineWidth = 1.0; - // ctx.beginPath(); - // ctx.moveTo(p1[0], p1[1]); - // ctx.lineTo(p2[0], p2[1]); - // ctx.closePath(); - // ctx.stroke(); - // ctx.restore(); - // } - // } diff --git a/tests/linear-regression.html b/tests/linear-regression.html index bed74e0..9f18d58 100644 --- a/tests/linear-regression.html +++ b/tests/linear-regression.html @@ -35,7 +35,8 @@ { labels: ['X', 'Y1', 'Y2'], underlayCallback: drawLines, - drawPoints: true + drawPoints: true, + strokeWidth: 0.0 } );