| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Analog Gauge Widget</title> |
| 5 | <style> |
| 6 | @import "../_Gauge.css"; |
| 7 | @import "../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 9 | </style> |
| 10 | <script type="text/javascript"> |
| 11 | djConfig = { |
| 12 | parseOnLoad: true, |
| 13 | isDebug: true |
| 14 | }; |
| 15 | </script> |
| 16 | <script type="text/javascript" src="../../../dojo/dojo.js" dojoConfig="parseOnLoad: true"></script> |
| 17 | <script language="JavaScript" type="text/javascript"> |
| 18 | dojo.require('dojox.gauges.AnalogGauge'); |
| 19 | dojo.require('dojox.gauges.AnalogArcIndicator'); |
| 20 | dojo.require('dojox.gauges.AnalogNeedleIndicator'); |
| 21 | dojo.require('dojox.gauges.AnalogArrowIndicator'); |
| 22 | dojo.require('dijit.form.Button'); |
| 23 | dojo.require('dojo.parser'); |
| 24 | dojo.ready(init); |
| 25 | |
| 26 | var gauge, valueIndicator, targetIndicator, handle; |
| 27 | var ranges1 = [ {low:5, high:10, hover:'5 - 10'}, |
| 28 | {low:10, high:20, hover:'10 - 20'}, |
| 29 | {low:20, high:30, hover:'20 - 30'}, |
| 30 | {low:30, high:40, hover:'30 - 40'}, |
| 31 | {low:40, high:50, hover:'40 - 50'}, |
| 32 | {low:50, high:60, hover:'50 - 60'}, |
| 33 | {low:60, high:70, hover:'60 - 70'}, |
| 34 | {low:70, high:75, hover:'70 - 75'} |
| 35 | ]; |
| 36 | var ranges2 = [ {low:5, high:10, hover:'5 - 10'}, |
| 37 | {low:10, high:20, hover:'10 - 20'}, |
| 38 | {low:20, high:30, hover:'20 - 30'}, |
| 39 | {low:30, high:40, hover:'30 - 40'}, |
| 40 | {low:40, high:50, hover:'40 - 50'}, |
| 41 | {low:50, high:60, hover:'50 - 60'}, |
| 42 | {low:60, high:70, hover:'60 - 70'}, |
| 43 | {low:70, high:75, hover:'70 - 75'} |
| 44 | ]; |
| 45 | |
| 46 | function init() { |
| 47 | gauge = dojo.byId("defaultGauge"); |
| 48 | gauge = new dojox.gauges.AnalogGauge({ |
| 49 | id: "defaultGauge", |
| 50 | width: 350, |
| 51 | height: 200, |
| 52 | cx: 175, |
| 53 | cy: 175, |
| 54 | radius: 125, |
| 55 | ranges: ranges1, |
| 56 | minorTicks: { |
| 57 | offset: 125, |
| 58 | interval: 2.5, |
| 59 | length: 5, |
| 60 | color: 'gray' |
| 61 | }, |
| 62 | majorTicks: { |
| 63 | offset: 125, |
| 64 | interval: 5, |
| 65 | length: 10 |
| 66 | }, |
| 67 | indicators: [ |
| 68 | new dojox.gauges.AnalogArrowIndicator({ |
| 69 | value:17, |
| 70 | width: 3, |
| 71 | hover:'Value: 17', |
| 72 | title: 'Value' |
| 73 | }), |
| 74 | new dojox.gauges.AnalogLineIndicator({ |
| 75 | value:6, |
| 76 | color:'#D00000', |
| 77 | width: 3, |
| 78 | hover:'Target: 6', |
| 79 | title: 'Target' |
| 80 | }) |
| 81 | ] |
| 82 | }, gauge); |
| 83 | gauge.startup(); |
| 84 | var g = gauge; |
| 85 | var int = 10; |
| 86 | dojo.connect(dijit.byId('changeTicks'), 'onClick', function(){ |
| 87 | var o = g.majorTicks; |
| 88 | o.interval = ++int; |
| 89 | g.setMajorTicks(o); |
| 90 | }); |
| 91 | |
| 92 | /* Entirely programmatic gauge (ranges, ticks, indicators, etc.) */ |
| 93 | var fill = { |
| 94 | 'type': 'linear', |
| 95 | 'x1': 0, |
| 96 | 'x2': 0, |
| 97 | 'y2': 0, |
| 98 | 'y1': gauge.height, |
| 99 | 'colors': [{offset: 0, color: "#ECECEC"}, {offset: 1, color: "white"}] |
| 100 | }; |
| 101 | gauge = dojo.byId("programmaticGauge"); |
| 102 | gauge = new dojox.gauges.AnalogGauge({ |
| 103 | id: "programmaticGauge", |
| 104 | width: 350, |
| 105 | height: 200, |
| 106 | cx: 175, |
| 107 | cy: 175, |
| 108 | radius: 125, |
| 109 | background: fill, |
| 110 | image: { |
| 111 | url: "images/gaugeOverlay.png", |
| 112 | width: 280, |
| 113 | height: 155, |
| 114 | x: 35, |
| 115 | y: 38, |
| 116 | overlay: true |
| 117 | }, |
| 118 | useRangeStyles: 8 |
| 119 | }, gauge); |
| 120 | gauge.startup(); |
| 121 | gauge.addRanges(ranges2); |
| 122 | gauge.setMajorTicks({ |
| 123 | length: 5, |
| 124 | interval: 5, |
| 125 | offset: 125, |
| 126 | font: {family: "Arial", style: "italic", variant: 'small-caps', weight: 'bold', size: "18px"} |
| 127 | }); |
| 128 | valueIndicator = new dojox.gauges.AnalogArrowIndicator({ |
| 129 | value:17, |
| 130 | width: 3, |
| 131 | hover:'Value: 17', |
| 132 | title: 'Value', |
| 133 | easing: dojo.fx.easing.bounceOut |
| 134 | }); |
| 135 | gauge.addIndicator(valueIndicator); |
| 136 | targetIndicator = new dojox.gauges.AnalogLineIndicator({ |
| 137 | value:6, |
| 138 | color:'#D00000', |
| 139 | width: 3, |
| 140 | hover:'Target: 6', |
| 141 | title: 'Target', |
| 142 | // Can use string to indicate easing function (just like in de |
| 143 | easing: 'dojo.fx.easing.linear' |
| 144 | }); |
| 145 | gauge.addIndicator(targetIndicator); |
| 146 | handle = setInterval((function(t, v){ |
| 147 | return (function(){ |
| 148 | t.update(Math.floor(Math.random() * 70) + 5); |
| 149 | v.update(Math.floor(Math.random() * 70) + 5); |
| 150 | }); |
| 151 | })(valueIndicator, targetIndicator), 3000); |
| 152 | dojo.connect(dijit.byId('stop'), 'onClick', function(){ |
| 153 | clearInterval(handle); |
| 154 | }); |
| 155 | |
| 156 | gauge = dojo.byId("speedometer"); |
| 157 | gauge = new dojox.gauges.AnalogGauge({ |
| 158 | id: "speedometer", |
| 159 | width:270, |
| 160 | height: 230, |
| 161 | cx: 135, |
| 162 | cy: 135, |
| 163 | radius: 125, |
| 164 | image: { |
| 165 | url: "images/flare.png", |
| 166 | width: 112, |
| 167 | height: 116, |
| 168 | x: 140, |
| 169 | y: 40, |
| 170 | overlay: true |
| 171 | }, |
| 172 | startAngle: -135, |
| 173 | endAngle: 135, |
| 174 | useRangeStyles: 8, |
| 175 | ranges: [{low:0, high:180, color: 'black'}], |
| 176 | majorTicks: { |
| 177 | offset: 85, |
| 178 | length: 10, |
| 179 | interval: 20, |
| 180 | color: 'gray' |
| 181 | }, |
| 182 | minorTicks: { |
| 183 | offset: 85, |
| 184 | length: 5, |
| 185 | interval: 5, |
| 186 | color: 'gray' |
| 187 | }, |
| 188 | indicators: [new dojox.gauges.AnalogNeedleIndicator({ |
| 189 | value:0, |
| 190 | width: 3, |
| 191 | length: 100, |
| 192 | hover:'Value: 0', |
| 193 | title: 'Value', |
| 194 | color: 'red' |
| 195 | })] |
| 196 | }, gauge); |
| 197 | gauge.startup(); |
| 198 | |
| 199 | gauge = dojo.byId("tachometer"); |
| 200 | gauge = new dojox.gauges.AnalogGauge({ |
| 201 | id: "tachometer", |
| 202 | width:270, |
| 203 | height: 230, |
| 204 | cx: 135, |
| 205 | cy: 135, |
| 206 | radius: 125, |
| 207 | image: { |
| 208 | url: "images/flare.png", |
| 209 | width: 112, |
| 210 | height: 116, |
| 211 | x: 140, |
| 212 | y: 40, |
| 213 | overlay: true |
| 214 | }, |
| 215 | startAngle: -135, |
| 216 | endAngle: 135, |
| 217 | useRangeStyles: 8, |
| 218 | ranges: [{low:0, high:9000, color: 'black'}], |
| 219 | majorTicks: { |
| 220 | offset: 75, |
| 221 | length: 10, |
| 222 | color: 'gray', |
| 223 | interval: 1000 |
| 224 | }, |
| 225 | minorTicks: { |
| 226 | offset: 75, |
| 227 | length: 5, |
| 228 | color: 'gray', |
| 229 | interval: 500 |
| 230 | }, |
| 231 | indicators: [new dojox.gauges.AnalogNeedleIndicator({ |
| 232 | value:0, |
| 233 | width: 3, |
| 234 | length: 100, |
| 235 | hover:'Value: 0', |
| 236 | title: 'Value', |
| 237 | color: 'red' |
| 238 | })] |
| 239 | }, gauge); |
| 240 | gauge.startup(); |
| 241 | |
| 242 | // Used for a gradient arc indicator below: |
| 243 | var fill = { |
| 244 | 'type': 'linear', |
| 245 | 'x1': 50, |
| 246 | 'y1': 50, |
| 247 | 'x2': 550, |
| 248 | 'y2': 550, |
| 249 | 'colors': [{offset: 0, color: 'black'}, {offset: 0.5, color: 'black'}, {offset: 0.75, color: 'yellow'}, {offset: 1, color: 'red'}] |
| 250 | }; |
| 251 | gauge = dojo.byId("arctest"); |
| 252 | gauge = new dojox.gauges.AnalogGauge({ |
| 253 | id: "arctest", |
| 254 | width: 650, |
| 255 | height: 550, |
| 256 | radius: 300, |
| 257 | cx: 320, |
| 258 | cy: 310, |
| 259 | startAngle: -135, |
| 260 | endAngle: 135, |
| 261 | ranges: [ |
| 262 | {low: 0, high: 100, color: 'black'}, |
| 263 | {low: 100, high: 200, color: 'black'} |
| 264 | ], |
| 265 | minorTicks: { |
| 266 | offset: 235, |
| 267 | interval: 5, |
| 268 | length: 5, |
| 269 | color: 'gray' |
| 270 | }, |
| 271 | majorTicks: { |
| 272 | offset: 235, |
| 273 | interval: 10, |
| 274 | length: 10, |
| 275 | color: 'gray' |
| 276 | }, |
| 277 | indicators: [new dojox.gauges.AnalogArcIndicator({ |
| 278 | value: 200, |
| 279 | width: 20, |
| 280 | offset: 280, |
| 281 | color: fill, |
| 282 | noChange: true, |
| 283 | hideValue: true |
| 284 | }), |
| 285 | new dojox.gauges.AnalogArcIndicator({ |
| 286 | value: 80, |
| 287 | width: 10, |
| 288 | offset: 280, |
| 289 | hover:'Arc: 80', |
| 290 | title: 'Arc', |
| 291 | color: 'blue' |
| 292 | }), |
| 293 | new dojox.gauges.AnalogLineIndicator({ |
| 294 | value:6, |
| 295 | color:'#D00000', |
| 296 | width: 8, |
| 297 | hover:'Target: 6', |
| 298 | title: 'Target', |
| 299 | // Can use string to indicate easing function (just like in declarative version) |
| 300 | easing: 'dojo.fx.easing.linear' |
| 301 | }), |
| 302 | new dojox.gauges.AnalogArrowIndicator({ |
| 303 | value: 20, |
| 304 | width: 8, |
| 305 | length: 300, |
| 306 | hover:'Arrow: 20', |
| 307 | title: 'Arrow', |
| 308 | color: 'red', |
| 309 | easing: dojo.fx.easing.bounceOut |
| 310 | }), |
| 311 | new dojox.gauges.AnalogNeedleIndicator({ |
| 312 | value: 100, |
| 313 | width: 8, |
| 314 | length: 300, |
| 315 | hover: 'Needle: 100', |
| 316 | title: 'Needle', |
| 317 | color: 'red' |
| 318 | }) |
| 319 | ] |
| 320 | }, gauge); |
| 321 | gauge.startup(); |
| 322 | |
| 323 | var fill = { |
| 324 | 'type': 'linear', |
| 325 | 'x1': 0, |
| 326 | 'x2': 0, |
| 327 | 'y2': 0, |
| 328 | 'y1': gauge.height, |
| 329 | 'colors': [{offset: 0, color: "#ECECEC"}, {offset: 1, color: "white"}] |
| 330 | }; |
| 331 | gauge.setBackground(fill); |
| 332 | } |
| 333 | dojo.addOnUnload(function(){ |
| 334 | clearInterval(handle); |
| 335 | }); |
| 336 | |
| 337 | </script> |
| 338 | </head> |
| 339 | <body class="tundra"> |
| 340 | <h1>Analog Gauge Widget</h1> |
| 341 | <h2>Default Colored Gauge</h2> |
| 342 | <div id="defaultGauge"></div> |
| 343 | <button dojoType="dijit.form.Button" id="changeTicks">Change Ticks</button> |
| 344 | <h2>CSS Themed Ranges, Image Overlay, Gradient Background, Updating to Random Values on 3s Timer</h2> |
| 345 | <div id="programmaticGauge"></div> |
| 346 | <button dojoType="dijit.form.Button" id="stop">Stop Timer</button> |
| 347 | <div style="float: left;"> |
| 348 | <h2>Speedometer</h2> |
| 349 | <div id="speedometer"></div> |
| 350 | </div> |
| 351 | <div style="float: left;"> |
| 352 | <h2>Tachometer</h2> |
| 353 | <div id="tachometer"></div> |
| 354 | </div> |
| 355 | <div style="clear: both;"> |
| 356 | <h2>Various Indicators Test</h2> |
| 357 | <div id="arctest"></div> |
| 358 | </div> |
| 359 | <h2>Declarative, Gradient Ranges, Gradient Background, No Indicator Boxes</h2> |
| 360 | <div dojoType="dojox.gauges.AnalogGauge" |
| 361 | id="declarativeGauge" |
| 362 | width="270" |
| 363 | height="265" |
| 364 | cx="110" |
| 365 | cy="150" |
| 366 | radius="125" |
| 367 | startAngle="-45" |
| 368 | endAngle="135" |
| 369 | useRangeStyles="0" |
| 370 | hideValues="true" |
| 371 | majorTicks="{length: 5, offset: 125, interval: 5}" |
| 372 | background="{ |
| 373 | 'type': 'linear', |
| 374 | 'x1': 0, |
| 375 | 'y1': 265, |
| 376 | 'x2': 0, |
| 377 | 'y2': 0, |
| 378 | 'colors': [{offset: 0, color: '#ECECEC'}, {offset: 1, color: 'white'}] |
| 379 | }"> |
| 380 | <div dojoType="dojox.gauges.Range" |
| 381 | low="5" |
| 382 | high="10" |
| 383 | hover="5 - 10" |
| 384 | color="{ |
| 385 | 'type': 'linear', |
| 386 | 'colors': [{offset: 0, color:'#606060'}, {offset: 1, color: '#707070'}] |
| 387 | }"> |
| 388 | </div> |
| 389 | <div dojoType="dojox.gauges.Range" |
| 390 | id="range1" |
| 391 | low="10" |
| 392 | high="20" |
| 393 | hover="10 - 20" |
| 394 | color="{ |
| 395 | 'type': 'linear', |
| 396 | 'colors': [{offset: 0, color:'#707070'}, {offset: 1, color: '#808080'}] |
| 397 | }"> |
| 398 | </div> |
| 399 | <div dojoType="dojox.gauges.Range" |
| 400 | id="range2" |
| 401 | low="20" |
| 402 | high="30" |
| 403 | hover="20 - 30" |
| 404 | color="{ |
| 405 | 'type': 'linear', |
| 406 | 'colors': [{offset: 0, color:'#808080'}, {offset: 1, color: '#909090'}] |
| 407 | }"> |
| 408 | </div> |
| 409 | <div dojoType="dojox.gauges.Range" |
| 410 | id="range3" |
| 411 | low="30" |
| 412 | high="40" |
| 413 | hover="30 - 40" |
| 414 | color="{ |
| 415 | 'type': 'linear', |
| 416 | 'colors': [{offset: 0, color:'#909090'}, {offset: 1, color: '#A0A0A0'}] |
| 417 | }"> |
| 418 | </div> |
| 419 | <div dojoType="dojox.gauges.Range" |
| 420 | id="range4" |
| 421 | low="40" |
| 422 | high="50" |
| 423 | hover="40 - 50" |
| 424 | color="{ |
| 425 | 'type': 'linear', |
| 426 | 'colors': [{offset: 0, color:'#A0A0A0'}, {offset: 1, color: '#B0B0B0'}] |
| 427 | }"> |
| 428 | </div> |
| 429 | <div dojoType="dojox.gauges.Range" |
| 430 | id="range5" |
| 431 | low="50" |
| 432 | high="60" |
| 433 | hover="50 - 60" |
| 434 | color="{ |
| 435 | 'type': 'linear', |
| 436 | 'colors': [{offset: 0, color:'#B0B0B0'}, {offset: 1, color: '#C0C0C0'}] |
| 437 | }"> |
| 438 | </div> |
| 439 | <div dojoType="dojox.gauges.Range" |
| 440 | id="range6" |
| 441 | low="60" |
| 442 | high="70" |
| 443 | hover="60 - 70" |
| 444 | color="{ |
| 445 | 'type': 'linear', |
| 446 | 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#D0D0D0'}] |
| 447 | }"> |
| 448 | </div> |
| 449 | <div dojoType="dojox.gauges.Range" |
| 450 | id="range7" |
| 451 | low="70" |
| 452 | high="75" |
| 453 | hover="70 - 75" |
| 454 | color="{ |
| 455 | 'type': 'linear', |
| 456 | 'colors': [{offset: 0, color:'#D0D0D0'}, {offset: 1, color: '#E0E0E0'}] |
| 457 | }"> |
| 458 | </div> |
| 459 | <div dojoType="dojox.gauges.AnalogLineIndicator" |
| 460 | id="target" |
| 461 | value="6" |
| 462 | color="#D00000" |
| 463 | width="3" |
| 464 | hover="Target: 6" |
| 465 | title="Target"> |
| 466 | </div> |
| 467 | <div dojoType="dojox.gauges.AnalogArrowIndicator" |
| 468 | id="value" |
| 469 | value="17" |
| 470 | type="arrow" |
| 471 | length="135" |
| 472 | width="3" |
| 473 | hover="Value: 17" |
| 474 | title="Value"> |
| 475 | </div> |
| 476 | </div> |
| 477 | <h2>Declarative, (Ugly) Colored Ranges, No Numbers, No Indicator Boxes</h2> |
| 478 | <div dojoType="dojox.gauges.AnalogGauge" |
| 479 | id="declarativeGauge2" |
| 480 | width="270" |
| 481 | height="270" |
| 482 | cx="135" |
| 483 | cy="135" |
| 484 | radius="125" |
| 485 | startAngle="-90" |
| 486 | endAngle="270" |
| 487 | useRangeStyles="0" |
| 488 | hideValues="true" |
| 489 | background="{color: 'green'}"> |
| 490 | <div dojoType="dojox.gauges.Range" |
| 491 | low="5" |
| 492 | high="10" |
| 493 | hover="5 - 10" |
| 494 | color="{color: 'red'}"> |
| 495 | </div> |
| 496 | <div dojoType="dojox.gauges.Range" |
| 497 | low="10" |
| 498 | high="20" |
| 499 | hover="10 - 20" |
| 500 | color="{color: '#FFA500'}"> |
| 501 | </div> |
| 502 | <div dojoType="dojox.gauges.Range" |
| 503 | low="20" |
| 504 | high="30" |
| 505 | hover="20 - 30" |
| 506 | color="{color: 'yellow'}"> |
| 507 | </div> |
| 508 | <div dojoType="dojox.gauges.Range" |
| 509 | low="30" |
| 510 | high="40" |
| 511 | hover="30 - 40" |
| 512 | color="{color: '#7FFF00'}"> |
| 513 | </div> |
| 514 | <div dojoType="dojox.gauges.Range" |
| 515 | low="40" |
| 516 | high="50" |
| 517 | hover="40 - 50" |
| 518 | color="{color: '#00FFFF'}"> |
| 519 | </div> |
| 520 | <div dojoType="dojox.gauges.Range" |
| 521 | low="50" |
| 522 | high="60" |
| 523 | hover="50 - 60" |
| 524 | color="{color: 'blue'}"> |
| 525 | </div> |
| 526 | <div dojoType="dojox.gauges.Range" |
| 527 | low="60" |
| 528 | high="70" |
| 529 | hover="60 - 70" |
| 530 | color="{color: '#191970'}"> |
| 531 | </div> |
| 532 | <div dojoType="dojox.gauges.Range" |
| 533 | low="70" |
| 534 | high="75" |
| 535 | hover="70 - 75" |
| 536 | color="{color: 'purple'}"> |
| 537 | </div> |
| 538 | <div dojoType="dojox.gauges.AnalogLineIndicator" |
| 539 | value="6" |
| 540 | color="#D00000" |
| 541 | width="3" |
| 542 | hover="Target: 6" |
| 543 | title="Target"> |
| 544 | </div> |
| 545 | <div dojoType="dojox.gauges.AnalogArrowIndicator" |
| 546 | value="55" |
| 547 | length="135" |
| 548 | width="3" |
| 549 | hover="Value: 55" |
| 550 | title="Value"> |
| 551 | </div> |
| 552 | </div> |
| 553 | </body> |
| 554 | </html> |