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 | 1×
1×
1×
1×
104×
1×
240×
240×
240×
240×
240×
240×
240×
102×
102×
138×
138×
254×
138×
240×
240×
20×
21×
21×
21×
21×
3808×
3808×
3808×
3788×
3805×
240×
240×
7425×
248×
248×
248×
139×
37276×
248×
248×
1×
1×
1×
2×
1×
1×
1×
240×
46×
45×
343×
343×
46×
240×
240×
240×
240×
6×
6×
1×
240×
240×
240×
240×
240×
240×
1×
240×
240×
250×
250×
250×
250×
250×
250×
250×
250×
250×
139×
250×
250×
240×
1×
240×
240×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
119×
1×
720×
1×
1×
| define(["require", "exports", "../../chart/chart", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base", "../../common/model/constants", "../../common/utils/helper", "@syncfusion/ej2-data"], function (require, exports, chart_1, ej2_svg_base_1, ej2_base_1, constants_1, helper_1, ej2_data_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CartesianChart = (function () {
function CartesianChart(chart) {
this.stockChart = chart;
}
CartesianChart.prototype.initializeChart = function (chartArgsData) {
var _this = this;
var stockChart = this.stockChart;
var isProtect = 'isProtectedOnChange';
var startValue = null;
var endValue = null;
stockChart[isProtect] = true;
if (!stockChart.chartObject) {
stockChart.chartObject = stockChart.renderer.createGroup({
id: stockChart.element.id + '_stockChart_chart'
});
stockChart.mainObject.appendChild(stockChart.chartObject);
}
else {
var chartElement = document.getElementById(stockChart.chartObject.id);
while (chartElement.firstChild) {
chartElement.removeChild(chartElement.firstChild);
}
Iif (helper_1.getElement(stockChart.chartObject + '_tooltip')) {
ej2_base_1.remove(helper_1.getElement(stockChart.chartObject + '_tooltip'));
}
}
this.stockChart.isDateTimeCategory = this.stockChart.primaryXAxis.valueType === 'DateTimeCategory';
if (this.stockChart.isDateTimeCategory && !this.stockChart.sortedData.length) {
for (var _i = 0, _a = this.stockChart.series; _i < _a.length; _i++) {
var series = _a[_i];
var dataSource = series.dataSource;
var xName = series.xName;
for (var _b = 0, dataSource_1 = dataSource; _b < dataSource_1.length; _b++) {
var dataItem = dataSource_1[_b];
var currentData = Date.parse(new Date(ej2_data_1.DataUtil.parse.parseJson({ val: dataItem[xName] }).val).toString());
if (this.stockChart.sortedData.indexOf(currentData) === -1) {
this.stockChart.sortedData.push(currentData);
}
}
}
this.stockChart.sortedData.sort(function (a, b) { return a - b; });
}
this.cartesianChartSize = this.calculateChartSize();
stockChart.chart = new chart_1.Chart({
chartArea: stockChart.chartArea,
margin: this.findMargin(stockChart),
primaryXAxis: this.copyObject(stockChart.primaryXAxis),
primaryYAxis: this.copyObject(stockChart.primaryYAxis),
rows: stockChart.rows,
indicators: stockChart.indicators,
axes: stockChart.axes,
tooltipRender: function (args) {
_this.stockChart.trigger('tooltipRender', args);
},
axisLabelRender: function (args) {
_this.stockChart.trigger('axisLabelRender', args);
},
seriesRender: function (args) {
startValue = (_this.stockChart.startValue != null && _this.stockChart.isDateTimeCategory) ?
_this.stockChart.sortedData[Math.floor(_this.stockChart.startValue)] : _this.stockChart.startValue;
endValue = (_this.stockChart.endValue != null && _this.stockChart.isDateTimeCategory) ?
_this.stockChart.sortedData[Math.floor(_this.stockChart.endValue)] : _this.stockChart.endValue;
if (args.data && startValue && endValue) {
args.data = args.data
.filter(function (data) {
return (new Date(ej2_data_1.DataUtil.parse.parseJson({ val: (data[args.series.xName]) }).val).getTime() >= startValue &&
new Date(ej2_data_1.DataUtil.parse.parseJson({ val: (data[args.series.xName]) }).val).getTime() <= endValue);
});
}
args.data = chartArgsData ? chartArgsData : args.data;
_this.stockChart.trigger('seriesRender', args);
},
onZooming: function (args) { _this.stockChart.trigger(constants_1.onZooming, args); },
pointClick: function (args) {
_this.stockChart.trigger('pointClick', args);
},
pointMove: function (args) {
_this.stockChart.trigger('pointMove', args);
},
dataSource: stockChart.dataSource,
series: this.findSeriesCollection(stockChart.series),
zoomSettings: this.copyObject(stockChart.zoomSettings),
tooltip: stockChart.tooltip,
crosshair: stockChart.crosshair,
height: this.cartesianChartSize.height.toString(),
selectedDataIndexes: stockChart.selectedDataIndexes,
selectionMode: stockChart.selectionMode,
isMultiSelect: stockChart.isMultiSelect,
annotations: stockChart.annotations,
theme: stockChart.theme,
legendSettings: { visible: false },
enableRtl: stockChart.enableRtl,
zoomComplete: function (args) {
if (args.axis.valueType.indexOf('DateTime') !== -1 && stockChart.rangeNavigator) {
_this.stockChart.zoomChange = true;
var newRange = _this.calculateUpdatedRange(args.currentZoomFactor, args.currentZoomPosition, args.axis);
stockChart.rangeSelector.sliderChange(newRange.start, newRange.end);
}
}
});
if (stockChart.indicators.length !== 0) {
if (stockChart.isSelect) {
for (var i = 0; i < stockChart.indicators.length; i++) {
stockChart.chart.indicators[i].animation.enable = false;
stockChart.chart.indicators[i].dataSource = ej2_base_1.extend([], stockChart.chart.series[0].dataSource, null, true);
}
}
stockChart.isSelect = true;
}
stockChart.chart.stockChart = stockChart;
stockChart.chart.appendTo(stockChart.chartObject);
stockChart[isProtect] = false;
if (stockChart.onPanning) {
helper_1.getElement(this.stockChart.element.id + '_stockChart_chart').setAttribute('cursor', 'pointer');
stockChart.chart.mouseMove(stockChart.mouseMoveEvent);
}
};
CartesianChart.prototype.findMargin = function (stockChart) {
var margin = {};
margin.top = stockChart.stockLegendModule && stockChart.legendSettings.visible && stockChart.legendSettings.position === 'Top' ?
stockChart.margin.top : stockChart.margin.top * 2;
margin.left = stockChart.margin.left;
margin.right = stockChart.margin.right;
margin.bottom = stockChart.margin.bottom;
return margin;
};
CartesianChart.prototype.findSeriesCollection = function (series) {
var chartSeries = [];
for (var i = 0, len = series.length; i < len; i++) {
chartSeries.push(series[i]);
chartSeries[i].high = series[i].high;
chartSeries[i].low = series[i].low;
chartSeries[i].open = series[i].open;
chartSeries[i].close = series[i].close;
chartSeries[i].xName = series[i].xName;
chartSeries[i].volume = series[i].volume;
chartSeries[i].animation = series[i].animation;
if (series[i].localData) {
chartSeries[i].dataSource = series[i].localData;
}
chartSeries[i].yName = series[i].yName === '' ? series[i].close : series[i].yName;
chartSeries[i].splineType = chartSeries[i].type === 'Spline' ? 'Cardinal' : 'Natural';
}
return chartSeries;
};
CartesianChart.prototype.calculateChartSize = function () {
var stockChart = this.stockChart;
return (new ej2_svg_base_1.Size(stockChart.availableSize.width, (stockChart.enablePeriodSelector && stockChart.enableSelector) ?
((stockChart.availableSize.height - stockChart.toolbarHeight - 51)) :
(stockChart.enableSelector && !stockChart.enablePeriodSelector) ? (stockChart.availableSize.height - 51) :
(stockChart.enablePeriodSelector && !stockChart.enableSelector) ?
stockChart.availableSize.height - stockChart.toolbarHeight : stockChart.availableSize.height));
};
CartesianChart.prototype.calculateUpdatedRange = function (zoomFactor, zoomPosition, axis) {
var start;
var end;
var chartRange = axis.actualRange;
var inversed = false;
Eif (!inversed) {
start = chartRange.min + zoomPosition * chartRange.delta;
end = start + zoomFactor * chartRange.delta;
}
else {
start = chartRange.max - (zoomPosition * chartRange.delta);
end = start - (zoomFactor * chartRange.delta);
}
Iif (this.stockChart.isDateTimeCategory) {
start = this.stockChart.sortedData.indexOf(parseInt(axis.labels[Math.floor(start)], 10));
end = this.stockChart.sortedData.indexOf(parseInt(axis.labels[Math.floor(end)], 10));
}
var result = { start: start, end: end };
return result;
};
CartesianChart.prototype.cartesianChartRefresh = function (stockChart, data) {
stockChart.cartesianChart.initializeChart(data);
};
CartesianChart.prototype.copyObject = function (originalObject) {
return (ej2_base_1.extend({}, originalObject, {}, true));
};
return CartesianChart;
}());
exports.CartesianChart = CartesianChart;
});
|