forked from dojo/dgauges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RectangularValueIndicator.js
executable file
·92 lines (79 loc) · 2.62 KB
/
RectangularValueIndicator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
define(["dojo/_base/declare", "./ScaleIndicatorBase", "dojox/gfx", "dojo/_base/event", "dojo/dom-geometry"],
function(declare, ScaleIndicatorBase, gfx, eventUtil, domGeom){
return declare("dojox.dgauges.RectangularValueIndicator", ScaleIndicatorBase, {
// summary:
// The rectangular value indicator, typically used for creating markers or thumbs.
// paddingLeft: Number
// The left padding.
paddingLeft: 0,
// paddingTop: Number
// The top padding.
paddingTop: 0,
// paddingRight: Number
// The right padding.
paddingRight: 0,
// paddingBottom: Number
// The bottom padding.
paddingBottom: 0,
constructor: function(){
this.addInvalidatingProperties(["paddingTop", "paddingLeft", "paddingRight", "paddingBottom"]);
},
indicatorShapeFunc: function(group, indicator){
// summary:
// Draws the indicator.
// group: dojox/gfx/Group
// A GFX group for drawing. The indicator is always centered horizontally and is
// automatically rotated if the scale is vertical.
// indicator: dojox/dgauges/IndicatorBase
// A reference to this indicator.
// returns: dojox/gfx/shape.Shape
// A GFX shape retrievable using the getIndicatorRenderer method of the associated scale.
return group.createPolyline([0, 0, 10, 0, 0, 10, -10, 0, 0, 0]).setStroke({
color: "black",
width: 1
});
},
refreshRendering: function(){
this.inherited(arguments);
// get position corresponding to the value
var v = isNaN(this._transitionValue) ? this.value : this._transitionValue;
var pos = this.scale.positionForValue(v);
// computes offsets to move the indicator
var dx = 0, dy = 0;
var angle = 0;
if(this.scale._gauge.orientation == "horizontal"){
dx = pos;
dy = this.paddingTop;
}else{
dx = this.paddingLeft;
dy = pos;
angle = 90;
}
// translate the indicator
this._gfxGroup.setTransform([{
dx: dx,
dy: dy
}, gfx.matrix.rotateg(angle)]);
},
_onMouseDown: function(event){
// summary:
// Internal method.
// tags:
// private
this.inherited(arguments);
var np = domGeom.position(this.scale._gauge.domNode, true);
this.set("value", this.scale.valueForPosition({x: event.pageX - np.x, y: event.pageY - np.y}));
// prevent the browser from selecting text
eventUtil.stop(event);
},
_onMouseMove: function(event){
// summary:
// Internal method.
// tags:
// private
this.inherited(arguments);
var np = domGeom.position(this.scale._gauge.domNode, true);
this.set("value", this.scale.valueForPosition({x: event.pageX - np.x, y: event.pageY - np.y}));
}
})
});