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.
Files changed (141) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +40 -40
  3. package/dist/evui.common.js +1907 -1832
  4. package/dist/evui.common.js.map +1 -1
  5. package/dist/evui.umd.js +1907 -1832
  6. package/dist/evui.umd.js.map +1 -1
  7. package/dist/evui.umd.min.js +1 -1
  8. package/dist/evui.umd.min.js.map +1 -1
  9. package/dist/img/{EVUI.7f3588fb.svg → EVUI.b82ee81a.svg} +292 -292
  10. package/dist/img/{icon_mysql.7ea26d5d.svg → icon_mysql.1085fdc9.svg} +78 -78
  11. package/dist/img/{icon_oracle.9009b108.svg → icon_oracle.0572d3ee.svg} +13 -13
  12. package/dist/img/{icon_postgresql.f8fffba9.svg → icon_postgresql.ee12bde8.svg} +58 -58
  13. package/package.json +61 -61
  14. package/src/common/emitter.js +20 -20
  15. package/src/common/utils.debounce.js +223 -223
  16. package/src/common/utils.js +134 -134
  17. package/src/common/utils.table.js +78 -78
  18. package/src/common/utils.throttle.js +83 -83
  19. package/src/common/utils.tree.js +18 -18
  20. package/src/components/button/Button.vue +198 -198
  21. package/src/components/button/index.js +7 -7
  22. package/src/components/buttonGroup/ButtonGroup.vue +11 -11
  23. package/src/components/buttonGroup/index.js +7 -7
  24. package/src/components/calendar/Calendar.vue +661 -661
  25. package/src/components/calendar/index.js +7 -7
  26. package/src/components/calendar/uses.js +1272 -1272
  27. package/src/components/chart/Chart.vue +189 -192
  28. package/src/components/chart/chart.core.js +870 -870
  29. package/src/components/chart/element/element.bar.js +524 -524
  30. package/src/components/chart/element/element.bar.time.js +156 -156
  31. package/src/components/chart/element/element.heatmap.js +533 -533
  32. package/src/components/chart/element/element.line.js +339 -339
  33. package/src/components/chart/element/element.pie.js +197 -197
  34. package/src/components/chart/element/element.scatter.js +184 -184
  35. package/src/components/chart/element/element.tip.js +550 -542
  36. package/src/components/chart/helpers/helpers.canvas.js +265 -265
  37. package/src/components/chart/helpers/helpers.constant.js +206 -206
  38. package/src/components/chart/helpers/helpers.util.js +346 -338
  39. package/src/components/chart/index.js +9 -9
  40. package/src/components/chart/model/index.js +4 -4
  41. package/src/components/chart/model/model.series.js +93 -93
  42. package/src/components/chart/model/model.store.js +977 -967
  43. package/src/components/chart/plugins/plugins.interaction.js +769 -769
  44. package/src/components/chart/plugins/plugins.legend.gradient.js +602 -602
  45. package/src/components/chart/plugins/plugins.legend.js +1155 -1151
  46. package/src/components/chart/plugins/plugins.pie.js +254 -254
  47. package/src/components/chart/plugins/plugins.title.js +56 -56
  48. package/src/components/chart/plugins/plugins.tooltip.js +692 -692
  49. package/src/components/chart/scale/scale.js +848 -848
  50. package/src/components/chart/scale/scale.linear.js +38 -38
  51. package/src/components/chart/scale/scale.logarithmic.js +128 -128
  52. package/src/components/chart/scale/scale.step.js +336 -336
  53. package/src/components/chart/scale/scale.time.category.js +277 -277
  54. package/src/components/chart/scale/scale.time.js +48 -48
  55. package/src/components/chart/style/chart.scss +312 -312
  56. package/src/components/chart/uses.js +264 -252
  57. package/src/components/checkbox/Checkbox.vue +200 -200
  58. package/src/components/checkbox/index.js +7 -7
  59. package/src/components/checkboxGroup/CheckboxGroup.vue +44 -44
  60. package/src/components/checkboxGroup/index.js +7 -7
  61. package/src/components/contextMenu/ContextMenu.vue +80 -80
  62. package/src/components/contextMenu/MenuList.vue +149 -149
  63. package/src/components/contextMenu/index.js +7 -7
  64. package/src/components/contextMenu/uses.js +203 -203
  65. package/src/components/datePicker/DatePicker.vue +437 -437
  66. package/src/components/datePicker/index.js +7 -7
  67. package/src/components/datePicker/uses.js +419 -419
  68. package/src/components/grid/Grid.vue +827 -827
  69. package/src/components/grid/grid.filter.window.vue +493 -493
  70. package/src/components/grid/grid.pagination.vue +75 -75
  71. package/src/components/grid/grid.summary.vue +265 -265
  72. package/src/components/grid/grid.toolbar.vue +26 -26
  73. package/src/components/grid/index.js +11 -11
  74. package/src/components/grid/style/grid.scss +263 -263
  75. package/src/components/grid/uses.js +1002 -1007
  76. package/src/components/icon/Icon.vue +49 -49
  77. package/src/components/icon/index.js +8 -8
  78. package/src/components/inputNumber/InputNumber.vue +212 -212
  79. package/src/components/inputNumber/index.js +7 -7
  80. package/src/components/inputNumber/uses.js +217 -217
  81. package/src/components/loading/Loading.vue +125 -125
  82. package/src/components/loading/index.js +7 -7
  83. package/src/components/menu/Menu.vue +68 -68
  84. package/src/components/menu/MenuItem.vue +187 -187
  85. package/src/components/menu/index.js +7 -7
  86. package/src/components/message/Message.vue +223 -223
  87. package/src/components/message/index.js +31 -31
  88. package/src/components/messageBox/MessageBox.vue +358 -358
  89. package/src/components/messageBox/index.js +22 -22
  90. package/src/components/notification/Notification.vue +316 -316
  91. package/src/components/notification/index.js +49 -49
  92. package/src/components/pagination/Pagination.vue +271 -271
  93. package/src/components/pagination/index.js +7 -7
  94. package/src/components/pagination/pageButton.vue +30 -30
  95. package/src/components/progress/Progress.vue +139 -139
  96. package/src/components/progress/index.js +7 -7
  97. package/src/components/radio/Radio.vue +159 -159
  98. package/src/components/radio/index.js +7 -7
  99. package/src/components/radioGroup/RadioGroup.vue +41 -41
  100. package/src/components/radioGroup/index.js +7 -7
  101. package/src/components/scheduler/Scheduler.vue +149 -149
  102. package/src/components/scheduler/index.js +7 -7
  103. package/src/components/scheduler/uses.js +183 -183
  104. package/src/components/select/Select.vue +440 -440
  105. package/src/components/select/index.js +7 -7
  106. package/src/components/select/uses.js +270 -270
  107. package/src/components/slider/Slider.vue +505 -505
  108. package/src/components/slider/index.js +7 -7
  109. package/src/components/slider/uses.js +390 -390
  110. package/src/components/tabPanel/TabPanel.vue +74 -74
  111. package/src/components/tabPanel/index.js +7 -7
  112. package/src/components/tabs/Tabs.vue +517 -517
  113. package/src/components/tabs/index.js +7 -7
  114. package/src/components/textField/TextField.vue +375 -375
  115. package/src/components/textField/index.js +7 -7
  116. package/src/components/timePicker/TimePicker.vue +352 -352
  117. package/src/components/timePicker/index.js +7 -7
  118. package/src/components/toggle/Toggle.vue +115 -115
  119. package/src/components/toggle/index.js +7 -7
  120. package/src/components/tree/Tree.vue +313 -313
  121. package/src/components/tree/TreeNode.vue +293 -293
  122. package/src/components/tree/index.js +7 -7
  123. package/src/components/treeGrid/TreeGrid.vue +758 -758
  124. package/src/components/treeGrid/TreeGridNode.vue +275 -275
  125. package/src/components/treeGrid/index.js +9 -9
  126. package/src/components/treeGrid/style/treeGrid.scss +261 -261
  127. package/src/components/treeGrid/treeGrid.toolbar.vue +26 -26
  128. package/src/components/treeGrid/uses.js +867 -867
  129. package/src/components/window/Window.vue +329 -329
  130. package/src/components/window/index.js +7 -7
  131. package/src/components/window/uses.js +899 -899
  132. package/src/directives/clickoutside.js +90 -90
  133. package/src/main.js +116 -116
  134. package/src/style/components/input.scss +108 -108
  135. package/src/style/functions.scss +3 -3
  136. package/src/style/index.scss +6 -6
  137. package/src/style/lib/fonts/EVUI.svg +292 -292
  138. package/src/style/lib/icon.css +888 -888
  139. package/src/style/mixins.scss +94 -94
  140. package/src/style/themes.scss +67 -67
  141. package/src/style/variables.scss +22 -22
