evui 3.3.8 → 3.3.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evui",
3
- "version": "3.3.8",
3
+ "version": "3.3.9",
4
4
  "description": "A EXEM Library project",
5
5
  "author": "exem <dev_client@ex-em.com>",
6
6
  "license": "MIT",
@@ -332,7 +332,7 @@ class Bar {
332
332
  */
333
333
  drawValueLabels({ context, data, positions, isHighlight }) {
334
334
  const isHorizontal = this.isHorizontal;
335
- const { fontSize, textColor, align, formatter } = this.showValue;
335
+ const { fontSize, textColor, align, formatter, decimalPoint } = this.showValue;
336
336
  const { x, y, w, h } = positions;
337
337
  const ctx = context;
338
338
 
@@ -361,7 +361,7 @@ class Bar {
361
361
  }
362
362
 
363
363
  if (!formatter || typeof formattedTxt !== 'string') {
364
- formattedTxt = Util.labelSignFormat(value);
364
+ formattedTxt = Util.labelSignFormat(value, decimalPoint);
365
365
  }
366
366
 
367
367
  const vw = Math.round(ctx.measureText(formattedTxt).width);
@@ -24,6 +24,7 @@ class Pie {
24
24
  this.centerX = 0;
25
25
  this.centerY = 0;
26
26
  this.radius = 0;
27
+ this.doughnutHoleSize = 0;
27
28
  this.startAngle = 0;
28
29
  this.endAngle = 0;
29
30
  this.slice = null;
@@ -45,6 +46,7 @@ class Pie {
45
46
  const slice = new Path2D();
46
47
 
47
48
  const radius = this.isSelect ? this.radius + 5 : this.radius;
49
+ const doughnutHoleRadius = this.radius * this.doughnutHoleSize;
48
50
 
49
51
  const color = this.color;
50
52
  const noneDownplayOpacity = color.includes('rgba') ? Util.getOpacity(color) : 1;
@@ -64,6 +66,10 @@ class Pie {
64
66
  ctx.stroke(slice);
65
67
  }
66
68
 
69
+ if (this.showValue?.use) {
70
+ this.drawValueLabels(ctx, doughnutHoleRadius);
71
+ }
72
+
67
73
  ctx.closePath();
68
74
 
69
75
  this.slice = slice;
@@ -101,6 +107,7 @@ class Pie {
101
107
  itemHighlight(item, context) {
102
108
  const ctx = context;
103
109
  const radius = this.isSelect ? this.radius + 5 : this.radius;
110
+ const doughnutHoleRadius = this.radius * this.doughnutHoleSize;
104
111
 
105
112
  ctx.save();
106
113
  ctx.shadowOffsetX = 0;
@@ -116,7 +123,62 @@ class Pie {
116
123
  ctx.arc(this.centerX, this.centerY, radius, this.startAngle, this.endAngle);
117
124
  ctx.lineTo(this.centerX, this.centerY);
118
125
  ctx.fill();
126
+
127
+ if (this.showValue?.use) {
128
+ this.drawValueLabels(ctx, doughnutHoleRadius);
129
+ }
130
+
119
131
  ctx.closePath();
132
+ ctx.restore();
133
+ }
134
+
135
+ /**
136
+ * Draw value label if series 'use' of showValue option is true
137
+ *
138
+ * @param context canvas context
139
+ */
140
+ drawValueLabels(context) {
141
+ const { fontSize, textColor, formatter } = this.showValue;
142
+ const ctx = context;
143
+
144
+ ctx.save();
145
+ ctx.beginPath();
146
+
147
+ ctx.font = `normal normal normal ${fontSize}px Roboto`;
148
+ ctx.fillStyle = textColor;
149
+ ctx.lineWidth = 1;
150
+ ctx.textAlign = 'center';
151
+ ctx.textBaseline = 'middle';
152
+
153
+ const value = this.data.o;
154
+
155
+ let formattedTxt;
156
+ if (formatter) {
157
+ formattedTxt = formatter(value);
158
+ }
159
+
160
+ if (!formatter || typeof formattedTxt !== 'string') {
161
+ formattedTxt = Util.labelSignFormat(value);
162
+ }
163
+
164
+ const ratio = 1.8;
165
+ const radius = this.radius - this.doughnutHoleSize;
166
+ const innerAngle = ((this.endAngle - this.startAngle) * 180) / Math.PI;
167
+ const valueHeight = fontSize + 4;
168
+ const valueWidth = Math.round(ctx.measureText(formattedTxt).width);
169
+
170
+ if (innerAngle >= valueWidth * ratio
171
+ && innerAngle >= valueHeight * ratio
172
+ && radius >= valueWidth * ratio
173
+ && radius >= valueHeight * ratio
174
+ ) {
175
+ const halfRadius = (radius / 2) + this.doughnutHoleSize;
176
+ const centerAngle = ((this.endAngle - this.startAngle) / 2) + this.startAngle;
177
+ const xPos = halfRadius * Math.cos(centerAngle) + this.centerX;
178
+ const yPos = halfRadius * Math.sin(centerAngle) + this.centerY;
179
+
180
+ ctx.fillText(formattedTxt, xPos, yPos);
181
+ }
120
182
 
121
183
  ctx.restore();
122
184
  }
@@ -59,6 +59,7 @@ export const BAR_OPTION = {
59
59
  fontSize: 12,
60
60
  textColor: '#000000',
61
61
  formatter: null,
62
+ decimalPoint: 0,
62
63
  },
63
64
  };
64
65
 
@@ -70,6 +71,12 @@ export const PIE_OPTION = {
70
71
  color: '#FFFFFF',
71
72
  lineWidth: 2,
72
73
  },
74
+ showValue: {
75
+ use: false,
76
+ fontSize: 12,
77
+ textColor: '#000000',
78
+ formatter: null,
79
+ },
73
80
  };
74
81
 
75
82
  export const AXIS_OPTION = {
@@ -452,8 +452,14 @@ const modules = {
452
452
 
453
453
  getItem({ seriesID, dataIndex }, useApproximate = false) {
454
454
  const dataInfo = this.getDataByValues(seriesID, dataIndex);
455
+
456
+ if (!dataInfo || !dataInfo?.xp || !dataInfo?.yp) {
457
+ return null;
458
+ }
459
+
455
460
  return this.getItemByPosition([dataInfo.xp, dataInfo.yp], useApproximate);
456
461
  },
462
+
457
463
  /**
458
464
  *
459
465
  * @param seriesID
@@ -75,6 +75,7 @@ const modules = {
75
75
  series.centerX = centerX;
76
76
  series.centerY = centerY;
77
77
  series.radius = radius;
78
+ series.doughnutHoleSize = radius * (pieOption.doughnutHoleSize ?? 0);
78
79
  series.startAngle = startAngle;
79
80
  series.endAngle = endAngle;
80
81
  series.data = { o: value };
@@ -166,6 +167,7 @@ const modules = {
166
167
  series.centerX = centerX;
167
168
  series.centerY = centerY;
168
169
  series.radius = radius;
170
+ series.doughnutHoleSize = radius * (pieOption.doughnutHoleSize ?? 0);
169
171
  series.startAngle = slice.sa;
170
172
  series.endAngle = slice.ea;
171
173
  series.data = { o: slice.value };