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 | 1×
1×
1×
1×
4937×
4937×
4937×
4937×
4937×
4937×
1×
985×
985×
985×
985×
985×
985×
985×
985×
1508×
1508×
1508×
1508×
1508×
1508×
66×
48×
48×
18×
18×
1508×
1266×
1508×
674×
311×
1×
1527×
1×
1266×
1266×
1266×
1266×
1266×
1266×
1266×
1266×
1266×
1266×
7190×
7190×
6824×
264×
6926×
366×
366×
366×
366×
366×
366×
366×
366×
366×
366×
366×
366×
366×
366×
6×
6920×
555×
38×
38×
6882×
626×
6256×
4×
592×
1×
6882×
6882×
7257×
7257×
1×
555×
555×
555×
555×
555×
555×
555×
555×
555×
555×
555×
234×
4×
4×
230×
230×
321×
24×
12×
12×
12×
12×
297×
31×
31×
266×
266×
555×
725×
1×
1448×
1448×
1448×
1448×
1448×
1448×
1448×
37×
37×
37×
103×
103×
51×
103×
15×
103×
33×
33×
33×
37×
33×
37×
15×
1448×
1158×
22494×
22494×
6380×
1448×
1448×
1158×
290×
1×
1128×
1128×
1128×
1128×
1128×
1128×
3030×
3030×
1128×
1128×
1902×
1135×
767×
1128×
1×
1418×
1418×
1418×
1366×
1157×
209×
1418×
1418×
1418×
1111×
40×
1071×
307×
1×
4527×
3702×
3702×
3443×
4527×
1×
1259×
1259×
2704×
22847×
22847×
21945×
1259×
1×
3443×
3443×
3443×
3443×
3443×
3443×
61184×
61184×
60956×
60956×
3443×
56026×
56026×
437×
437×
3443×
1×
1×
| define(["require", "exports", "../../common/utils/helper", "@syncfusion/ej2-svg-base"], function (require, exports, helper_1, ej2_svg_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ChartData = (function () {
function ChartData(chart) {
this.currentPoints = [];
this.previousPoints = [];
this.insideRegion = false;
this.commonXvalues = [];
this.chart = chart;
this.lierIndex = 0;
}
ChartData.prototype.getData = function () {
var chart = this.chart;
var point = null;
var series = null;
var width;
var height;
var mouseX;
var mouseY;
for (var len = chart.visibleSeries.length, i = len - 1; i >= 0; i--) {
series = chart.visibleSeries[i];
width = (series.type === 'Scatter' || series.drawType === 'Scatter' || (series.marker.visible))
? (series.marker.height + 5) / 2 : 0;
height = (series.type === 'Scatter' || series.drawType === 'Scatter' || (series.marker.visible))
? (series.marker.width + 5) / 2 : 0;
mouseX = chart.mouseX;
mouseY = chart.mouseY;
if (series.dragSettings.enable && series.isRectSeries) {
if (!(series.type === 'Bar' && chart.isTransposed) && (chart.isTransposed || series.type === 'Bar')) {
var markerWidth = series.marker.width / 2;
mouseX = series.yAxis.isAxisInverse ? mouseX + markerWidth : mouseX - markerWidth;
}
else {
var markerHeight = series.marker.height / 2;
mouseY = series.yAxis.isAxisInverse ? mouseY - markerHeight : mouseY + markerHeight;
}
}
if (series.visible && helper_1.withInBounds(mouseX, mouseY, series.clipRect, width, height)) {
point = this.getRectPoint(series, series.clipRect, mouseX, mouseY);
}
if (point) {
return new helper_1.PointData(point, series);
}
}
return new helper_1.PointData(point, series);
};
ChartData.prototype.isSelected = function (chart) {
return ((chart.selectionMode.indexOf('Drag') > -1 || chart.selectionMode.indexOf('Lasso') > -1) && chart.selectionModule &&
chart.selectionModule.rectPoints !== null);
};
ChartData.prototype.getRectPoint = function (series, rect, x, y) {
var chart = this.chart;
var fromCenterX;
var fromCenterY;
var clickAngle;
var arcAngle = 0;
var startAngle;
var endAngle;
var distanceFromCenter;
Iif (chart.isScrolling) {
return null;
}
for (var _i = 0, _a = series.points; _i < _a.length; _i++) {
var point = _a[_i];
if (!point.regionData) {
if (!point.regions || !point.regions.length) {
continue;
}
}
if (point.regionData && this.chart.chartAreaType === 'PolarRadar' && series.drawType.indexOf('Column') > -1) {
fromCenterX = x - (series.clipRect.width / 2 + series.clipRect.x);
fromCenterY = y - (series.clipRect.height / 2 + series.clipRect.y);
arcAngle = 2 * Math.PI * (point.regionData.currentXPosition < 0 ? 1 + point.regionData.currentXPosition
: point.regionData.currentXPosition);
clickAngle = (Math.atan2(fromCenterY, fromCenterX) + 0.5 * Math.PI - arcAngle) % (2 * Math.PI);
clickAngle = clickAngle < 0 ? 2 * Math.PI + clickAngle : clickAngle;
clickAngle = clickAngle + 2 * Math.PI * series.chart.primaryXAxis.startAngle;
startAngle = point.regionData.startAngle;
startAngle -= arcAngle;
startAngle = startAngle < 0 ? 2 * Math.PI + startAngle : startAngle;
endAngle = point.regionData.endAngle;
endAngle -= arcAngle;
endAngle = endAngle < 0 ? 2 * Math.PI + endAngle : endAngle;
distanceFromCenter = Math.sqrt(Math.pow(Math.abs(fromCenterX), 2) + Math.pow(Math.abs(fromCenterY), 2));
if (clickAngle >= startAngle && clickAngle <= endAngle &&
(((distanceFromCenter >= point.regionData.innerRadius && distanceFromCenter <= point.regionData.radius) ||
(distanceFromCenter <= point.regionData.innerRadius && distanceFromCenter >= point.regionData.radius))
&& distanceFromCenter <= series.chart.radius)) {
return point;
}
}
if ((series.dragSettings.enable && series.isRectSeries) || (series.isRectSeries && series.marker.visible && this.chart.chartAreaType !== 'PolarRadar')) {
if (this.isPointInThresholdRegion(x, y, point, rect, series)) {
this.insideRegion = true;
return point;
}
}
if (!this.insideRegion && this.checkRegionContainsPoint(point.regions, rect, x, y)) {
return point;
}
else if (this.insideRegion && this.checkRegionContainsPoint(point.regions, rect, x, y)) {
return point;
}
}
return null;
};
ChartData.prototype.checkRegionContainsPoint = function (regionRect, rect, x, y) {
var _this = this;
return regionRect.some(function (region, index) {
_this.lierIndex = index;
return helper_1.withInBounds(x, y, new ej2_svg_base_1.Rect((_this.chart.chartAreaType === 'Cartesian' ? rect.x : 0) + region.x, (_this.chart.chartAreaType === 'Cartesian' ? rect.y : 0) + region.y, region.width, region.height));
});
};
ChartData.prototype.isPointInThresholdRegion = function (x, y, point, rect, series) {
var _this = this;
var isBar = series.type === 'Bar';
var isInversed = series.yAxis.isAxisInverse;
var isTransposed = series.chart.isTransposed;
var heightValue = 10;
var yValue = 0;
var xValue = 0;
var width;
var height = width = 2 * heightValue;
Iif (isInversed && isTransposed) {
if (isBar) {
yValue = point.regions[0].height - heightValue;
width = point.regions[0].width;
}
else {
xValue = -heightValue;
height = point.regions[0].height;
}
}
else if (isInversed || point.yValue < 0) {
if (isBar) {
xValue = -heightValue;
height = point.regions[0].height;
}
else {
yValue = point.regions[0].height - heightValue;
width = point.regions[0].width;
}
}
else if (isTransposed) {
if (isBar) {
yValue = -heightValue;
width = point.regions[0].width;
}
else {
xValue = point.regions[0].width - heightValue;
height = point.regions[0].height;
}
}
else {
if (isBar) {
xValue = point.regions[0].width - heightValue;
height = point.regions[0].height;
}
else {
yValue = -heightValue;
width = point.regions[0].width;
}
}
return point.regions.some(function (region) {
return helper_1.withInBounds(x, y, new ej2_svg_base_1.Rect((_this.chart.chartAreaType === 'Cartesian' ? rect.x : 0) + region.x + xValue, (_this.chart.chartAreaType === 'Cartesian' ? rect.y : 0) + region.y + yValue, width, height));
});
};
ChartData.prototype.getClosest = function (series, value, xvalues) {
var closest;
var data;
var xData = xvalues ? xvalues : series.xData;
var xLength = xData.length;
var leftSideNearest = 0.5;
var rightSideNearest = 0.5;
if (series.xAxis.valueType === 'DateTime' && series.points.length === 1) {
leftSideNearest = series.xAxis.visibleRange.min;
rightSideNearest = series.xAxis.visibleRange.max;
for (var index = 0; index < series.chart.visibleSeries.length; index++) {
var visibleSeries = series.chart.visibleSeries[index];
if (visibleSeries.xMin >= leftSideNearest && visibleSeries.xMin < series.xMin) {
leftSideNearest = visibleSeries.xMin + 0.1;
}
if (visibleSeries.xMax <= rightSideNearest && visibleSeries.xMax > series.xMax) {
rightSideNearest = visibleSeries.xMax - 0.1;
}
if (visibleSeries.visible && visibleSeries.points.length > 1) {
Eif (visibleSeries.xMax >= leftSideNearest && visibleSeries.xMax < series.xMin) {
leftSideNearest = visibleSeries.xMax + 0.1;
}
Iif (visibleSeries.xMin <= rightSideNearest && visibleSeries.xMin > series.xMax) {
rightSideNearest = visibleSeries.xMin - 0.1;
}
}
}
if (leftSideNearest !== series.xAxis.visibleRange.min) {
leftSideNearest = Math.abs(series.xMin - leftSideNearest) / 2;
}
if (rightSideNearest !== series.xAxis.visibleRange.max) {
rightSideNearest = Math.abs(series.xMax - rightSideNearest) / 2;
}
}
if (value >= series.xMin - leftSideNearest && value <= series.xMax + rightSideNearest) {
for (var i = 0; i < xLength; i++) {
data = xData[i];
if (closest == null || Math.abs(data - value) < Math.abs(closest - value)) {
closest = data;
}
}
}
var isDataExist = series.xData.indexOf(closest) !== -1;
if (isDataExist) {
return closest;
}
else {
return null;
}
};
ChartData.prototype.binarySearch = function (target, list) {
var first = 0;
var last = list.length;
var position = -1;
var found = false;
var middle;
while (found === false && first <= last) {
middle = Math.floor((first + last) / 2);
if (list[middle].xValue === target) {
found = true;
position = middle;
}
else if (list[middle].xValue > target) {
last = middle - 1;
}
else {
first = middle + 1;
}
}
return position !== -1 ? list[position] : null;
};
ChartData.prototype.getClosestX = function (chart, series, xvalues) {
var value;
var rect = series.clipRect;
if (chart.mouseX <= rect.x + rect.width && chart.mouseX >= rect.x) {
if (!chart.requireInvertedAxis) {
value = helper_1.getValueXByPoint(chart.mouseX - rect.x, rect.width, series.xAxis);
}
else {
value = helper_1.getValueYByPoint(chart.mouseY - rect.y, rect.height, series.xAxis);
}
}
var closest = this.getClosest(series, value, xvalues);
var point = ((closest || closest === 0) && series.points.length > 0) ? this.binarySearch(closest, helper_1.sort(series.points, ['xValue'])) : null;
if (point && point.visible) {
if (!(this.chart.chartAreaType === 'Cartesian' && ((series.category === 'Indicator' && series.name === 'Histogram') ||
(point.symbolLocations && point.symbolLocations.length > 0 && point.symbolLocations[0].x >= 0 &&
point.symbolLocations[0].x <= rect.width)))) {
return null;
}
return new helper_1.PointData(point, series);
}
return null;
};
ChartData.prototype.mergeXvalues = function (visibleSeries) {
if (visibleSeries.length && (!this.commonXvalues.length || (this.commonXvalues.length !== visibleSeries[0].xData.length))) {
this.commonXvalues = visibleSeries[0].xData;
for (var index = 1; index < visibleSeries.length; index++) {
this.commonXvalues = this.getDistinctValues(this.commonXvalues, visibleSeries[index].xData);
}
}
return this.commonXvalues;
};
ChartData.prototype.commonXValue = function (visibleSeries) {
var commonXValues = [];
for (var j = 0; j < visibleSeries.length; j++) {
for (var i = 0; (visibleSeries[j].points && i < visibleSeries[j].points.length); i++) {
var point = visibleSeries[j].points[i];
if (point && (point.index === 0 || point.index === visibleSeries[j].points.length - 1 ||
(point.symbolLocations && point.symbolLocations.length > 0))) {
commonXValues.push(point.xValue);
}
}
}
return commonXValues;
};
ChartData.prototype.getDistinctValues = function (first, second) {
Iif (first === void 0) { first = []; }
if (second === void 0) { second = []; }
var intial = {};
var result = [];
var index;
for (index = 0; index < first.length; index++) {
var temp = first[index];
if (!intial[temp]) {
intial[temp] = true;
result.push(temp);
}
}
for (index = 0; index < second.length; index++) {
var temp = second[index];
if (!intial[temp]) {
intial[temp] = true;
result.push(temp);
}
}
return result;
};
return ChartData;
}());
exports.ChartData = ChartData;
});
|