evui 3.4.206 → 3.4.208

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 (162) hide show
  1. package/README.md +18 -33
  2. package/dist/404.html +44 -0
  3. package/dist/favicon.ico +0 -0
  4. package/dist/index.js +22645 -0
  5. package/dist/index.umd.cjs +28 -0
  6. package/dist/style.css +1 -0
  7. package/package.json +46 -43
  8. package/dist/evui.common.js +0 -63678
  9. package/dist/evui.common.js.map +0 -1
  10. package/dist/evui.umd.js +0 -63688
  11. package/dist/evui.umd.js.map +0 -1
  12. package/dist/evui.umd.min.js +0 -2
  13. package/dist/evui.umd.min.js.map +0 -1
  14. package/dist/img/EVUI.b82ee81a.svg +0 -293
  15. package/src/assets/logo.png +0 -0
  16. package/src/common/emitter.js +0 -20
  17. package/src/common/utils.bignumber.js +0 -67
  18. package/src/common/utils.debounce.js +0 -223
  19. package/src/common/utils.js +0 -151
  20. package/src/common/utils.table.js +0 -78
  21. package/src/common/utils.throttle.js +0 -83
  22. package/src/common/utils.tree.js +0 -18
  23. package/src/components/button/Button.vue +0 -195
  24. package/src/components/button/index.js +0 -7
  25. package/src/components/buttonGroup/ButtonGroup.vue +0 -11
  26. package/src/components/buttonGroup/index.js +0 -7
  27. package/src/components/calendar/Calendar.vue +0 -725
  28. package/src/components/calendar/index.js +0 -7
  29. package/src/components/calendar/uses.js +0 -1410
  30. package/src/components/chart/Chart.vue +0 -363
  31. package/src/components/chart/ChartToolbar.vue +0 -52
  32. package/src/components/chart/chart.core.js +0 -1170
  33. package/src/components/chart/chartZoom.core.js +0 -540
  34. package/src/components/chart/element/element.bar.js +0 -672
  35. package/src/components/chart/element/element.bar.time.js +0 -166
  36. package/src/components/chart/element/element.heatmap.js +0 -743
  37. package/src/components/chart/element/element.line.js +0 -611
  38. package/src/components/chart/element/element.pie.js +0 -197
  39. package/src/components/chart/element/element.scatter.js +0 -320
  40. package/src/components/chart/element/element.tip.js +0 -717
  41. package/src/components/chart/helpers/helpers.canvas.js +0 -265
  42. package/src/components/chart/helpers/helpers.constant.js +0 -235
  43. package/src/components/chart/helpers/helpers.util.js +0 -400
  44. package/src/components/chart/index.js +0 -9
  45. package/src/components/chart/model/index.js +0 -50
  46. package/src/components/chart/model/model.series.js +0 -125
  47. package/src/components/chart/model/model.store.js +0 -1427
  48. package/src/components/chart/plugins/plugins.interaction.js +0 -1655
  49. package/src/components/chart/plugins/plugins.legend.gradient.js +0 -606
  50. package/src/components/chart/plugins/plugins.legend.js +0 -1543
  51. package/src/components/chart/plugins/plugins.pie.js +0 -254
  52. package/src/components/chart/plugins/plugins.scrollbar.js +0 -732
  53. package/src/components/chart/plugins/plugins.title.js +0 -61
  54. package/src/components/chart/plugins/plugins.tooltip.js +0 -1041
  55. package/src/components/chart/scale/scale.js +0 -951
  56. package/src/components/chart/scale/scale.linear.js +0 -268
  57. package/src/components/chart/scale/scale.logarithmic.js +0 -135
  58. package/src/components/chart/scale/scale.step.js +0 -430
  59. package/src/components/chart/scale/scale.time.category.js +0 -338
  60. package/src/components/chart/scale/scale.time.js +0 -49
  61. package/src/components/chart/style/chart.scss +0 -405
  62. package/src/components/chart/uses.js +0 -721
  63. package/src/components/chartBrush/ChartBrush.vue +0 -323
  64. package/src/components/chartBrush/chartBrush.core.js +0 -691
  65. package/src/components/chartBrush/index.js +0 -9
  66. package/src/components/chartBrush/uses.js +0 -23
  67. package/src/components/chartGroup/ChartGroup.vue +0 -144
  68. package/src/components/chartGroup/index.js +0 -9
  69. package/src/components/chartGroup/style/chartGroup.scss +0 -5
  70. package/src/components/chartGroup/uses.js +0 -53
  71. package/src/components/checkbox/Checkbox.vue +0 -229
  72. package/src/components/checkbox/index.js +0 -7
  73. package/src/components/checkboxGroup/CheckboxGroup.vue +0 -44
  74. package/src/components/checkboxGroup/index.js +0 -7
  75. package/src/components/contextMenu/ContextMenu.vue +0 -95
  76. package/src/components/contextMenu/MenuList.vue +0 -182
  77. package/src/components/contextMenu/index.js +0 -7
  78. package/src/components/contextMenu/uses.js +0 -223
  79. package/src/components/datePicker/DatePicker.vue +0 -504
  80. package/src/components/datePicker/index.js +0 -7
  81. package/src/components/datePicker/uses.js +0 -460
  82. package/src/components/grid/Grid.vue +0 -1535
  83. package/src/components/grid/GridColumnSetting.vue +0 -358
  84. package/src/components/grid/GridFilterSetting.vue +0 -323
  85. package/src/components/grid/GridPagination.vue +0 -75
  86. package/src/components/grid/GridSummary.vue +0 -314
  87. package/src/components/grid/GridToolbar.vue +0 -35
  88. package/src/components/grid/icon/icon-option-button.vue +0 -17
  89. package/src/components/grid/icon/icon-sort-button.vue +0 -67
  90. package/src/components/grid/index.js +0 -11
  91. package/src/components/grid/style/grid.scss +0 -417
  92. package/src/components/grid/uses.js +0 -1629
  93. package/src/components/icon/Icon.vue +0 -53
  94. package/src/components/icon/index.js +0 -8
  95. package/src/components/inputNumber/InputNumber.vue +0 -212
  96. package/src/components/inputNumber/index.js +0 -7
  97. package/src/components/inputNumber/uses.js +0 -217
  98. package/src/components/loading/Loading.vue +0 -125
  99. package/src/components/loading/index.js +0 -7
  100. package/src/components/menu/Menu.vue +0 -79
  101. package/src/components/menu/MenuItem.vue +0 -201
  102. package/src/components/menu/index.js +0 -7
  103. package/src/components/message/Message.vue +0 -229
  104. package/src/components/message/index.js +0 -34
  105. package/src/components/messageBox/MessageBox.vue +0 -358
  106. package/src/components/messageBox/index.js +0 -22
  107. package/src/components/notification/Notification.vue +0 -316
  108. package/src/components/notification/index.js +0 -49
  109. package/src/components/pagination/Pagination.vue +0 -317
  110. package/src/components/pagination/index.js +0 -7
  111. package/src/components/pagination/pageButton.vue +0 -31
  112. package/src/components/progress/Progress.vue +0 -139
  113. package/src/components/progress/index.js +0 -7
  114. package/src/components/radio/Radio.vue +0 -159
  115. package/src/components/radio/index.js +0 -7
  116. package/src/components/radioGroup/RadioGroup.vue +0 -41
  117. package/src/components/radioGroup/index.js +0 -7
  118. package/src/components/scheduler/Scheduler.vue +0 -149
  119. package/src/components/scheduler/index.js +0 -7
  120. package/src/components/scheduler/uses.js +0 -183
  121. package/src/components/select/Select.vue +0 -556
  122. package/src/components/select/index.js +0 -7
  123. package/src/components/select/uses.js +0 -379
  124. package/src/components/slider/Slider.vue +0 -505
  125. package/src/components/slider/index.js +0 -7
  126. package/src/components/slider/uses.js +0 -391
  127. package/src/components/tabPanel/TabPanel.vue +0 -74
  128. package/src/components/tabPanel/index.js +0 -7
  129. package/src/components/tabs/Tabs.vue +0 -517
  130. package/src/components/tabs/index.js +0 -7
  131. package/src/components/textField/TextField.vue +0 -399
  132. package/src/components/textField/index.js +0 -7
  133. package/src/components/timePicker/TimePicker.vue +0 -364
  134. package/src/components/timePicker/index.js +0 -7
  135. package/src/components/toggle/Toggle.vue +0 -115
  136. package/src/components/toggle/index.js +0 -7
  137. package/src/components/tree/Tree.vue +0 -338
  138. package/src/components/tree/TreeNode.vue +0 -293
  139. package/src/components/tree/index.js +0 -7
  140. package/src/components/treeGrid/TreeGrid.vue +0 -1074
  141. package/src/components/treeGrid/TreeGridNode.vue +0 -349
  142. package/src/components/treeGrid/TreeGridToolbar.vue +0 -35
  143. package/src/components/treeGrid/icon/icon-tree.png +0 -0
  144. package/src/components/treeGrid/index.js +0 -9
  145. package/src/components/treeGrid/style/treeGrid.scss +0 -277
  146. package/src/components/treeGrid/uses.js +0 -1178
  147. package/src/components/window/Window.vue +0 -329
  148. package/src/components/window/index.js +0 -7
  149. package/src/components/window/uses.js +0 -908
  150. package/src/directives/clickoutside.js +0 -90
  151. package/src/main.js +0 -120
  152. package/src/style/components/input.scss +0 -108
  153. package/src/style/functions.scss +0 -3
  154. package/src/style/index.scss +0 -6
  155. package/src/style/lib/fonts/EVUI.eot +0 -0
  156. package/src/style/lib/fonts/EVUI.svg +0 -293
  157. package/src/style/lib/fonts/EVUI.ttf +0 -0
  158. package/src/style/lib/fonts/EVUI.woff +0 -0
  159. package/src/style/lib/icon.css +0 -888
  160. package/src/style/mixins.scss +0 -94
  161. package/src/style/themes.scss +0 -69
  162. package/src/style/variables.scss +0 -22
