| 1 |
define(["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojox/gfx","./AnalogGauge","./AnalogCircleIndicator","./TextIndicator","./GlossyCircularGaugeNeedle"], |
| 2 |
function(declare, lang, connect, gfx, AnalogGauge, AnalogCircleIndicator, TextIndicator, GlossyCircularGaugeNeedle) { |
| 3 |
|
| 4 |
return declare("dojox.gauges.GlossyCircularGaugeBase", [AnalogGauge], { |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
_defaultIndicator: AnalogCircleIndicator, |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
_needle: null, |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
_textIndicator: null, |
| 20 |
|
| 21 |
_textIndicatorAdded: false, |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
_range: null, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
value: 0, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
color: 'black', |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
needleColor: '#c4c4c4', |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
textIndicatorFont: "normal normal normal 20pt serif", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
textIndicatorVisible: true, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
textIndicatorColor: '#c4c4c4', |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
_majorTicksOffset: 130, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
majorTicksInterval: 10, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
_majorTicksLength: 5, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
majorTicksColor: '#c4c4c4', |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
majorTicksLabelPlacement: 'inside', |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
_minorTicksOffset: 130, |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
minorTicksInterval: 5, |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
_minorTicksLength: 3, |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
minorTicksColor: '#c4c4c4', |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
noChange: false, |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
title: "", |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
font: "normal normal normal 10pt serif", |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
scalePrecision: 0, |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
textIndicatorPrecision: 0, |
| 106 |
|
| 107 |
_font: null, |
| 108 |
|
| 109 |
|
| 110 |
constructor: function(){ |
| 111 |
this.startAngle = -135; |
| 112 |
this.endAngle = 135; |
| 113 |
this.min = 0; |
| 114 |
this.max = 100; |
| 115 |
}, |
| 116 |
|
| 117 |
startup: function(){ |
| 118 |
|
| 119 |
|
| 120 |
this.inherited(arguments); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
if (this._needle) return; |
| 125 |
|
| 126 |
var scale = Math.min((this.width / this._designWidth), (this.height / this._designHeight)); |
| 127 |
this.cx = scale * this._designCx + (this.width - scale * this._designWidth) / 2; |
| 128 |
this.cy = scale * this._designCy + (this.height - scale * this._designHeight) / 2; |
| 129 |
|
| 130 |
this._range = { |
| 131 |
low: this.min ? this.min : 0, |
| 132 |
high: this.max ? this.max : 100, |
| 133 |
color: [255, 255, 255, 0] |
| 134 |
}; |
| 135 |
this.addRange(this._range); |
| 136 |
|
| 137 |
this._majorTicksOffset = this._minorTicksOffset = scale * this._majorTicksOffset; |
| 138 |
this._majorTicksLength = scale * this._majorTicksLength; |
| 139 |
this._minorTicksLength = scale * this._minorTicksLength; |
| 140 |
|
| 141 |
|
| 142 |
this.setMajorTicks({ |
| 143 |
fixedPrecision: true, |
| 144 |
precision: this.scalePrecision, |
| 145 |
font: this._font, |
| 146 |
offset: this._majorTicksOffset, |
| 147 |
interval: this.majorTicksInterval, |
| 148 |
length: this._majorTicksLength, |
| 149 |
color: this.majorTicksColor, |
| 150 |
labelPlacement: this.majorTicksLabelPlacement |
| 151 |
}); |
| 152 |
|
| 153 |
|
| 154 |
this.setMinorTicks({ |
| 155 |
offset: this._minorTicksOffset, |
| 156 |
interval: this.minorTicksInterval, |
| 157 |
length: this._minorTicksLength, |
| 158 |
color: this.minorTicksColor |
| 159 |
}); |
| 160 |
|
| 161 |
|
| 162 |
this._needle = new GlossyCircularGaugeNeedle({ |
| 163 |
hideValue: true, |
| 164 |
title: this.title, |
| 165 |
noChange: this.noChange, |
| 166 |
color: this.needleColor, |
| 167 |
value: this.value |
| 168 |
}); |
| 169 |
this.addIndicator(this._needle); |
| 170 |
|
| 171 |
|
| 172 |
this._textIndicator = new TextIndicator({ |
| 173 |
x: scale * this._designTextIndicatorX + (this.width - scale * this._designWidth) / 2, |
| 174 |
y: scale * this._designTextIndicatorY + (this.height - scale * this._designHeight) / 2, |
| 175 |
fixedPrecision: true, |
| 176 |
precision: this.textIndicatorPrecision, |
| 177 |
color: this.textIndicatorColor, |
| 178 |
value: this.value ? this.value : this.min, |
| 179 |
align: "middle", |
| 180 |
font: this._textIndicatorFont |
| 181 |
}); |
| 182 |
|
| 183 |
if (this.textIndicatorVisible){ |
| 184 |
this.addIndicator(this._textIndicator); |
| 185 |
this._textIndicatorAdded = true; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
connect.connect(this._needle, "valueChanged", lang.hitch(this, function(){ |
| 190 |
this.value = this._needle.value; |
| 191 |
this._textIndicator.update(this._needle.value); |
| 192 |
this.onValueChanged(); |
| 193 |
})); |
| 194 |
|
| 195 |
}, |
| 196 |
|
| 197 |
|
| 198 |
onValueChanged: function(){ |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
}, |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
_setColorAttr: function(color){ |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
this.color = color ? color : 'black'; |
| 214 |
if (this._gaugeBackground && this._gaugeBackground.parent) |
| 215 |
this._gaugeBackground.parent.remove(this._gaugeBackground); |
| 216 |
if (this._foreground && this._foreground.parent) |
| 217 |
this._foreground.parent.remove(this._foreground); |
| 218 |
this._gaugeBackground = null; |
| 219 |
this._foreground = null; |
| 220 |
this.draw(); |
| 221 |
}, |
| 222 |
|
| 223 |
_setNeedleColorAttr: function(color){ |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
this.needleColor = color; |
| 229 |
if (this._needle){ |
| 230 |
this.removeIndicator(this._needle); |
| 231 |
this._needle.color = this.needleColor; |
| 232 |
this._needle.shape = null; |
| 233 |
this.addIndicator(this._needle); |
| 234 |
} |
| 235 |
}, |
| 236 |
|
| 237 |
_setTextIndicatorColorAttr: function(color){ |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
this.textIndicatorColor = color; |
| 243 |
if (this._textIndicator){ |
| 244 |
this._textIndicator.color = this.textIndicatorColor; |
| 245 |
this.draw(); |
| 246 |
} |
| 247 |
}, |
| 248 |
|
| 249 |
_setTextIndicatorFontAttr: function(font){ |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
this.textIndicatorFont = font; |
| 257 |
this._textIndicatorFont = gfx.splitFontString(font); |
| 258 |
if (this._textIndicator){ |
| 259 |
this._textIndicator.font = this._textIndicatorFont; |
| 260 |
this.draw(); |
| 261 |
} |
| 262 |
}, |
| 263 |
|
| 264 |
setMajorTicksOffset: function(offset){ |
| 265 |
|
| 266 |
|
| 267 |
this._majorTicksOffset = offset; |
| 268 |
this._setMajorTicksProperty({ |
| 269 |
'offset': this._majorTicksOffset |
| 270 |
}); |
| 271 |
return this; |
| 272 |
}, |
| 273 |
|
| 274 |
getMajorTicksOffset: function(){ |
| 275 |
|
| 276 |
|
| 277 |
return this._majorTicksOffset; |
| 278 |
}, |
| 279 |
|
| 280 |
_setMajorTicksIntervalAttr: function(interval){ |
| 281 |
|
| 282 |
|
| 283 |
this.majorTicksInterval = interval; |
| 284 |
this._setMajorTicksProperty({ |
| 285 |
'interval': this.majorTicksInterval |
| 286 |
}); |
| 287 |
}, |
| 288 |
|
| 289 |
setMajorTicksLength: function(length){ |
| 290 |
|
| 291 |
|
| 292 |
this._majorTicksLength = length; |
| 293 |
this._setMajorTicksProperty({ |
| 294 |
'length': this._majorTicksLength |
| 295 |
}); |
| 296 |
return this; |
| 297 |
}, |
| 298 |
|
| 299 |
getMajorTicksLength: function(){ |
| 300 |
|
| 301 |
|
| 302 |
return this._majorTicksLength; |
| 303 |
}, |
| 304 |
|
| 305 |
_setMajorTicksColorAttr: function(color){ |
| 306 |
|
| 307 |
|
| 308 |
this.majorTicksColor = color; |
| 309 |
this._setMajorTicksProperty({ |
| 310 |
'color': this.majorTicksColor |
| 311 |
}); |
| 312 |
}, |
| 313 |
|
| 314 |
_setMajorTicksLabelPlacementAttr: function(placement){ |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
this.majorTicksLabelPlacement = placement; |
| 320 |
this._setMajorTicksProperty({ |
| 321 |
'labelPlacement': this.majorTicksLabelPlacement |
| 322 |
}); |
| 323 |
}, |
| 324 |
|
| 325 |
_setMajorTicksProperty: function(prop){ |
| 326 |
if (this.majorTicks){ |
| 327 |
lang.mixin(this.majorTicks, prop); |
| 328 |
this.setMajorTicks(this.majorTicks); |
| 329 |
} |
| 330 |
}, |
| 331 |
|
| 332 |
setMinorTicksOffset: function(offset){ |
| 333 |
|
| 334 |
|
| 335 |
this._minorTicksOffset = offset; |
| 336 |
this._setMinorTicksProperty({ |
| 337 |
'offset': this._minorTicksOffset |
| 338 |
}); |
| 339 |
return this; |
| 340 |
}, |
| 341 |
|
| 342 |
getMinorTicksOffset: function(){ |
| 343 |
|
| 344 |
|
| 345 |
return this._minorTicksOffset; |
| 346 |
}, |
| 347 |
|
| 348 |
_setMinorTicksIntervalAttr: function(interval){ |
| 349 |
|
| 350 |
|
| 351 |
this.minorTicksInterval = interval; |
| 352 |
this._setMinorTicksProperty({ |
| 353 |
'interval': this.minorTicksInterval |
| 354 |
}); |
| 355 |
}, |
| 356 |
|
| 357 |
setMinorTicksLength: function(length){ |
| 358 |
|
| 359 |
|
| 360 |
this._minorTicksLength = length; |
| 361 |
this._setMinorTicksProperty({ |
| 362 |
'length': this._minorTicksLength |
| 363 |
}); |
| 364 |
return this; |
| 365 |
}, |
| 366 |
|
| 367 |
getMinorTicksLength: function(){ |
| 368 |
|
| 369 |
|
| 370 |
return this._minorTicksLength; |
| 371 |
}, |
| 372 |
|
| 373 |
_setMinorTicksColorAttr: function(color){ |
| 374 |
|
| 375 |
|
| 376 |
this.minorTicksColor = color; |
| 377 |
this._setMinorTicksProperty({ |
| 378 |
'color': this.minorTicksColor |
| 379 |
}); |
| 380 |
}, |
| 381 |
|
| 382 |
_setMinorTicksProperty: function(prop){ |
| 383 |
if (this.minorTicks){ |
| 384 |
lang.mixin(this.minorTicks, prop); |
| 385 |
this.setMinorTicks(this.minorTicks); |
| 386 |
} |
| 387 |
}, |
| 388 |
|
| 389 |
_setMinAttr: function(min){ |
| 390 |
this.min = min; |
| 391 |
|
| 392 |
if (this.majorTicks != null) |
| 393 |
this.setMajorTicks(this.majorTicks); |
| 394 |
if (this.minorTicks != null) |
| 395 |
this.setMinorTicks(this.minorTicks); |
| 396 |
this.draw(); |
| 397 |
this._updateNeedle(); |
| 398 |
}, |
| 399 |
|
| 400 |
_setMaxAttr: function(max){ |
| 401 |
this.max = max; |
| 402 |
|
| 403 |
if (this.majorTicks != null) |
| 404 |
this.setMajorTicks(this.majorTicks); |
| 405 |
if (this.minorTicks != null) |
| 406 |
this.setMinorTicks(this.minorTicks); |
| 407 |
this.draw(); |
| 408 |
this._updateNeedle(); |
| 409 |
}, |
| 410 |
|
| 411 |
_setScalePrecisionAttr: function(value){ |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
this.scalePrecision = value; |
| 417 |
this._setMajorTicksProperty({ |
| 418 |
'precision': value |
| 419 |
}); |
| 420 |
}, |
| 421 |
|
| 422 |
_setTextIndicatorPrecisionAttr: function(value){ |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
this.textIndicatorPrecision = value; |
| 428 |
this._setMajorTicksProperty({ |
| 429 |
'precision': value |
| 430 |
}); |
| 431 |
}, |
| 432 |
|
| 433 |
_setValueAttr: function(value){ |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
value = Math.min(this.max, value); |
| 440 |
value = Math.max(this.min, value); |
| 441 |
this.value = value; |
| 442 |
if (this._needle){ |
| 443 |
|
| 444 |
var noChange = this._needle.noChange; |
| 445 |
this._needle.noChange = false; |
| 446 |
this._needle.update(value); |
| 447 |
this._needle.noChange = noChange; |
| 448 |
} |
| 449 |
}, |
| 450 |
|
| 451 |
_setNoChangeAttr: function(value){ |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
this.noChange = value; |
| 457 |
if (this._needle) |
| 458 |
this._needle.noChange = this.noChange; |
| 459 |
}, |
| 460 |
|
| 461 |
_setTextIndicatorVisibleAttr: function(value){ |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
this.textIndicatorVisible = value; |
| 468 |
if (this._textIndicator && this._needle){ |
| 469 |
if (this.textIndicatorVisible && !this._textIndicatorAdded){ |
| 470 |
this.addIndicator(this._textIndicator); |
| 471 |
this._textIndicatorAdded = true; |
| 472 |
this.moveIndicatorToFront(this._needle); |
| 473 |
|
| 474 |
} |
| 475 |
else |
| 476 |
if (!this.textIndicatorVisible && this._textIndicatorAdded){ |
| 477 |
this.removeIndicator(this._textIndicator); |
| 478 |
this._textIndicatorAdded = false; |
| 479 |
} |
| 480 |
} |
| 481 |
}, |
| 482 |
|
| 483 |
_setTitleAttr: function(value){ |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
this.title = value; |
| 490 |
if (this._needle){ |
| 491 |
this._needle.title = this.title; |
| 492 |
} |
| 493 |
}, |
| 494 |
|
| 495 |
_setOrientationAttr: function(orientation){ |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
this.orientation = orientation; |
| 502 |
if (this.majorTicks != null) |
| 503 |
this.setMajorTicks(this.majorTicks); |
| 504 |
if (this.minorTicks != null) |
| 505 |
this.setMinorTicks(this.minorTicks); |
| 506 |
this.draw(); |
| 507 |
this._updateNeedle(); |
| 508 |
|
| 509 |
}, |
| 510 |
|
| 511 |
_updateNeedle: function(){ |
| 512 |
|
| 513 |
this.value = Math.max(this.min, this.value); |
| 514 |
this.value = Math.min(this.max, this.value); |
| 515 |
|
| 516 |
if (this._needle){ |
| 517 |
|
| 518 |
var noChange = this._needle.noChange; |
| 519 |
this._needle.noChange = false; |
| 520 |
this._needle.update(this.value, false); |
| 521 |
this._needle.noChange = noChange; |
| 522 |
} |
| 523 |
}, |
| 524 |
|
| 525 |
_setFontAttr: function(font){ |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
this.font = font; |
| 532 |
this._font = gfx.splitFontString(font); |
| 533 |
this._setMajorTicksProperty({ |
| 534 |
'font': this._font |
| 535 |
}); |
| 536 |
}}); |
| 537 |
}); |