| 1 |
define(["dojo/_base/declare", "dojox/gfx", "./ScaleIndicatorBase", "dojo/_base/event", "dojo/dom-geometry"], |
| 2 |
function(declare, gfx, ScaleIndicatorBase, eventUtil, domGeom){ |
| 3 |
return declare("dojox.dgauges.RectangularRangeIndicator", ScaleIndicatorBase, { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
start: 0, |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
startThickness: 10, |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
endThickness: 10, |
| 20 |
|
| 21 |
|
| 22 |
fill: null, |
| 23 |
|
| 24 |
|
| 25 |
stroke: null, |
| 26 |
|
| 27 |
|
| 28 |
paddingLeft: 10, |
| 29 |
|
| 30 |
|
| 31 |
paddingTop: 10, |
| 32 |
|
| 33 |
|
| 34 |
paddingRight: 10, |
| 35 |
|
| 36 |
|
| 37 |
paddingBottom: 10, |
| 38 |
|
| 39 |
constructor: function(){ |
| 40 |
this.fill = [255, 120, 0]; |
| 41 |
this.stroke = { |
| 42 |
color: "black", |
| 43 |
width: .2 |
| 44 |
}; |
| 45 |
this.interactionMode = "none"; |
| 46 |
|
| 47 |
this.addInvalidatingProperties(["start", "startThickness", "endThickness", "fill", "stroke"]); |
| 48 |
}, |
| 49 |
|
| 50 |
_defaultHorizontalShapeFunc: function(indicator, group, scale, startX, startY, endPosition, startThickness, endThickness, fill, stroke){ |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
var gp = [startX, startY, endPosition, startY, endPosition, startY + endThickness, startX, startY + startThickness, startX, startY] |
| 56 |
if(fill && fill.colors){ |
| 57 |
|
| 58 |
fill.x1 = startX; |
| 59 |
fill.y1 = startY; |
| 60 |
fill.x2 = endPosition; |
| 61 |
fill.y2 = startY; |
| 62 |
} |
| 63 |
return group.createPolyline(gp).setFill(fill).setStroke(stroke); |
| 64 |
}, |
| 65 |
|
| 66 |
_defaultVerticalShapeFunc: function(indicator, group, scale, startX, startY, endPosition, startThickness, endThickness, fill, stroke){ |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
var gp = [startX, startY, startX, endPosition, startX + endThickness, endPosition, startX + startThickness, startY, startX, startY] |
| 72 |
if(fill && fill.colors){ |
| 73 |
|
| 74 |
fill.x1 = startX; |
| 75 |
fill.y1 = startY; |
| 76 |
fill.x2 = startX; |
| 77 |
fill.y2 = endPosition; |
| 78 |
} |
| 79 |
return group.createPolyline(gp).setFill(fill).setStroke(stroke); |
| 80 |
}, |
| 81 |
|
| 82 |
_shapeFunc: function(indicator, group, scale, startX, startY, endPosition, startThickness, endThickness, fill, stroke){ |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if(this.scale._gauge.orientation == "horizontal"){ |
| 88 |
this._defaultHorizontalShapeFunc(indicator, group, scale, startX, startY, endPosition, startThickness, endThickness, fill, stroke); |
| 89 |
}else{ |
| 90 |
this._defaultVerticalShapeFunc(indicator, group, scale, startX, startY, endPosition, startThickness, endThickness, fill, stroke); |
| 91 |
} |
| 92 |
}, |
| 93 |
|
| 94 |
refreshRendering: function(){ |
| 95 |
this.inherited(arguments); |
| 96 |
|
| 97 |
if(this._gfxGroup == null || this.scale == null){ |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
var spos = this.scale.positionForValue(this.start); |
| 102 |
var v = isNaN(this._transitionValue) ? this.value : this._transitionValue; |
| 103 |
var pos = this.scale.positionForValue(v); |
| 104 |
this._gfxGroup.clear(); |
| 105 |
|
| 106 |
var startX; |
| 107 |
var startY; |
| 108 |
var endPosition; |
| 109 |
if(this.scale._gauge.orientation == "horizontal"){ |
| 110 |
startX = spos; |
| 111 |
startY = this.paddingTop; |
| 112 |
endPosition = pos; |
| 113 |
}else{ |
| 114 |
startX = this.paddingLeft; |
| 115 |
startY = spos; |
| 116 |
endPosition = pos; |
| 117 |
} |
| 118 |
this._shapeFunc(this, this._gfxGroup, this.scale, startX, startY, endPosition, this.startThickness, this.endThickness, this.fill, this.stroke); |
| 119 |
}, |
| 120 |
|
| 121 |
_onMouseDown: function(event){ |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
this.inherited(arguments); |
| 127 |
|
| 128 |
var np = domGeom.position(this.scale._gauge.domNode, true); |
| 129 |
this.set("value", this.scale.valueForPosition({x: event.pageX - np.x, y: event.pageY - np.y})); |
| 130 |
|
| 131 |
|
| 132 |
eventUtil.stop(event); |
| 133 |
}, |
| 134 |
|
| 135 |
_onMouseMove: function(event){ |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
this.inherited(arguments); |
| 141 |
|
| 142 |
var np = domGeom.position(this.scale._gauge.domNode, true); |
| 143 |
this.set("value", this.scale.valueForPosition({x: event.pageX - np.x, y: event.pageY - np.y})); |
| 144 |
} |
| 145 |
}) |
| 146 |
}); |