| 1 | <!DOCTYPE HTML> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 | <meta http-equiv="X-UA-Compatible" content="IE=Edge"> |
| 6 | <title>Chart 2D: dynamics</title> |
| 7 | <style type="text/css"> |
| 8 | @import "../../../../dojo/resources/dojo.css"; |
| 9 | @import "../../../../dijit/tests/css/dijitTests.css"; |
| 10 | @import "../../../../dijit/themes/claro/claro.css"; |
| 11 | .dojoxLegendNode {border: 1px solid #ccc; margin: 5px 10px 5px 10px; padding: 3px} |
| 12 | .dojoxLegendText {vertical-align: text-top; padding-right: 10px} |
| 13 | </style> |
| 14 | <script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: false, async: true"></script> |
| 15 | <script type="text/javascript"> |
| 16 | require([ |
| 17 | "dojo/parser", |
| 18 | "dijit/registry", |
| 19 | "dojox/lang/functional/sequence", |
| 20 | "dojox/charting/Chart", |
| 21 | "dojox/charting/themes/CubanShirts", |
| 22 | "dojox/charting/widget/Legend", |
| 23 | "dojox/charting/axis2d/Log", |
| 24 | "dojox/charting/plot2d/Grid", |
| 25 | // Used indirectly/by parser |
| 26 | "dijit/form/Button", |
| 27 | "dijit/form/CheckBox", |
| 28 | "dijit/form/ComboBox", |
| 29 | "dojox/charting/axis2d/Default", |
| 30 | "dojox/charting/plot2d/Columns", |
| 31 | "dojox/charting/plot2d/ClusteredColumns", |
| 32 | "dojox/charting/plot2d/StackedColumns", |
| 33 | "dojox/charting/plot2d/Areas", |
| 34 | "dojox/charting/plot2d/StackedAreas", |
| 35 | "dojo/domReady!" |
| 36 | ], function(parser, registry, dlfs, Chart, CubanShirts, Legend, LogAxis, GridPlot){ |
| 37 | parser.parse(); |
| 38 | |
| 39 | var chart, legend, size = 10, magnitude = 30; |
| 40 | |
| 41 | var getData = function(){ |
| 42 | var data = new Array(size); |
| 43 | for(var i = 0; i < size; ++i){ |
| 44 | data[i] = Math.random() * magnitude; |
| 45 | } |
| 46 | return data; |
| 47 | }; |
| 48 | |
| 49 | var getZeroes = function(){ |
| 50 | return dlfs.repeat(size, "-> 0", 0); |
| 51 | }; |
| 52 | |
| 53 | var makeObjects = function(){ |
| 54 | chart = new Chart("test"); |
| 55 | chart.setTheme(CubanShirts); |
| 56 | |
| 57 | if(registry.byId("hAxis").get("checked")){ |
| 58 | chart.addAxis("x", {natural: true, includeZero: true, fixUpper: "minor"}); |
| 59 | } |
| 60 | |
| 61 | if(registry.byId("vAxis").get("checked")){ |
| 62 | chart.addAxis("y", {vertical: true, type: LogAxis}); |
| 63 | } |
| 64 | |
| 65 | chart.addPlot("default", {type: registry.byId("plot").get("value"), gap: 2}); |
| 66 | |
| 67 | if(registry.byId("grid").get("checked")){ |
| 68 | chart.addPlot("grid", {type: GridPlot, hMinorLines: true, vMinorLines: true}); |
| 69 | } |
| 70 | |
| 71 | for(var i = 1; i <= 5; ++i){ |
| 72 | if(registry.byId("s" + i).get("checked")){ |
| 73 | chart.addSeries("Series " + i, getData(), {stroke: {color: "black", width: 1}}); |
| 74 | } |
| 75 | } |
| 76 | if(registry.byId("s6").get("checked")){ |
| 77 | chart.addSeries("Series 6", getZeroes(), {stroke: {color: "black", width: 1}}); |
| 78 | } |
| 79 | |
| 80 | chart.render(); |
| 81 | |
| 82 | legend = new Legend({chart: chart}, "legend"); |
| 83 | }; |
| 84 | |
| 85 | dojo.addOnLoad(makeObjects); |
| 86 | |
| 87 | changePlot = function(){ |
| 88 | var type = registry.byId("plot").get("value"); |
| 89 | chart.addPlot("default", {type: type, gap: 2}); |
| 90 | chart.render(); |
| 91 | legend.refresh(); |
| 92 | }; |
| 93 | |
| 94 | changeGrid = function(){ |
| 95 | if(registry.byId("grid").get("checked")){ |
| 96 | chart.addPlot("grid", {type: GridPlot, hMinorLines: true, vMinorLines: true}); |
| 97 | }else{ |
| 98 | chart.removePlot("grid"); |
| 99 | } |
| 100 | chart.render(); |
| 101 | }; |
| 102 | |
| 103 | changeX = function(){ |
| 104 | if(registry.byId("hAxis").get("checked")){ |
| 105 | chart.addAxis("x", {natural: true, includeZero: true, fixUpper: "minor"}); |
| 106 | }else{ |
| 107 | chart.removeAxis("x"); |
| 108 | } |
| 109 | chart.render(); |
| 110 | }; |
| 111 | |
| 112 | changeY = function(){ |
| 113 | if(registry.byId("vAxis").get("checked")){ |
| 114 | chart.addAxis("y", {vertical: true, type: LogAxis}); |
| 115 | }else{ |
| 116 | chart.removeAxis("y"); |
| 117 | } |
| 118 | chart.render(); |
| 119 | }; |
| 120 | |
| 121 | changeSeries = function(n){ |
| 122 | if(n == 6){ |
| 123 | // special case |
| 124 | if(registry.byId("s6").get("checked")){ |
| 125 | chart.addSeries("Series 6", getZeroes(), {stroke: {color: "black", width: 1}}); |
| 126 | }else{ |
| 127 | chart.removeSeries("Series 6"); |
| 128 | } |
| 129 | }else{ |
| 130 | if(registry.byId("s" + n).get("checked")){ |
| 131 | chart.addSeries("Series " + n, getData(), {stroke: {color: "black", width: 1}}); |
| 132 | registry.byId("sb" + n).get("disabled", false); |
| 133 | }else{ |
| 134 | chart.removeSeries("Series " + n); |
| 135 | registry.byId("sb" + n).get("disabled", true); |
| 136 | } |
| 137 | } |
| 138 | chart.render(); |
| 139 | legend.refresh(); |
| 140 | }; |
| 141 | |
| 142 | addSeries = function(n){ |
| 143 | chart.addSeries("Series " + n, getData(), {stroke: {color: "black", width: 1}}); |
| 144 | chart.render(); |
| 145 | legend.refresh(); |
| 146 | }; |
| 147 | }); |
| 148 | </script> |
| 149 | </head> |
| 150 | <body class="claro"> |
| 151 | <h1>Chart 2D: dynamics</h1> |
| 152 | <button id="reset1" type="reset" data-dojo-type="dijit/form/Button">Reset with no onClick handler should reset</button> |
| 153 | <table> |
| 154 | <tr> |
| 155 | <td>Plot:</td> |
| 156 | <td> |
| 157 | <select data-dojo-type="dijit/form/ComboBox" id="plot" onChange="changePlot()"> |
| 158 | <option value="Columns">Columns</option> |
| 159 | <option value="ClusteredColumns">ClusteredColumns</option> |
| 160 | <option value="StackedColumns">StackedColumns</option> |
| 161 | <option value="Areas">Areas</option> |
| 162 | <option value="StackedAreas">StackedAreas</option> |
| 163 | </select> |
| 164 | </td> |
| 165 | </tr> |
| 166 | <tr> |
| 167 | <td>Grid:</td> |
| 168 | <td> |
| 169 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="grid" onChange="changeGrid()"> |
| 170 | <label for="grid">include</label> |
| 171 | </td> |
| 172 | </tr> |
| 173 | <tr> |
| 174 | <td>X axis:</td> |
| 175 | <td> |
| 176 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="hAxis" onChange="changeX()"> |
| 177 | <label for="hAxis">include</label> |
| 178 | </td> |
| 179 | </tr> |
| 180 | <tr> |
| 181 | <td>Y axis:</td> |
| 182 | <td> |
| 183 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="vAxis" onChange="changeY()"> |
| 184 | <label for="vAxis">include</label> |
| 185 | </td> |
| 186 | </tr> |
| 187 | <tr> |
| 188 | <td>Series 1:</td> |
| 189 | <td> |
| 190 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="s1" onChange="changeSeries(1)"> |
| 191 | <label for="s1">include</label> |
| 192 | |
| 193 | <button data-dojo-type="dijit/form/Button" id="sb1" onClick="addSeries(1)">Randomize</button> |
| 194 | </td> |
| 195 | </tr> |
| 196 | <tr> |
| 197 | <td>Series 2:</td> |
| 198 | <td> |
| 199 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="s2" onChange="changeSeries(2)"> |
| 200 | <label for="s2">include</label> |
| 201 | |
| 202 | <button data-dojo-type="dijit/form/Button" id="sb2" onClick="addSeries(2)">Randomize</button> |
| 203 | </td> |
| 204 | </tr> |
| 205 | <tr> |
| 206 | <td>Series 3:</td> |
| 207 | <td> |
| 208 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="s3" onChange="changeSeries(3)"> |
| 209 | <label for="s3">include</label> |
| 210 | |
| 211 | <button data-dojo-type="dijit/form/Button" id="sb3" onClick="addSeries(3)">Randomize</button> |
| 212 | </td> |
| 213 | </tr> |
| 214 | <tr> |
| 215 | <td>Series 4:</td> |
| 216 | <td> |
| 217 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="s4" onChange="changeSeries(4)"> |
| 218 | <label for="s4">include</label> |
| 219 | |
| 220 | <button data-dojo-type="dijit/form/Button" id="sb4" onClick="addSeries(4)">Randomize</button> |
| 221 | </td> |
| 222 | </tr> |
| 223 | <tr> |
| 224 | <td>Series 5:</td> |
| 225 | <td> |
| 226 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="true" id="s5" onChange="changeSeries(5)"> |
| 227 | <label for="s5">include</label> |
| 228 | |
| 229 | <button data-dojo-type="dijit/form/Button" id="sb5" onClick="addSeries(5)">Randomize</button> |
| 230 | </td> |
| 231 | </tr> |
| 232 | <tr> |
| 233 | <td>Series 6:</td> |
| 234 | <td> |
| 235 | <input type="checkbox" data-dojo-type="dijit/form/CheckBox" checked="false" id="s6" onChange="changeSeries(6)"> |
| 236 | <label for="s6">include</label> |
| 237 | this series contains all 0 values |
| 238 | </td> |
| 239 | </tr> |
| 240 | </table> |
| 241 | <div id="test" style="width: 600px; height: 400px;"></div> |
| 242 | <div id="legend"></div> |
| 243 | </body> |
| 244 | </html> |
| 245 |