| 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 |
1×
1×
1×
1×
1×
1×
1×
248×
248×
248×
1×
1×
1×
1×
1×
31×
31×
31×
31×
1×
31×
31×
31×
31×
1×
31×
2×
29×
29×
29×
1×
1×
1×
41×
41×
41×
41×
41×
41×
41×
113×
113×
74×
74×
74×
41×
39×
39×
39×
41×
39×
39×
39×
99×
93×
33×
33×
6×
6×
6×
6×
6×
18×
18×
18×
18×
6×
1×
41×
41×
41×
41×
11×
30×
41×
41×
41×
41×
41×
41×
41×
41×
41×
41×
41×
41×
41×
164×
164×
164×
164×
164×
164×
164×
164×
164×
152×
152×
152×
152×
106×
106×
106×
106×
106×
41×
41×
41×
41×
37×
4×
1×
152×
152×
152×
152×
106×
106×
46×
46×
152×
152×
1×
8×
8×
4×
4×
4×
1×
87×
1×
31×
1×
1×
| /* istanbul ignore next */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
define(["require", "exports", "@syncfusion/ej2-base", "../../common/legend/legend", "../../common/utils/helper", "@syncfusion/ej2-svg-base", "../../common/model/constants"], function (require, exports, ej2_base_1, legend_1, helper_1, ej2_svg_base_1, constants_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var BulletChartLegend = (function (_super) {
__extends(BulletChartLegend, _super);
function BulletChartLegend(chart) {
var _this = _super.call(this, chart) || this;
_this.library = _this;
_this.addEventListener();
return _this;
}
BulletChartLegend.prototype.addEventListener = function () {
Iif (this.chart.isDestroyed) {
return;
}
this.chart.on('click', this.click, this);
this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseEnd, this);
this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.bulletMouseMove, this);
};
BulletChartLegend.prototype.removeEventListener = function () {
if (this.chart.isDestroyed) {
return;
}
this.chart.off('click', this.click);
this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseEnd);
this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.bulletMouseMove);
};
BulletChartLegend.prototype.bulletMouseMove = function (e) {
if (this.chart.legendSettings.visible && this.chart.isTouch) {
this.move(e);
}
};
BulletChartLegend.prototype.mouseEnd = function (e) {
if (this.chart.legendSettings.visible && this.chart.isTouch) {
this.move(e);
}
};
BulletChartLegend.prototype.getLegendOptions = function (visibleRangeCollection) {
this.legendCollections = [];
var fill;
var count = 0;
this.isRtlEnable = this.chart.enableRtl;
var key = 'color';
var bulletChart = this.chart;
for (var _i = 0, visibleRangeCollection_1 = visibleRangeCollection; _i < visibleRangeCollection_1.length; _i++) {
var range = visibleRangeCollection_1[_i];
if (range.name !== null) {
fill = range.color ? range.color : bulletChart.themeStyle.rangeStrokes[range.index][key];
this.legendCollections.push(new legend_1.LegendOptions(range.name, fill, range.shape, this.chart.legendSettings.visible, null, range.legendImageUrl, null, false, range.index, null));
count++;
}
}
if (bulletChart.dataSource !== null && bulletChart.valueField !== '') {
fill = (bulletChart.theme.indexOf('Dark') > -1) ? 'white' : bulletChart.valueFill ? bulletChart.valueFill : 'black';
var shape = bulletChart.orientation === 'Vertical' ? 'TargetRect' : 'ActualRect';
this.legendCollections.push(new legend_1.LegendOptions('Actual', fill, shape, this.chart.legendSettings.visible, null, '', null, false, count++, null));
}
if (bulletChart.dataSource !== null && bulletChart.targetField !== '') {
fill = (bulletChart.theme.indexOf('Dark') > -1) ? 'white' : bulletChart.targetColor ? bulletChart.targetColor : 'black';
var shape = bulletChart.targetTypes[0] === 'Rect' ? bulletChart.orientation === 'Vertical' ? 'ActualRect' : 'TargetRect' : bulletChart.targetTypes[0];
for (var i = 0; i < Object.keys(bulletChart.dataSource).length; i++) {
if (ej2_base_1.isNullOrUndefined(bulletChart.dataSource[i][bulletChart.targetField].length)
|| bulletChart.dataSource[i][bulletChart.targetField].length === 1) {
while (i === 0) {
this.legendCollections.push(new legend_1.LegendOptions('Target', fill, shape, this.chart.legendSettings.visible, null, '', null, false, count++, null));
break;
}
}
else {
var targetTypes = bulletChart.targetTypes;
var targetType = [];
var targetTypeLength = targetTypes.length;
while (i === 0) {
for (var i_1 = 0; i_1 < targetTypeLength; i_1++) {
targetType[i_1] = targetTypes[i_1 % targetTypeLength];
targetType[i_1] = (targetType[i_1] === 'Rect') ? bulletChart.orientation === 'Vertical' ?
'ActualRect' : 'TargetRect' : (targetType[i_1]);
targetType[i_1] = (targetType[i_1] === 'Cross') ? 'Multiply' : targetType[i_1];
this.legendCollections.push(new legend_1.LegendOptions('Target_' + i_1, fill, targetType[i_1], this.chart.legendSettings.visible, null, '', null, false, count++, null));
}
break;
}
}
}
}
};
BulletChartLegend.prototype.getLegendBounds = function (availableSize, bulletLegendBounds, legend) {
var extraWidth = 0;
var padding = legend.padding;
var extraHeight = 0;
if (!this.isVertical) {
extraHeight = ((availableSize.height / 100) * 5);
}
else {
extraWidth = ((availableSize.width / 100) * 5);
}
bulletLegendBounds.height += extraHeight;
bulletLegendBounds.width += extraWidth;
var maximumWidth = 0;
var legendRowWidth = 0;
var legendRowCount = 0;
var legendWidth = 0;
var columnHeight = 0;
var shapeWidth = legend.shapeWidth;
var shapePadding = legend.shapePadding;
var legendEventArgs;
this.maxItemHeight = Math.max(ej2_svg_base_1.measureText('MeasureText', legend.textStyle, this.chart.themeStyle.legendLabelFont).height, legend.shapeHeight);
var render = false;
for (var _i = 0, _a = this.legendCollections; _i < _a.length; _i++) {
var bulletLegendOption = _a[_i];
legendEventArgs = {
fill: bulletLegendOption.fill, text: bulletLegendOption.text, shape: bulletLegendOption.shape,
name: constants_1.legendRender, cancel: false
};
this.chart.trigger(constants_1.legendRender, legendEventArgs);
bulletLegendOption.render = !legendEventArgs.cancel;
bulletLegendOption.text = legendEventArgs.text;
bulletLegendOption.fill = legendEventArgs.fill;
bulletLegendOption.shape = legendEventArgs.shape;
bulletLegendOption.textSize = ej2_svg_base_1.measureText(bulletLegendOption.text, legend.textStyle, this.chart.themeStyle.legendLabelFont);
if (bulletLegendOption.render && bulletLegendOption.text !== '') {
render = true;
legendWidth = shapeWidth + shapePadding + bulletLegendOption.textSize.width + padding;
legendRowWidth = legendRowWidth + legendWidth;
if (bulletLegendBounds.width < (padding + legendRowWidth) || this.isVertical) {
maximumWidth = Math.max(maximumWidth, (legendRowWidth + padding - (this.isVertical ? 0 : legendWidth)));
Iif (legendRowCount === 0 && (legendWidth !== legendRowWidth)) {
legendRowCount = 1;
}
legendRowWidth = this.isVertical ? 0 : legendWidth;
legendRowCount++;
columnHeight = (legendRowCount * (this.maxItemHeight + padding)) + padding;
}
}
}
columnHeight = Math.max(columnHeight, (this.maxItemHeight + padding) + padding);
this.isPaging = bulletLegendBounds.height < columnHeight;
this.totalPages = legendRowCount;
if (render) {
this.setBounds(Math.max((legendRowWidth + padding), maximumWidth), (this.position === 'Bottom' || this.position === 'Top') ? Math.min(columnHeight, this.chart.initialClipRect.height -
(this.legend.border.width + this.legend.margin.bottom + this.legend.margin.top)) : columnHeight, legend, bulletLegendBounds);
}
else {
this.setBounds(0, 0, legend, bulletLegendBounds);
}
};
BulletChartLegend.prototype.getRenderPoint = function (bulletLegendOption, start, textPadding, prevLegend, rect, count, firstLegend) {
var textWidth = textPadding + (this.legend.maximumLabelWidth ? this.legend.maximumLabelWidth : prevLegend.textSize.width);
var previousBound = prevLegend.location.x + ((!this.isRtlEnable) ? textWidth : -textWidth);
var padding = this.legend.padding;
if ((previousBound + (bulletLegendOption.textSize.width + textPadding)) > (rect.x + rect.width + this.legend.shapeWidth / 2) ||
this.isVertical) {
bulletLegendOption.location.x = start.x;
bulletLegendOption.location.y = (count === firstLegend) ? prevLegend.location.y :
prevLegend.location.y + this.maxItemHeight + padding;
}
else {
bulletLegendOption.location.x = (count === firstLegend) ? prevLegend.location.x : previousBound;
bulletLegendOption.location.y = prevLegend.location.y;
}
var availwidth = (!this.isRtlEnable) ? (this.legendBounds.x + this.legendBounds.width) - (bulletLegendOption.location.x +
textPadding - this.itemPadding - this.legend.shapeWidth / 2) : (bulletLegendOption.location.x - textPadding +
this.itemPadding + (this.legend.shapeWidth / 2)) - this.legendBounds.x;
bulletLegendOption.text = helper_1.textTrim(+availwidth.toFixed(4), bulletLegendOption.text, this.legend.textStyle, this.chart.enableRtl, this.chart.themeStyle.legendLabelFont);
};
BulletChartLegend.prototype.click = function (event) {
var symbolTargetId = event.target.id;
if (symbolTargetId.indexOf(this.legendID + '_pagedown') > -1) {
this.changePage(event, false);
}
else Eif (symbolTargetId.indexOf(this.legendID + '_pageup') > -1) {
this.changePage(event, true);
}
};
BulletChartLegend.prototype.getModuleName = function () {
return 'BulletChartLegend';
};
BulletChartLegend.prototype.destroy = function () {
this.removeEventListener();
};
return BulletChartLegend;
}(legend_1.BaseLegend));
exports.BulletChartLegend = BulletChartLegend;
});
|