@@ -1,602 +1,602 @@
1
- import { convertToPercent } from '../../../common/utils';
2
-
3
- const MAX_HANDLE_SIZE = 28;
4
-
5
- const MIN_BOX_SIZE = {
6
- width: 70,
7
- height: 60,
8
- };
9
-
10
- const modules = {
11
- /**
12
- * Create legend DOM
13
- *
14
- * @returns {undefined}
15
- */
16
- createLegendLayout() {
17
- this.legendDOM = document.createElement('div');
18
- this.legendDOM.className = 'ev-chart-legend';
19
- this.legendBoxDOM = document.createElement('div');
20
- this.legendBoxDOM.className = 'ev-chart-legend-box';
21
- this.containerDOM = document.createElement('div');
22
- this.containerDOM.className = 'ev-chart-legend-container';
23
-
24
- this.legendBoxDOM.appendChild(this.containerDOM);
25
- this.legendDOM.appendChild(this.legendBoxDOM);
26
- this.wrapperDOM.appendChild(this.legendDOM);
27
- },
28
-
29
- /**
30
- * Initialize legend
31
- * If there was no initialization, create DOM and set default layout.
32
- * It not, there will already be set layout, so add a legend for each series with group
33
- *
34
- * @returns {undefined}
35
- */
36
- initLegend() {
37
- if (!this.isInitLegend) {
38
- this.createLegendLayout();
39
- this.createLegend();
40
- }
41
-
42
- Object.values(this.seriesList).forEach((series) => {
43
- this.setLegendStyle(series);
44
- });
45
- this.initEvent();
46
-
47
- this.isInitLegend = true;
48
- this.legendDragInfo = {
49
- dragging: false,
50
- isStart: true,
51
- };
52
- },
53
-
54
- /**
55
- * Initialize legend event
56
- *
57
- * @returns {undefined}
58
- */
59
- initEvent() {
60
- if (this.isInitLegend) {
61
- return;
62
- }
63
-
64
- this.onLegendMouseDown = (e) => {
65
- e.stopPropagation();
66
- e.preventDefault();
67
-
68
- const type = e.target.dataset.type;
69
-
70
- let targetDOM;
71
- if (type === 'handle') {
72
- targetDOM = e.target;
73
- } else if (type === 'handle-btn') {
74
- targetDOM = e.target.parentElement;
75
- } else if (type === 'handle-btn-color') {
76
- targetDOM = e.target.parentElement.parentElement;
77
- } else {
78
- return;
79
- }
80
-
81
- const seriesList = Object.values(this.seriesList);
82
- if (!seriesList.length) {
83
- return;
84
- }
85
-
86
- const { colorState } = seriesList[0];
87
- const { start, end } = colorState[0];
88
-
89
- colorState[0].selectedValue = null;
90
- this.clearOverlay();
91
-
92
- this.legendDragInfo.dragging = true;
93
- this.legendDragInfo.isStart = start !== end
94
- ? targetDOM.className.includes('start')
95
- : this.legendDragInfo.isStart;
96
- targetDOM.classList.add('dragging');
97
- this.legendBoxDOM.addEventListener('mousemove', this.onLegendMouseMove, false);
98
- this.legendBoxDOM.addEventListener('mouseup', this.onLegendMouseUp, false);
99
- };
100
-
101
- this.onLegendMouseMove = (e) => {
102
- e.stopPropagation();
103
- e.preventDefault();
104
-
105
- const { dragging, isStart } = this.legendDragInfo;
106
-
107
- if (dragging) {
108
- let value = this.getSelectedValue(e);
109
- value = this.isSide ? 100 - value : value;
110
- const dir = isStart ? 'start' : 'end';
111
-
112
- const seriesList = Object.values(this.seriesList);
113
- if (!seriesList.length) {
114
- return;
115
- }
116
-
117
- const { colorState } = seriesList[0];
118
- const { start, end } = colorState[0];
119
- if ((isStart && value > end) || (!isStart && value < start)) {
120
- return;
121
- }
122
- colorState[0][dir] = value;
123
-
124
- this.update({
125
- updateSeries: false,
126
- updateSelTip: { update: false, keepDomain: false },
127
- });
128
- }
129
- };
130
-
131
- this.onLegendMouseUp = () => {
132
- this.legendDragInfo.dragging = false;
133
-
134
- const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle dragging')[0];
135
- targetDOM?.classList.remove('dragging');
136
- this.legendBoxDOM.removeEventListener('mouseup', this.onLegendMouseUp, false);
137
- };
138
-
139
- /**
140
- * callback for legendBoxDOM hovering
141
- *
142
- * @returns {undefined}
143
- */
144
- this.onLegendBoxOver = (e) => {
145
- const type = e.target.dataset.type;
146
-
147
- const seriesList = Object.values(this.seriesList);
148
- if (!seriesList.length) {
149
- return;
150
- }
151
-
152
- const { colorState, valueOpt } = seriesList[0];
153
- const state = colorState[0];
154
-
155
- let value = this.getSelectedValue(e);
156
- value = this.isSide ? 100 - value : value;
157
- if (['line', 'thumb', 'layer', 'overlay', 'overlay-item'].includes(type)) {
158
- if (state.start <= value && value <= state.end) {
159
- state.selectedValue = value;
160
- this.createLegendOverlay(value, valueOpt);
161
- } else {
162
- return;
163
- }
164
- } else if (['handle', 'handle-btn', 'handle-btn-color'].includes(type)) {
165
- const isStart = e.target.className.includes('start');
166
- state.selectedValue = isStart ? state.start : state.end;
167
- this.clearOverlay();
168
- } else {
169
- return;
170
- }
171
-
172
- this.update({
173
- updateSeries: false,
174
- updateSelTip: { update: false, keepDomain: false },
175
- });
176
- };
177
-
178
- /**
179
- * callback for mouseleave event on legendBoxDOM
180
- *
181
- * @returns {undefined}
182
- */
183
- this.onLegendBoxLeave = () => {
184
- this.legendDragInfo.dragging = false;
185
-
186
- this.clearOverlay();
187
-
188
- const seriesList = Object.values(this.seriesList);
189
- if (!seriesList.length) {
190
- return;
191
- }
192
-
193
- const { colorState } = seriesList[0];
194
- colorState[0].selectedValue = null;
195
-
196
- this.update({
197
- updateSeries: false,
198
- updateSelTip: { update: false, keepDomain: false },
199
- });
200
- };
201
-
202
- this.legendBoxDOM.addEventListener('mousedown', this.onLegendMouseDown);
203
- this.legendBoxDOM.addEventListener('mouseover', this.onLegendBoxOver);
204
- this.legendBoxDOM.addEventListener('mouseleave', this.onLegendBoxLeave);
205
- },
206
-
207
- getSelectedValue(evt) {
208
- const { x, y, width, height } = this.containerDOM.getBoundingClientRect();
209
- const isTop = !this.isSide;
210
-
211
- const sp = isTop ? x : y;
212
- const size = isTop ? width : height;
213
- let movePoint = isTop ? evt.clientX : evt.clientY;
214
- if (movePoint < sp) {
215
- movePoint = sp;
216
- } else if (movePoint > sp + size) {
217
- movePoint = sp + size;
218
- }
219
-
220
- const move = movePoint - sp;
221
- return +convertToPercent(move, size);
222
- },
223
-
224
- /**
225
- * To update legend, reset all process.
226
- *
227
- * @returns {undefined}
228
- */
229
- updateLegend() {
230
- this.resetLegend();
231
- this.createLegend();
232
-
233
- Object.values(this.seriesList).forEach((series) => {
234
- this.setLegendStyle(series);
235
- });
236
- },
237
-
238
- /**
239
- * To update legend, remove all of legendBoxDOM's children
240
- *
241
- * @returns {undefined}
242
- */
243
- resetLegend() {
244
- const containerDOM = this.containerDOM;
245
-
246
- if (!containerDOM) {
247
- return;
248
- }
249
-
250
- while (containerDOM.hasChildNodes()) {
251
- containerDOM.removeChild(containerDOM.firstChild);
252
- }
253
- },
254
-
255
- clearOverlay() {
256
- const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-line')[0];
257
- const overlayDOM = targetDOM?.getElementsByClassName('ev-chart-legend-overlay')[0];
258
- if (overlayDOM) {
259
- targetDOM.removeChild(overlayDOM);
260
-
261
- const thumbDOM = targetDOM.getElementsByClassName('ev-chart-legend-thumb')[0];
262
- const labels = thumbDOM.children;
263
- labels.forEach((labelDOM) => {
264
- labelDOM.style.opacity = 1;
265
- });
266
- }
267
- },
268
-
269
- createLegendOverlay(value, opt) {
270
- this.clearOverlay();
271
- const handleSize = this.legendHandleSize;
272
- const { min, max } = opt;
273
- if (min === undefined || max === undefined) {
274
- return;
275
- }
276
-
277
- const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-line')[0];
278
-
279
- const overlayDOM = document.createElement('div');
280
- overlayDOM.className = 'ev-chart-legend-overlay';
281
- overlayDOM.dataset.type = 'overlay';
282
-
283
- const tooltipDOM = document.createElement('div');
284
- tooltipDOM.className = 'ev-chart-legend-overlay-tooltip';
285
- tooltipDOM.innerText = Math.floor(min + ((max - min) * (value / 100)));
286
-
287
- const itemDOM = document.createElement('span');
288
- itemDOM.className = 'ev-chart-legend-overlay-item';
289
- itemDOM.dataset.type = 'overlay-item';
290
-
291
- let itemStyle;
292
- let tooltipStyle;
293
- const position = Math.floor(handleSize / 2) + 14;
294
- if (this.isSide) {
295
- tooltipStyle = `top:${100 - value}%;left:${position}px;transform:translateY(-50%);`;
296
- itemStyle = `top:${100 - value}%;transform:translateY(-50%);`;
297
- } else {
298
- tooltipStyle = `top:-${position}px;left:${value}%;transform:translateX(-50%);`;
299
- itemStyle = `left:${value}%;transform:translateX(-50%);`;
300
- }
301
- itemStyle += `width:${handleSize - 10}px;height:${handleSize - 10}px;`;
302
-
303
- tooltipDOM.style.cssText = tooltipStyle;
304
- itemDOM.style.cssText = itemStyle;
305
-
306
- overlayDOM.appendChild(tooltipDOM);
307
- overlayDOM.appendChild(itemDOM);
308
- targetDOM?.appendChild(overlayDOM);
309
-
310
- const thumbDOM = targetDOM?.getElementsByClassName('ev-chart-legend-thumb')[0];
311
- if (thumbDOM) {
312
- const labels = thumbDOM.children;
313
- labels.forEach((labelDOM) => {
314
- labelDOM.style.opacity = 0.2;
315
- });
316
- }
317
- },
318
-
319
- createLegendHandle(type) {
320
- const colorBtnDOM = document.createElement('span');
321
- colorBtnDOM.className = `ev-chart-legend-handle-btn-color ${type}`;
322
- colorBtnDOM.dataset.type = 'handle-btn-color';
323
-
324
- const btnDOM = document.createElement('div');
325
- btnDOM.className = `ev-chart-legend-handle-btn ${type}`;
326
- btnDOM.dataset.type = 'handle-btn';
327
-
328
- btnDOM.appendChild(colorBtnDOM);
329
-
330
- const handleDOM = document.createElement('div');
331
- handleDOM.className = `ev-chart-legend-handle ${type}`;
332
- handleDOM.dataset.type = 'handle';
333
-
334
- handleDOM.appendChild(btnDOM);
335
-
336
- return handleDOM;
337
- },
338
-
339
- createLegendLabel() {
340
- const textDOM = document.createElement('span');
341
- textDOM.className = 'ev-chart-legend-label-text';
342
-
343
- const labelDOM = document.createElement('div');
344
- labelDOM.className = 'ev-chart-legend-label';
345
-
346
- return labelDOM;
347
- },
348
-
349
- /**
350
- * Create legend DOM
351
- *
352
- * @returns {undefined}
353
- */
354
- createLegend() {
355
- if (!Object.values(this.seriesList).length) {
356
- return;
357
- }
358
-
359
- const opt = this.options.legend;
360
- this.isSide = !['top', 'bottom'].includes(opt.position);
361
- const legendSize = this.isSide ? opt.width : opt.height;
362
- this.legendHandleSize = legendSize > MAX_HANDLE_SIZE ? MAX_HANDLE_SIZE : legendSize;
363
- const handleSize = this.legendHandleSize;
364
-
365
- const startHandleDOM = this.createLegendHandle(this.isSide ? 'end' : 'start', handleSize);
366
- const endHandleDOM = this.createLegendHandle(this.isSide ? 'start' : 'end', handleSize);
367
-
368
- const lineLayerDOM = document.createElement('div');
369
- lineLayerDOM.className = 'ev-chart-legend-line-layer';
370
- lineLayerDOM.dataset.type = 'line-layer';
371
- const thumbDOM = document.createElement('div');
372
- thumbDOM.className = 'ev-chart-legend-thumb';
373
- thumbDOM.dataset.type = 'thumb';
374
-
375
- thumbDOM.appendChild(this.createLegendLabel());
376
- thumbDOM.appendChild(this.createLegendLabel());
377
-
378
- const lineDOM = document.createElement('div');
379
- lineDOM.className = 'ev-chart-legend-line';
380
- lineDOM.dataset.type = 'line';
381
-
382
- lineDOM.appendChild(lineLayerDOM);
383
- lineDOM.appendChild(thumbDOM);
384
-
385
- this.containerDOM.appendChild(lineDOM);
386
- this.containerDOM.appendChild(startHandleDOM);
387
- this.containerDOM.appendChild(endHandleDOM);
388
- },
389
-
390
- setLegendStyle(series) {
391
- const dir = this.isSide ? 'top' : 'right';
392
- const handleSize = this.legendHandleSize;
393
-
394
- const { valueOpt, colorState } = series;
395
-
396
- const { min, max, decimalPoint } = valueOpt;
397
-
398
- const { start, end } = colorState[0];
399
- const startColor = series.getColorForGradient(start);
400
- const endColor = series.getColorForGradient(end);
401
- let gradient = `linear-gradient(to ${dir}, `;
402
- gradient += `${startColor}, ${endColor})`;
403
-
404
- const labelPosition = Math.floor(handleSize / 2) + 14;
405
- let defaultHandleStyle = `width:${handleSize}px;height:${handleSize}px;`;
406
- let labelStyle;
407
- let startStyle;
408
- let endStyle;
409
- let thumbStyle = `background:${gradient};`;
410
-
411
- if (this.isSide) {
412
- defaultHandleStyle += `margin-top:-${handleSize / 2}px;`;
413
- labelStyle = `left:${labelPosition}px;transform:translateY(-50%);top:`;
414
- startStyle = `top:${100 - end}%;`;
415
- endStyle = `top:${100 - start}%;`;
416
- thumbStyle += `top:${100 - end}%;height:${end - start}%;`;
417
- } else {
418
- defaultHandleStyle += `margin-left:-${handleSize / 2}px;`;
419
- labelStyle = `top:-${labelPosition}px;transform:translateX(-50%);left:`;
420
- startStyle = `left:${start}%;`;
421
- endStyle = `left:${end}%;`;
422
- thumbStyle += `left:${start}%;width:${end - start}%;`;
423
- }
424
-
425
- const minText = (min + ((max - min) * (start / 100))).toFixed(decimalPoint);
426
- const maxText = (min + ((max - min) * (end / 100))).toFixed(decimalPoint);
427
-
428
- const thumbDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-thumb')[0];
429
- thumbDOM.style.cssText = thumbStyle;
430
-
431
- const labelDOM = thumbDOM.getElementsByClassName('ev-chart-legend-label');
432
- labelDOM[0].style.cssText = `${labelStyle}0%;`;
433
- labelDOM[1].style.cssText = `${labelStyle}100%;`;
434
- if (min !== undefined && max !== undefined) {
435
- labelDOM[0].innerText = this.isSide ? maxText : minText;
436
- labelDOM[1].innerText = this.isSide ? minText : maxText;
437
- }
438
-
439
- const handleDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle');
440
- handleDOM[0].style.cssText = defaultHandleStyle + startStyle;
441
- handleDOM[1].style.cssText = defaultHandleStyle + endStyle;
442
-
443
- const btnDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle-btn-color');
444
- btnDOM[0].style.backgroundColor = this.isSide ? endColor : startColor;
445
- btnDOM[1].style.backgroundColor = this.isSide ? startColor : endColor;
446
- },
447
-
448
- /**
449
- * Set legend components position by option
450
- *
451
- * @returns {undefined}
452
- */
453
- setLegendPosition() {
454
- const opt = this.options;
455
- const position = opt?.legend?.position;
456
- const { width: minWidth, height: minHeight } = MIN_BOX_SIZE;
457
- const handleSize = this.legendHandleSize;
458
-
459
- const title = opt?.title?.show ? opt?.title?.height : 0;
460
- const positionTop = title + minHeight;
461
- const { top = 0, bottom = 0, left = 0, right = 0 } = opt?.legend?.padding ?? {};
462
- const wrapperStyle = this.wrapperDOM.style;
463
-
464
- if (!wrapperStyle) {
465
- return;
466
- }
467
-
468
- let legendStyle;
469
- let boxStyle;
470
- let containerStyle;
471
- let chartRect;
472
-
473
- switch (position) {
474
- case 'top':
475
- wrapperStyle.padding = `${positionTop}px 0 0 0`;
476
- chartRect = this.chartDOM.getBoundingClientRect();
477
-
478
- boxStyle = `padding:${handleSize + 7}px ${right}px ${bottom}px ${left}px;`;
479
- boxStyle += 'width:100%';
480
- boxStyle += `height${minHeight}px;`;
481
-
482
- legendStyle = `width:${chartRect.width}px;`;
483
- legendStyle += `height:${minHeight}px;`;
484
- legendStyle += `top:${title}px;`;
485
- break;
486
- case 'right':
487
- wrapperStyle.padding = `${title}px ${minWidth}px 0 0`;
488
- chartRect = this.chartDOM.getBoundingClientRect();
489
-
490
- boxStyle = `padding:${top}px ${right}px ${bottom}px ${left}px;`;
491
- boxStyle += `width:${minWidth}px;`;
492
- boxStyle += 'height:100%;';
493
- boxStyle += `max-height:${chartRect.height}px;`;
494
-
495
- legendStyle = `width:${minWidth}px;`;
496
- legendStyle += `height:${chartRect.height}px;`;
497
- legendStyle += `top:${title}px;right:0px;`;
498
- break;
499
- case 'bottom':
500
- wrapperStyle.padding = `${title}px 0 ${minHeight}px 0`;
501
- chartRect = this.chartDOM.getBoundingClientRect();
502
-
503
- boxStyle = `padding:${handleSize + 7}px ${right}px ${bottom}px ${left}px;`;
504
- boxStyle += 'width:100%;';
505
- boxStyle += `height:${minHeight}px;`;
506
-
507
- legendStyle = `width:${chartRect.width}px;`;
508
- legendStyle += `height:${minHeight}px;`;
509
-
510
- legendStyle += 'bottom:0px;left:0px;';
511
- break;
512
- case 'left':
513
- wrapperStyle.padding = `${title}px 0 0 ${minWidth}px`;
514
- chartRect = this.chartDOM.getBoundingClientRect();
515
-
516
- boxStyle = `padding:${top}px ${right}px ${bottom}px ${left}px;`;
517
- boxStyle += 'display:absolute;';
518
- boxStyle += 'bottom:0px;';
519
- boxStyle += `width:${minWidth}px;`;
520
- boxStyle += 'height:100%;';
521
- boxStyle += `maxHeight:${chartRect.height}px;`;
522
-
523
- legendStyle = `width:${minWidth}px;`;
524
- legendStyle += `height:${chartRect.height}px;`;
525
- legendStyle += `top:${title}px;left:0px`;
526
- break;
527
- default:
528
- break;
529
- }
530
- if (['top', 'bottom'].includes(position)) {
531
- const containerSize = chartRect.width / 2;
532
-
533
- containerStyle = `left:${(chartRect.width / 2) - (containerSize / 2)}px;`;
534
- containerStyle += `width:${containerSize}px;`;
535
- containerStyle += `height:${handleSize}px;`;
536
- containerStyle += 'padding:4px 0;';
537
- containerStyle += 'margin:0 4px;';
538
- } else {
539
- const containerSize = chartRect.height / 2;
540
-
541
- containerStyle = `top:${(chartRect.height / 2) - (containerSize / 2)}px;`;
542
- containerStyle += 'left:5px;';
543
- containerStyle += `width:${handleSize}px;`;
544
- containerStyle += `height:${containerSize}px;`;
545
- containerStyle += 'padding:0 4px;';
546
- containerStyle += 'margin:4px 0;';
547
- }
548
-
549
- this.containerDOM.style.cssText = containerStyle;
550
- this.legendBoxDOM.style.cssText = boxStyle;
551
- this.legendDOM.style.cssText = legendStyle;
552
- },
553
-
554
- /**
555
- * Update legend components size
556
- *
557
- * @returns {undefined}
558
- */
559
- updateLegendContainerSize() {
560
- Object.values(this.seriesList).forEach((series) => {
561
- this.setLegendStyle(series);
562
- });
563
- },
564
-
565
- /**
566
- * Show legend components by manipulating css
567
- *
568
- * @returns {undefined}
569
- */
570
- showLegend() {
571
- if (this.resizeDOM) {
572
- this.resizeDOM.style.display = 'block';
573
- }
574
-
575
- if (this.legendDOM) {
576
- this.legendDOM.style.display = 'block';
577
- }
578
- },
579
-
580
- /**
581
- * Hide legend components by manipulating css
582
- *
583
- * @returns {undefined}
584
- */
585
- hideLegend() {
586
- const opt = this.options;
587
- const wrapperStyle = this.wrapperDOM?.style;
588
- const legendStyle = this.legendDOM?.style;
589
- const title = opt?.title?.show ? opt?.title?.height : 0;
590
-
591
- if (!legendStyle || !wrapperStyle) {
592
- return;
593
- }
594
-
595
- legendStyle.display = 'none';
596
- legendStyle.width = '0';
597
- legendStyle.height = '0';
598
- wrapperStyle.padding = `${title}px 0 0 0`;
599
- },
600
- };
601
-
602
- export default modules;
1
+ import { convertToPercent } from '../../../common/utils';
2
+
3
+ const MAX_HANDLE_SIZE = 28;
4
+
5
+ const MIN_BOX_SIZE = {
6
+ width: 70,
7
+ height: 60,
8
+ };
9
+
10
+ const modules = {
11
+ /**
12
+ * Create legend DOM
13
+ *
14
+ * @returns {undefined}
15
+ */
16
+ createLegendLayout() {
17
+ this.legendDOM = document.createElement('div');
18
+ this.legendDOM.className = 'ev-chart-legend';
19
+ this.legendBoxDOM = document.createElement('div');
20
+ this.legendBoxDOM.className = 'ev-chart-legend-box';
21
+ this.containerDOM = document.createElement('div');
22
+ this.containerDOM.className = 'ev-chart-legend-container';
23
+
24
+ this.legendBoxDOM.appendChild(this.containerDOM);
25
+ this.legendDOM.appendChild(this.legendBoxDOM);
26
+ this.wrapperDOM.appendChild(this.legendDOM);
27
+ },
28
+
29
+ /**
30
+ * Initialize legend
31
+ * If there was no initialization, create DOM and set default layout.
32
+ * It not, there will already be set layout, so add a legend for each series with group
33
+ *
34
+ * @returns {undefined}
35
+ */
36
+ initLegend() {
37
+ if (!this.isInitLegend) {
38
+ this.createLegendLayout();
39
+ this.createLegend();
40
+ }
41
+
42
+ Object.values(this.seriesList).forEach((series) => {
43
+ this.setLegendStyle(series);
44
+ });
45
+ this.initEvent();
46
+
47
+ this.isInitLegend = true;
48
+ this.legendDragInfo = {
49
+ dragging: false,
50
+ isStart: true,
51
+ };
52
+ },
53
+
54
+ /**
55
+ * Initialize legend event
56
+ *
57
+ * @returns {undefined}
58
+ */
59
+ initEvent() {
60
+ if (this.isInitLegend) {
61
+ return;
62
+ }
63
+
64
+ this.onLegendMouseDown = (e) => {
65
+ e.stopPropagation();
66
+ e.preventDefault();
67
+
68
+ const type = e.target.dataset.type;
69
+
70
+ let targetDOM;
71
+ if (type === 'handle') {
72
+ targetDOM = e.target;
73
+ } else if (type === 'handle-btn') {
74
+ targetDOM = e.target.parentElement;
75
+ } else if (type === 'handle-btn-color') {
76
+ targetDOM = e.target.parentElement.parentElement;
77
+ } else {
78
+ return;
79
+ }
80
+
81
+ const seriesList = Object.values(this.seriesList);
82
+ if (!seriesList.length) {
83
+ return;
84
+ }
85
+
86
+ const { colorState } = seriesList[0];
87
+ const { start, end } = colorState[0];
88
+
89
+ colorState[0].selectedValue = null;
90
+ this.clearOverlay();
91
+
92
+ this.legendDragInfo.dragging = true;
93
+ this.legendDragInfo.isStart = start !== end
94
+ ? targetDOM.className.includes('start')
95
+ : this.legendDragInfo.isStart;
96
+ targetDOM.classList.add('dragging');
97
+ this.legendBoxDOM.addEventListener('mousemove', this.onLegendMouseMove, false);
98
+ this.legendBoxDOM.addEventListener('mouseup', this.onLegendMouseUp, false);
99
+ };
100
+
101
+ this.onLegendMouseMove = (e) => {
102
+ e.stopPropagation();
103
+ e.preventDefault();
104
+
105
+ const { dragging, isStart } = this.legendDragInfo;
106
+
107
+ if (dragging) {
108
+ let value = this.getSelectedValue(e);
109
+ value = this.isSide ? 100 - value : value;
110
+ const dir = isStart ? 'start' : 'end';
111
+
112
+ const seriesList = Object.values(this.seriesList);
113
+ if (!seriesList.length) {
114
+ return;
115
+ }
116
+
117
+ const { colorState } = seriesList[0];
118
+ const { start, end } = colorState[0];
119
+ if ((isStart && value > end) || (!isStart && value < start)) {
120
+ return;
121
+ }
122
+ colorState[0][dir] = value;
123
+
124
+ this.update({
125
+ updateSeries: false,
126
+ updateSelTip: { update: false, keepDomain: false },
127
+ });
128
+ }
129
+ };
130
+
131
+ this.onLegendMouseUp = () => {
132
+ this.legendDragInfo.dragging = false;
133
+
134
+ const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle dragging')[0];
135
+ targetDOM?.classList.remove('dragging');
136
+ this.legendBoxDOM.removeEventListener('mouseup', this.onLegendMouseUp, false);
137
+ };
138
+
139
+ /**
140
+ * callback for legendBoxDOM hovering
141
+ *
142
+ * @returns {undefined}
143
+ */
144
+ this.onLegendBoxOver = (e) => {
145
+ const type = e.target.dataset.type;
146
+
147
+ const seriesList = Object.values(this.seriesList);
148
+ if (!seriesList.length) {
149
+ return;
150
+ }
151
+
152
+ const { colorState, valueOpt } = seriesList[0];
153
+ const state = colorState[0];
154
+
155
+ let value = this.getSelectedValue(e);
156
+ value = this.isSide ? 100 - value : value;
157
+ if (['line', 'thumb', 'layer', 'overlay', 'overlay-item'].includes(type)) {
158
+ if (state.start <= value && value <= state.end) {
159
+ state.selectedValue = value;
160
+ this.createLegendOverlay(value, valueOpt);
161
+ } else {
162
+ return;
163
+ }
164
+ } else if (['handle', 'handle-btn', 'handle-btn-color'].includes(type)) {
165
+ const isStart = e.target.className.includes('start');
166
+ state.selectedValue = isStart ? state.start : state.end;
167
+ this.clearOverlay();
168
+ } else {
169
+ return;
170
+ }
171
+
172
+ this.update({
173
+ updateSeries: false,
174
+ updateSelTip: { update: false, keepDomain: false },
175
+ });
176
+ };
177
+
178
+ /**
179
+ * callback for mouseleave event on legendBoxDOM
180
+ *
181
+ * @returns {undefined}
182
+ */
183
+ this.onLegendBoxLeave = () => {
184
+ this.legendDragInfo.dragging = false;
185
+
186
+ this.clearOverlay();
187
+
188
+ const seriesList = Object.values(this.seriesList);
189
+ if (!seriesList.length) {
190
+ return;
191
+ }
192
+
193
+ const { colorState } = seriesList[0];
194
+ colorState[0].selectedValue = null;
195
+
196
+ this.update({
197
+ updateSeries: false,
198
+ updateSelTip: { update: false, keepDomain: false },
199
+ });
200
+ };
201
+
202
+ this.legendBoxDOM.addEventListener('mousedown', this.onLegendMouseDown);
203
+ this.legendBoxDOM.addEventListener('mouseover', this.onLegendBoxOver);
204
+ this.legendBoxDOM.addEventListener('mouseleave', this.onLegendBoxLeave);
205
+ },
206
+
207
+ getSelectedValue(evt) {
208
+ const { x, y, width, height } = this.containerDOM.getBoundingClientRect();
209
+ const isTop = !this.isSide;
210
+
211
+ const sp = isTop ? x : y;
212
+ const size = isTop ? width : height;
213
+ let movePoint = isTop ? evt.clientX : evt.clientY;
214
+ if (movePoint < sp) {
215
+ movePoint = sp;
216
+ } else if (movePoint > sp + size) {
217
+ movePoint = sp + size;
218
+ }
219
+
220
+ const move = movePoint - sp;
221
+ return +convertToPercent(move, size);
222
+ },
223
+
224
+ /**
225
+ * To update legend, reset all process.
226
+ *
227
+ * @returns {undefined}
228
+ */
229
+ updateLegend() {
230
+ this.resetLegend();
231
+ this.createLegend();
232
+
233
+ Object.values(this.seriesList).forEach((series) => {
234
+ this.setLegendStyle(series);
235
+ });
236
+ },
237
+
238
+ /**
239
+ * To update legend, remove all of legendBoxDOM's children
240
+ *
241
+ * @returns {undefined}
242
+ */
243
+ resetLegend() {
244
+ const containerDOM = this.containerDOM;
245
+
246
+ if (!containerDOM) {
247
+ return;
248
+ }
249
+
250
+ while (containerDOM.hasChildNodes()) {
251
+ containerDOM.removeChild(containerDOM.firstChild);
252
+ }
253
+ },
254
+
255
+ clearOverlay() {
256
+ const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-line')[0];
257
+ const overlayDOM = targetDOM?.getElementsByClassName('ev-chart-legend-overlay')[0];
258
+ if (overlayDOM) {
259
+ targetDOM.removeChild(overlayDOM);
260
+
261
+ const thumbDOM = targetDOM.getElementsByClassName('ev-chart-legend-thumb')[0];
262
+ const labels = thumbDOM.children;
263
+ labels.forEach((labelDOM) => {
264
+ labelDOM.style.opacity = 1;
265
+ });
266
+ }
267
+ },
268
+
269
+ createLegendOverlay(value, opt) {
270
+ this.clearOverlay();
271
+ const handleSize = this.legendHandleSize;
272
+ const { min, max } = opt;
273
+ if (min === undefined || max === undefined) {
274
+ return;
275
+ }
276
+
277
+ const targetDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-line')[0];
278
+
279
+ const overlayDOM = document.createElement('div');
280
+ overlayDOM.className = 'ev-chart-legend-overlay';
281
+ overlayDOM.dataset.type = 'overlay';
282
+
283
+ const tooltipDOM = document.createElement('div');
284
+ tooltipDOM.className = 'ev-chart-legend-overlay-tooltip';
285
+ tooltipDOM.innerText = Math.floor(min + ((max - min) * (value / 100)));
286
+
287
+ const itemDOM = document.createElement('span');
288
+ itemDOM.className = 'ev-chart-legend-overlay-item';
289
+ itemDOM.dataset.type = 'overlay-item';
290
+
291
+ let itemStyle;
292
+ let tooltipStyle;
293
+ const position = Math.floor(handleSize / 2) + 14;
294
+ if (this.isSide) {
295
+ tooltipStyle = `top:${100 - value}%;left:${position}px;transform:translateY(-50%);`;
296
+ itemStyle = `top:${100 - value}%;transform:translateY(-50%);`;
297
+ } else {
298
+ tooltipStyle = `top:-${position}px;left:${value}%;transform:translateX(-50%);`;
299
+ itemStyle = `left:${value}%;transform:translateX(-50%);`;
300
+ }
301
+ itemStyle += `width:${handleSize - 10}px;height:${handleSize - 10}px;`;
302
+
303
+ tooltipDOM.style.cssText = tooltipStyle;
304
+ itemDOM.style.cssText = itemStyle;
305
+
306
+ overlayDOM.appendChild(tooltipDOM);
307
+ overlayDOM.appendChild(itemDOM);
308
+ targetDOM?.appendChild(overlayDOM);
309
+
310
+ const thumbDOM = targetDOM?.getElementsByClassName('ev-chart-legend-thumb')[0];
311
+ if (thumbDOM) {
312
+ const labels = thumbDOM.children;
313
+ labels.forEach((labelDOM) => {
314
+ labelDOM.style.opacity = 0.2;
315
+ });
316
+ }
317
+ },
318
+
319
+ createLegendHandle(type) {
320
+ const colorBtnDOM = document.createElement('span');
321
+ colorBtnDOM.className = `ev-chart-legend-handle-btn-color ${type}`;
322
+ colorBtnDOM.dataset.type = 'handle-btn-color';
323
+
324
+ const btnDOM = document.createElement('div');
325
+ btnDOM.className = `ev-chart-legend-handle-btn ${type}`;
326
+ btnDOM.dataset.type = 'handle-btn';
327
+
328
+ btnDOM.appendChild(colorBtnDOM);
329
+
330
+ const handleDOM = document.createElement('div');
331
+ handleDOM.className = `ev-chart-legend-handle ${type}`;
332
+ handleDOM.dataset.type = 'handle';
333
+
334
+ handleDOM.appendChild(btnDOM);
335
+
336
+ return handleDOM;
337
+ },
338
+
339
+ createLegendLabel() {
340
+ const textDOM = document.createElement('span');
341
+ textDOM.className = 'ev-chart-legend-label-text';
342
+
343
+ const labelDOM = document.createElement('div');
344
+ labelDOM.className = 'ev-chart-legend-label';
345
+
346
+ return labelDOM;
347
+ },
348
+
349
+ /**
350
+ * Create legend DOM
351
+ *
352
+ * @returns {undefined}
353
+ */
354
+ createLegend() {
355
+ if (!Object.values(this.seriesList).length) {
356
+ return;
357
+ }
358
+
359
+ const opt = this.options.legend;
360
+ this.isSide = !['top', 'bottom'].includes(opt.position);
361
+ const legendSize = this.isSide ? opt.width : opt.height;
362
+ this.legendHandleSize = legendSize > MAX_HANDLE_SIZE ? MAX_HANDLE_SIZE : legendSize;
363
+ const handleSize = this.legendHandleSize;
364
+
365
+ const startHandleDOM = this.createLegendHandle(this.isSide ? 'end' : 'start', handleSize);
366
+ const endHandleDOM = this.createLegendHandle(this.isSide ? 'start' : 'end', handleSize);
367
+
368
+ const lineLayerDOM = document.createElement('div');
369
+ lineLayerDOM.className = 'ev-chart-legend-line-layer';
370
+ lineLayerDOM.dataset.type = 'line-layer';
371
+ const thumbDOM = document.createElement('div');
372
+ thumbDOM.className = 'ev-chart-legend-thumb';
373
+ thumbDOM.dataset.type = 'thumb';
374
+
375
+ thumbDOM.appendChild(this.createLegendLabel());
376
+ thumbDOM.appendChild(this.createLegendLabel());
377
+
378
+ const lineDOM = document.createElement('div');
379
+ lineDOM.className = 'ev-chart-legend-line';
380
+ lineDOM.dataset.type = 'line';
381
+
382
+ lineDOM.appendChild(lineLayerDOM);
383
+ lineDOM.appendChild(thumbDOM);
384
+
385
+ this.containerDOM.appendChild(lineDOM);
386
+ this.containerDOM.appendChild(startHandleDOM);
387
+ this.containerDOM.appendChild(endHandleDOM);
388
+ },
389
+
390
+ setLegendStyle(series) {
391
+ const dir = this.isSide ? 'top' : 'right';
392
+ const handleSize = this.legendHandleSize;
393
+
394
+ const { valueOpt, colorState } = series;
395
+
396
+ const { min, max, decimalPoint } = valueOpt;
397
+
398
+ const { start, end } = colorState[0];
399
+ const startColor = series.getColorForGradient(start);
400
+ const endColor = series.getColorForGradient(end);
401
+ let gradient = `linear-gradient(to ${dir}, `;
402
+ gradient += `${startColor}, ${endColor})`;
403
+
404
+ const labelPosition = Math.floor(handleSize / 2) + 14;
405
+ let defaultHandleStyle = `width:${handleSize}px;height:${handleSize}px;`;
406
+ let labelStyle;
407
+ let startStyle;
408
+ let endStyle;
409
+ let thumbStyle = `background:${gradient};`;
410
+
411
+ if (this.isSide) {
412
+ defaultHandleStyle += `margin-top:-${handleSize / 2}px;`;
413
+ labelStyle = `left:${labelPosition}px;transform:translateY(-50%);top:`;
414
+ startStyle = `top:${100 - end}%;`;
415
+ endStyle = `top:${100 - start}%;`;
416
+ thumbStyle += `top:${100 - end}%;height:${end - start}%;`;
417
+ } else {
418
+ defaultHandleStyle += `margin-left:-${handleSize / 2}px;`;
419
+ labelStyle = `top:-${labelPosition}px;transform:translateX(-50%);left:`;
420
+ startStyle = `left:${start}%;`;
421
+ endStyle = `left:${end}%;`;
422
+ thumbStyle += `left:${start}%;width:${end - start}%;`;
423
+ }
424
+
425
+ const minText = (min + ((max - min) * (start / 100))).toFixed(decimalPoint);
426
+ const maxText = (min + ((max - min) * (end / 100))).toFixed(decimalPoint);
427
+
428
+ const thumbDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-thumb')[0];
429
+ thumbDOM.style.cssText = thumbStyle;
430
+
431
+ const labelDOM = thumbDOM.getElementsByClassName('ev-chart-legend-label');
432
+ labelDOM[0].style.cssText = `${labelStyle}0%;`;
433
+ labelDOM[1].style.cssText = `${labelStyle}100%;`;
434
+ if (min !== undefined && max !== undefined) {
435
+ labelDOM[0].innerText = this.isSide ? maxText : minText;
436
+ labelDOM[1].innerText = this.isSide ? minText : maxText;
437
+ }
438
+
439
+ const handleDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle');
440
+ handleDOM[0].style.cssText = defaultHandleStyle + startStyle;
441
+ handleDOM[1].style.cssText = defaultHandleStyle + endStyle;
442
+
443
+ const btnDOM = this.containerDOM.getElementsByClassName('ev-chart-legend-handle-btn-color');
444
+ btnDOM[0].style.backgroundColor = this.isSide ? endColor : startColor;
445
+ btnDOM[1].style.backgroundColor = this.isSide ? startColor : endColor;
446
+ },
447
+
448
+ /**
449
+ * Set legend components position by option
450
+ *
451
+ * @returns {undefined}
452
+ */
453
+ setLegendPosition() {
454
+ const opt = this.options;
455
+ const position = opt?.legend?.position;
456
+ const { width: minWidth, height: minHeight } = MIN_BOX_SIZE;
457
+ const handleSize = this.legendHandleSize;
458
+
459
+ const title = opt?.title?.show ? opt?.title?.height : 0;
460
+ const positionTop = title + minHeight;
461
+ const { top = 0, bottom = 0, left = 0, right = 0 } = opt?.legend?.padding ?? {};
462
+ const wrapperStyle = this.wrapperDOM.style;
463
+
464
+ if (!wrapperStyle) {
465
+ return;
466
+ }
467
+
468
+ let legendStyle;
469
+ let boxStyle;
470
+ let containerStyle;
471
+ let chartRect;
472
+
473
+ switch (position) {
474
+ case 'top':
475
+ wrapperStyle.padding = `${positionTop}px 0 0 0`;
476
+ chartRect = this.chartDOM.getBoundingClientRect();
477
+
478
+ boxStyle = `padding:${handleSize + 7}px ${right}px ${bottom}px ${left}px;`;
479
+ boxStyle += 'width:100%';
480
+ boxStyle += `height${minHeight}px;`;
481
+
482
+ legendStyle = `width:${chartRect.width}px;`;
483
+ legendStyle += `height:${minHeight}px;`;
484
+ legendStyle += `top:${title}px;`;
485
+ break;
486
+ case 'right':
487
+ wrapperStyle.padding = `${title}px ${minWidth}px 0 0`;
488
+ chartRect = this.chartDOM.getBoundingClientRect();
489
+
490
+ boxStyle = `padding:${top}px ${right}px ${bottom}px ${left}px;`;
491
+ boxStyle += `width:${minWidth}px;`;
492
+ boxStyle += 'height:100%;';
493
+ boxStyle += `max-height:${chartRect.height}px;`;
494
+
495
+ legendStyle = `width:${minWidth}px;`;
496
+ legendStyle += `height:${chartRect.height}px;`;
497
+ legendStyle += `top:${title}px;right:0px;`;
498
+ break;
499
+ case 'bottom':
500
+ wrapperStyle.padding = `${title}px 0 ${minHeight}px 0`;
501
+ chartRect = this.chartDOM.getBoundingClientRect();
502
+
503
+ boxStyle = `padding:${handleSize + 7}px ${right}px ${bottom}px ${left}px;`;
504
+ boxStyle += 'width:100%;';
505
+ boxStyle += `height:${minHeight}px;`;
506
+
507
+ legendStyle = `width:${chartRect.width}px;`;
508
+ legendStyle += `height:${minHeight}px;`;
509
+
510
+ legendStyle += 'bottom:0px;left:0px;';
511
+ break;
512
+ case 'left':
513
+ wrapperStyle.padding = `${title}px 0 0 ${minWidth}px`;
514
+ chartRect = this.chartDOM.getBoundingClientRect();
515
+
516
+ boxStyle = `padding:${top}px ${right}px ${bottom}px ${left}px;`;
517
+ boxStyle += 'display:absolute;';
518
+ boxStyle += 'bottom:0px;';
519
+ boxStyle += `width:${minWidth}px;`;
520
+ boxStyle += 'height:100%;';
521
+ boxStyle += `maxHeight:${chartRect.height}px;`;
522
+
523
+ legendStyle = `width:${minWidth}px;`;
524
+ legendStyle += `height:${chartRect.height}px;`;
525
+ legendStyle += `top:${title}px;left:0px`;
526
+ break;
527
+ default:
528
+ break;
529
+ }
530
+ if (['top', 'bottom'].includes(position)) {
531
+ const containerSize = chartRect.width / 2;
532
+
533
+ containerStyle = `left:${(chartRect.width / 2) - (containerSize / 2)}px;`;
534
+ containerStyle += `width:${containerSize}px;`;
535
+ containerStyle += `height:${handleSize}px;`;
536
+ containerStyle += 'padding:4px 0;';
537
+ containerStyle += 'margin:0 4px;';
538
+ } else {
539
+ const containerSize = chartRect.height / 2;
540
+
541
+ containerStyle = `top:${(chartRect.height / 2) - (containerSize / 2)}px;`;
542
+ containerStyle += 'left:5px;';
543
+ containerStyle += `width:${handleSize}px;`;
544
+ containerStyle += `height:${containerSize}px;`;
545
+ containerStyle += 'padding:0 4px;';
546
+ containerStyle += 'margin:4px 0;';
547
+ }
548
+
549
+ this.containerDOM.style.cssText = containerStyle;
550
+ this.legendBoxDOM.style.cssText = boxStyle;
551
+ this.legendDOM.style.cssText = legendStyle;
552
+ },
553
+
554
+ /**
555
+ * Update legend components size
556
+ *
557
+ * @returns {undefined}
558
+ */
559
+ updateLegendContainerSize() {
560
+ Object.values(this.seriesList).forEach((series) => {
561
+ this.setLegendStyle(series);
562
+ });
563
+ },
564
+
565
+ /**
566
+ * Show legend components by manipulating css
567
+ *
568
+ * @returns {undefined}
569
+ */
570
+ showLegend() {
571
+ if (this.resizeDOM) {
572
+ this.resizeDOM.style.display = 'block';
573
+ }
574
+
575
+ if (this.legendDOM) {
576
+ this.legendDOM.style.display = 'block';
577
+ }
578
+ },
579
+
580
+ /**
581
+ * Hide legend components by manipulating css
582
+ *
583
+ * @returns {undefined}
584
+ */
585
+ hideLegend() {
586
+ const opt = this.options;
587
+ const wrapperStyle = this.wrapperDOM?.style;
588
+ const legendStyle = this.legendDOM?.style;
589
+ const title = opt?.title?.show ? opt?.title?.height : 0;
590
+
591
+ if (!legendStyle || !wrapperStyle) {
592
+ return;
593
+ }
594
+
595
+ legendStyle.display = 'none';
596
+ legendStyle.width = '0';
597
+ legendStyle.height = '0';
598
+ wrapperStyle.padding = `${title}px 0 0 0`;
599
+ },
600
+ };
601
+
602
+ export default modules;