[483] | 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 | // summary: |
---|
| 5 | // A RectangularRangeIndicator is used to represent a range of values on a scale. |
---|
| 6 | // For adding this kind of indicator instance to the gauge, use the addIndicator |
---|
| 7 | // method of RectangularScale. |
---|
| 8 | |
---|
| 9 | // start: Number |
---|
| 10 | // The start value of the range. Default is 0. |
---|
| 11 | start: 0, |
---|
| 12 | // startThickness: Number |
---|
| 13 | // The thickness in pixels of the shape at the position defined by the start property. |
---|
| 14 | // Default is 10. |
---|
| 15 | startThickness: 10, |
---|
| 16 | // endThickness: Number |
---|
| 17 | // The thickness in pixels of the shape at the position defined by the value property. |
---|
| 18 | // Default is 10. |
---|
| 19 | endThickness: 10, |
---|
| 20 | // fill: Object |
---|
| 21 | // A fill object that will be passed to the setFill method of GFX. |
---|
| 22 | fill: null, |
---|
| 23 | // stroke: Object |
---|
| 24 | // A stroke object that will be passed to the setStroke method of GFX. |
---|
| 25 | stroke: null, |
---|
| 26 | // paddingLeft: Number |
---|
| 27 | // The left padding. Not used for horizontal gauges. |
---|
| 28 | paddingLeft: 10, |
---|
| 29 | // paddingTop: Number |
---|
| 30 | // The top padding. Not used for vertical gauges. |
---|
| 31 | paddingTop: 10, |
---|
| 32 | // paddingRight: Number |
---|
| 33 | // The right padding. Not used for horizontal gauges. |
---|
| 34 | paddingRight: 10, |
---|
| 35 | // paddingBottom: Number |
---|
| 36 | // The bottom padding. Not used for vertical gauges. |
---|
| 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 | // summary: |
---|
| 52 | // Internal method. |
---|
| 53 | // tags: |
---|
| 54 | // private |
---|
| 55 | var gp = [startX, startY, endPosition, startY, endPosition, startY + endThickness, startX, startY + startThickness, startX, startY] |
---|
| 56 | if(fill && fill.colors){ |
---|
| 57 | // Configure gradient |
---|
| 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 | // summary: |
---|
| 68 | // Internal method. |
---|
| 69 | // tags: |
---|
| 70 | // private |
---|
| 71 | var gp = [startX, startY, startX, endPosition, startX + endThickness, endPosition, startX + startThickness, startY, startX, startY] |
---|
| 72 | if(fill && fill.colors){ |
---|
| 73 | // Configure gradient |
---|
| 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 | // summary: |
---|
| 84 | // Internal method. |
---|
| 85 | // tags: |
---|
| 86 | // private |
---|
| 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 | // gets position corresponding to the values |
---|
| 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 | // summary: |
---|
| 123 | // Internal method. |
---|
| 124 | // tags: |
---|
| 125 | // private |
---|
| 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 | // prevent the browser from selecting text |
---|
| 132 | eventUtil.stop(event); |
---|
| 133 | }, |
---|
| 134 | |
---|
| 135 | _onMouseMove: function(event){ |
---|
| 136 | // summary: |
---|
| 137 | // Internal method. |
---|
| 138 | // tags: |
---|
| 139 | // private |
---|
| 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 | }); |
---|