X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=tests%2Flinear-regression.html;h=5caae90a10f9aa30e7dcd73f54a4442bd27f3c22;hb=514a10f302043e48459a79806775b6925dc9a7b5;hp=9f18d589f980d8217854bf068fbb2e5dd8f973ff;hpb=895b3657b0ab22bb35815a1687c71116b2d8b36c;p=dygraphs.git diff --git a/tests/linear-regression.html b/tests/linear-regression.html index 9f18d58..5caae90 100644 --- a/tests/linear-regression.html +++ b/tests/linear-regression.html @@ -1,13 +1,13 @@ + Linear Regression - - - - - + + + @@ -55,6 +55,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; @@ -67,7 +71,7 @@ var b = (sum_y - a * sum_x) / num; coeffs[series] = [b, a]; - if (console) { + if (typeof(console) != 'undefined') { console.log("coeffs(" + series + "): [" + b + ", " + a + "]"); } @@ -79,6 +83,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. @@ -96,11 +104,11 @@ var p1 = g.toDomCoords(x1, y1); var p2 = g.toDomCoords(x2, y2); - var c = new RGBColor(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 = c.toHex(); + var color = toHex(c); ctx.save(); ctx.strokeStyle = color; ctx.lineWidth = 1.0;