Merge pull request #128 from klausw-g/custom-circle-tweaks
[dygraphs.git] / gallery / linear-regression.js
index 77f69c5..de02075 100644 (file)
@@ -5,17 +5,17 @@ Gallery.register(
     name: 'Linear Regressions',
     title: 'Linear Regression Demo',
     setup: function(parent) {
-      parent.innerHTML =
-        "<p>Click the buttons to generate linear regressions over either data "+
-        "series. If you zoom in and then click the regression button, the regression "+
-        "will only be run over visible points. Zoom back out to see what the local "+
-        "regression looks like over the full data.</p> "+
-        "<div id='demodiv' style='width: 480px; height: 320px;'></div>" +
-        "<div style='text-align:center; width: 480px'>" + 
-        "<button style='color: green;' id='ry1'>Regression (Y1)</button> " +
-        "<button style='color: blue;' id='ry2'>Regression (Y2)</button> " +
-        "<button id='clear'>Clear Lines</button>" +
-        "</div>";
+      parent.innerHTML = [
+        "<p>Click the buttons to generate linear regressions over either data ",
+        "series. If you zoom in and then click the regression button, the regression ",
+        "will only be run over visible points. Zoom back out to see what the local ",
+        "regression looks like over the full data.</p> ",
+        "<div id='demodiv' style='width: 480px; height: 320px;'></div>",
+        "<div style='text-align:center; width: 480px'>",
+        "<button style='color: green;' id='ry1'>Regression (Y1)</button> ",
+        "<button style='color: blue;' id='ry2'>Regression (Y2)</button> ",
+        "<button id='clear'>Clear Lines</button>",
+        "</div>"].join("\n");
     },
     run: function() {
       document.getElementById("ry1").onclick = function() { regression(1) };
@@ -29,17 +29,6 @@ Gallery.register(
                    30.0 - i / 5.0 - 10.0 * Math.sin(i / 3.0 + 1.0)]);
       }
 
-      g = new Dygraph(
-              document.getElementById("demodiv"),
-              data,
-              {
-                labels: ['X', 'Y1', 'Y2'],
-                underlayCallback: drawLines,
-                drawPoints: true,
-                strokeWidth: 0.0
-              }
-          );
-
       // coefficients of regression for each series.
       // if coeffs = [ null, [1, 2], null ] then we draw a regression for series 1
       // only. The regression line is y = 1 + 2 * x.
@@ -116,5 +105,16 @@ Gallery.register(
           ctx.restore();
         }
       }
+      
+      g = new Dygraph(
+              document.getElementById("demodiv"),
+              data,
+              {
+                labels: ['X', 'Y1', 'Y2'],
+                underlayCallback: drawLines,
+                drawPoints: true,
+                strokeWidth: 0.0
+              }
+          );
     }
   });