| 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369 | 1×
1×
1×
1×
200×
1×
206×
206×
206×
206×
206×
206×
206×
206×
206×
206×
206×
206×
206×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
111×
111×
111×
111×
132×
132×
132×
132×
243×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
111×
111×
111×
132×
132×
132×
243×
243×
240×
110×
130×
3×
3×
1×
2×
243×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
111×
111×
111×
111×
132×
132×
132×
132×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
111×
111×
132×
132×
243×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
245×
245×
245×
245×
1×
204×
204×
204×
204×
204×
204×
204×
204×
204×
204×
95×
95×
95×
109×
109×
109×
204×
1×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
43×
18×
18×
18×
18×
18×
18×
18×
25×
25×
25×
25×
25×
25×
25×
43×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
247×
247×
17×
17×
17×
17×
17×
17×
17×
17×
4×
4×
4×
4×
4×
4×
4×
13×
13×
13×
13×
13×
13×
13×
1×
280×
280×
280×
280×
40×
40×
240×
280×
1×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
243×
2790×
2790×
2790×
2790×
2790×
243×
1×
243×
243×
243×
2790×
2790×
2790×
721×
2790×
243×
1×
206×
15×
15×
1×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../model/constant", "../utils/helper", "../utils/helper"], function (require, exports, ej2_base_1, constant_1, helper_1, helper_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var AxisLayoutPanel = (function () {
function AxisLayoutPanel(gauge) {
this.gauge = gauge;
}
AxisLayoutPanel.prototype.calculateAxesBounds = function () {
var axis;
var bounds;
var pointer;
this.gauge.nearSizes = [];
this.gauge.farSizes = [];
var x;
var y;
var width;
var height;
var axisPadding = 8;
var containerRect = this.gauge.containerBounds;
this.checkThermometer();
for (var i = 0; i < this.gauge.axes.length; i++) {
axis = this.gauge.axes[i];
axis.checkAlign = new helper_2.Align(i, ((!axis.opposedPosition) ? 'Near' : 'Far'));
(!axis.opposedPosition) ? this.gauge.nearSizes.push(1) : this.gauge.farSizes.push(1);
this.calculateLineBounds(axis, i);
this.calculateTickBounds(axis, i);
this.calculateLabelBounds(axis, i);
Eif (axis.pointers.length > 0) {
this.calculatePointerBounds(axis, i);
}
Eif (axis.ranges.length > 0) {
this.calculateRangesBounds(axis, i);
}
bounds = axis.labelBounds;
if (this.gauge.orientation === 'Vertical') {
x = (!axis.opposedPosition) ? bounds.x - axisPadding : axis.lineBounds.x;
y = axis.lineBounds.y;
height = axis.lineBounds.height;
width = Math.abs((!axis.opposedPosition) ? (axis.lineBounds.x - x) : ((bounds.x + bounds.width + axisPadding) - x));
}
else {
y = (!axis.opposedPosition) ? bounds.y - bounds.height - axisPadding : axis.lineBounds.y;
x = axis.lineBounds.x;
width = axis.lineBounds.width;
height = Math.abs((!axis.opposedPosition) ? Math.abs(axis.lineBounds.y - y) : (bounds.y + axisPadding) - y);
}
axis.bounds = new helper_1.Rect(x, y, width, height);
}
};
AxisLayoutPanel.prototype.calculateLineBounds = function (axis, axisIndex) {
var x;
var y;
var width;
var height;
var index;
var prevAxis;
var lineHeight = axis.line.height;
var orientation = this.gauge.orientation;
var containerRect = this.gauge.containerBounds;
lineHeight = (axis.line.width > 0) ? lineHeight : null;
if (orientation === 'Vertical') {
y = (ej2_base_1.isNullOrUndefined(lineHeight)) ? containerRect.y :
containerRect.y + ((containerRect.height / 2) - (lineHeight / 2));
width = axis.line.width;
height = (ej2_base_1.isNullOrUndefined(lineHeight)) ? containerRect.height : lineHeight;
}
else {
x = (ej2_base_1.isNullOrUndefined(lineHeight)) ? containerRect.x :
containerRect.x + ((containerRect.width / 2) - (lineHeight / 2));
height = axis.line.width;
width = (ej2_base_1.isNullOrUndefined(lineHeight)) ? containerRect.width : lineHeight;
}
index = this.checkPreviousAxes(axis, axisIndex);
if (ej2_base_1.isNullOrUndefined(index)) {
if (orientation === 'Vertical') {
x = (!axis.opposedPosition ? containerRect.x : containerRect.x + containerRect.width) + axis.line.offset;
}
else {
y = (!axis.opposedPosition ? containerRect.y : containerRect.y + containerRect.height) + axis.line.offset;
}
}
else {
prevAxis = this.gauge.axes[index];
if (orientation === 'Vertical') {
x = ((!axis.opposedPosition) ? prevAxis.bounds.x : (prevAxis.bounds.x + prevAxis.bounds.width)) + axis.line.offset;
}
else {
y = ((!axis.opposedPosition) ? prevAxis.bounds.y : (prevAxis.bounds.y + prevAxis.bounds.height)) + axis.line.offset;
}
}
axis.lineBounds = new helper_1.Rect(x, y, width, height);
};
AxisLayoutPanel.prototype.calculateTickBounds = function (axis, axisIndex) {
var x;
var y;
var width;
var height;
var major;
var minor;
var min = Math.min(axis.minimum, axis.maximum);
var max = Math.max(axis.minimum, axis.maximum);
min = (min === max) ? max - 1 : min;
var interval = axis.majorTicks.interval;
var bounds = axis.lineBounds;
major = axis.majorTicks;
minor = axis.minorTicks;
axis.majorInterval = major.interval;
axis.minorInterval = minor.interval;
var size = (this.gauge.orientation === 'Vertical' ? bounds.height : bounds.width);
var lineSize = (this.gauge.orientation === 'Vertical' ? bounds.width : bounds.height) / 2;
axis.majorInterval = ej2_base_1.isNullOrUndefined(axis.majorInterval) ? helper_2.calculateNiceInterval(min, max, size, this.gauge.orientation)
: major.interval;
axis.visibleRange = new helper_2.VisibleRange(min, max, axis.majorInterval, (max - min));
axis.minorInterval = (ej2_base_1.isNullOrUndefined(axis.minorInterval)) ? axis.majorInterval / 2 : axis.minorInterval;
if (this.gauge.orientation === 'Vertical') {
x = (!axis.opposedPosition ? (bounds.x - lineSize - major.height) : bounds.x + lineSize) + major.offset;
axis.majorTickBounds = new helper_1.Rect(x, bounds.y, major.height, bounds.height);
x = (!axis.opposedPosition ? (bounds.x - lineSize - minor.height) : bounds.x + lineSize) + minor.offset;
axis.minorTickBounds = new helper_1.Rect(x, bounds.y, minor.height, bounds.height);
}
else {
y = (!axis.opposedPosition ? (bounds.y - lineSize - major.height) : bounds.y + lineSize) + major.offset;
axis.majorTickBounds = new helper_1.Rect(bounds.x, y, bounds.width, major.height);
y = (!axis.opposedPosition ? (bounds.y - lineSize - minor.height) : bounds.y + lineSize) + minor.offset;
axis.minorTickBounds = new helper_1.Rect(bounds.x, y, bounds.width, minor.height);
}
};
AxisLayoutPanel.prototype.calculateLabelBounds = function (axis, axisIndex) {
var x;
var y;
var width;
var height;
var padding = 5;
var bounds = axis.majorTickBounds;
var offset = axis.labelStyle.offset;
this.calculateVisibleLabels(axis);
width = axis.maxLabelSize.width;
height = axis.maxLabelSize.height / 2;
if (this.gauge.orientation === 'Vertical') {
x = (!axis.opposedPosition ? (bounds.x - width - padding) : (bounds.x + bounds.width + padding)) + offset;
y = axis.lineBounds.y;
}
else {
y = (!axis.opposedPosition ? (bounds.y - padding) : ((bounds.y + bounds.height + padding) + height)) + offset;
x = axis.lineBounds.x;
}
axis.labelBounds = new helper_1.Rect(x, y, width, height);
};
AxisLayoutPanel.prototype.calculatePointerBounds = function (axis, axisIndex) {
var pointer;
var actualValue;
var length;
var val = [];
var range = axis.visibleRange;
var orientation = this.gauge.orientation;
var bounds;
var line = axis.lineBounds;
var label = axis.labelBounds;
var currentVal;
var type;
var markerType;
var nearX;
var farX;
var nearY;
var farY;
var minimumValue = Math.min(range.min, range.max);
var maximumValue = Math.max(range.min, range.max);
for (var i = 0; i < axis.pointers.length; i++) {
pointer = axis.pointers[i];
pointer.currentValue = pointer.value !== null ?
pointer.value < minimumValue ? minimumValue : pointer.value > maximumValue ? maximumValue : pointer.value
: minimumValue;
Eif (pointer.width > 0 && helper_2.withInRange(pointer.currentValue, null, null, range.max, range.min, 'pointer')) {
this['calculate' + pointer.type + 'Bounds'](axisIndex, axis, i, pointer);
}
}
};
AxisLayoutPanel.prototype.calculateMarkerBounds = function (axisIndex, axis, pointerIndex, pointer) {
var x;
var y;
var line = axis.lineBounds;
var offset = pointer.offset;
var range = axis.visibleRange;
var placement = pointer.placement;
var tick = axis.majorTickBounds;
var label = axis.labelBounds;
var border = pointer.border.width;
if (this.gauge.orientation === 'Vertical') {
x = (!axis.opposedPosition) ? (placement === 'Near') ? label.x : (placement === 'Center') ? tick.x : line.x :
placement === 'Far' ? label.x + label.width : (placement === 'Center' ? tick.x + tick.width : line.x);
x = !axis.opposedPosition ? ((pointer.placement === 'Far' ? x + border : x - border) + (offset)) :
((pointer.placement === 'Near' ? x - border : x + border) + (offset));
y = ((helper_2.valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * line.height) + line.y);
}
else {
y = (!axis.opposedPosition) ? (placement === 'Near') ? label.y - label.height : (placement === 'Center') ? tick.y :
line.y : (placement === 'Far') ? label.y : (placement === 'Center') ? tick.y + tick.height : line.y;
y = !axis.opposedPosition ? ((pointer.placement === 'Far' ? y + border : y - border) + (offset)) :
((pointer.placement === 'Near' ? y - border : y + border) + (offset));
x = ((helper_2.valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * line.width) + line.x);
}
pointer.bounds = new helper_1.Rect(x, y, pointer.width, pointer.height);
};
AxisLayoutPanel.prototype.calculateBarBounds = function (axisIndex, axis, pointerIndex, pointer) {
var x1;
var x2;
var y1;
var y2;
var height;
var width;
var line = axis.lineBounds;
var padding = 10;
var range = axis.visibleRange;
var orientation = this.gauge.orientation;
var offset = pointer.offset;
var container = this.gauge.containerBounds;
if (orientation === 'Vertical') {
x1 = (container.width > 0) ? container.x + ((container.width / 2) - (pointer.width / 2)) :
(!axis.opposedPosition) ? (line.x + padding) : (line.x - pointer.width - padding);
x1 += (offset);
y1 = ((helper_2.valueToCoefficient(pointer.currentValue, axis, orientation, range) * line.height) + line.y);
y2 = ((helper_2.valueToCoefficient(range.min, axis, orientation, range) * line.height) + line.y);
height = Math.abs(y2 - y1);
y1 = (!axis.isInversed) ? y1 : y2;
width = pointer.width;
}
else {
x1 = ((helper_2.valueToCoefficient(range.min, axis, orientation, range) * line.width) + line.x);
y1 = (container.height > 0) ? (container.y + (container.height / 2) - (pointer.height) / 2) :
(!axis.opposedPosition) ? (line.y + padding) : (line.y - pointer.height - padding);
y1 += (offset);
height = pointer.height;
x2 = ((helper_2.valueToCoefficient(pointer.currentValue, axis, orientation, range) * line.width) + line.x);
width = Math.abs(x2 - x1);
x1 = (!axis.isInversed) ? x1 : x2;
}
pointer.bounds = new helper_1.Rect(x1, y1, width, height);
};
AxisLayoutPanel.prototype.calculateRangesBounds = function (axis, axisIndex) {
var range;
var start;
var end;
var line = axis.lineBounds;
var visibleRange = axis.visibleRange;
var orientation = this.gauge.orientation;
var startVal;
var endVal;
var pointX;
var pointY;
var width;
var height;
var position;
var startWidth;
var endWidth;
var colors;
for (var i = 0; i < axis.ranges.length; i++) {
range = axis.ranges[i];
if (helper_2.withInRange(null, range.start, range.end, visibleRange.max, visibleRange.min, 'range')) {
start = Math.min(range.start, range.end);
end = Math.max(range.start, range.end);
position = range.position;
startWidth = range.startWidth;
endWidth = range.endWidth;
colors = this.gauge.rangePalettes.length ? this.gauge.rangePalettes : helper_2.getRangePalette();
range.interior = range.color ? range.color : colors[i % colors.length];
if (this.gauge.orientation === 'Vertical') {
pointX = line.x + (range.offset);
pointY = (helper_2.valueToCoefficient(end, axis, orientation, visibleRange) * line.height) + line.y;
height = (helper_2.valueToCoefficient(start, axis, orientation, visibleRange) * line.height) + line.y;
height -= pointY;
startVal = !axis.opposedPosition ? position === 'Inside' ? (pointX + startWidth) : (pointX - startWidth)
: position === 'Inside' ? (pointX - startWidth) : (pointX + startWidth);
endVal = !axis.opposedPosition ? position === 'Inside' ? (pointX + endWidth) : (pointX - endWidth) :
position === 'Inside' ? (pointX - endWidth) : (pointX + endWidth);
range.path = 'M' + pointX + ' ' + pointY + ' L ' + pointX + ' ' + (pointY + height) +
' L ' + startVal + ' ' + (pointY + height) + ' L ' + endVal + ' ' + pointY +
' L ' + pointX + ' ' + pointY + ' z ';
}
else {
pointX = (helper_2.valueToCoefficient(end, axis, orientation, visibleRange) * line.width) + line.x;
pointY = axis.lineBounds.y + (range.offset);
width = (helper_2.valueToCoefficient(start, axis, orientation, visibleRange) * line.width) + line.x;
width = pointX - width;
startVal = !axis.opposedPosition ? position === 'Inside' ? (pointY + startWidth) :
(pointY - startWidth) : (position === 'Inside') ? (pointY - startWidth) :
(pointY + startWidth);
endVal = !axis.opposedPosition ? position === 'Inside' ? (pointY + endWidth) : (pointY - endWidth) :
(position === 'Inside') ? (pointY - endWidth) : (pointY + endWidth);
range.path = 'M' + pointX + ' ' + pointY + ' L ' + (pointX - width) + ' ' + pointY +
' L ' + (pointX - width) + ' ' + startVal + ' L ' + pointX + ' ' + endVal +
' L ' + pointX + ' ' + pointY + ' z ';
}
}
}
};
AxisLayoutPanel.prototype.checkPreviousAxes = function (currentAxis, axisIndex) {
var index = axisIndex - 1;
var prevAxis;
var isPositive = (index >= 0) ? true : false;
if (isPositive) {
prevAxis = this.gauge.axes[index];
index = (prevAxis.checkAlign.align === currentAxis.checkAlign.align) ? index : this.checkPreviousAxes(currentAxis, index);
}
else {
index = null;
}
return index;
};
AxisLayoutPanel.prototype.calculateVisibleLabels = function (axis) {
axis.visibleLabels = [];
var min = axis.visibleRange.min;
var max = axis.visibleRange.max;
var interval = axis.visibleRange.interval;
var format;
var argsData;
var style = axis.labelStyle;
var text;
var labelSize;
var customLabelFormat = style.format && style.format.match('{value}') !== null;
format = this.gauge.intl.getNumberFormat({
format: helper_1.getLabelFormat(style.format), useGrouping: this.gauge.useGroupingSeparator
});
for (var i = min; (i <= max && interval > 0); i += interval) {
argsData = {
cancel: false, name: constant_1.axisLabelRender, axis: axis,
text: customLabelFormat ? style.format.replace(new RegExp('{value}', 'g'), format(i)) :
format(i),
value: i
};
this.gauge.trigger(constant_1.axisLabelRender, argsData);
labelSize = helper_1.measureText(argsData.text, axis.labelStyle.font);
Eif (!argsData.cancel) {
axis.visibleLabels.push(new helper_1.VisibleLabels(argsData.text, i, labelSize));
}
}
this.getMaxLabelWidth(this.gauge, axis);
};
AxisLayoutPanel.prototype.getMaxLabelWidth = function (gauge, axis) {
axis.maxLabelSize = new helper_1.Size(0, 0);
var label;
for (var i = 0; i < axis.visibleLabels.length; i++) {
label = axis.visibleLabels[i];
label.size = helper_1.measureText(label.text, axis.labelStyle.font);
if (label.size.width > axis.maxLabelSize.width) {
axis.maxLabelSize.width = label.size.width;
}
if (label.size.height > axis.maxLabelSize.height) {
axis.maxLabelSize.height = label.size.height;
}
}
};
AxisLayoutPanel.prototype.checkThermometer = function () {
if (this.gauge.container.type === 'Thermometer') {
this.gauge.axes.map(function (axis, index) {
if (axis.isInversed) {
axis.pointers.map(function (pointer, index) {
Eif (pointer.type === 'Bar') {
axis.isInversed = false;
}
});
}
});
}
};
return AxisLayoutPanel;
}());
exports.AxisLayoutPanel = AxisLayoutPanel;
});
|