X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=tests%2Flinear-regression.html;h=c38ed3366daf798dc58570532c812c92a83275ca;hb=6e20721120a88fcf451c19559dfc62e2d316dd85;hp=22017d397f510032f895235b481e658eb544c417;hpb=05a1d11691a0f5ee3bfe2ff87e3eb8c90059a91c;p=dygraphs.git diff --git a/tests/linear-regression.html b/tests/linear-regression.html index 22017d3..c38ed33 100644 --- a/tests/linear-regression.html +++ b/tests/linear-regression.html @@ -1,13 +1,10 @@ + + Linear Regression - - - - - + + @@ -35,7 +32,8 @@ { labels: ['X', 'Y1', 'Y2'], underlayCallback: drawLines, - drawPoints: true + drawPoints: true, + strokeWidth: 0.0 } ); @@ -54,6 +52,10 @@ var y = g.getValue(i, series); if (y == null) continue; + if (y.length == 2) { + // using fractions + y = y[0] / y[1]; + } num++; sum_x += x; @@ -66,7 +68,9 @@ var b = (sum_y - a * sum_x) / num; coeffs[series] = [b, a]; - console.log("coeffs(" + series + "): [" + b + ", " + a + "]"); + if (typeof(console) != 'undefined') { + console.log("coeffs(" + series + "): [" + b + ", " + a + "]"); + } g.updateOptions({}); // forces a redraw. } @@ -76,6 +80,10 @@ g.updateOptions({}); } + function toHex(rgb) { + return 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')'; + } + function drawLines(ctx, area, layout) { if (typeof(g) == 'undefined') return; // won't be set on the initial draw. @@ -93,8 +101,11 @@ var p1 = g.toDomCoords(x1, y1); var p2 = g.toDomCoords(x2, y2); - console.log("(" + x1 + ", " + y1 + ") - (" + x2 + ", " + y2 + ")"); - var color = g.getColors()[i - 1]; + var c = Dygraph.toRGB_(g.getColors()[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)); + var color = toHex(c); ctx.save(); ctx.strokeStyle = color; ctx.lineWidth = 1.0;