| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/sniff", "dojo/_base/array", "dojo/on", "dojox/gfx", "./IndicatorBase"], |
| 2 |
function(lang, declare, has, array, on, gfx, IndicatorBase){ |
| 3 |
return declare("dojox.dgauges.TextIndicator", IndicatorBase, { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
font: null, |
| 14 |
|
| 15 |
|
| 16 |
x: 0, |
| 17 |
|
| 18 |
|
| 19 |
y: 0, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
align: "middle", |
| 28 |
|
| 29 |
|
| 30 |
color: "black", |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
indicator: null, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
labelFunc: null, |
| 39 |
|
| 40 |
constructor: function(){ |
| 41 |
this.addInvalidatingProperties(["indicator"]); |
| 42 |
|
| 43 |
var resetProps = ["x", "y", "font", "align", "color", "labelFunc"]; |
| 44 |
array.forEach(resetProps, lang.hitch(this, function(entry){ |
| 45 |
this.watch(entry, this._resetText); |
| 46 |
})); |
| 47 |
|
| 48 |
this.watch("indicator", lang.hitch(this, this._indicatorChanged)); |
| 49 |
}, |
| 50 |
|
| 51 |
postscript: function(mixin){ |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
this.inherited(arguments); |
| 57 |
if(mixin && mixin.indicator){ |
| 58 |
this._indicatorChanged("indicator", null, mixin.indicator); |
| 59 |
} |
| 60 |
}, |
| 61 |
|
| 62 |
_resetText: function(){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
this._textCreated = false; |
| 68 |
this.invalidateRendering(); |
| 69 |
}, |
| 70 |
|
| 71 |
_valueWatcher: null, |
| 72 |
|
| 73 |
_indicatorChanged: function(name, oldValue, newValue){ |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
if(this._valueWatcher){ |
| 79 |
this._valueWatcher.unwatch(); |
| 80 |
} |
| 81 |
this._valueWatcher = newValue.watch("value", lang.hitch(this, this.refreshRendering)); |
| 82 |
}, |
| 83 |
|
| 84 |
_getFont: function(){ |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
var font = this.font; |
| 90 |
if(!font && this._gauge){ |
| 91 |
font = this._gauge.font; |
| 92 |
} |
| 93 |
if(!font){ |
| 94 |
font = gfx.defaultFont; |
| 95 |
} |
| 96 |
return font; |
| 97 |
}, |
| 98 |
|
| 99 |
_textCreated: false, |
| 100 |
_textInstance: null, |
| 101 |
|
| 102 |
_createText: function(group, font, color, text, x, y, align){ |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
var gfxText = group.createText({ |
| 108 |
x: x, |
| 109 |
y: y, |
| 110 |
text: text, |
| 111 |
align: align |
| 112 |
}).setFont(font).setFill(color); |
| 113 |
return gfxText; |
| 114 |
}, |
| 115 |
|
| 116 |
refreshRendering: function(){ |
| 117 |
if(this._gfxGroup == null){ |
| 118 |
return; |
| 119 |
} |
| 120 |
var text; |
| 121 |
if(this.indicator){ |
| 122 |
text = this.indicator.value; |
| 123 |
}else{ |
| 124 |
text = this.value; |
| 125 |
} |
| 126 |
if(this.labelFunc){ |
| 127 |
text = this.labelFunc(text); |
| 128 |
} |
| 129 |
var iOsVersion = has("iphone"); |
| 130 |
|
| 131 |
if(!this._textCreated || (iOsVersion != undefined && iOsVersion < 5)){ |
| 132 |
this._gfxGroup.clear(); |
| 133 |
var font = this._getFont(); |
| 134 |
this._textInstance = this._createText(this._gfxGroup, font, font.color ? font.color : this.color, "", this.x, this.y, this.align); |
| 135 |
this._textCreated = true; |
| 136 |
} |
| 137 |
this._textInstance.setShape({ |
| 138 |
text: text |
| 139 |
}); |
| 140 |
|
| 141 |
return this._textInstance; |
| 142 |
} |
| 143 |
}) |
| 144 |
}); |