-
Notifications
You must be signed in to change notification settings - Fork 11
/
RectangularScale.js
176 lines (154 loc) · 4.53 KB
/
RectangularScale.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
define(["dojo/_base/declare", "dojox/gfx", "./ScaleBase"], function(declare, gfx, ScaleBase){
return declare("dojox.dgauges.RectangularScale", ScaleBase, {
// summary:
// The rectangular scale. A scaler must be set to use this class.
// paddingLeft: Number
// The left padding.
paddingLeft: 15,
// paddingTop: Number
// The top padding.
paddingTop: 12,
// paddingRight: Number
// The right padding.
paddingRight: 15,
// paddingBottom: Number
// The bottom padding.
paddingBottom: 0,
_contentBox: null,
constructor: function(){
this.labelPosition = "leading";
this.addInvalidatingProperties(["paddingTop", "paddingLeft", "paddingRight", "paddingBottom"]);
},
positionForValue: function(value){
// summary:
// Transforms a value into a position using the associated scaler.
// value:
// The value to transform.
// returns: Number
// A position in pixels.
var relativePos = 0;
var position;
var spos = 0;
var length = 0;
if(this._contentBox){
if(this._gauge.orientation == "horizontal"){
spos = this._contentBox.x;
length = this._contentBox.w;
}else{
spos = this._contentBox.y;
length = this._contentBox.h;
}
}
relativePos = this.scaler.positionForValue(value);
position = spos + (relativePos * length);
return position;
},
valueForPosition: function(pos){
// summary:
// Transforms a position in pixels into a value using the associated scaler.
// pos:
// The position to transform.
// returns: Number
// The value represented by pos.
var value = this.scaler.minimum;
var position = NaN;
var spos = 0;
var epos = 0;
if(this._gauge.orientation == "horizontal"){
position = pos.x;
spos = this._contentBox.x;
epos = this._contentBox.x + this._contentBox.w;
}else{
position = pos.y;
spos = this._contentBox.y;
epos = this._contentBox.y + this._contentBox.h;
}
if(position <= spos){
value = this.scaler.minimum;
}else if(position >= epos){
value = this.scaler.maximum;
}else {
value = this.scaler.valueForPosition((position - spos)/(epos - spos));
}
return value;
},
refreshRendering: function(){
this.inherited(arguments);
if(!this._gfxGroup || !this.scaler)
return;
this._ticksGroup.clear();
// variables for ticks rendering
var middleBox = this._gauge._layoutInfos.middle;
this._contentBox = {};
this._contentBox.x = middleBox.x + this.paddingLeft;
this._contentBox.y = middleBox.y + this.paddingTop;
this._contentBox.w = middleBox.w - (this.paddingLeft + this.paddingRight);
this._contentBox.h = middleBox.h - (this.paddingBottom + this.paddingTop);
var renderer;
// variables for tick labels
var labelText;
var font = this._getFont();
// Layout ticks
var allTicks = this.scaler.computeTicks();
for(var i = 0; i < allTicks.length; i++){
var tickItem = allTicks[i];
renderer = this.tickShapeFunc(this._ticksGroup, this, tickItem);
if(renderer){
var a = this.positionForValue(tickItem.value);
var tickSize = this._gauge._computeBoundingBox(renderer).width;
var x1 = 0, y1 = 0, angle = 0;
if(this._gauge.orientation == "horizontal"){
x1 = a;
y1 = this._contentBox.y;
angle = 90;
}else{
x1 = this._contentBox.x;
y1 = a;
}
renderer.setTransform([{
dx: x1,
dy: y1
}, gfx.matrix.rotateg(angle)]);
}
labelText = this.tickLabelFunc(tickItem);
if(labelText){
var tbox = gfx._base._getTextBox(labelText, {
font: gfx.makeFontString(gfx.makeParameters(gfx.defaultFont, font))
});
var tw = tbox.w;
var th = tbox.h;
var al = "start";
var xt = x1;
var yt = y1;
if(this._gauge.orientation == "horizontal"){
xt = x1;
if(this.labelPosition == "trailing"){
yt = y1 + tickSize + this.labelGap + th;
}else{
yt = y1 - this.labelGap;
}
al = "middle";
}else{
if(this.labelPosition == "trailing"){
xt = x1 + tickSize + this.labelGap;
}else{
xt = x1 - this.labelGap - tw;
}
yt = y1 + th / 2;
}
var t = this._ticksGroup.createText({
x: xt,
y: yt,
text: labelText,
align: al
});
t.setFill(font.color ? font.color : "black");
t.setFont(font);
}
}
for(var key in this._indicatorsIndex){
this._indicatorsRenderers[key] = this._indicatorsIndex[key].invalidateRendering();
}
}
})
});