Fix issue 67 and add a test
authorDan Vanderkam <danvdk@gmail.com>
Tue, 26 Jan 2010 09:06:07 +0000 (01:06 -0800)
committerDan Vanderkam <danvdk@gmail.com>
Tue, 26 Jan 2010 09:06:07 +0000 (01:06 -0800)
dygraph.js
tests/color-visibility.html [new file with mode: 0644]

index 30bb7e6..a08f668 100644 (file)
@@ -397,11 +397,13 @@ Dygraph.prototype.setColors_ = function() {
     var sat = this.attr_('colorSaturation') || 1.0;
     var val = this.attr_('colorValue') || 0.5;
     for (var i = 1; i <= num; i++) {
+      if (!this.visibility()[i-1]) continue;
       var hue = (1.0*i/(1+num));
       this.colors_.push( Dygraph.hsvToRGB(hue, sat, val) );
     }
   } else {
     for (var i = 0; i < num; i++) {
+      if (!this.visibility()[i]) continue;
       var colorStr = colors[i % colors.length];
       this.colors_.push(colorStr);
     }
diff --git a/tests/color-visibility.html b/tests/color-visibility.html
new file mode 100644 (file)
index 0000000..c72c1d6
--- /dev/null
@@ -0,0 +1,41 @@
+<html>
+  <head>
+    <title>color visibility</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../dygraph-combined.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+  </head>
+  <body>
+    <p>The lines should maintain their colors as their visibility is toggled.</p>
+
+    <div id="blah"></div>
+    <p><b>Display: </b>
+    <input type=checkbox id=0 onClick="change(this)" checked>
+    <label for="0"> a</label>
+    <input type=checkbox id=1 onClick="change(this)" checked>
+    <label for="1"> b</label>
+    <input type=checkbox id=2 onClick="change(this)" checked>
+    <label for="2"> c</label>
+    </p>
+
+    <script type="text/javascript">
+      chart = new Dygraph(document.getElementById("blah"),
+                          "X,a,b,c\n" +
+                          "10,12345,23456,34567\n" +
+                          "11,12345,20123,31345\n",
+                          {
+                            width: 640,
+                            height: 480,
+                            colors: ['#284785', '#EE1111', '#8AE234'],
+                            visibility: [true, true, true]
+                          });
+
+      function change(el) {
+        chart.setVisibility(el.id, el.checked);
+      }
+    </script>
+  </body>
+</html>