@@ -1,951 +0,0 @@
1
- import Canvas from '@/components/chart/helpers/helpers.canvas';
2
- import { defaultsDeep } from 'lodash-es';
3
- import {
4
- AXIS_OPTION,
5
- AXIS_UNITS,
6
- PLOT_LINE_OPTION,
7
- PLOT_LINE_LABEL_OPTION,
8
- PLOT_BAND_OPTION,
9
- } from '../helpers/helpers.constant';
10
- import Util from '../helpers/helpers.util';
11
-
12
- class Scale {
13
- constructor(type, axisOpt, ctx, options) {
14
- const merged = defaultsDeep({}, axisOpt, AXIS_OPTION);
15
- Object.keys(merged).forEach((key) => {
16
- this[key] = merged[key];
17
- });
18
-
19
- this.type = type;
20
- this.ctx = ctx;
21
- this.units = AXIS_UNITS[this.type];
22
- this.options = options;
23
-
24
- if (!this.position) {
25
- this.position = type === 'x' ? 'bottom' : 'left';
26
- }
27
- }
28
-
29
- /**
30
- * Calculate axis's min/max label steps
31
- * @param {string} type axis direction ('x', 'y')
32
- * @param {object} chartRect chart size information
33
- * @param {object} labelOffset chart label offset information
34
- * @param {number} tickSize label's size
35
- *
36
- * @returns {object} label range
37
- */
38
- calculateLabelRange(type, chartRect, labelOffset, tickSize) {
39
- let chartSize;
40
- let axisOffset;
41
- let bufferedTickSize;
42
-
43
- if (type === 'x') {
44
- chartSize = chartRect.chartWidth;
45
- bufferedTickSize = Math.floor(tickSize * 1.1);
46
- axisOffset = [labelOffset.left, labelOffset.right];
47
- } else {
48
- chartSize = chartRect.chartHeight;
49
- axisOffset = [labelOffset.top, labelOffset.bottom];
50
- bufferedTickSize = tickSize + (Math.floor(chartSize * 0.1));
51
- }
52
-
53
- const drawRange = chartSize - (axisOffset[0] + axisOffset[1]);
54
- const minSteps = 1;
55
- const maxSteps = Math.max(Math.floor(drawRange / bufferedTickSize) - 1, 1);
56
-
57
- return {
58
- min: minSteps,
59
- max: maxSteps,
60
- };
61
- }
62
-
63
- /**
64
- * Calculate min/max value, label and size information for axis
65
- * @param {object} minMax min/max information
66
- * @param {object} scrollbarOpt scrollbar option
67
- *
68
- * @returns {object} min/max value and label
69
- */
70
- calculateScaleRange(minMax, scrollbarOpt) {
71
- let maxValue;
72
- let minValue;
73
- let isDefaultMaxSameAsMin = false;
74
-
75
- const range = scrollbarOpt?.use ? scrollbarOpt?.range : this.range;
76
- if (Array.isArray(range) && range?.length === 2) {
77
- if (this.options.type === 'heatMap') {
78
- maxValue = range[1] > +minMax.max ? +minMax.max : range[1];
79
- minValue = range[0] < +minMax.min ? +minMax.min : range[0];
80
- } else {
81
- maxValue = range[1];
82
- minValue = range[0];
83
- }
84
- } else if (typeof range === 'function') {
85
- [minValue, maxValue] = range(minMax.min, minMax.max);
86
- } else {
87
- maxValue = minMax.max;
88
- minValue = minMax.min;
89
- }
90
-
91
- if (this.autoScaleRatio) {
92
- maxValue = Math.ceil(maxValue * (this.autoScaleRatio + 1));
93
- }
94
-
95
- if (this.startToZero) {
96
- minValue = 0;
97
- }
98
-
99
- if (maxValue === minValue) {
100
- maxValue += 1;
101
- isDefaultMaxSameAsMin = true;
102
- }
103
-
104
- const minLabel = this.getLabelFormat(minValue);
105
- const maxLabel = this.getLabelFormat(maxValue, {
106
- isMaxValueSameAsMin: isDefaultMaxSameAsMin,
107
- });
108
-
109
- return {
110
- min: minValue,
111
- max: maxValue,
112
- minLabel,
113
- maxLabel,
114
- size: Util.calcTextSize(
115
- maxLabel,
116
- Util.getLabelStyle(this.labelStyle),
117
- this.labelStyle?.padding,
118
- ),
119
- };
120
- }
121
-
122
- /**
123
- * return width what has max length
124
- * @param {string[]} notFormattedLabels
125
- * @reutrn number maxWidth
126
- */
127
- getLabelWidthHasMaxLength(notFormattedLabels) {
128
- return (notFormattedLabels ?? []).reduce((max, label) => {
129
- const formattedLabel = this.getLabelFormat(label);
130
- const width = Util.calcTextSize(
131
- formattedLabel,
132
- Util.getLabelStyle(this.labelStyle),
133
- )?.width ?? 0;
134
-
135
- return Math.max(max, width);
136
- }, 0);
137
- }
138
-
139
- /**
140
- * With range information, calculate how many labels in axis
141
- * linear type은 scale.linear.js에서 처리
142
- * @param {object} range min/max information
143
- *
144
- * @returns {object} steps, interval, min/max graph value
145
- */
146
- calculateSteps(range) {
147
- const { maxValue, minValue } = range;
148
- let { maxSteps } = range;
149
-
150
- let interval = this.getInterval(range);
151
- let increase = minValue;
152
- let numberOfSteps;
153
-
154
- while (increase < maxValue) {
155
- increase += interval;
156
- }
157
-
158
- const graphMax = increase;
159
- const graphMin = minValue;
160
- const graphRange = graphMax - graphMin;
161
-
162
- numberOfSteps = Math.round(graphRange / interval);
163
-
164
- if (maxValue === 1) {
165
- if (!this.decimalPoint) {
166
- interval = 1;
167
- numberOfSteps = 1;
168
- maxSteps = 1;
169
- } else if (maxSteps > 2) {
170
- interval = 0.2;
171
- numberOfSteps = 5;
172
- maxSteps = 5;
173
- } else {
174
- interval = 0.5;
175
- numberOfSteps = 2;
176
- maxSteps = 2;
177
- }
178
- }
179
-
180
- while (numberOfSteps > maxSteps) {
181
- interval *= 2;
182
- numberOfSteps = Math.round(graphRange / interval);
183
- interval = Math.ceil(graphRange / numberOfSteps);
184
- }
185
-
186
- if (graphMax - graphMin > (numberOfSteps * interval)) {
187
- interval = Math.ceil((graphMax - graphMin) / numberOfSteps);
188
- }
189
-
190
- return {
191
- steps: numberOfSteps,
192
- interval,
193
- graphMin,
194
- graphMax,
195
- };
196
- }
197
-
198
- /**
199
- * Draw Axis Title
200
- *
201
- * @param {object} chartRect min/max information
202
- * @param {object} labelOffset label offset information
203
- *
204
- * @returns {undefined}
205
- */
206
- drawAxisTitle(chartRect, labelOffset) {
207
- const titleOpt = this.title;
208
-
209
- if (!titleOpt?.use || isNaN(titleOpt.fontSize)) {
210
- return;
211
- }
212
-
213
- const ctx = this.ctx;
214
- ctx.save();
215
- ctx.font = Util.getLabelStyle(titleOpt);
216
- ctx.fillStyle = titleOpt.color;
217
- ctx.textAlign = titleOpt.textAlign;
218
-
219
- const axisLinePosition = {
220
- xLeft: chartRect.x1 + labelOffset.left,
221
- xRight: chartRect.x2 - labelOffset.right,
222
- yTop: chartRect.y1,
223
- };
224
-
225
- let titleXPos;
226
- let titleYPos;
227
-
228
- const margin = 10;
229
- if (this.type === 'x') {
230
- titleXPos = axisLinePosition.xRight;
231
- titleYPos = chartRect.y2 + titleOpt.fontSize + margin;
232
- } else {
233
- titleYPos = axisLinePosition.yTop - titleOpt.fontSize - margin;
234
- titleXPos = axisLinePosition.xLeft;
235
- }
236
-
237
- if (titleXPos > 0 && titleYPos > 0) {
238
- ctx.fillText(titleOpt.text, titleXPos, titleYPos);
239
- }
240
-
241
- ctx.restore();
242
- }
243
-
244
- /**
245
- * Draw axis
246
- * @param {object} chartRect min/max information
247
- * @param {object} labelOffset label offset information
248
- * @param {object} stepInfo label steps information
249
- * @param {object} hitInfo hit information
250
- * @param {object} selectLabelInfo selected label information
251
- * @param {object} dataLabels data label information, x axis only
252
- *
253
- * @returns {undefined}
254
- */
255
- draw(chartRect, labelOffset, stepInfo, hitInfo, selectLabelInfo, dataLabels) {
256
- const ctx = this.ctx;
257
- const options = this.options;
258
- const aPos = {
259
- x1: chartRect.x1 + labelOffset.left,
260
- x2: chartRect.x2 - labelOffset.right,
261
- y1: chartRect.y1 + labelOffset.top,
262
- y2: chartRect.y2 - labelOffset.bottom,
263
- };
264
-
265
- const steps = stepInfo.steps;
266
- const axisMin = stepInfo.graphMin;
267
- const axisMax = stepInfo.graphMax;
268
- const stepValue = stepInfo.interval;
269
-
270
- const startPoint = aPos[this.units.rectStart];
271
- const endPoint = aPos[this.units.rectEnd];
272
- const offsetPoint = aPos[this.units.rectOffset(this.position)];
273
- const offsetCounterPoint = aPos[this.units.rectOffsetCounter(this.position)];
274
-
275
- const AXIS_TICK_LENGTH = 5;
276
-
277
- let aliasPixel;
278
-
279
- this.drawAxisTitle(chartRect, labelOffset);
280
-
281
- // label font 설정
282
- ctx.font = Util.getLabelStyle(this.labelStyle);
283
- ctx.fillStyle = this.labelStyle.color;
284
-
285
- if (this.type === 'x') {
286
- ctx.textAlign = 'center';
287
- ctx.textBaseline = this.position === 'top' ? 'bottom' : 'top';
288
- } else {
289
- ctx.textAlign = this.position === 'left' ? 'right' : 'left';
290
- ctx.textBaseline = 'middle';
291
- }
292
-
293
- if (this.showAxis) {
294
- ctx.lineWidth = this.axisLineWidth;
295
- aliasPixel = Util.aliasPixel(ctx.lineWidth);
296
-
297
- ctx.beginPath();
298
- ctx.strokeStyle = this.axisLineColor;
299
-
300
- if (this.type === 'x') {
301
- ctx.moveTo(startPoint, offsetPoint + aliasPixel);
302
- ctx.lineTo(endPoint, offsetPoint + aliasPixel);
303
- } else {
304
- ctx.moveTo(offsetPoint + aliasPixel, startPoint);
305
- ctx.lineTo(offsetPoint + aliasPixel, endPoint);
306
- }
307
- ctx.stroke();
308
- ctx.closePath();
309
- }
310
-
311
- if (steps === 0 || axisMin === null) {
312
- return;
313
- }
314
-
315
- if (this.labelStyle?.show) {
316
- const distance = endPoint - startPoint;
317
- const labelGap = distance / steps;
318
- const ticks = [];
319
- const size = stepInfo.interval;
320
- let labelCenter = null;
321
- let linePosition = null;
322
- let offsetStartPoint = startPoint;
323
- let axisMinForLabel = axisMin;
324
-
325
- if (this.type === 'x' && options?.axesX[0].flow && dataLabels.length !== steps + 1) {
326
- const axisMinByMinutes = Math.floor(axisMin / size) * size;
327
- if (axisMinByMinutes !== +axisMin) {
328
- axisMinForLabel = axisMinByMinutes + size;
329
- offsetStartPoint += (distance / (axisMax - axisMin)) * (axisMinForLabel - axisMin);
330
- }
331
- }
332
-
333
- ctx.strokeStyle = this.gridLineColor;
334
- ctx.lineWidth = 1;
335
- aliasPixel = Util.aliasPixel(ctx.lineWidth);
336
-
337
- let labelText;
338
- for (let ix = 0; ix <= steps; ix++) {
339
- labelCenter = Math.round(offsetStartPoint + (labelGap * ix));
340
-
341
- if (labelCenter <= endPoint || this.type !== 'x' || !options?.axesX[0].flow || dataLabels.length === steps + 1) {
342
- ctx.beginPath();
343
- ticks[ix] = axisMinForLabel + (ix * stepValue);
344
-
345
- const isZeroLine = ticks[ix] === 0;
346
- if (isZeroLine && this.zeroLineColor) {
347
- ctx.strokeStyle = this.zeroLineColor;
348
- } else {
349
- ctx.strokeStyle = this.gridLineColor;
350
- }
351
-
352
- linePosition = labelCenter + aliasPixel;
353
- labelText = this.getLabelFormat(Math.min(axisMax, ticks[ix]), {
354
- prev: ticks[ix - 1] ?? '',
355
- });
356
-
357
- const isBlurredLabel = this.options?.selectLabel?.use
358
- && this.options?.selectLabel?.useLabelOpacity
359
- && (this.options.horizontal === (this.type === 'y'))
360
- && selectLabelInfo?.dataIndex?.length
361
- && !selectLabelInfo?.label
362
- .map(t => this.getLabelFormat(Math.min(axisMax, t), {
363
- prev: ticks[ix - 1] ?? '',
364
- })).includes(labelText);
365
-
366
- const labelColor = this.labelStyle.color;
367
- let defaultOpacity = 1;
368
-
369
- if (Util.getColorStringType(labelColor) === 'RGBA') {
370
- defaultOpacity = Util.getOpacity(labelColor);
371
- }
372
-
373
- ctx.fillStyle = Util.colorStringToRgba(labelColor, isBlurredLabel ? 0.1 : defaultOpacity);
374
-
375
- let labelPoint;
376
-
377
- if (this.type === 'x') {
378
- labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
379
- if (options?.brush?.showLabel || !options?.brush) {
380
- ctx.fillText(labelText, labelCenter, labelPoint);
381
- }
382
-
383
- if (!isBlurredLabel
384
- && options?.selectItem?.showLabelTip
385
- && hitInfo?.label
386
- && !this.options?.horizontal) {
387
- const selectedLabel = this.getLabelFormat(
388
- Math.min(axisMax, hitInfo.label + (0 * stepValue)),
389
- );
390
- if (selectedLabel === labelText) {
391
- const height = Math.round(ctx.measureText(this.labelStyle?.fontSize).width);
392
- Util.showLabelTip({
393
- ctx: this.ctx,
394
- width: Math.round(ctx.measureText(selectedLabel).width) + 10,
395
- height,
396
- x: labelCenter,
397
- y: labelPoint + (height - 2),
398
- borderRadius: 2,
399
- arrowSize: 3,
400
- text: labelText,
401
- backgroundColor: options?.selectItem?.labelTipStyle?.backgroundColor,
402
- textColor: options?.selectItem?.labelTipStyle?.textColor,
403
- });
404
- }
405
- }
406
-
407
- if (this.showAxisTick) {
408
- ctx.beginPath();
409
- ctx.strokeStyle = this.axisLineColor;
410
- ctx.moveTo(linePosition, offsetPoint);
411
- ctx.lineTo(linePosition, offsetPoint + AXIS_TICK_LENGTH);
412
- ctx.stroke();
413
- ctx.closePath();
414
- }
415
-
416
- if ((ix !== 0 || options?.axesX[0].flow) && this.showGrid) {
417
- ctx.beginPath();
418
- ctx.strokeStyle = this.gridLineColor;
419
- ctx.moveTo(linePosition, offsetPoint);
420
- ctx.lineTo(linePosition, offsetCounterPoint);
421
- ctx.stroke();
422
- ctx.closePath();
423
- }
424
- } else {
425
- labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
426
- if (options?.brush?.showLabel || !options?.brush) {
427
- ctx.fillText(labelText, labelPoint, labelCenter);
428
- }
429
-
430
- if (ix === steps) {
431
- linePosition -= 1;
432
- }
433
-
434
- if (this.showAxisTick) {
435
- ctx.beginPath();
436
- ctx.strokeStyle = this.axisLineColor;
437
- ctx.moveTo(offsetPoint + (this.axisLineWidth ?? 1), linePosition);
438
- ctx.lineTo(offsetPoint - AXIS_TICK_LENGTH, linePosition);
439
- ctx.stroke();
440
- ctx.closePath();
441
- }
442
-
443
- if (ix !== 0 && this.showGrid) {
444
- ctx.beginPath();
445
- ctx.strokeStyle = this.gridLineColor;
446
- ctx.moveTo(offsetPoint, linePosition);
447
- ctx.lineTo(offsetCounterPoint, linePosition);
448
- ctx.stroke();
449
- ctx.closePath();
450
- }
451
- }
452
- }
453
- }
454
- }
455
-
456
- // Draw plot lines and plot bands
457
- if (this.plotBands?.length || this.plotLines?.length) {
458
- const xArea = chartRect.chartWidth - (labelOffset.left + labelOffset.right);
459
- const yArea = chartRect.chartHeight - (labelOffset.top + labelOffset.bottom);
460
- const padding = aliasPixel + 1;
461
- const minX = aPos.x1;
462
- const maxX = aPos.x2 + padding;
463
- const minY = aPos.y1 - padding; // top
464
- const maxY = aPos.y2; // bottom
465
-
466
- this.plotBands?.forEach((plotBand) => {
467
- const mergedPlotBandOpt = defaultsDeep({}, plotBand, PLOT_BAND_OPTION);
468
- const { from: userDefinedFrom, to: userDefinedTo, label: labelOpt } = mergedPlotBandOpt;
469
- const from = !Util.isNullOrUndefined(userDefinedFrom)
470
- ? Math.max(userDefinedFrom, axisMin)
471
- : axisMin;
472
- const to = !Util.isNullOrUndefined(userDefinedTo)
473
- ? Math.min(userDefinedTo, axisMax)
474
- : axisMax;
475
-
476
- this.setPlotBandStyle(mergedPlotBandOpt);
477
-
478
- let fromPos;
479
- let toPos;
480
- if (this.type === 'x') {
481
- fromPos = Canvas.calculateX(from, axisMin, axisMax, xArea, minX);
482
- toPos = Canvas.calculateX(to, axisMin, axisMax, xArea, minX);
483
-
484
- if (fromPos === null || toPos === null) {
485
- return;
486
- }
487
-
488
- this.drawXPlotBand(fromPos, toPos, minX, maxX, minY, maxY);
489
- } else {
490
- fromPos = Canvas.calculateY(from, axisMin, axisMax, yArea, maxY);
491
- toPos = Canvas.calculateY(to, axisMin, axisMax, yArea, maxY);
492
-
493
- if (fromPos === null || toPos === null) {
494
- return;
495
- }
496
-
497
- this.drawYPlotBand(fromPos, toPos, minX, maxX, minY, maxY);
498
- }
499
-
500
- if (labelOpt.show) {
501
- const labelOptions = this.getNormalizedLabelOptions(chartRect, labelOpt);
502
- const textXY = this.getPlotBandLabelPosition(fromPos, toPos, labelOptions, maxX, minY);
503
- this.drawPlotLabel(labelOptions, textXY);
504
- }
505
-
506
- ctx.restore();
507
- });
508
-
509
- this.plotLines?.forEach((plotLine) => {
510
- if (typeof +plotLine.value !== 'number') {
511
- return;
512
- }
513
-
514
- const mergedPlotLineOpt = defaultsDeep({}, plotLine, PLOT_LINE_OPTION);
515
- const { value, label: labelOpt } = mergedPlotLineOpt;
516
-
517
- let dataPos;
518
- if (this.type === 'x') {
519
- dataPos = Canvas.calculateX(value, axisMin, axisMax, xArea, minX);
520
-
521
- if (dataPos === null) {
522
- return;
523
- }
524
-
525
- this.setPlotLineStyle(mergedPlotLineOpt);
526
- this.drawXPlotLine(dataPos, minX, maxX, minY, maxY);
527
- } else {
528
- dataPos = Canvas.calculateY(value, axisMin, axisMax, yArea, maxY);
529
-
530
- if (dataPos === null) {
531
- return;
532
- }
533
-
534
- this.setPlotLineStyle(mergedPlotLineOpt);
535
- this.drawYPlotLine(dataPos, minX, maxX, minY, maxY);
536
- }
537
-
538
- if (labelOpt.show) {
539
- const labelOptions = this.getNormalizedLabelOptions(chartRect, labelOpt);
540
- const textXY = this.getPlotLineLabelPosition(dataPos, labelOptions, maxX, minY);
541
- this.drawPlotLabel(labelOptions, textXY);
542
- }
543
-
544
- ctx.restore();
545
- });
546
- }
547
- }
548
-
549
- /**
550
- * Set plot line style
551
- * @param {object} plotLine plotLine Options
552
- *
553
- * @returns {undefined}
554
- */
555
- setPlotLineStyle(plotLine) {
556
- const ctx = this.ctx;
557
- const { color, lineWidth } = plotLine;
558
-
559
- ctx.beginPath();
560
- ctx.save();
561
- ctx.lineWidth = lineWidth;
562
- ctx.strokeStyle = color;
563
-
564
- if (plotLine.segments) {
565
- ctx.setLineDash(plotLine.segments);
566
- }
567
- }
568
-
569
- /**
570
- * Set plot band style
571
- * @param {object} plotBand plotBand Options
572
- *
573
- * @returns {undefined}
574
- */
575
- setPlotBandStyle(plotBand) {
576
- const ctx = this.ctx;
577
- const { color } = plotBand;
578
-
579
- ctx.beginPath();
580
- ctx.save();
581
- ctx.fillStyle = color;
582
- }
583
-
584
- /**
585
- * Draw X Plot band
586
- * @param {number} fromDataX From data's X Position
587
- * @param {number} toDataX To data's X Position
588
- * @param {number} minX Min X Position
589
- * @param {number} maxX Max X Position
590
- * @param {number} minY Min Y Position
591
- * @param {number} maxY Max Y Position
592
- *
593
- * @returns {undefined}
594
- */
595
- drawXPlotBand(fromDataX, toDataX, minX, maxX, minY, maxY) {
596
- const ctx = this.ctx;
597
-
598
- const checkValidPosition = x => x || x > minX || x < maxX;
599
-
600
- if (!checkValidPosition(fromDataX) || !checkValidPosition(toDataX)) {
601
- ctx.closePath();
602
- ctx.restore();
603
- return;
604
- }
605
-
606
- ctx.moveTo(fromDataX, minY);
607
- ctx.lineTo(fromDataX, maxY);
608
- ctx.lineTo(toDataX, maxY);
609
- ctx.lineTo(toDataX, minY);
610
- ctx.lineTo(fromDataX, minY);
611
-
612
- ctx.stroke();
613
- ctx.fill();
614
- ctx.restore();
615
- ctx.closePath();
616
- }
617
-
618
- /**
619
- * Draw X Plot line
620
- * @param {number} dataX Data's X Position
621
- * @param {number} minX Min X Position
622
- * @param {number} maxX Max X Position
623
- * @param {number} minY Min Y Position
624
- * @param {number} maxY Max Y Position
625
- *
626
- * @returns {undefined}
627
- */
628
- drawXPlotLine(dataX, minX, maxX, minY, maxY) {
629
- const ctx = this.ctx;
630
-
631
- if (!dataX || dataX < minX || dataX > maxX) {
632
- ctx.closePath();
633
- ctx.restore();
634
- return;
635
- }
636
-
637
- let dataXPos = dataX;
638
- dataXPos += Util.aliasPixel(ctx.lineWidth);
639
-
640
- ctx.moveTo(dataXPos, maxY);
641
- ctx.lineTo(dataXPos, minY);
642
-
643
- ctx.stroke();
644
- ctx.restore();
645
- ctx.closePath();
646
- }
647
-
648
- /**
649
- * Draw Y Plot line
650
- * @param {number} dataY Data's Y Position
651
- * @param {number} minX Min X Position
652
- * @param {number} maxX Max X Position
653
- * @param {number} minY Min Y Position
654
- * @param {number} maxY Max Y Position
655
- *
656
- * @returns {undefined}
657
- */
658
- drawYPlotLine(dataY, minX, maxX, minY, maxY) {
659
- const ctx = this.ctx;
660
-
661
- if (!dataY || dataY > maxY || dataY < minY) {
662
- ctx.closePath();
663
- ctx.restore();
664
- return;
665
- }
666
-
667
- let dataYPos = dataY;
668
- dataYPos += Util.aliasPixel(ctx.lineWidth);
669
-
670
- ctx.moveTo(minX, dataYPos);
671
- ctx.lineTo(maxX, dataYPos);
672
-
673
- ctx.stroke();
674
- ctx.restore();
675
- ctx.closePath();
676
- }
677
-
678
- /**
679
- * Draw Y Plot band
680
- * @param {number} fromDataY From data's Y Position (bottom)
681
- * @param {number} toDataY To data's Y Position (top)
682
- * @param {number} minX Min X Position
683
- * @param {number} maxX Max X Position
684
- * @param {number} minY Min Y Position
685
- * @param {number} maxY Max Y Position
686
- *
687
- * @returns {undefined}
688
- */
689
- drawYPlotBand(fromDataY, toDataY, minX, maxX, minY, maxY) {
690
- const ctx = this.ctx;
691
-
692
- const checkValidPosition = y => y || y > minY || y < maxY;
693
-
694
- if (!checkValidPosition(fromDataY) || !checkValidPosition(toDataY)) {
695
- ctx.closePath();
696
- ctx.restore();
697
- return;
698
- }
699
-
700
- ctx.moveTo(minX, fromDataY);
701
- ctx.lineTo(minX, toDataY);
702
- ctx.lineTo(maxX, toDataY);
703
- ctx.lineTo(maxX, fromDataY);
704
- ctx.lineTo(minX, fromDataY);
705
-
706
- ctx.fill();
707
- ctx.restore();
708
- ctx.closePath();
709
- }
710
-
711
- /**
712
- * get normalized options for plot label
713
- * @param {object} chartRect chartRect
714
- * @param {object} labelOpt plotLine Options
715
- *
716
- * @returns {object}
717
- */
718
- getNormalizedLabelOptions(chartRect, labelOpt) {
719
- const mergedLabelOpt = defaultsDeep({}, labelOpt, PLOT_LINE_LABEL_OPTION);
720
-
721
- const ctx = this.ctx;
722
- const { maxWidth } = mergedLabelOpt;
723
- const fontSize = mergedLabelOpt.fontSize > 20 ? 20 : mergedLabelOpt.fontSize;
724
- let label = mergedLabelOpt.text;
725
- let labelWidth = maxWidth ?? ctx.measureText(label).width;
726
-
727
- const plotLabelAreaWidth = this.type === 'y'
728
- ? chartRect.width - chartRect.chartWidth
729
- : maxWidth ?? chartRect.width;
730
-
731
- if (plotLabelAreaWidth < ctx.measureText(label).width && mergedLabelOpt.textOverflow === 'ellipsis') {
732
- label = Util.truncateLabelWithEllipsis(mergedLabelOpt.text, plotLabelAreaWidth, ctx);
733
- labelWidth = ctx.measureText(label).width;
734
- }
735
-
736
- return {
737
- label,
738
- fontSize,
739
- labelWidth,
740
- labelBoxPadding: fontSize / 4,
741
- labelHalfWidth: labelWidth / 2,
742
- labelHalfHeight: fontSize / 2,
743
- ...mergedLabelOpt,
744
- };
745
- }
746
-
747
- /**
748
- * Calculate position of plot band's label
749
- * @param {object} fromPos from data position
750
- * @param {object} toPos to data position
751
- * @param {object} labelOpt label options
752
- * @param {object} maxX max x position
753
- * @param {object} minY min y position
754
- *
755
- * @returns {object}
756
- */
757
- getPlotBandLabelPosition(fromPos, toPos, labelOpt, maxX, minY) {
758
- const {
759
- fontSize,
760
- labelWidth,
761
- labelHalfWidth,
762
- labelHalfHeight,
763
- labelBoxPadding,
764
- textAlign,
765
- verticalAlign,
766
- } = labelOpt;
767
-
768
- if (fontSize <= 0) {
769
- return { textX: 0, textY: 0 };
770
- }
771
-
772
- let textX;
773
- let textY;
774
-
775
- if (this.type === 'x') {
776
- textY = minY - labelBoxPadding - fontSize;
777
-
778
- switch (textAlign) {
779
- case 'left':
780
- textX = fromPos + labelHalfWidth + labelBoxPadding;
781
- break;
782
-
783
- case 'right':
784
- textX = toPos - labelHalfWidth - labelBoxPadding;
785
- break;
786
-
787
- case 'center':
788
- default:
789
- textX = ((toPos - fromPos) / 2) + fromPos;
790
- break;
791
- }
792
- } else {
793
- textX = maxX + labelWidth + labelBoxPadding;
794
-
795
- switch (verticalAlign) {
796
- case 'top':
797
- textY = toPos + labelHalfHeight + labelBoxPadding;
798
- break;
799
-
800
- case 'bottom':
801
- textY = fromPos - labelHalfHeight - labelBoxPadding;
802
- break;
803
-
804
- case 'middle':
805
- default:
806
- textY = ((fromPos - toPos) / 2) + toPos;
807
- break;
808
- }
809
- }
810
-
811
- return { textX, textY };
812
- }
813
-
814
- /**
815
- * Calculate position of plot line's label
816
- * @param {object} dataPos data position
817
- * @param {object} labelOpt label options
818
- * @param {object} maxX max x position
819
- * @param {object} minY min y position
820
- *
821
- * @returns {undefined}
822
- */
823
- getPlotLineLabelPosition(dataPos, labelOpt, maxX, minY) {
824
- const {
825
- fontSize,
826
- labelWidth,
827
- labelHalfWidth,
828
- labelHalfHeight,
829
- labelBoxPadding,
830
- } = labelOpt;
831
-
832
- if (fontSize <= 0) {
833
- return { textX: 0, textY: 0 };
834
- }
835
-
836
- let textX;
837
- let textY;
838
-
839
- if (this.type === 'x') {
840
- textY = minY - labelBoxPadding - fontSize;
841
-
842
- switch (labelOpt.textAlign) {
843
- case 'left':
844
- textX = dataPos - labelHalfWidth - labelBoxPadding;
845
- break;
846
-
847
- case 'right':
848
- textX = dataPos + labelHalfWidth + labelBoxPadding;
849
- break;
850
-
851
- case 'center':
852
- default:
853
- textX = dataPos;
854
- break;
855
- }
856
- } else {
857
- textX = maxX + labelWidth + labelBoxPadding;
858
-
859
- switch (labelOpt.verticalAlign) {
860
- case 'top':
861
- textY = dataPos - labelHalfHeight - labelBoxPadding;
862
- break;
863
-
864
- case 'bottom':
865
- textY = dataPos + labelHalfHeight + labelBoxPadding;
866
- break;
867
-
868
- case 'middle':
869
- default:
870
- textY = dataPos;
871
- break;
872
- }
873
- }
874
-
875
- return { textX, textY };
876
- }
877
-
878
- /**
879
- * Calculate Values for drawing label
880
- * @param {object} labelOptions plot line Label Options
881
- * @param {object} positions x, y Position
882
- *
883
- * @returns {undefined}
884
- */
885
- drawPlotLabel(labelOptions, positions) {
886
- if (!positions) {
887
- return;
888
- }
889
-
890
- const { textX, textY } = positions;
891
- const {
892
- label,
893
- fontSize,
894
- fontColor,
895
- fillColor,
896
- lineColor,
897
- lineWidth,
898
- labelBoxPadding,
899
- labelWidth,
900
- labelHalfWidth,
901
- labelHalfHeight,
902
- } = labelOptions;
903
-
904
- if (fontSize <= 0) {
905
- return;
906
- }
907
-
908
- const ctx = this.ctx;
909
- ctx.save();
910
- ctx.beginPath();
911
- ctx.font = Util.getLabelStyle(labelOptions);
912
-
913
- let top = 0;
914
- let bottom = 0;
915
- let left = 0;
916
- let right = 0;
917
-
918
- if (this.type === 'x') {
919
- top = textY - labelBoxPadding;
920
- bottom = textY + fontSize;
921
- left = textX - labelHalfWidth - labelBoxPadding;
922
- right = textX + labelHalfWidth + labelBoxPadding;
923
- } else {
924
- top = textY - labelHalfHeight - labelBoxPadding;
925
- bottom = textY + labelHalfHeight + labelBoxPadding;
926
- left = textX - labelWidth;
927
- right = textX + labelBoxPadding;
928
- }
929
-
930
- ctx.fillStyle = fillColor;
931
- ctx.strokeStyle = lineColor;
932
- ctx.lineWidth = lineWidth;
933
- ctx.moveTo(left, bottom);
934
- ctx.lineTo(left, top);
935
- ctx.lineTo(right, top);
936
- ctx.lineTo(right, bottom);
937
- ctx.lineTo(left, bottom);
938
- ctx.fill();
939
-
940
- if (lineWidth > 0) {
941
- ctx.stroke();
942
- }
943
-
944
- ctx.fillStyle = fontColor;
945
-
946
- ctx.fillText(label, textX, textY);
947
- ctx.closePath();
948
- }
949
- }
950
-
951
- export default Scale;