evui 3.3.36 → 3.3.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +40 -40
- package/dist/evui.common.js +1907 -1832
- package/dist/evui.common.js.map +1 -1
- package/dist/evui.umd.js +1907 -1832
- package/dist/evui.umd.js.map +1 -1
- package/dist/evui.umd.min.js +1 -1
- package/dist/evui.umd.min.js.map +1 -1
- package/dist/img/{EVUI.7f3588fb.svg → EVUI.b82ee81a.svg} +292 -292
- package/dist/img/{icon_mysql.7ea26d5d.svg → icon_mysql.1085fdc9.svg} +78 -78
- package/dist/img/{icon_oracle.9009b108.svg → icon_oracle.0572d3ee.svg} +13 -13
- package/dist/img/{icon_postgresql.f8fffba9.svg → icon_postgresql.ee12bde8.svg} +58 -58
- package/package.json +61 -61
- package/src/common/emitter.js +20 -20
- package/src/common/utils.debounce.js +223 -223
- package/src/common/utils.js +134 -134
- package/src/common/utils.table.js +78 -78
- package/src/common/utils.throttle.js +83 -83
- package/src/common/utils.tree.js +18 -18
- package/src/components/button/Button.vue +198 -198
- package/src/components/button/index.js +7 -7
- package/src/components/buttonGroup/ButtonGroup.vue +11 -11
- package/src/components/buttonGroup/index.js +7 -7
- package/src/components/calendar/Calendar.vue +661 -661
- package/src/components/calendar/index.js +7 -7
- package/src/components/calendar/uses.js +1272 -1272
- package/src/components/chart/Chart.vue +189 -192
- package/src/components/chart/chart.core.js +870 -870
- package/src/components/chart/element/element.bar.js +524 -524
- package/src/components/chart/element/element.bar.time.js +156 -156
- package/src/components/chart/element/element.heatmap.js +533 -533
- package/src/components/chart/element/element.line.js +339 -339
- package/src/components/chart/element/element.pie.js +197 -197
- package/src/components/chart/element/element.scatter.js +184 -184
- package/src/components/chart/element/element.tip.js +550 -542
- package/src/components/chart/helpers/helpers.canvas.js +265 -265
- package/src/components/chart/helpers/helpers.constant.js +206 -206
- package/src/components/chart/helpers/helpers.util.js +346 -338
- package/src/components/chart/index.js +9 -9
- package/src/components/chart/model/index.js +4 -4
- package/src/components/chart/model/model.series.js +93 -93
- package/src/components/chart/model/model.store.js +977 -967
- package/src/components/chart/plugins/plugins.interaction.js +769 -769
- package/src/components/chart/plugins/plugins.legend.gradient.js +602 -602
- package/src/components/chart/plugins/plugins.legend.js +1155 -1151
- package/src/components/chart/plugins/plugins.pie.js +254 -254
- package/src/components/chart/plugins/plugins.title.js +56 -56
- package/src/components/chart/plugins/plugins.tooltip.js +692 -692
- package/src/components/chart/scale/scale.js +848 -848
- package/src/components/chart/scale/scale.linear.js +38 -38
- package/src/components/chart/scale/scale.logarithmic.js +128 -128
- package/src/components/chart/scale/scale.step.js +336 -336
- package/src/components/chart/scale/scale.time.category.js +277 -277
- package/src/components/chart/scale/scale.time.js +48 -48
- package/src/components/chart/style/chart.scss +312 -312
- package/src/components/chart/uses.js +264 -252
- package/src/components/checkbox/Checkbox.vue +200 -200
- package/src/components/checkbox/index.js +7 -7
- package/src/components/checkboxGroup/CheckboxGroup.vue +44 -44
- package/src/components/checkboxGroup/index.js +7 -7
- package/src/components/contextMenu/ContextMenu.vue +80 -80
- package/src/components/contextMenu/MenuList.vue +149 -149
- package/src/components/contextMenu/index.js +7 -7
- package/src/components/contextMenu/uses.js +203 -203
- package/src/components/datePicker/DatePicker.vue +437 -437
- package/src/components/datePicker/index.js +7 -7
- package/src/components/datePicker/uses.js +419 -419
- package/src/components/grid/Grid.vue +827 -827
- package/src/components/grid/grid.filter.window.vue +493 -493
- package/src/components/grid/grid.pagination.vue +75 -75
- package/src/components/grid/grid.summary.vue +265 -265
- package/src/components/grid/grid.toolbar.vue +26 -26
- package/src/components/grid/index.js +11 -11
- package/src/components/grid/style/grid.scss +263 -263
- package/src/components/grid/uses.js +1002 -1007
- package/src/components/icon/Icon.vue +49 -49
- package/src/components/icon/index.js +8 -8
- package/src/components/inputNumber/InputNumber.vue +212 -212
- package/src/components/inputNumber/index.js +7 -7
- package/src/components/inputNumber/uses.js +217 -217
- package/src/components/loading/Loading.vue +125 -125
- package/src/components/loading/index.js +7 -7
- package/src/components/menu/Menu.vue +68 -68
- package/src/components/menu/MenuItem.vue +187 -187
- package/src/components/menu/index.js +7 -7
- package/src/components/message/Message.vue +223 -223
- package/src/components/message/index.js +31 -31
- package/src/components/messageBox/MessageBox.vue +358 -358
- package/src/components/messageBox/index.js +22 -22
- package/src/components/notification/Notification.vue +316 -316
- package/src/components/notification/index.js +49 -49
- package/src/components/pagination/Pagination.vue +271 -271
- package/src/components/pagination/index.js +7 -7
- package/src/components/pagination/pageButton.vue +30 -30
- package/src/components/progress/Progress.vue +139 -139
- package/src/components/progress/index.js +7 -7
- package/src/components/radio/Radio.vue +159 -159
- package/src/components/radio/index.js +7 -7
- package/src/components/radioGroup/RadioGroup.vue +41 -41
- package/src/components/radioGroup/index.js +7 -7
- package/src/components/scheduler/Scheduler.vue +149 -149
- package/src/components/scheduler/index.js +7 -7
- package/src/components/scheduler/uses.js +183 -183
- package/src/components/select/Select.vue +440 -440
- package/src/components/select/index.js +7 -7
- package/src/components/select/uses.js +270 -270
- package/src/components/slider/Slider.vue +505 -505
- package/src/components/slider/index.js +7 -7
- package/src/components/slider/uses.js +390 -390
- package/src/components/tabPanel/TabPanel.vue +74 -74
- package/src/components/tabPanel/index.js +7 -7
- package/src/components/tabs/Tabs.vue +517 -517
- package/src/components/tabs/index.js +7 -7
- package/src/components/textField/TextField.vue +375 -375
- package/src/components/textField/index.js +7 -7
- package/src/components/timePicker/TimePicker.vue +352 -352
- package/src/components/timePicker/index.js +7 -7
- package/src/components/toggle/Toggle.vue +115 -115
- package/src/components/toggle/index.js +7 -7
- package/src/components/tree/Tree.vue +313 -313
- package/src/components/tree/TreeNode.vue +293 -293
- package/src/components/tree/index.js +7 -7
- package/src/components/treeGrid/TreeGrid.vue +758 -758
- package/src/components/treeGrid/TreeGridNode.vue +275 -275
- package/src/components/treeGrid/index.js +9 -9
- package/src/components/treeGrid/style/treeGrid.scss +261 -261
- package/src/components/treeGrid/treeGrid.toolbar.vue +26 -26
- package/src/components/treeGrid/uses.js +867 -867
- package/src/components/window/Window.vue +329 -329
- package/src/components/window/index.js +7 -7
- package/src/components/window/uses.js +899 -899
- package/src/directives/clickoutside.js +90 -90
- package/src/main.js +116 -116
- package/src/style/components/input.scss +108 -108
- package/src/style/functions.scss +3 -3
- package/src/style/index.scss +6 -6
- package/src/style/lib/fonts/EVUI.svg +292 -292
- package/src/style/lib/icon.css +888 -888
- package/src/style/mixins.scss +94 -94
- package/src/style/themes.scss +67 -67
- package/src/style/variables.scss +22 -22
|
@@ -1,533 +1,533 @@
|
|
|
1
|
-
import { merge } from 'lodash-es';
|
|
2
|
-
import Util from '../helpers/helpers.util';
|
|
3
|
-
import { HEAT_MAP_OPTION } from '../helpers/helpers.constant';
|
|
4
|
-
import { convertToPercent } from '../../../common/utils';
|
|
5
|
-
|
|
6
|
-
class HeatMap {
|
|
7
|
-
constructor(sId, opt, colorOpt, isGradient) {
|
|
8
|
-
const merged = merge({}, HEAT_MAP_OPTION, opt);
|
|
9
|
-
Object.keys(merged).forEach((key) => {
|
|
10
|
-
this[key] = merged[key];
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
this.isGradient = isGradient;
|
|
14
|
-
this.createColorState(colorOpt);
|
|
15
|
-
|
|
16
|
-
this.sId = sId;
|
|
17
|
-
this.data = [];
|
|
18
|
-
this.labels = {
|
|
19
|
-
x: [],
|
|
20
|
-
y: [],
|
|
21
|
-
};
|
|
22
|
-
this.valueOpt = {};
|
|
23
|
-
this.size = {
|
|
24
|
-
w: 0,
|
|
25
|
-
h: 0,
|
|
26
|
-
};
|
|
27
|
-
this.type = 'heatMap';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* create series color axis
|
|
32
|
-
* @param colorOpt
|
|
33
|
-
* @returns {*[]}
|
|
34
|
-
*/
|
|
35
|
-
createColorState(colorOpt) {
|
|
36
|
-
const colorState = [];
|
|
37
|
-
const regex = /[^0-9]&[^,]/g;
|
|
38
|
-
const { min, max, categoryCnt, error, stroke } = colorOpt;
|
|
39
|
-
|
|
40
|
-
const minColor = min.includes('#') ? Util.hexToRgb(min) : min.replace(regex, '');
|
|
41
|
-
const maxColor = max.includes('#') ? Util.hexToRgb(max) : max.replace(regex, '');
|
|
42
|
-
|
|
43
|
-
const [minR, minG, minB] = minColor.split(',');
|
|
44
|
-
const [maxR, maxG, maxB] = maxColor.split(',');
|
|
45
|
-
|
|
46
|
-
if (this.isGradient) {
|
|
47
|
-
colorState.push({
|
|
48
|
-
minColor: { minR, minG, minB },
|
|
49
|
-
maxColor: { maxR, maxG, maxB },
|
|
50
|
-
categoryCnt,
|
|
51
|
-
start: 0,
|
|
52
|
-
end: 100,
|
|
53
|
-
selectedValue: null,
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
const unitR = Math.floor((minR - maxR) / (categoryCnt - 1));
|
|
57
|
-
const unitG = Math.floor((minG - maxG) / (categoryCnt - 1));
|
|
58
|
-
const unitB = Math.floor((minB - maxB) / (categoryCnt - 1));
|
|
59
|
-
|
|
60
|
-
for (let ix = 0; ix < categoryCnt; ix++) {
|
|
61
|
-
const r = +minR - (unitR * ix);
|
|
62
|
-
const g = +minG - (unitG * ix);
|
|
63
|
-
const b = +minB - (unitB * ix);
|
|
64
|
-
|
|
65
|
-
colorState.push({
|
|
66
|
-
id: `color#${ix}`,
|
|
67
|
-
color: `rgb(${r},${g},${b})`,
|
|
68
|
-
state: 'normal',
|
|
69
|
-
show: true,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.colorState = colorState;
|
|
75
|
-
this.errorColor = error;
|
|
76
|
-
this.stroke = stroke;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getColorForGradient(value) {
|
|
80
|
-
const { minColor, maxColor } = this.colorState[0];
|
|
81
|
-
|
|
82
|
-
const { minR, minG, minB } = minColor;
|
|
83
|
-
const { maxR, maxG, maxB } = maxColor;
|
|
84
|
-
|
|
85
|
-
const r = +minR - Math.floor(((minR - maxR) * value) / 100);
|
|
86
|
-
const g = +minG - Math.floor(((minG - maxG) * value) / 100);
|
|
87
|
-
const b = +minB - Math.floor(((minB - maxB) * value) / 100);
|
|
88
|
-
|
|
89
|
-
return `rgb(${r},${g},${b})`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getColorIndexForIcon(value) {
|
|
93
|
-
const { existError, min, interval, decimalPoint } = this.valueOpt;
|
|
94
|
-
const maxIndex = this.colorState.length - 1;
|
|
95
|
-
if (existError && value < 0) {
|
|
96
|
-
return maxIndex;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const colorIndex = Math.floor(+(value - min).toFixed(decimalPoint) / interval);
|
|
100
|
-
|
|
101
|
-
if (colorIndex >= maxIndex) {
|
|
102
|
-
return existError ? maxIndex - 1 : maxIndex;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return colorIndex;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getItemInfo(value) {
|
|
109
|
-
const { min, max } = this.valueOpt;
|
|
110
|
-
const itemInfo = {
|
|
111
|
-
show: false,
|
|
112
|
-
opacity: 0,
|
|
113
|
-
dataColor: null,
|
|
114
|
-
id: null,
|
|
115
|
-
isHighlight: null,
|
|
116
|
-
};
|
|
117
|
-
if (this.isGradient) {
|
|
118
|
-
const ratio = convertToPercent(value - min, max - min);
|
|
119
|
-
const { start, end, selectedValue } = this.colorState[0];
|
|
120
|
-
if (value < 0 || (start <= ratio && ratio <= end)) {
|
|
121
|
-
itemInfo.show = true;
|
|
122
|
-
itemInfo.isHighlight = selectedValue !== null
|
|
123
|
-
&& (Math.floor(value) === Math.floor(min + ((max - min) * (selectedValue / 100))));
|
|
124
|
-
itemInfo.opacity = 1;
|
|
125
|
-
itemInfo.dataColor = value < 0
|
|
126
|
-
? this.errorColor : this.getColorForGradient(ratio);
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
const colorIndex = this.getColorIndexForIcon(value);
|
|
130
|
-
const { show, state, color, id } = this.colorState[colorIndex];
|
|
131
|
-
itemInfo.show = show;
|
|
132
|
-
itemInfo.opacity = state === 'downplay' ? 0.1 : 1;
|
|
133
|
-
itemInfo.dataColor = value < 0 ? this.errorColor : color;
|
|
134
|
-
itemInfo.id = id;
|
|
135
|
-
}
|
|
136
|
-
return itemInfo;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
drawItem(ctx, x, y, w, h) {
|
|
140
|
-
ctx.beginPath();
|
|
141
|
-
if (this.stroke.show) {
|
|
142
|
-
const { radius } = this.stroke;
|
|
143
|
-
if (radius > 0 && radius < h && radius < w) {
|
|
144
|
-
ctx.moveTo(x + radius, y);
|
|
145
|
-
ctx.arcTo(x + w, y, x + w, y + h, radius);
|
|
146
|
-
ctx.arcTo(x + w, y + h, x, y + h, radius);
|
|
147
|
-
ctx.arcTo(x, y + h, x, y, radius);
|
|
148
|
-
ctx.arcTo(x, y, x + w, y, radius);
|
|
149
|
-
ctx.fill();
|
|
150
|
-
} else {
|
|
151
|
-
ctx.strokeRect(x, y, w, h);
|
|
152
|
-
ctx.fillRect(x, y, w, h);
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
const aliasPixel = Util.aliasPixel(1);
|
|
156
|
-
ctx.fillRect(
|
|
157
|
-
x,
|
|
158
|
-
y - aliasPixel,
|
|
159
|
-
w + aliasPixel,
|
|
160
|
-
h + aliasPixel,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
ctx.closePath();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
calculateXY(dir, value, startPoint) {
|
|
167
|
-
let point = null;
|
|
168
|
-
|
|
169
|
-
if (this.labels[dir] && this.labels[dir].length) {
|
|
170
|
-
const index = this.labels[dir].findIndex(label => label === value);
|
|
171
|
-
|
|
172
|
-
if (index > -1) {
|
|
173
|
-
point = dir === 'x'
|
|
174
|
-
? startPoint + (this.size.w * index)
|
|
175
|
-
: startPoint - (this.size.h * (index + 1));
|
|
176
|
-
} else {
|
|
177
|
-
const timeIndex = this.labels[dir].findIndex(label =>
|
|
178
|
-
new Date(label).getTime() === new Date(value).getTime(),
|
|
179
|
-
);
|
|
180
|
-
if (timeIndex > -1) {
|
|
181
|
-
point = dir === 'x'
|
|
182
|
-
? startPoint + (this.size.w * timeIndex)
|
|
183
|
-
: startPoint - (this.size.h * (timeIndex + 1));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return point;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
draw(param) {
|
|
192
|
-
if (!this.show) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const { ctx, chartRect, labelOffset, overlayCtx } = param;
|
|
197
|
-
|
|
198
|
-
const xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
|
|
199
|
-
const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
|
|
200
|
-
|
|
201
|
-
const xsp = chartRect.x1 + labelOffset.left;
|
|
202
|
-
const ysp = chartRect.y2 - labelOffset.bottom;
|
|
203
|
-
|
|
204
|
-
this.size.w = xArea / this.labels.x.length;
|
|
205
|
-
this.size.h = yArea / this.labels.y.length;
|
|
206
|
-
|
|
207
|
-
this.data.forEach((item) => {
|
|
208
|
-
let xp = this.calculateXY('x', item.x, xsp);
|
|
209
|
-
let yp = this.calculateXY('y', item.y, ysp);
|
|
210
|
-
let w = this.size.w;
|
|
211
|
-
let h = this.size.h;
|
|
212
|
-
const value = item.o;
|
|
213
|
-
|
|
214
|
-
if (xp !== null && yp !== null
|
|
215
|
-
&& (value !== null && value !== undefined)) {
|
|
216
|
-
const { show, opacity, dataColor, id, isHighlight } = this.getItemInfo(value);
|
|
217
|
-
item.dataColor = dataColor;
|
|
218
|
-
item.cId = id;
|
|
219
|
-
ctx.save();
|
|
220
|
-
if (show) {
|
|
221
|
-
ctx.fillStyle = Util.colorStringToRgba(item.dataColor, opacity);
|
|
222
|
-
if (this.stroke.show) {
|
|
223
|
-
const { color, lineWidth, opacity: sOpacity } = this.stroke;
|
|
224
|
-
ctx.strokeStyle = Util.colorStringToRgba(
|
|
225
|
-
color,
|
|
226
|
-
opacity === 1 ? sOpacity : opacity,
|
|
227
|
-
);
|
|
228
|
-
ctx.lineWidth = lineWidth;
|
|
229
|
-
xp += (lineWidth * 1.5);
|
|
230
|
-
yp += (lineWidth * 1.5);
|
|
231
|
-
w -= (lineWidth * 2);
|
|
232
|
-
h -= (lineWidth * 2);
|
|
233
|
-
}
|
|
234
|
-
this.drawItem(ctx, xp, yp, w, h);
|
|
235
|
-
ctx.restore();
|
|
236
|
-
|
|
237
|
-
item.xp = xp;
|
|
238
|
-
item.yp = yp;
|
|
239
|
-
item.w = w;
|
|
240
|
-
item.h = h;
|
|
241
|
-
|
|
242
|
-
if (this.showValue.use) {
|
|
243
|
-
this.drawValueLabels({
|
|
244
|
-
context: ctx,
|
|
245
|
-
data: item,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
if (isHighlight) {
|
|
249
|
-
this.itemHighlight({
|
|
250
|
-
data: item,
|
|
251
|
-
}, overlayCtx);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Draw value label if series 'use' of showValue option is true
|
|
260
|
-
*
|
|
261
|
-
* @param context canvas context
|
|
262
|
-
* @param data series value data (model.store.js addData return value)
|
|
263
|
-
*/
|
|
264
|
-
drawValueLabels({ context, data }) {
|
|
265
|
-
const { fontSize, textColor, align, formatter, decimalPoint } = this.showValue;
|
|
266
|
-
const { xp: x, yp: y, w, h, o: value } = data;
|
|
267
|
-
const ctx = context;
|
|
268
|
-
|
|
269
|
-
ctx.save();
|
|
270
|
-
ctx.beginPath();
|
|
271
|
-
|
|
272
|
-
ctx.font = `normal normal normal ${fontSize}px Roboto`;
|
|
273
|
-
ctx.fillStyle = textColor;
|
|
274
|
-
ctx.lineWidth = 1;
|
|
275
|
-
ctx.textBaseline = 'middle';
|
|
276
|
-
ctx.textAlign = align !== 'center' ? 'left' : 'center';
|
|
277
|
-
|
|
278
|
-
let formattedTxt;
|
|
279
|
-
if (formatter) {
|
|
280
|
-
formattedTxt = formatter(value);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (!formatter || typeof formattedTxt !== 'string') {
|
|
284
|
-
formattedTxt = Util.labelSignFormat(value, decimalPoint);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const vw = Math.round(ctx.measureText(formattedTxt).width);
|
|
288
|
-
const vh = fontSize;
|
|
289
|
-
const centerX = x + (w / 2);
|
|
290
|
-
const centerY = y + (h / 2);
|
|
291
|
-
|
|
292
|
-
if (vw >= w || vh >= h || formattedTxt < 0) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
switch (align) {
|
|
297
|
-
case 'top': {
|
|
298
|
-
const xPos = centerX - (vw / 2);
|
|
299
|
-
const yPos = centerY - (vh / 2);
|
|
300
|
-
ctx.fillText(formattedTxt, xPos, yPos);
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
case 'right': {
|
|
304
|
-
const xPos = x + w - vw;
|
|
305
|
-
ctx.fillText(formattedTxt, xPos, centerY);
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
case 'bottom': {
|
|
309
|
-
const xPos = centerX - (vw / 2);
|
|
310
|
-
const yPos = centerY + (vh / 2);
|
|
311
|
-
ctx.fillText(formattedTxt, xPos, yPos);
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
case 'left':
|
|
315
|
-
ctx.fillText(formattedTxt, x, centerY);
|
|
316
|
-
break;
|
|
317
|
-
default: {
|
|
318
|
-
const xPos = centerX - (vw / 2);
|
|
319
|
-
ctx.fillText(formattedTxt, xPos, centerY);
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
ctx.restore();
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
*Returns items in range
|
|
329
|
-
* @param {object} params range values
|
|
330
|
-
*
|
|
331
|
-
* @returns {array}
|
|
332
|
-
*/
|
|
333
|
-
findItems({ xsp, ysp, width, height }) {
|
|
334
|
-
const gdata = this.data;
|
|
335
|
-
const xep = xsp + width;
|
|
336
|
-
const yep = ysp + height;
|
|
337
|
-
return gdata.filter(({ xp, yp, w, h }) => {
|
|
338
|
-
const x1 = xp;
|
|
339
|
-
const x2 = xp + w;
|
|
340
|
-
const y1 = yp;
|
|
341
|
-
const y2 = yp + h;
|
|
342
|
-
|
|
343
|
-
return ((x1 >= xsp && x1 <= xep) && (y1 >= ysp && y1 <= yep))
|
|
344
|
-
|| ((x1 >= xsp && x1 <= xep) && (y2 >= ysp && y2 <= yep))
|
|
345
|
-
|| ((x2 >= xsp && x2 <= xep) && (y1 >= ysp && y1 <= yep))
|
|
346
|
-
|| ((x2 >= xsp && x2 <= xep) && (y2 >= ysp && y2 <= yep));
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Draw item highlight
|
|
352
|
-
* @param {object} item object for drawing series data
|
|
353
|
-
* @param {object} context canvas context
|
|
354
|
-
*
|
|
355
|
-
* @returns {undefined}
|
|
356
|
-
*/
|
|
357
|
-
itemHighlight(item, context) {
|
|
358
|
-
const gdata = item.data;
|
|
359
|
-
const ctx = context;
|
|
360
|
-
|
|
361
|
-
const x = gdata.xp;
|
|
362
|
-
const y = gdata.yp;
|
|
363
|
-
const w = gdata.w;
|
|
364
|
-
const h = gdata.h;
|
|
365
|
-
const cId = gdata.cId;
|
|
366
|
-
|
|
367
|
-
let isShow;
|
|
368
|
-
if (this.isGradient) {
|
|
369
|
-
const { min, max } = this.valueOpt;
|
|
370
|
-
const ratio = convertToPercent(gdata.o - min, max - min);
|
|
371
|
-
const { start, end } = this.colorState[0];
|
|
372
|
-
isShow = (start <= ratio && ratio <= end) || gdata.o === -1;
|
|
373
|
-
} else {
|
|
374
|
-
isShow = this.colorState.find(({ id }) => id === cId)?.show;
|
|
375
|
-
}
|
|
376
|
-
ctx.save();
|
|
377
|
-
ctx.shadowOffsetX = 2;
|
|
378
|
-
ctx.shadowOffsetY = 2;
|
|
379
|
-
ctx.shadowBlur = 4;
|
|
380
|
-
|
|
381
|
-
if (x !== null && y !== null && isShow) {
|
|
382
|
-
const color = gdata.dataColor;
|
|
383
|
-
ctx.shadowColor = Util.colorStringToRgba('#605F5F');
|
|
384
|
-
ctx.strokeStyle = Util.colorStringToRgba(color);
|
|
385
|
-
ctx.fillStyle = Util.colorStringToRgba(color);
|
|
386
|
-
this.drawItem(ctx, x - 2, y - 2, w + 4, h + 4);
|
|
387
|
-
|
|
388
|
-
ctx.restore();
|
|
389
|
-
|
|
390
|
-
if (this.showValue.use) {
|
|
391
|
-
this.drawValueLabels({
|
|
392
|
-
context: ctx,
|
|
393
|
-
data: gdata,
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Find graph item for tooltip
|
|
401
|
-
* @param {array} offset mouse position
|
|
402
|
-
*
|
|
403
|
-
* @returns {object} graph item
|
|
404
|
-
*/
|
|
405
|
-
findGraphData(offset) {
|
|
406
|
-
const xp = offset[0];
|
|
407
|
-
const yp = offset[1];
|
|
408
|
-
const item = {
|
|
409
|
-
data: null,
|
|
410
|
-
hit: false,
|
|
411
|
-
color: null,
|
|
412
|
-
name: null,
|
|
413
|
-
};
|
|
414
|
-
const gdata = this.data;
|
|
415
|
-
|
|
416
|
-
const foundItem = gdata.find((data) => {
|
|
417
|
-
const { xp: x, yp: y, w: wSize, h: hSize } = data;
|
|
418
|
-
|
|
419
|
-
return (x <= xp)
|
|
420
|
-
&& (xp <= x + wSize)
|
|
421
|
-
&& (y <= yp)
|
|
422
|
-
&& (yp <= y + hSize);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
if (foundItem) {
|
|
426
|
-
item.data = foundItem;
|
|
427
|
-
item.color = foundItem.dataColor;
|
|
428
|
-
item.hit = true;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
return item;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
findBlockRange({ xcp, xep, ycp, yep, range }) {
|
|
435
|
-
const labels = this.labels;
|
|
436
|
-
|
|
437
|
-
const blockRange = {
|
|
438
|
-
xsp: Math.min(xcp, xep),
|
|
439
|
-
ysp: Math.min(ycp, yep),
|
|
440
|
-
width: Math.ceil(Math.abs(xep - xcp)),
|
|
441
|
-
height: Math.ceil(Math.abs(yep - ycp)),
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
if (labels.x.length && labels.y.length) {
|
|
445
|
-
const { x1, x2, y1, y2 } = range;
|
|
446
|
-
const gapX = (x2 - x1) / labels.x.length;
|
|
447
|
-
const gapY = (y2 - y1) / labels.y.length;
|
|
448
|
-
|
|
449
|
-
const point = {
|
|
450
|
-
xsp: xcp,
|
|
451
|
-
xep,
|
|
452
|
-
ysp: ycp,
|
|
453
|
-
yep,
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
const setPoint = (dir, target, key) => {
|
|
457
|
-
let itemPoint;
|
|
458
|
-
let gap;
|
|
459
|
-
let startPoint;
|
|
460
|
-
|
|
461
|
-
if (dir === 'x') {
|
|
462
|
-
gap = gapX;
|
|
463
|
-
startPoint = x1;
|
|
464
|
-
} else {
|
|
465
|
-
gap = gapY;
|
|
466
|
-
startPoint = y1;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const findItem = labels[dir].findIndex((item, index) => {
|
|
470
|
-
itemPoint = Math.round(startPoint + (gap * index)) + Util.aliasPixel(1);
|
|
471
|
-
return itemPoint <= target && target <= itemPoint + gap;
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
if (findItem > -1) {
|
|
475
|
-
point[key] = ['xsp', 'ysp'].includes(key) ? itemPoint : itemPoint + gap;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
setPoint('x', Math.min(xcp, xep), 'xsp');
|
|
480
|
-
setPoint('x', Math.max(xcp, xep), 'xep');
|
|
481
|
-
setPoint('y', Math.min(ycp, yep), 'ysp');
|
|
482
|
-
setPoint('y', Math.max(ycp, yep), 'yep');
|
|
483
|
-
|
|
484
|
-
blockRange.xsp = Math.min(point.xsp, point.xep);
|
|
485
|
-
blockRange.ysp = Math.min(point.ysp, point.yep);
|
|
486
|
-
blockRange.width = Math.abs(point.xep - point.xsp);
|
|
487
|
-
blockRange.height = Math.abs(point.yep - point.ysp);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
return blockRange;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
findSelectionRange(rangeInfo) {
|
|
494
|
-
const { xcp, ycp, width, height, range } = rangeInfo;
|
|
495
|
-
|
|
496
|
-
let selectionRange = null;
|
|
497
|
-
|
|
498
|
-
const { x1, x2, y1, y2 } = range;
|
|
499
|
-
const { x: labelX, y: labelY } = this.labels;
|
|
500
|
-
|
|
501
|
-
if (labelX.length && labelY.length) {
|
|
502
|
-
const gapX = (x2 - x1) / labelX.length;
|
|
503
|
-
const gapY = (y2 - y1) / labelY.length;
|
|
504
|
-
|
|
505
|
-
const xsp = xcp;
|
|
506
|
-
const xep = xcp + width;
|
|
507
|
-
const ysp = ycp;
|
|
508
|
-
const yep = ycp + height;
|
|
509
|
-
|
|
510
|
-
const xIndex = {
|
|
511
|
-
min: Math.floor((xsp - x1) / gapX),
|
|
512
|
-
max: Math.floor((xep - x1 - gapX) / gapX),
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
const lastIndexY = labelY.length - 1;
|
|
516
|
-
const yIndex = {
|
|
517
|
-
min: lastIndexY - Math.floor((yep - y1 - gapY) / gapY),
|
|
518
|
-
max: lastIndexY - Math.floor((ysp - y1) / gapY),
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
selectionRange = {
|
|
522
|
-
xMin: labelX[xIndex.min],
|
|
523
|
-
xMax: labelX[xIndex.max],
|
|
524
|
-
yMin: labelY[yIndex.min],
|
|
525
|
-
yMax: labelY[yIndex.max],
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return selectionRange;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
export default HeatMap;
|
|
1
|
+
import { merge } from 'lodash-es';
|
|
2
|
+
import Util from '../helpers/helpers.util';
|
|
3
|
+
import { HEAT_MAP_OPTION } from '../helpers/helpers.constant';
|
|
4
|
+
import { convertToPercent } from '../../../common/utils';
|
|
5
|
+
|
|
6
|
+
class HeatMap {
|
|
7
|
+
constructor(sId, opt, colorOpt, isGradient) {
|
|
8
|
+
const merged = merge({}, HEAT_MAP_OPTION, opt);
|
|
9
|
+
Object.keys(merged).forEach((key) => {
|
|
10
|
+
this[key] = merged[key];
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
this.isGradient = isGradient;
|
|
14
|
+
this.createColorState(colorOpt);
|
|
15
|
+
|
|
16
|
+
this.sId = sId;
|
|
17
|
+
this.data = [];
|
|
18
|
+
this.labels = {
|
|
19
|
+
x: [],
|
|
20
|
+
y: [],
|
|
21
|
+
};
|
|
22
|
+
this.valueOpt = {};
|
|
23
|
+
this.size = {
|
|
24
|
+
w: 0,
|
|
25
|
+
h: 0,
|
|
26
|
+
};
|
|
27
|
+
this.type = 'heatMap';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* create series color axis
|
|
32
|
+
* @param colorOpt
|
|
33
|
+
* @returns {*[]}
|
|
34
|
+
*/
|
|
35
|
+
createColorState(colorOpt) {
|
|
36
|
+
const colorState = [];
|
|
37
|
+
const regex = /[^0-9]&[^,]/g;
|
|
38
|
+
const { min, max, categoryCnt, error, stroke } = colorOpt;
|
|
39
|
+
|
|
40
|
+
const minColor = min.includes('#') ? Util.hexToRgb(min) : min.replace(regex, '');
|
|
41
|
+
const maxColor = max.includes('#') ? Util.hexToRgb(max) : max.replace(regex, '');
|
|
42
|
+
|
|
43
|
+
const [minR, minG, minB] = minColor.split(',');
|
|
44
|
+
const [maxR, maxG, maxB] = maxColor.split(',');
|
|
45
|
+
|
|
46
|
+
if (this.isGradient) {
|
|
47
|
+
colorState.push({
|
|
48
|
+
minColor: { minR, minG, minB },
|
|
49
|
+
maxColor: { maxR, maxG, maxB },
|
|
50
|
+
categoryCnt,
|
|
51
|
+
start: 0,
|
|
52
|
+
end: 100,
|
|
53
|
+
selectedValue: null,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
const unitR = Math.floor((minR - maxR) / (categoryCnt - 1));
|
|
57
|
+
const unitG = Math.floor((minG - maxG) / (categoryCnt - 1));
|
|
58
|
+
const unitB = Math.floor((minB - maxB) / (categoryCnt - 1));
|
|
59
|
+
|
|
60
|
+
for (let ix = 0; ix < categoryCnt; ix++) {
|
|
61
|
+
const r = +minR - (unitR * ix);
|
|
62
|
+
const g = +minG - (unitG * ix);
|
|
63
|
+
const b = +minB - (unitB * ix);
|
|
64
|
+
|
|
65
|
+
colorState.push({
|
|
66
|
+
id: `color#${ix}`,
|
|
67
|
+
color: `rgb(${r},${g},${b})`,
|
|
68
|
+
state: 'normal',
|
|
69
|
+
show: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.colorState = colorState;
|
|
75
|
+
this.errorColor = error;
|
|
76
|
+
this.stroke = stroke;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getColorForGradient(value) {
|
|
80
|
+
const { minColor, maxColor } = this.colorState[0];
|
|
81
|
+
|
|
82
|
+
const { minR, minG, minB } = minColor;
|
|
83
|
+
const { maxR, maxG, maxB } = maxColor;
|
|
84
|
+
|
|
85
|
+
const r = +minR - Math.floor(((minR - maxR) * value) / 100);
|
|
86
|
+
const g = +minG - Math.floor(((minG - maxG) * value) / 100);
|
|
87
|
+
const b = +minB - Math.floor(((minB - maxB) * value) / 100);
|
|
88
|
+
|
|
89
|
+
return `rgb(${r},${g},${b})`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getColorIndexForIcon(value) {
|
|
93
|
+
const { existError, min, interval, decimalPoint } = this.valueOpt;
|
|
94
|
+
const maxIndex = this.colorState.length - 1;
|
|
95
|
+
if (existError && value < 0) {
|
|
96
|
+
return maxIndex;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const colorIndex = Math.floor(+(value - min).toFixed(decimalPoint) / interval);
|
|
100
|
+
|
|
101
|
+
if (colorIndex >= maxIndex) {
|
|
102
|
+
return existError ? maxIndex - 1 : maxIndex;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return colorIndex;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getItemInfo(value) {
|
|
109
|
+
const { min, max } = this.valueOpt;
|
|
110
|
+
const itemInfo = {
|
|
111
|
+
show: false,
|
|
112
|
+
opacity: 0,
|
|
113
|
+
dataColor: null,
|
|
114
|
+
id: null,
|
|
115
|
+
isHighlight: null,
|
|
116
|
+
};
|
|
117
|
+
if (this.isGradient) {
|
|
118
|
+
const ratio = convertToPercent(value - min, max - min);
|
|
119
|
+
const { start, end, selectedValue } = this.colorState[0];
|
|
120
|
+
if (value < 0 || (start <= ratio && ratio <= end)) {
|
|
121
|
+
itemInfo.show = true;
|
|
122
|
+
itemInfo.isHighlight = selectedValue !== null
|
|
123
|
+
&& (Math.floor(value) === Math.floor(min + ((max - min) * (selectedValue / 100))));
|
|
124
|
+
itemInfo.opacity = 1;
|
|
125
|
+
itemInfo.dataColor = value < 0
|
|
126
|
+
? this.errorColor : this.getColorForGradient(ratio);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
const colorIndex = this.getColorIndexForIcon(value);
|
|
130
|
+
const { show, state, color, id } = this.colorState[colorIndex];
|
|
131
|
+
itemInfo.show = show;
|
|
132
|
+
itemInfo.opacity = state === 'downplay' ? 0.1 : 1;
|
|
133
|
+
itemInfo.dataColor = value < 0 ? this.errorColor : color;
|
|
134
|
+
itemInfo.id = id;
|
|
135
|
+
}
|
|
136
|
+
return itemInfo;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
drawItem(ctx, x, y, w, h) {
|
|
140
|
+
ctx.beginPath();
|
|
141
|
+
if (this.stroke.show) {
|
|
142
|
+
const { radius } = this.stroke;
|
|
143
|
+
if (radius > 0 && radius < h && radius < w) {
|
|
144
|
+
ctx.moveTo(x + radius, y);
|
|
145
|
+
ctx.arcTo(x + w, y, x + w, y + h, radius);
|
|
146
|
+
ctx.arcTo(x + w, y + h, x, y + h, radius);
|
|
147
|
+
ctx.arcTo(x, y + h, x, y, radius);
|
|
148
|
+
ctx.arcTo(x, y, x + w, y, radius);
|
|
149
|
+
ctx.fill();
|
|
150
|
+
} else {
|
|
151
|
+
ctx.strokeRect(x, y, w, h);
|
|
152
|
+
ctx.fillRect(x, y, w, h);
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
const aliasPixel = Util.aliasPixel(1);
|
|
156
|
+
ctx.fillRect(
|
|
157
|
+
x,
|
|
158
|
+
y - aliasPixel,
|
|
159
|
+
w + aliasPixel,
|
|
160
|
+
h + aliasPixel,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
ctx.closePath();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
calculateXY(dir, value, startPoint) {
|
|
167
|
+
let point = null;
|
|
168
|
+
|
|
169
|
+
if (this.labels[dir] && this.labels[dir].length) {
|
|
170
|
+
const index = this.labels[dir].findIndex(label => label === value);
|
|
171
|
+
|
|
172
|
+
if (index > -1) {
|
|
173
|
+
point = dir === 'x'
|
|
174
|
+
? startPoint + (this.size.w * index)
|
|
175
|
+
: startPoint - (this.size.h * (index + 1));
|
|
176
|
+
} else {
|
|
177
|
+
const timeIndex = this.labels[dir].findIndex(label =>
|
|
178
|
+
new Date(label).getTime() === new Date(value).getTime(),
|
|
179
|
+
);
|
|
180
|
+
if (timeIndex > -1) {
|
|
181
|
+
point = dir === 'x'
|
|
182
|
+
? startPoint + (this.size.w * timeIndex)
|
|
183
|
+
: startPoint - (this.size.h * (timeIndex + 1));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return point;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
draw(param) {
|
|
192
|
+
if (!this.show) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const { ctx, chartRect, labelOffset, overlayCtx } = param;
|
|
197
|
+
|
|
198
|
+
const xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
|
|
199
|
+
const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
|
|
200
|
+
|
|
201
|
+
const xsp = chartRect.x1 + labelOffset.left;
|
|
202
|
+
const ysp = chartRect.y2 - labelOffset.bottom;
|
|
203
|
+
|
|
204
|
+
this.size.w = xArea / this.labels.x.length;
|
|
205
|
+
this.size.h = yArea / this.labels.y.length;
|
|
206
|
+
|
|
207
|
+
this.data.forEach((item) => {
|
|
208
|
+
let xp = this.calculateXY('x', item.x, xsp);
|
|
209
|
+
let yp = this.calculateXY('y', item.y, ysp);
|
|
210
|
+
let w = this.size.w;
|
|
211
|
+
let h = this.size.h;
|
|
212
|
+
const value = item.o;
|
|
213
|
+
|
|
214
|
+
if (xp !== null && yp !== null
|
|
215
|
+
&& (value !== null && value !== undefined)) {
|
|
216
|
+
const { show, opacity, dataColor, id, isHighlight } = this.getItemInfo(value);
|
|
217
|
+
item.dataColor = dataColor;
|
|
218
|
+
item.cId = id;
|
|
219
|
+
ctx.save();
|
|
220
|
+
if (show) {
|
|
221
|
+
ctx.fillStyle = Util.colorStringToRgba(item.dataColor, opacity);
|
|
222
|
+
if (this.stroke.show) {
|
|
223
|
+
const { color, lineWidth, opacity: sOpacity } = this.stroke;
|
|
224
|
+
ctx.strokeStyle = Util.colorStringToRgba(
|
|
225
|
+
color,
|
|
226
|
+
opacity === 1 ? sOpacity : opacity,
|
|
227
|
+
);
|
|
228
|
+
ctx.lineWidth = lineWidth;
|
|
229
|
+
xp += (lineWidth * 1.5);
|
|
230
|
+
yp += (lineWidth * 1.5);
|
|
231
|
+
w -= (lineWidth * 2);
|
|
232
|
+
h -= (lineWidth * 2);
|
|
233
|
+
}
|
|
234
|
+
this.drawItem(ctx, xp, yp, w, h);
|
|
235
|
+
ctx.restore();
|
|
236
|
+
|
|
237
|
+
item.xp = xp;
|
|
238
|
+
item.yp = yp;
|
|
239
|
+
item.w = w;
|
|
240
|
+
item.h = h;
|
|
241
|
+
|
|
242
|
+
if (this.showValue.use) {
|
|
243
|
+
this.drawValueLabels({
|
|
244
|
+
context: ctx,
|
|
245
|
+
data: item,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (isHighlight) {
|
|
249
|
+
this.itemHighlight({
|
|
250
|
+
data: item,
|
|
251
|
+
}, overlayCtx);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Draw value label if series 'use' of showValue option is true
|
|
260
|
+
*
|
|
261
|
+
* @param context canvas context
|
|
262
|
+
* @param data series value data (model.store.js addData return value)
|
|
263
|
+
*/
|
|
264
|
+
drawValueLabels({ context, data }) {
|
|
265
|
+
const { fontSize, textColor, align, formatter, decimalPoint } = this.showValue;
|
|
266
|
+
const { xp: x, yp: y, w, h, o: value } = data;
|
|
267
|
+
const ctx = context;
|
|
268
|
+
|
|
269
|
+
ctx.save();
|
|
270
|
+
ctx.beginPath();
|
|
271
|
+
|
|
272
|
+
ctx.font = `normal normal normal ${fontSize}px Roboto`;
|
|
273
|
+
ctx.fillStyle = textColor;
|
|
274
|
+
ctx.lineWidth = 1;
|
|
275
|
+
ctx.textBaseline = 'middle';
|
|
276
|
+
ctx.textAlign = align !== 'center' ? 'left' : 'center';
|
|
277
|
+
|
|
278
|
+
let formattedTxt;
|
|
279
|
+
if (formatter) {
|
|
280
|
+
formattedTxt = formatter(value);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (!formatter || typeof formattedTxt !== 'string') {
|
|
284
|
+
formattedTxt = Util.labelSignFormat(value, decimalPoint);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const vw = Math.round(ctx.measureText(formattedTxt).width);
|
|
288
|
+
const vh = fontSize;
|
|
289
|
+
const centerX = x + (w / 2);
|
|
290
|
+
const centerY = y + (h / 2);
|
|
291
|
+
|
|
292
|
+
if (vw >= w || vh >= h || formattedTxt < 0) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
switch (align) {
|
|
297
|
+
case 'top': {
|
|
298
|
+
const xPos = centerX - (vw / 2);
|
|
299
|
+
const yPos = centerY - (vh / 2);
|
|
300
|
+
ctx.fillText(formattedTxt, xPos, yPos);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case 'right': {
|
|
304
|
+
const xPos = x + w - vw;
|
|
305
|
+
ctx.fillText(formattedTxt, xPos, centerY);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case 'bottom': {
|
|
309
|
+
const xPos = centerX - (vw / 2);
|
|
310
|
+
const yPos = centerY + (vh / 2);
|
|
311
|
+
ctx.fillText(formattedTxt, xPos, yPos);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case 'left':
|
|
315
|
+
ctx.fillText(formattedTxt, x, centerY);
|
|
316
|
+
break;
|
|
317
|
+
default: {
|
|
318
|
+
const xPos = centerX - (vw / 2);
|
|
319
|
+
ctx.fillText(formattedTxt, xPos, centerY);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
ctx.restore();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
*Returns items in range
|
|
329
|
+
* @param {object} params range values
|
|
330
|
+
*
|
|
331
|
+
* @returns {array}
|
|
332
|
+
*/
|
|
333
|
+
findItems({ xsp, ysp, width, height }) {
|
|
334
|
+
const gdata = this.data;
|
|
335
|
+
const xep = xsp + width;
|
|
336
|
+
const yep = ysp + height;
|
|
337
|
+
return gdata.filter(({ xp, yp, w, h }) => {
|
|
338
|
+
const x1 = xp;
|
|
339
|
+
const x2 = xp + w;
|
|
340
|
+
const y1 = yp;
|
|
341
|
+
const y2 = yp + h;
|
|
342
|
+
|
|
343
|
+
return ((x1 >= xsp && x1 <= xep) && (y1 >= ysp && y1 <= yep))
|
|
344
|
+
|| ((x1 >= xsp && x1 <= xep) && (y2 >= ysp && y2 <= yep))
|
|
345
|
+
|| ((x2 >= xsp && x2 <= xep) && (y1 >= ysp && y1 <= yep))
|
|
346
|
+
|| ((x2 >= xsp && x2 <= xep) && (y2 >= ysp && y2 <= yep));
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Draw item highlight
|
|
352
|
+
* @param {object} item object for drawing series data
|
|
353
|
+
* @param {object} context canvas context
|
|
354
|
+
*
|
|
355
|
+
* @returns {undefined}
|
|
356
|
+
*/
|
|
357
|
+
itemHighlight(item, context) {
|
|
358
|
+
const gdata = item.data;
|
|
359
|
+
const ctx = context;
|
|
360
|
+
|
|
361
|
+
const x = gdata.xp;
|
|
362
|
+
const y = gdata.yp;
|
|
363
|
+
const w = gdata.w;
|
|
364
|
+
const h = gdata.h;
|
|
365
|
+
const cId = gdata.cId;
|
|
366
|
+
|
|
367
|
+
let isShow;
|
|
368
|
+
if (this.isGradient) {
|
|
369
|
+
const { min, max } = this.valueOpt;
|
|
370
|
+
const ratio = convertToPercent(gdata.o - min, max - min);
|
|
371
|
+
const { start, end } = this.colorState[0];
|
|
372
|
+
isShow = (start <= ratio && ratio <= end) || gdata.o === -1;
|
|
373
|
+
} else {
|
|
374
|
+
isShow = this.colorState.find(({ id }) => id === cId)?.show;
|
|
375
|
+
}
|
|
376
|
+
ctx.save();
|
|
377
|
+
ctx.shadowOffsetX = 2;
|
|
378
|
+
ctx.shadowOffsetY = 2;
|
|
379
|
+
ctx.shadowBlur = 4;
|
|
380
|
+
|
|
381
|
+
if (x !== null && y !== null && isShow) {
|
|
382
|
+
const color = gdata.dataColor;
|
|
383
|
+
ctx.shadowColor = Util.colorStringToRgba('#605F5F');
|
|
384
|
+
ctx.strokeStyle = Util.colorStringToRgba(color);
|
|
385
|
+
ctx.fillStyle = Util.colorStringToRgba(color);
|
|
386
|
+
this.drawItem(ctx, x - 2, y - 2, w + 4, h + 4);
|
|
387
|
+
|
|
388
|
+
ctx.restore();
|
|
389
|
+
|
|
390
|
+
if (this.showValue.use) {
|
|
391
|
+
this.drawValueLabels({
|
|
392
|
+
context: ctx,
|
|
393
|
+
data: gdata,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Find graph item for tooltip
|
|
401
|
+
* @param {array} offset mouse position
|
|
402
|
+
*
|
|
403
|
+
* @returns {object} graph item
|
|
404
|
+
*/
|
|
405
|
+
findGraphData(offset) {
|
|
406
|
+
const xp = offset[0];
|
|
407
|
+
const yp = offset[1];
|
|
408
|
+
const item = {
|
|
409
|
+
data: null,
|
|
410
|
+
hit: false,
|
|
411
|
+
color: null,
|
|
412
|
+
name: null,
|
|
413
|
+
};
|
|
414
|
+
const gdata = this.data;
|
|
415
|
+
|
|
416
|
+
const foundItem = gdata.find((data) => {
|
|
417
|
+
const { xp: x, yp: y, w: wSize, h: hSize } = data;
|
|
418
|
+
|
|
419
|
+
return (x <= xp)
|
|
420
|
+
&& (xp <= x + wSize)
|
|
421
|
+
&& (y <= yp)
|
|
422
|
+
&& (yp <= y + hSize);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
if (foundItem) {
|
|
426
|
+
item.data = foundItem;
|
|
427
|
+
item.color = foundItem.dataColor;
|
|
428
|
+
item.hit = true;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return item;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
findBlockRange({ xcp, xep, ycp, yep, range }) {
|
|
435
|
+
const labels = this.labels;
|
|
436
|
+
|
|
437
|
+
const blockRange = {
|
|
438
|
+
xsp: Math.min(xcp, xep),
|
|
439
|
+
ysp: Math.min(ycp, yep),
|
|
440
|
+
width: Math.ceil(Math.abs(xep - xcp)),
|
|
441
|
+
height: Math.ceil(Math.abs(yep - ycp)),
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
if (labels.x.length && labels.y.length) {
|
|
445
|
+
const { x1, x2, y1, y2 } = range;
|
|
446
|
+
const gapX = (x2 - x1) / labels.x.length;
|
|
447
|
+
const gapY = (y2 - y1) / labels.y.length;
|
|
448
|
+
|
|
449
|
+
const point = {
|
|
450
|
+
xsp: xcp,
|
|
451
|
+
xep,
|
|
452
|
+
ysp: ycp,
|
|
453
|
+
yep,
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const setPoint = (dir, target, key) => {
|
|
457
|
+
let itemPoint;
|
|
458
|
+
let gap;
|
|
459
|
+
let startPoint;
|
|
460
|
+
|
|
461
|
+
if (dir === 'x') {
|
|
462
|
+
gap = gapX;
|
|
463
|
+
startPoint = x1;
|
|
464
|
+
} else {
|
|
465
|
+
gap = gapY;
|
|
466
|
+
startPoint = y1;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const findItem = labels[dir].findIndex((item, index) => {
|
|
470
|
+
itemPoint = Math.round(startPoint + (gap * index)) + Util.aliasPixel(1);
|
|
471
|
+
return itemPoint <= target && target <= itemPoint + gap;
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
if (findItem > -1) {
|
|
475
|
+
point[key] = ['xsp', 'ysp'].includes(key) ? itemPoint : itemPoint + gap;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
setPoint('x', Math.min(xcp, xep), 'xsp');
|
|
480
|
+
setPoint('x', Math.max(xcp, xep), 'xep');
|
|
481
|
+
setPoint('y', Math.min(ycp, yep), 'ysp');
|
|
482
|
+
setPoint('y', Math.max(ycp, yep), 'yep');
|
|
483
|
+
|
|
484
|
+
blockRange.xsp = Math.min(point.xsp, point.xep);
|
|
485
|
+
blockRange.ysp = Math.min(point.ysp, point.yep);
|
|
486
|
+
blockRange.width = Math.abs(point.xep - point.xsp);
|
|
487
|
+
blockRange.height = Math.abs(point.yep - point.ysp);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return blockRange;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
findSelectionRange(rangeInfo) {
|
|
494
|
+
const { xcp, ycp, width, height, range } = rangeInfo;
|
|
495
|
+
|
|
496
|
+
let selectionRange = null;
|
|
497
|
+
|
|
498
|
+
const { x1, x2, y1, y2 } = range;
|
|
499
|
+
const { x: labelX, y: labelY } = this.labels;
|
|
500
|
+
|
|
501
|
+
if (labelX.length && labelY.length) {
|
|
502
|
+
const gapX = (x2 - x1) / labelX.length;
|
|
503
|
+
const gapY = (y2 - y1) / labelY.length;
|
|
504
|
+
|
|
505
|
+
const xsp = xcp;
|
|
506
|
+
const xep = xcp + width;
|
|
507
|
+
const ysp = ycp;
|
|
508
|
+
const yep = ycp + height;
|
|
509
|
+
|
|
510
|
+
const xIndex = {
|
|
511
|
+
min: Math.floor((xsp - x1) / gapX),
|
|
512
|
+
max: Math.floor((xep - x1 - gapX) / gapX),
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
const lastIndexY = labelY.length - 1;
|
|
516
|
+
const yIndex = {
|
|
517
|
+
min: lastIndexY - Math.floor((yep - y1 - gapY) / gapY),
|
|
518
|
+
max: lastIndexY - Math.floor((ysp - y1) / gapY),
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
selectionRange = {
|
|
522
|
+
xMin: labelX[xIndex.min],
|
|
523
|
+
xMax: labelX[xIndex.max],
|
|
524
|
+
yMin: labelY[yIndex.min],
|
|
525
|
+
yMax: labelY[yIndex.max],
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return selectionRange;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export default HeatMap;
|