| 1 | /** |
| 2 | * @fileoverview Tests for per-series options. |
| 3 | * |
| 4 | * @author danvk@google.com (Dan Vanderkam) |
| 5 | */ |
| 6 | var perSeriesTestCase = TestCase("per-series"); |
| 7 | |
| 8 | perSeriesTestCase.prototype.setUp = function() { |
| 9 | document.body.innerHTML = "<div id='graph'></div>"; |
| 10 | }; |
| 11 | |
| 12 | perSeriesTestCase.prototype.tearDown = function() { |
| 13 | }; |
| 14 | |
| 15 | perSeriesTestCase.prototype.testPerSeriesFill = function() { |
| 16 | var opts = { |
| 17 | width: 480, |
| 18 | height: 320, |
| 19 | drawXGrid: false, |
| 20 | drawYGrid: false, |
| 21 | drawXAxis: false, |
| 22 | drawYAxis: false, |
| 23 | Y: { fillGraph: true }, |
| 24 | colors: [ '#FF0000', '#0000FF' ], |
| 25 | fillAlpha: 0.15 |
| 26 | }; |
| 27 | var data = "X,Y,Z\n" + |
| 28 | "1,0,0\n" + |
| 29 | "2,0,1\n" + |
| 30 | "3,0,1\n" + |
| 31 | "4,0,0\n" + |
| 32 | "5,0,0\n" + |
| 33 | "6,1,0\n" + |
| 34 | "7,1,0\n" + |
| 35 | "8,0,0\n" |
| 36 | ; |
| 37 | |
| 38 | var graph = document.getElementById("graph"); |
| 39 | g = new Dygraph(graph, data, opts); |
| 40 | |
| 41 | var sampler = new PixelSampler(g); |
| 42 | |
| 43 | // Inside of the "Z" bump -- no fill. |
| 44 | assertEquals([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5)); |
| 45 | |
| 46 | // Inside of the "Y" bump -- filled in. |
| 47 | assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); |
| 48 | }; |
| 49 | |
| 50 | perSeriesTestCase.prototype.testOldStyleSeries = function() { |
| 51 | var opts = { |
| 52 | pointSize : 5, |
| 53 | Y: { pointSize : 4 }, |
| 54 | }; |
| 55 | var graph = document.getElementById("graph"); |
| 56 | var data = "X,Y,Z\n1,0,0\n"; |
| 57 | g = new Dygraph(graph, data, opts); |
| 58 | |
| 59 | assertEquals(5, g.getOption("pointSize")); |
| 60 | assertEquals(4, g.getOption("pointSize", "Y")); |
| 61 | assertEquals(5, g.getOption("pointSize", "Z")); |
| 62 | }; |
| 63 | |
| 64 | perSeriesTestCase.prototype.testNewStyleSeries = function() { |
| 65 | var opts = { |
| 66 | pointSize : 5, |
| 67 | series : { |
| 68 | Y: { pointSize : 4 } |
| 69 | }, |
| 70 | }; |
| 71 | var graph = document.getElementById("graph"); |
| 72 | var data = "X,Y,Z\n1,0,0\n"; |
| 73 | g = new Dygraph(graph, data, opts); |
| 74 | |
| 75 | assertEquals(5, g.getOption("pointSize")); |
| 76 | assertEquals(4, g.getOption("pointSize", "Y")); |
| 77 | assertEquals(5, g.getOption("pointSize", "Z")); |
| 78 | }; |
| 79 | |
| 80 | perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() { |
| 81 | var opts = { |
| 82 | pointSize : 5, |
| 83 | Z : { pointSize : 6 }, |
| 84 | series : { |
| 85 | Y: { pointSize : 4 } |
| 86 | }, |
| 87 | }; |
| 88 | var graph = document.getElementById("graph"); |
| 89 | var data = "X,Y,Z\n1,0,0\n"; |
| 90 | g = new Dygraph(graph, data, opts); |
| 91 | |
| 92 | assertEquals(5, g.getOption("pointSize")); |
| 93 | assertEquals(4, g.getOption("pointSize", "Y")); |
| 94 | assertEquals(5, g.getOption("pointSize", "Z")); |
| 95 | |
| 96 | // Erase the series object, and Z will become visible again. |
| 97 | g.updateOptions({ series : undefined }); |
| 98 | assertEquals(5, g.getOption("pointSize")); |
| 99 | assertEquals(6, g.getOption("pointSize", "Z")); |
| 100 | assertEquals(5, g.getOption("pointSize", "Y")); |
| 101 | }; |
| 102 | |
| 103 | // TODO(konigsberg): move to multiple_axes.js |
| 104 | perSeriesTestCase.prototype.testAxisInNewSeries = function() { |
| 105 | var opts = { |
| 106 | series : { |
| 107 | D : { axis : 'y2' }, |
| 108 | C : { axis : 1 }, |
| 109 | B : { axis : 0 }, |
| 110 | E : { axis : 'y' } |
| 111 | } |
| 112 | }; |
| 113 | var graph = document.getElementById("graph"); |
| 114 | var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; |
| 115 | g = new Dygraph(graph, data, opts); |
| 116 | |
| 117 | assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); |
| 118 | assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); |
| 119 | }; |
| 120 | |
| 121 | // TODO(konigsberg): move to multiple_axes.js |
| 122 | perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() { |
| 123 | var opts = { |
| 124 | series : { |
| 125 | D : { axis : 'y2' }, |
| 126 | C : { axis : 1 }, |
| 127 | B : { axis : 0 }, |
| 128 | E : { axis : 'y' } |
| 129 | }, |
| 130 | axes : { |
| 131 | y : { pointSize : 7 }, |
| 132 | y2 : { pointSize : 6 } |
| 133 | } |
| 134 | }; |
| 135 | var graph = document.getElementById("graph"); |
| 136 | var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; |
| 137 | g = new Dygraph(graph, data, opts); |
| 138 | |
| 139 | assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0)); |
| 140 | assertEquals(["C", "D"], g.attributes_.seriesForAxis(1)); |
| 141 | |
| 142 | assertEquals(1.5, g.getOption("pointSize")); |
| 143 | assertEquals(7, g.getOption("pointSize", "A")); |
| 144 | assertEquals(7, g.getOption("pointSize", "B")); |
| 145 | assertEquals(6, g.getOption("pointSize", "C")); |
| 146 | assertEquals(6, g.getOption("pointSize", "D")); |
| 147 | assertEquals(7, g.getOption("pointSize", "E")); |
| 148 | }; |