X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fupdate_options.js;h=ac28e99b2abc38fe5670e26cac8c11ef31f81325;hb=0d0a92db6678ca5a1c7086d1af0e1369a105b258;hp=628f6151135270bfe399ae4fee014c313ccb341a;hpb=a9aa25756c4e6d9430d412f3d594aff337e3d4ab;p=dygraphs.git
diff --git a/auto_tests/tests/update_options.js b/auto_tests/tests/update_options.js
index 628f615..ac28e99 100644
--- a/auto_tests/tests/update_options.js
+++ b/auto_tests/tests/update_options.js
@@ -19,25 +19,30 @@ UpdateOptionsTestCase.prototype.data = "X,Y1,Y2\n" +
"2011-05-05,8,3\n";
UpdateOptionsTestCase.prototype.setUp = function() {
- document.body.innerHTML = "
";
+ document.body.innerHTML = "
";
};
UpdateOptionsTestCase.prototype.tearDown = function() {
};
-UpdateOptionsTestCase.prototype.wrap = function(g) {
+/*
+ * Tweaks the dygraph so it sets g._testDrawCalled to true when internal method
+ * drawGraph_ is called. Call unWrapDrawGraph when done with this.
+ */
+UpdateOptionsTestCase.prototype.wrapDrawGraph = function(g) {
g._testDrawCalled = false;
- var oldDrawGraph = Dygraph.prototype.drawGraph_;
- Dygraph.prototype.drawGraph_ = function() {
+ g._oldDrawGraph = g.drawGraph_;
+ g.drawGraph_ = function() {
g._testDrawCalled = true;
- oldDrawGraph.call(g);
+ g._oldDrawGraph.call(g);
}
-
- return oldDrawGraph;
}
-UpdateOptionsTestCase.prototype.unWrap = function(oldDrawGraph) {
- Dygraph.prototype.drawGraph_ = oldDrawGraph;
+/*
+ * See wrapDrawGraph
+ */
+UpdateOptionsTestCase.prototype.unwrapDrawGraph = function(g) {
+ g.drawGraph_ = g._oldDrawGraph;
}
UpdateOptionsTestCase.prototype.testStrokeAll = function() {
@@ -49,9 +54,9 @@ UpdateOptionsTestCase.prototype.testStrokeAll = function() {
// These options will allow us to jump to renderGraph_()
// drawGraph_() will be skipped.
- var oldDrawGraph = this.wrap(graph);
+ this.wrapDrawGraph(graph);
graph.updateOptions(updatedOptions);
- this.unWrap(oldDrawGraph);
+ this.unwrapDrawGraph(graph);
assertFalse(graph._testDrawCalled);
};
@@ -66,9 +71,9 @@ UpdateOptionsTestCase.prototype.testStrokeSingleSeries = function() {
// These options will allow us to jump to renderGraph_()
// drawGraph_() will be skipped.
- var oldDrawGraph = this.wrap(graph);
+ this.wrapDrawGraph(graph);
graph.updateOptions(updatedOptions);
- this.unWrap(oldDrawGraph);
+ this.unwrapDrawGraph(graph);
assertFalse(graph._testDrawCalled);
};
@@ -89,9 +94,9 @@ UpdateOptionsTestCase.prototype.testSingleSeriesRequiresNewPoints = function() {
// These options will not allow us to jump to renderGraph_()
// drawGraph_() must be called
- var oldDrawGraph = this.wrap(graph);
+ this.wrapDrawGraph(graph);
graph.updateOptions(updatedOptions);
- this.unWrap(oldDrawGraph);
+ this.unwrapDrawGraph(graph);
assertTrue(graph._testDrawCalled);
};
@@ -105,9 +110,9 @@ UpdateOptionsTestCase.prototype.testWidthChangeNeedsNewPoints = function() {
// These options will not allow us to jump to renderGraph_()
// drawGraph_() must be called
- var oldDrawGraph = this.wrap(graph);
+ this.wrapDrawGraph(graph);
graph.updateOptions(updatedOptions);
- this.unWrap(oldDrawGraph);
+ this.unwrapDrawGraph(graph);
assertTrue(graph._testDrawCalled);
};
@@ -119,3 +124,51 @@ UpdateOptionsTestCase.prototype.testUpdateLabelsDivDoesntInfiniteLoop = function
graph.updateOptions({labelsDiv : labelsDiv});
}
+// Test https://github.com/danvk/dygraphs/issues/247
+UpdateOptionsTestCase.prototype.testUpdateColors = function() {
+ var graphDiv = document.getElementById("graph");
+ var graph = new Dygraph(graphDiv, this.data, this.opts);
+
+ var defaultColors = ["rgb(0,128,0)", "rgb(0,0,128)"];
+ assertEquals(["rgb(0,128,0)", "rgb(0,0,128)"], graph.getColors());
+
+ var colors1 = [ "#aaa", "#bbb" ];
+ graph.updateOptions({ colors: colors1 });
+ assertEquals(colors1, graph.getColors());
+
+ // extra colors are ignored until you add additional data series.
+ var colors2 = [ "#ddd", "#eee", "#fff" ];
+ graph.updateOptions({ colors: colors2 });
+ assertEquals(["#ddd", "#eee"], graph.getColors());
+
+ graph.updateOptions({ file:
+ "X,Y1,Y2,Y3\n" +
+ "2011-01-01,2,3,4\n" +
+ "2011-02-02,5,3,2\n"
+ });
+ assertEquals(colors2, graph.getColors());
+
+ graph.updateOptions({ colors: null, file: this.data });
+ assertEquals(defaultColors, graph.getColors());
+}
+
+// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=249
+// Verifies that setting 'legend: always' via update immediately shows the
+// legend.
+UpdateOptionsTestCase.prototype.testUpdateLegendAlways = function() {
+ var graphDiv = document.getElementById("graph");
+ var graph = new Dygraph(graphDiv, this.data, this.opts);
+
+ var legend = document.getElementsByClassName("dygraph-legend");
+ assertEquals(1, legend.length);
+ legend = legend[0];
+ assertEquals("", legend.innerHTML);
+
+ graph.updateOptions({legend: 'always'});
+
+ legend = document.getElementsByClassName("dygraph-legend");
+ assertEquals(1, legend.length);
+ legend = legend[0];
+ assertNotEquals(-1, legend.textContent.indexOf("Y1"));
+ assertNotEquals(-1, legend.textContent.indexOf("Y2"));
+};