| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojox/gfx", "dojo/_base/array", "dojox/widget/_Invalidating", "dojo/_base/sniff"], |
| 2 |
function(lang, declare, gfx, array, _Invalidating, has){ |
| 3 |
return declare("dojox.dgauges.ScaleBase", _Invalidating, { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
scaler: null, |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
font: null, |
| 18 |
|
| 19 |
|
| 20 |
labelPosition: null, |
| 21 |
|
| 22 |
|
| 23 |
labelGap: 1, |
| 24 |
|
| 25 |
|
| 26 |
tickStroke: null, |
| 27 |
_gauge: null, |
| 28 |
_gfxGroup: null, |
| 29 |
_bgGroup: null, |
| 30 |
_fgGroup: null, |
| 31 |
_indicators: null, |
| 32 |
_indicatorsIndex: null, |
| 33 |
_indicatorsRenderers: null, |
| 34 |
|
| 35 |
constructor: function(){ |
| 36 |
this._indicators = []; |
| 37 |
this._indicatorsIndex = {}; |
| 38 |
this._indicatorsRenderers = {}; |
| 39 |
this._gauge = null; |
| 40 |
this._gfxGroup = null; |
| 41 |
|
| 42 |
this.tickStroke = {color: "black", width: has("ie") <= 8 ? 1 : 0.5}; |
| 43 |
|
| 44 |
this.addInvalidatingProperties(["scaler", "font", "labelGap", "labelPosition", "tickShapeFunc", "tickLabelFunc", "tickStroke"]); |
| 45 |
|
| 46 |
this.watch("scaler", lang.hitch(this, this._watchScaler)); |
| 47 |
}, |
| 48 |
|
| 49 |
postscript: function(mixin){ |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
this.inherited(arguments); |
| 55 |
if(mixin && mixin.scaler){ |
| 56 |
this._watchScaler("scaler", null, mixin.scaler); |
| 57 |
} |
| 58 |
}, |
| 59 |
|
| 60 |
_watchers: null, |
| 61 |
|
| 62 |
_watchScaler: function(name, oldValue, newValue){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
array.forEach(this._watchers, lang.hitch(this, function(entry){ |
| 68 |
entry.unwatch(); |
| 69 |
})); |
| 70 |
|
| 71 |
|
| 72 |
var props = newValue.watchedProperties; |
| 73 |
this._watchers = []; |
| 74 |
array.forEach(props, lang.hitch(this, function(entry){ |
| 75 |
this._watchers.push(newValue.watch(entry, lang.hitch(this, this.invalidateRendering))); |
| 76 |
})); |
| 77 |
}, |
| 78 |
|
| 79 |
_getFont: function(){ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
var font = this.font; |
| 85 |
if(!font){ |
| 86 |
font = this._gauge.font; |
| 87 |
} |
| 88 |
if(!font){ |
| 89 |
font = gfx.defaultFont; |
| 90 |
} |
| 91 |
return font; |
| 92 |
}, |
| 93 |
|
| 94 |
positionForValue: function(value){ |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
return 0; |
| 102 |
}, |
| 103 |
|
| 104 |
valueForPosition: function(position){ |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
}, |
| 112 |
|
| 113 |
tickLabelFunc: function(tickItem){ |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
if(tickItem.isMinor){ |
| 121 |
return null; |
| 122 |
}else{ |
| 123 |
return String(tickItem.value); |
| 124 |
} |
| 125 |
}, |
| 126 |
|
| 127 |
tickShapeFunc: function(group, scale, tickItem){ |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
return group.createLine({ |
| 137 |
x1: 0, |
| 138 |
y1: 0, |
| 139 |
x2: tickItem.isMinor ? 6 : 10, |
| 140 |
y2: 0 |
| 141 |
}).setStroke(this.tickStroke); |
| 142 |
}, |
| 143 |
|
| 144 |
getIndicatorRenderer: function(name){ |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
return this._indicatorsRenderers[name]; |
| 152 |
}, |
| 153 |
|
| 154 |
removeIndicator: function(name){ |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
var indicator = this._indicatorsIndex[name]; |
| 162 |
if(indicator){ |
| 163 |
indicator._gfxGroup.removeShape(); |
| 164 |
var idx = this._indicators.indexOf(indicator); |
| 165 |
this._indicators.splice(idx, 1); |
| 166 |
|
| 167 |
indicator._disconnectListeners(); |
| 168 |
|
| 169 |
delete this._indicatorsIndex[name]; |
| 170 |
delete this._indicatorsRenderers[name]; |
| 171 |
} |
| 172 |
if(this._gauge){ |
| 173 |
this._gauge._resetMainIndicator(); |
| 174 |
} |
| 175 |
this.invalidateRendering(); |
| 176 |
return indicator; |
| 177 |
}, |
| 178 |
|
| 179 |
getIndicator: function(name){ |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
return this._indicatorsIndex[name]; |
| 187 |
}, |
| 188 |
|
| 189 |
addIndicator: function(name, indicator, behindScale){ |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
if(this._indicatorsIndex[name] && this._indicatorsIndex[name] != indicator){ |
| 201 |
this.removeIndicator(name); |
| 202 |
} |
| 203 |
|
| 204 |
this._indicators.push(indicator); |
| 205 |
this._indicatorsIndex[name] = indicator; |
| 206 |
|
| 207 |
if(!this._ticksGroup){ |
| 208 |
this._createSubGroups(); |
| 209 |
} |
| 210 |
|
| 211 |
var group = behindScale ? this._bgGroup : this._fgGroup; |
| 212 |
indicator._gfxGroup = group.createGroup(); |
| 213 |
|
| 214 |
indicator.scale = this; |
| 215 |
|
| 216 |
return this.invalidateRendering(); |
| 217 |
}, |
| 218 |
|
| 219 |
_createSubGroups: function(){ |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
if(!this._gfxGroup || this._ticksGroup){ |
| 225 |
return; |
| 226 |
} |
| 227 |
this._bgGroup = this._gfxGroup.createGroup(); |
| 228 |
this._ticksGroup = this._gfxGroup.createGroup(); |
| 229 |
this._fgGroup = this._gfxGroup.createGroup(); |
| 230 |
}, |
| 231 |
|
| 232 |
refreshRendering: function(){ |
| 233 |
if(!this._ticksGroup){ |
| 234 |
this._createSubGroups(); |
| 235 |
} |
| 236 |
} |
| 237 |
}); |
| 238 |
}); |
| 239 |
|