| 1 |
define(["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/html","dojo/_base/event","dojox/gfx", |
| 2 |
"./_Gauge","./BarLineIndicator", "dojo/dom-geometry"], |
| 3 |
function(declare, lang, arr, html, event, gfx, Gauge, BarLineIndicator, domGeometry) { |
| 4 |
|
| 5 |
return declare("dojox.gauges.BarGauge", Gauge, { |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
dataX: 5, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
dataY: 5, |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
dataWidth: 0, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
dataHeight: 0, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
_defaultIndicator: BarLineIndicator, |
| 45 |
|
| 46 |
startup: function(){ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if(this.getChildren){ |
| 53 |
arr.forEach(this.getChildren(), function(child){ child.startup(); }); |
| 54 |
} |
| 55 |
|
| 56 |
if(!this.dataWidth){this.dataWidth = this.gaugeWidth - 10;} |
| 57 |
if(!this.dataHeight){this.dataHeight = this.gaugeHeight - 10;} |
| 58 |
|
| 59 |
this.inherited(arguments); |
| 60 |
}, |
| 61 |
|
| 62 |
_getPosition: function(value){ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
return this.dataX + Math.floor((value - this.min)/(this.max - this.min)*this.dataWidth); |
| 70 |
}, |
| 71 |
|
| 72 |
_getValueForPosition: function(pos){ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
return (pos - this.dataX)*(this.max - this.min)/this.dataWidth + this.min; |
| 79 |
}, |
| 80 |
|
| 81 |
drawRange: function( group, range){ |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if(range.shape){ |
| 93 |
range.shape.parent.remove(range.shape); |
| 94 |
range.shape = null; |
| 95 |
} |
| 96 |
|
| 97 |
var x1 = this._getPosition(range.low); |
| 98 |
var x2 = this._getPosition(range.high); |
| 99 |
var path = group.createRect({ |
| 100 |
x: x1, |
| 101 |
y: this.dataY, |
| 102 |
width: x2 - x1, |
| 103 |
height: this.dataHeight |
| 104 |
}); |
| 105 |
if(lang.isArray(range.color) || lang.isString(range.color)){ |
| 106 |
path.setStroke({color: range.color}); |
| 107 |
path.setFill(range.color); |
| 108 |
}else if(range.color.type){ |
| 109 |
|
| 110 |
var y = this.dataY + this.dataHeight/2; |
| 111 |
range.color.x1 = x1; |
| 112 |
range.color.x2 = x2; |
| 113 |
range.color.y1 = y; |
| 114 |
range.color.y2 = y; |
| 115 |
path.setFill(range.color); |
| 116 |
path.setStroke({color: range.color.colors[0].color}); |
| 117 |
}else if (gfx.svg){ |
| 118 |
|
| 119 |
path.setStroke({color: "green"}); |
| 120 |
path.setFill("green"); |
| 121 |
path.getEventSource().setAttribute("class", range.color.style); |
| 122 |
} |
| 123 |
|
| 124 |
path.connect("onmouseover", lang.hitch(this, this._handleMouseOverRange, range)); |
| 125 |
path.connect("onmouseout", lang.hitch(this, this._handleMouseOutRange, range)); |
| 126 |
|
| 127 |
range.shape = path; |
| 128 |
}, |
| 129 |
|
| 130 |
getRangeUnderMouse: function(e){ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
var range = null; |
| 136 |
var pos = domGeometry.getContentBox(this.gaugeContent); |
| 137 |
var x = e.clientX - pos.x; |
| 138 |
var value = this._getValueForPosition(x); |
| 139 |
if(this._rangeData){ |
| 140 |
for(var i=0; (i<this._rangeData.length) && !range; i++){ |
| 141 |
if((Number(this._rangeData[i].low) <= value) && (Number(this._rangeData[i].high) >= value)){ |
| 142 |
range = this._rangeData[i]; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
return range; |
| 147 |
}, |
| 148 |
|
| 149 |
_dragIndicator: function(widget, e){ |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
this._dragIndicatorAt(widget, e.pageX, e.pageY); |
| 154 |
event.stop(e); |
| 155 |
}, |
| 156 |
|
| 157 |
_dragIndicatorAt: function( widget, x, y){ |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
var pos = domGeometry.position(widget.gaugeContent, true); |
| 163 |
var xl = x - pos.x; |
| 164 |
var value = widget._getValueForPosition(xl); |
| 165 |
if(value < widget.min){value = widget.min;} |
| 166 |
if(value > widget.max){value = widget.max;} |
| 167 |
|
| 168 |
widget._drag.value = value; |
| 169 |
|
| 170 |
widget._drag.onDragMove(widget._drag); |
| 171 |
|
| 172 |
widget._drag.draw(this._indicatorsGroup, true); |
| 173 |
widget._drag.valueChanged(); |
| 174 |
} |
| 175 |
}); |
| 176 |
}); |