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,339 +1,339 @@
|
|
|
1
|
-
import { defaultsDeep } from 'lodash-es';
|
|
2
|
-
import { COLOR, LINE_OPTION } from '../helpers/helpers.constant';
|
|
3
|
-
import Util from '../helpers/helpers.util';
|
|
4
|
-
import Canvas from '../helpers/helpers.canvas';
|
|
5
|
-
|
|
6
|
-
class Line {
|
|
7
|
-
constructor(sId, opt, sIdx) {
|
|
8
|
-
const merged = defaultsDeep({}, opt, LINE_OPTION);
|
|
9
|
-
Object.keys(merged).forEach((key) => {
|
|
10
|
-
this[key] = merged[key];
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
if (this.name === undefined) {
|
|
14
|
-
this.name = `series-${sIdx}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
['color', 'pointFill', 'fillColor'].forEach((colorProp) => {
|
|
18
|
-
if (this[colorProp] === undefined) {
|
|
19
|
-
this[colorProp] = colorProp === 'pointFill' ? this.color : COLOR[sIdx];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
this.type = 'line';
|
|
23
|
-
this.sId = sId;
|
|
24
|
-
this.extent = {
|
|
25
|
-
downplay: { opacity: 0.1, lineWidth: 1 },
|
|
26
|
-
normal: { opacity: 1, lineWidth: 1 },
|
|
27
|
-
highlight: { opacity: 1, lineWidth: 2 },
|
|
28
|
-
};
|
|
29
|
-
this.data = [];
|
|
30
|
-
this.size = {
|
|
31
|
-
comboOffset: 0,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Draw series data
|
|
37
|
-
* @param {object} param object for drawing series data
|
|
38
|
-
*
|
|
39
|
-
* @returns {undefined}
|
|
40
|
-
*/
|
|
41
|
-
draw(param) {
|
|
42
|
-
if (!this.show) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
ctx, chartRect,
|
|
48
|
-
labelOffset, axesSteps,
|
|
49
|
-
selectLabel, selectSeries, legendHitInfo,
|
|
50
|
-
} = param;
|
|
51
|
-
|
|
52
|
-
// about selectLabel
|
|
53
|
-
const selectLabelOption = selectLabel?.option;
|
|
54
|
-
const useSelectLabel = selectLabelOption?.use && selectLabelOption?.useSeriesOpacity;
|
|
55
|
-
const selectedLabelIndexList = selectLabel?.selected?.dataIndex ?? [];
|
|
56
|
-
|
|
57
|
-
// set Style
|
|
58
|
-
let extent;
|
|
59
|
-
if (legendHitInfo) {
|
|
60
|
-
extent = this.extent[legendHitInfo?.sId === this.sId ? 'highlight' : 'downplay'];
|
|
61
|
-
} else if (selectSeries?.option?.use && selectSeries?.selected?.seriesId?.length) {
|
|
62
|
-
const isSelectedSeries = selectSeries?.selected?.seriesId?.includes(this.sId);
|
|
63
|
-
extent = this.extent[isSelectedSeries ? 'highlight' : 'downplay'];
|
|
64
|
-
} else if (useSelectLabel && selectedLabelIndexList.length) {
|
|
65
|
-
extent = this.extent.downplay;
|
|
66
|
-
} else {
|
|
67
|
-
extent = this.extent.normal;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const getOpacity = colorStr => (colorStr.includes('rgba') ? Util.getOpacity(colorStr) : extent.opacity);
|
|
71
|
-
const mainColor = this.color;
|
|
72
|
-
const mainColorOpacity = getOpacity(mainColor);
|
|
73
|
-
const pointFillColor = this.pointFill;
|
|
74
|
-
const pointFillColorOpacity = getOpacity(pointFillColor);
|
|
75
|
-
const fillOpacity = getOpacity(mainColor) * this.fillOpacity;
|
|
76
|
-
const lineWidth = this.lineWidth * extent.lineWidth;
|
|
77
|
-
|
|
78
|
-
ctx.beginPath();
|
|
79
|
-
ctx.save();
|
|
80
|
-
ctx.lineJoin = 'round';
|
|
81
|
-
ctx.lineWidth = lineWidth;
|
|
82
|
-
ctx.strokeStyle = Util.colorStringToRgba(mainColor, mainColorOpacity);
|
|
83
|
-
|
|
84
|
-
if (this.fill) {
|
|
85
|
-
ctx.fillStyle = Util.colorStringToRgba(mainColor, fillOpacity);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let startFillIndex = 0;
|
|
89
|
-
const endPoint = chartRect.y2 - labelOffset.bottom;
|
|
90
|
-
|
|
91
|
-
let x;
|
|
92
|
-
let y;
|
|
93
|
-
let barAreaByCombo = 0;
|
|
94
|
-
|
|
95
|
-
const minmaxX = axesSteps.x[this.xAxisIndex];
|
|
96
|
-
const minmaxY = axesSteps.y[this.yAxisIndex];
|
|
97
|
-
|
|
98
|
-
let xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
|
|
99
|
-
const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
|
|
100
|
-
|
|
101
|
-
if (this.combo) {
|
|
102
|
-
barAreaByCombo = xArea / (this.data.length || 1);
|
|
103
|
-
xArea -= barAreaByCombo;
|
|
104
|
-
this.size.comboOffset = barAreaByCombo;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const xsp = chartRect.x1 + labelOffset.left + (barAreaByCombo / 2);
|
|
108
|
-
const ysp = chartRect.y2 - labelOffset.bottom;
|
|
109
|
-
|
|
110
|
-
const getXPos = val => Canvas.calculateX(val, minmaxX.graphMin, minmaxX.graphMax, xArea, xsp);
|
|
111
|
-
const getYPos = val => Canvas.calculateY(val, minmaxY.graphMin, minmaxY.graphMax, yArea, ysp);
|
|
112
|
-
|
|
113
|
-
// draw line
|
|
114
|
-
this.data.reduce((prev, curr, ix) => {
|
|
115
|
-
x = getXPos(curr.x);
|
|
116
|
-
y = getYPos(curr.y);
|
|
117
|
-
|
|
118
|
-
if (x !== null) {
|
|
119
|
-
x += Util.aliasPixel(x);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (ix === 0) {
|
|
123
|
-
ctx.moveTo(x, y);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const isNullValue = prev.y === null || curr.y === null || prev.x === null || curr.x === null;
|
|
127
|
-
if (isNullValue) {
|
|
128
|
-
ctx.moveTo(x, y);
|
|
129
|
-
} else {
|
|
130
|
-
ctx.lineTo(x, y);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
curr.xp = x; // eslint-disable-line
|
|
134
|
-
curr.yp = y; // eslint-disable-line
|
|
135
|
-
|
|
136
|
-
return curr;
|
|
137
|
-
}, this.data[0]);
|
|
138
|
-
|
|
139
|
-
ctx.stroke();
|
|
140
|
-
|
|
141
|
-
// draw fill
|
|
142
|
-
if (this.fill && this.data.length) {
|
|
143
|
-
ctx.beginPath();
|
|
144
|
-
|
|
145
|
-
ctx.fillStyle = Util.colorStringToRgba(mainColor, fillOpacity);
|
|
146
|
-
|
|
147
|
-
this.data.forEach((currData, ix) => {
|
|
148
|
-
const isEmptyPoint = data => data?.x === null || data?.y === null
|
|
149
|
-
|| data?.x === undefined || data?.y === undefined;
|
|
150
|
-
|
|
151
|
-
const nextData = this.data[ix + 1];
|
|
152
|
-
|
|
153
|
-
if (isEmptyPoint(currData)) {
|
|
154
|
-
startFillIndex = ix + 1;
|
|
155
|
-
|
|
156
|
-
if (!isEmptyPoint(nextData)) {
|
|
157
|
-
ctx.moveTo(nextData.xp, nextData.yp);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
ctx.lineTo(currData.xp, currData.yp);
|
|
164
|
-
|
|
165
|
-
if (isEmptyPoint(nextData)) {
|
|
166
|
-
for (let jx = ix; jx >= startFillIndex; jx--) {
|
|
167
|
-
const prevData = this.data[jx];
|
|
168
|
-
const xp = prevData.xp;
|
|
169
|
-
const bp = getYPos(prevData.b) ?? endPoint;
|
|
170
|
-
ctx.lineTo(xp, bp);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
ctx.closePath();
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
ctx.fill();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Draw points
|
|
181
|
-
if (this.point || useSelectLabel) {
|
|
182
|
-
ctx.strokeStyle = Util.colorStringToRgba(mainColor, mainColorOpacity);
|
|
183
|
-
const focusStyle = Util.colorStringToRgba(pointFillColor, 1);
|
|
184
|
-
const blurStyle = Util.colorStringToRgba(pointFillColor, pointFillColorOpacity);
|
|
185
|
-
|
|
186
|
-
this.data.forEach((curr, ix) => {
|
|
187
|
-
const isSelectedLabel = selectedLabelIndexList.includes(ix);
|
|
188
|
-
if (curr.xp === null || curr.yp === null) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.point || isSelectedLabel) {
|
|
193
|
-
ctx.fillStyle = isSelectedLabel && !legendHitInfo ? focusStyle : blurStyle;
|
|
194
|
-
Canvas.drawPoint(ctx, this.pointStyle, this.pointSize, curr.xp, curr.yp);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
ctx.restore();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Draw item highlight
|
|
204
|
-
* @param {object} item object for drawing series data
|
|
205
|
-
* @param {object} context canvas context
|
|
206
|
-
* @param {boolean} isMax determines if this series has max value
|
|
207
|
-
*
|
|
208
|
-
* @returns {undefined}
|
|
209
|
-
*/
|
|
210
|
-
itemHighlight(item, context) {
|
|
211
|
-
const gdata = item.data;
|
|
212
|
-
const ctx = context;
|
|
213
|
-
|
|
214
|
-
const x = gdata.xp;
|
|
215
|
-
const y = gdata.yp;
|
|
216
|
-
|
|
217
|
-
ctx.save();
|
|
218
|
-
if (x !== null && y !== null) {
|
|
219
|
-
ctx.strokeStyle = Util.colorStringToRgba(this.color, 0);
|
|
220
|
-
ctx.fillStyle = Util.colorStringToRgba(this.color, this.highlight.maxShadowOpacity);
|
|
221
|
-
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.maxShadowSize, x, y);
|
|
222
|
-
|
|
223
|
-
ctx.fillStyle = this.color;
|
|
224
|
-
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.maxSize, x, y);
|
|
225
|
-
|
|
226
|
-
ctx.fillStyle = '#fff';
|
|
227
|
-
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.defaultSize, x, y);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
ctx.restore();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Find graph item
|
|
235
|
-
* @param {array} offset mouse position
|
|
236
|
-
*
|
|
237
|
-
* @returns {object} graph item
|
|
238
|
-
*/
|
|
239
|
-
findGraphData(offset) {
|
|
240
|
-
const xp = offset[0];
|
|
241
|
-
const yp = offset[1];
|
|
242
|
-
const item = { data: null, hit: false, color: this.color };
|
|
243
|
-
const gdata = this.data;
|
|
244
|
-
|
|
245
|
-
let s = 0;
|
|
246
|
-
let e = gdata.length - 1;
|
|
247
|
-
|
|
248
|
-
while (s <= e) {
|
|
249
|
-
const m = Math.floor((s + e) / 2);
|
|
250
|
-
const x = gdata[m].xp;
|
|
251
|
-
const y = gdata[m].yp;
|
|
252
|
-
|
|
253
|
-
if ((x - 6 <= xp) && (xp <= x + 6)) {
|
|
254
|
-
item.data = gdata[m];
|
|
255
|
-
item.index = m;
|
|
256
|
-
|
|
257
|
-
if ((y - 6 <= yp) && (yp <= y + 6)) {
|
|
258
|
-
item.hit = true;
|
|
259
|
-
}
|
|
260
|
-
return item;
|
|
261
|
-
} else if (x + 6 < xp) {
|
|
262
|
-
s = m + 1;
|
|
263
|
-
} else {
|
|
264
|
-
e = m - 1;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return item;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Find approximate graph item
|
|
273
|
-
* @param {array} offset mouse position
|
|
274
|
-
*
|
|
275
|
-
* @returns {object} graph item
|
|
276
|
-
*/
|
|
277
|
-
findApproximateData(offset) {
|
|
278
|
-
const xp = offset[0];
|
|
279
|
-
const yp = offset[1];
|
|
280
|
-
const item = { data: null, hit: false, color: this.color };
|
|
281
|
-
const gdata = this.data;
|
|
282
|
-
|
|
283
|
-
let s = 0;
|
|
284
|
-
let e = gdata.length - 1;
|
|
285
|
-
|
|
286
|
-
while (s <= e) {
|
|
287
|
-
const m = Math.floor((s + e) / 2);
|
|
288
|
-
const x = gdata[m].xp;
|
|
289
|
-
const y = gdata[m].yp;
|
|
290
|
-
|
|
291
|
-
if ((x - 2 <= xp) && (xp <= x + 2)) {
|
|
292
|
-
item.data = gdata[m];
|
|
293
|
-
item.index = m;
|
|
294
|
-
|
|
295
|
-
if ((y - 2 <= yp) && (yp <= y + 2)) {
|
|
296
|
-
item.hit = true;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return item;
|
|
300
|
-
} else if (x + 2 < xp) {
|
|
301
|
-
if (m < e && xp < gdata[m + 1].xp) {
|
|
302
|
-
const curr = Math.abs(gdata[m].xp - xp);
|
|
303
|
-
const next = Math.abs(gdata[m + 1].xp - xp);
|
|
304
|
-
|
|
305
|
-
item.data = curr > next ? gdata[m + 1] : gdata[m];
|
|
306
|
-
item.index = curr > next ? m + 1 : m;
|
|
307
|
-
return item;
|
|
308
|
-
}
|
|
309
|
-
s = m + 1;
|
|
310
|
-
} else {
|
|
311
|
-
if (m > 0 && xp > gdata[m - 1].xp) {
|
|
312
|
-
const prev = Math.abs(gdata[m - 1].xp - xp);
|
|
313
|
-
const curr = Math.abs(gdata[m].xp - xp);
|
|
314
|
-
|
|
315
|
-
item.data = prev > curr ? gdata[m] : gdata[m - 1];
|
|
316
|
-
item.index = prev > curr ? m : m - 1;
|
|
317
|
-
return item;
|
|
318
|
-
}
|
|
319
|
-
e = m - 1;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return item;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Returns items in range
|
|
328
|
-
* @param {object} params range values
|
|
329
|
-
*
|
|
330
|
-
* @returns {array}
|
|
331
|
-
*/
|
|
332
|
-
findItems({ xsp, width }) {
|
|
333
|
-
const xep = xsp + width;
|
|
334
|
-
|
|
335
|
-
return this.data.filter(seriesData => (xsp - 1 <= seriesData.xp) && (seriesData.xp <= xep + 1));
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
export default Line;
|
|
1
|
+
import { defaultsDeep } from 'lodash-es';
|
|
2
|
+
import { COLOR, LINE_OPTION } from '../helpers/helpers.constant';
|
|
3
|
+
import Util from '../helpers/helpers.util';
|
|
4
|
+
import Canvas from '../helpers/helpers.canvas';
|
|
5
|
+
|
|
6
|
+
class Line {
|
|
7
|
+
constructor(sId, opt, sIdx) {
|
|
8
|
+
const merged = defaultsDeep({}, opt, LINE_OPTION);
|
|
9
|
+
Object.keys(merged).forEach((key) => {
|
|
10
|
+
this[key] = merged[key];
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (this.name === undefined) {
|
|
14
|
+
this.name = `series-${sIdx}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
['color', 'pointFill', 'fillColor'].forEach((colorProp) => {
|
|
18
|
+
if (this[colorProp] === undefined) {
|
|
19
|
+
this[colorProp] = colorProp === 'pointFill' ? this.color : COLOR[sIdx];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
this.type = 'line';
|
|
23
|
+
this.sId = sId;
|
|
24
|
+
this.extent = {
|
|
25
|
+
downplay: { opacity: 0.1, lineWidth: 1 },
|
|
26
|
+
normal: { opacity: 1, lineWidth: 1 },
|
|
27
|
+
highlight: { opacity: 1, lineWidth: 2 },
|
|
28
|
+
};
|
|
29
|
+
this.data = [];
|
|
30
|
+
this.size = {
|
|
31
|
+
comboOffset: 0,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Draw series data
|
|
37
|
+
* @param {object} param object for drawing series data
|
|
38
|
+
*
|
|
39
|
+
* @returns {undefined}
|
|
40
|
+
*/
|
|
41
|
+
draw(param) {
|
|
42
|
+
if (!this.show) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
ctx, chartRect,
|
|
48
|
+
labelOffset, axesSteps,
|
|
49
|
+
selectLabel, selectSeries, legendHitInfo,
|
|
50
|
+
} = param;
|
|
51
|
+
|
|
52
|
+
// about selectLabel
|
|
53
|
+
const selectLabelOption = selectLabel?.option;
|
|
54
|
+
const useSelectLabel = selectLabelOption?.use && selectLabelOption?.useSeriesOpacity;
|
|
55
|
+
const selectedLabelIndexList = selectLabel?.selected?.dataIndex ?? [];
|
|
56
|
+
|
|
57
|
+
// set Style
|
|
58
|
+
let extent;
|
|
59
|
+
if (legendHitInfo) {
|
|
60
|
+
extent = this.extent[legendHitInfo?.sId === this.sId ? 'highlight' : 'downplay'];
|
|
61
|
+
} else if (selectSeries?.option?.use && selectSeries?.selected?.seriesId?.length) {
|
|
62
|
+
const isSelectedSeries = selectSeries?.selected?.seriesId?.includes(this.sId);
|
|
63
|
+
extent = this.extent[isSelectedSeries ? 'highlight' : 'downplay'];
|
|
64
|
+
} else if (useSelectLabel && selectedLabelIndexList.length) {
|
|
65
|
+
extent = this.extent.downplay;
|
|
66
|
+
} else {
|
|
67
|
+
extent = this.extent.normal;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const getOpacity = colorStr => (colorStr.includes('rgba') ? Util.getOpacity(colorStr) : extent.opacity);
|
|
71
|
+
const mainColor = this.color;
|
|
72
|
+
const mainColorOpacity = getOpacity(mainColor);
|
|
73
|
+
const pointFillColor = this.pointFill;
|
|
74
|
+
const pointFillColorOpacity = getOpacity(pointFillColor);
|
|
75
|
+
const fillOpacity = getOpacity(mainColor) * this.fillOpacity;
|
|
76
|
+
const lineWidth = this.lineWidth * extent.lineWidth;
|
|
77
|
+
|
|
78
|
+
ctx.beginPath();
|
|
79
|
+
ctx.save();
|
|
80
|
+
ctx.lineJoin = 'round';
|
|
81
|
+
ctx.lineWidth = lineWidth;
|
|
82
|
+
ctx.strokeStyle = Util.colorStringToRgba(mainColor, mainColorOpacity);
|
|
83
|
+
|
|
84
|
+
if (this.fill) {
|
|
85
|
+
ctx.fillStyle = Util.colorStringToRgba(mainColor, fillOpacity);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let startFillIndex = 0;
|
|
89
|
+
const endPoint = chartRect.y2 - labelOffset.bottom;
|
|
90
|
+
|
|
91
|
+
let x;
|
|
92
|
+
let y;
|
|
93
|
+
let barAreaByCombo = 0;
|
|
94
|
+
|
|
95
|
+
const minmaxX = axesSteps.x[this.xAxisIndex];
|
|
96
|
+
const minmaxY = axesSteps.y[this.yAxisIndex];
|
|
97
|
+
|
|
98
|
+
let xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
|
|
99
|
+
const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
|
|
100
|
+
|
|
101
|
+
if (this.combo) {
|
|
102
|
+
barAreaByCombo = xArea / (this.data.length || 1);
|
|
103
|
+
xArea -= barAreaByCombo;
|
|
104
|
+
this.size.comboOffset = barAreaByCombo;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const xsp = chartRect.x1 + labelOffset.left + (barAreaByCombo / 2);
|
|
108
|
+
const ysp = chartRect.y2 - labelOffset.bottom;
|
|
109
|
+
|
|
110
|
+
const getXPos = val => Canvas.calculateX(val, minmaxX.graphMin, minmaxX.graphMax, xArea, xsp);
|
|
111
|
+
const getYPos = val => Canvas.calculateY(val, minmaxY.graphMin, minmaxY.graphMax, yArea, ysp);
|
|
112
|
+
|
|
113
|
+
// draw line
|
|
114
|
+
this.data.reduce((prev, curr, ix) => {
|
|
115
|
+
x = getXPos(curr.x);
|
|
116
|
+
y = getYPos(curr.y);
|
|
117
|
+
|
|
118
|
+
if (x !== null) {
|
|
119
|
+
x += Util.aliasPixel(x);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (ix === 0) {
|
|
123
|
+
ctx.moveTo(x, y);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const isNullValue = prev.y === null || curr.y === null || prev.x === null || curr.x === null;
|
|
127
|
+
if (isNullValue) {
|
|
128
|
+
ctx.moveTo(x, y);
|
|
129
|
+
} else {
|
|
130
|
+
ctx.lineTo(x, y);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
curr.xp = x; // eslint-disable-line
|
|
134
|
+
curr.yp = y; // eslint-disable-line
|
|
135
|
+
|
|
136
|
+
return curr;
|
|
137
|
+
}, this.data[0]);
|
|
138
|
+
|
|
139
|
+
ctx.stroke();
|
|
140
|
+
|
|
141
|
+
// draw fill
|
|
142
|
+
if (this.fill && this.data.length) {
|
|
143
|
+
ctx.beginPath();
|
|
144
|
+
|
|
145
|
+
ctx.fillStyle = Util.colorStringToRgba(mainColor, fillOpacity);
|
|
146
|
+
|
|
147
|
+
this.data.forEach((currData, ix) => {
|
|
148
|
+
const isEmptyPoint = data => data?.x === null || data?.y === null
|
|
149
|
+
|| data?.x === undefined || data?.y === undefined;
|
|
150
|
+
|
|
151
|
+
const nextData = this.data[ix + 1];
|
|
152
|
+
|
|
153
|
+
if (isEmptyPoint(currData)) {
|
|
154
|
+
startFillIndex = ix + 1;
|
|
155
|
+
|
|
156
|
+
if (!isEmptyPoint(nextData)) {
|
|
157
|
+
ctx.moveTo(nextData.xp, nextData.yp);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
ctx.lineTo(currData.xp, currData.yp);
|
|
164
|
+
|
|
165
|
+
if (isEmptyPoint(nextData)) {
|
|
166
|
+
for (let jx = ix; jx >= startFillIndex; jx--) {
|
|
167
|
+
const prevData = this.data[jx];
|
|
168
|
+
const xp = prevData.xp;
|
|
169
|
+
const bp = getYPos(prevData.b) ?? endPoint;
|
|
170
|
+
ctx.lineTo(xp, bp);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
ctx.closePath();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
ctx.fill();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Draw points
|
|
181
|
+
if (this.point || useSelectLabel) {
|
|
182
|
+
ctx.strokeStyle = Util.colorStringToRgba(mainColor, mainColorOpacity);
|
|
183
|
+
const focusStyle = Util.colorStringToRgba(pointFillColor, 1);
|
|
184
|
+
const blurStyle = Util.colorStringToRgba(pointFillColor, pointFillColorOpacity);
|
|
185
|
+
|
|
186
|
+
this.data.forEach((curr, ix) => {
|
|
187
|
+
const isSelectedLabel = selectedLabelIndexList.includes(ix);
|
|
188
|
+
if (curr.xp === null || curr.yp === null) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (this.point || isSelectedLabel) {
|
|
193
|
+
ctx.fillStyle = isSelectedLabel && !legendHitInfo ? focusStyle : blurStyle;
|
|
194
|
+
Canvas.drawPoint(ctx, this.pointStyle, this.pointSize, curr.xp, curr.yp);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
ctx.restore();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Draw item highlight
|
|
204
|
+
* @param {object} item object for drawing series data
|
|
205
|
+
* @param {object} context canvas context
|
|
206
|
+
* @param {boolean} isMax determines if this series has max value
|
|
207
|
+
*
|
|
208
|
+
* @returns {undefined}
|
|
209
|
+
*/
|
|
210
|
+
itemHighlight(item, context) {
|
|
211
|
+
const gdata = item.data;
|
|
212
|
+
const ctx = context;
|
|
213
|
+
|
|
214
|
+
const x = gdata.xp;
|
|
215
|
+
const y = gdata.yp;
|
|
216
|
+
|
|
217
|
+
ctx.save();
|
|
218
|
+
if (x !== null && y !== null) {
|
|
219
|
+
ctx.strokeStyle = Util.colorStringToRgba(this.color, 0);
|
|
220
|
+
ctx.fillStyle = Util.colorStringToRgba(this.color, this.highlight.maxShadowOpacity);
|
|
221
|
+
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.maxShadowSize, x, y);
|
|
222
|
+
|
|
223
|
+
ctx.fillStyle = this.color;
|
|
224
|
+
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.maxSize, x, y);
|
|
225
|
+
|
|
226
|
+
ctx.fillStyle = '#fff';
|
|
227
|
+
Canvas.drawPoint(ctx, this.pointStyle, this.highlight.defaultSize, x, y);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
ctx.restore();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Find graph item
|
|
235
|
+
* @param {array} offset mouse position
|
|
236
|
+
*
|
|
237
|
+
* @returns {object} graph item
|
|
238
|
+
*/
|
|
239
|
+
findGraphData(offset) {
|
|
240
|
+
const xp = offset[0];
|
|
241
|
+
const yp = offset[1];
|
|
242
|
+
const item = { data: null, hit: false, color: this.color };
|
|
243
|
+
const gdata = this.data;
|
|
244
|
+
|
|
245
|
+
let s = 0;
|
|
246
|
+
let e = gdata.length - 1;
|
|
247
|
+
|
|
248
|
+
while (s <= e) {
|
|
249
|
+
const m = Math.floor((s + e) / 2);
|
|
250
|
+
const x = gdata[m].xp;
|
|
251
|
+
const y = gdata[m].yp;
|
|
252
|
+
|
|
253
|
+
if ((x - 6 <= xp) && (xp <= x + 6)) {
|
|
254
|
+
item.data = gdata[m];
|
|
255
|
+
item.index = m;
|
|
256
|
+
|
|
257
|
+
if ((y - 6 <= yp) && (yp <= y + 6)) {
|
|
258
|
+
item.hit = true;
|
|
259
|
+
}
|
|
260
|
+
return item;
|
|
261
|
+
} else if (x + 6 < xp) {
|
|
262
|
+
s = m + 1;
|
|
263
|
+
} else {
|
|
264
|
+
e = m - 1;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return item;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Find approximate graph item
|
|
273
|
+
* @param {array} offset mouse position
|
|
274
|
+
*
|
|
275
|
+
* @returns {object} graph item
|
|
276
|
+
*/
|
|
277
|
+
findApproximateData(offset) {
|
|
278
|
+
const xp = offset[0];
|
|
279
|
+
const yp = offset[1];
|
|
280
|
+
const item = { data: null, hit: false, color: this.color };
|
|
281
|
+
const gdata = this.data;
|
|
282
|
+
|
|
283
|
+
let s = 0;
|
|
284
|
+
let e = gdata.length - 1;
|
|
285
|
+
|
|
286
|
+
while (s <= e) {
|
|
287
|
+
const m = Math.floor((s + e) / 2);
|
|
288
|
+
const x = gdata[m].xp;
|
|
289
|
+
const y = gdata[m].yp;
|
|
290
|
+
|
|
291
|
+
if ((x - 2 <= xp) && (xp <= x + 2)) {
|
|
292
|
+
item.data = gdata[m];
|
|
293
|
+
item.index = m;
|
|
294
|
+
|
|
295
|
+
if ((y - 2 <= yp) && (yp <= y + 2)) {
|
|
296
|
+
item.hit = true;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return item;
|
|
300
|
+
} else if (x + 2 < xp) {
|
|
301
|
+
if (m < e && xp < gdata[m + 1].xp) {
|
|
302
|
+
const curr = Math.abs(gdata[m].xp - xp);
|
|
303
|
+
const next = Math.abs(gdata[m + 1].xp - xp);
|
|
304
|
+
|
|
305
|
+
item.data = curr > next ? gdata[m + 1] : gdata[m];
|
|
306
|
+
item.index = curr > next ? m + 1 : m;
|
|
307
|
+
return item;
|
|
308
|
+
}
|
|
309
|
+
s = m + 1;
|
|
310
|
+
} else {
|
|
311
|
+
if (m > 0 && xp > gdata[m - 1].xp) {
|
|
312
|
+
const prev = Math.abs(gdata[m - 1].xp - xp);
|
|
313
|
+
const curr = Math.abs(gdata[m].xp - xp);
|
|
314
|
+
|
|
315
|
+
item.data = prev > curr ? gdata[m] : gdata[m - 1];
|
|
316
|
+
item.index = prev > curr ? m : m - 1;
|
|
317
|
+
return item;
|
|
318
|
+
}
|
|
319
|
+
e = m - 1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return item;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Returns items in range
|
|
328
|
+
* @param {object} params range values
|
|
329
|
+
*
|
|
330
|
+
* @returns {array}
|
|
331
|
+
*/
|
|
332
|
+
findItems({ xsp, width }) {
|
|
333
|
+
const xep = xsp + width;
|
|
334
|
+
|
|
335
|
+
return this.data.filter(seriesData => (xsp - 1 <= seriesData.xp) && (seriesData.xp <= xep + 1));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export default Line;
|