@easyv/charts 1.2.11 → 1.3.0

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 (77) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/Axis.js +10 -10
  5. package/lib/components/Background.js +13 -3
  6. package/lib/components/Band.js +8 -8
  7. package/lib/components/BaseLine.js +0 -1
  8. package/lib/components/Carousel.js +2 -2
  9. package/lib/components/CartesianChart.js +11 -6
  10. package/lib/components/ConicalGradient.js +21 -21
  11. package/lib/components/Indicator.js +2 -2
  12. package/lib/components/Label.js +11 -12
  13. package/lib/components/Lighter.js +179 -179
  14. package/lib/components/LinearGradient.js +2 -2
  15. package/lib/components/Marquee.js +23 -28
  16. package/lib/components/StackData.js +2 -4
  17. package/lib/components/StereoBar.js +14 -14
  18. package/lib/components/TextOverflow.js +3 -3
  19. package/lib/css/index.module.css +41 -41
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/element/ConicGradient.js +72 -72
  22. package/lib/hooks/useAnimateData.js +5 -5
  23. package/lib/hooks/useAxes.js +5 -5
  24. package/lib/hooks/useCarouselAxisX.js +5 -5
  25. package/lib/hooks/useExtentData.js +10 -8
  26. package/lib/hooks/useFilterData.js +5 -5
  27. package/lib/hooks/useStackData.js +11 -10
  28. package/lib/hooks/useTooltip.js +10 -10
  29. package/lib/utils/index.js +62 -41
  30. package/package.json +54 -53
  31. package/src/components/AnimateData.tsx +24 -24
  32. package/src/components/Axis.tsx +354 -354
  33. package/src/components/Background.tsx +62 -45
  34. package/src/components/Band.tsx +169 -173
  35. package/src/components/BaseLine.js +82 -83
  36. package/src/components/Brush.js +159 -159
  37. package/src/components/Carousel.tsx +144 -144
  38. package/src/components/CartesianChart.js +33 -22
  39. package/src/components/Chart.js +99 -99
  40. package/src/components/ChartContainer.tsx +63 -63
  41. package/src/components/ConicalGradient.js +258 -258
  42. package/src/components/ExtentData.js +17 -17
  43. package/src/components/FilterData.js +23 -23
  44. package/src/components/Indicator.js +13 -13
  45. package/src/components/Label.js +225 -206
  46. package/src/components/Legend.js +158 -158
  47. package/src/components/Lighter.jsx +173 -173
  48. package/src/components/Line.js +145 -145
  49. package/src/components/LinearGradient.js +29 -29
  50. package/src/components/Mapping.js +71 -71
  51. package/src/components/Marquee.js +88 -93
  52. package/src/components/PieChart.js +1278 -1278
  53. package/src/components/StackData.js +16 -20
  54. package/src/components/StereoBar.tsx +307 -311
  55. package/src/components/TextOverflow.js +51 -51
  56. package/src/components/Tooltip.js +169 -169
  57. package/src/components/index.js +55 -55
  58. package/src/context/index.js +2 -2
  59. package/src/css/index.module.css +41 -41
  60. package/src/css/piechart.module.css +26 -26
  61. package/src/element/ConicGradient.jsx +55 -55
  62. package/src/element/Line.tsx +33 -33
  63. package/src/element/index.ts +3 -3
  64. package/src/formatter/index.js +1 -1
  65. package/src/formatter/legend.js +90 -90
  66. package/src/hooks/index.js +17 -17
  67. package/src/hooks/useAnimateData.ts +67 -67
  68. package/src/hooks/useAxes.js +144 -144
  69. package/src/hooks/useCarouselAxisX.js +163 -163
  70. package/src/hooks/useExtentData.js +89 -88
  71. package/src/hooks/useFilterData.js +72 -72
  72. package/src/hooks/useStackData.js +101 -100
  73. package/src/hooks/useTooltip.ts +96 -96
  74. package/src/index.js +6 -6
  75. package/src/types/index.d.ts +67 -67
  76. package/src/utils/index.js +731 -714
  77. package/tsconfig.json +23 -23
@@ -1,311 +1,307 @@
1
- /**
2
- * 立体柱状图的柱子
3
- */
4
- import React, { memo } from 'react';
5
- import { min, max } from 'd3v7';
6
- import {
7
- getBandBackground,
8
- getBandwidth,
9
- getBandSeriesStepAndWidth,
10
- } from '../utils';
11
-
12
- const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
13
- switch (extent) {
14
- case 'min':
15
- const minData = min(data, (d: DataWithBoundType) => d.data.y);
16
- return data.map((item) => ({
17
- ...item,
18
- flag: minData == item.data.y ? 'min' : '',
19
- }));
20
- case 'max':
21
- const maxData = max(data, (d: DataWithBoundType) => d.data.y);
22
- return data.map((item) => ({
23
- ...item,
24
- flag: maxData == item.data.y ? 'max' : '',
25
- }));
26
- default:
27
- return data;
28
- }
29
- };
30
-
31
- const getAttr = ({
32
- isVertical,
33
- seriesWidth,
34
- length,
35
- x,
36
- y,
37
- }: {
38
- isVertical: boolean;
39
- seriesWidth: number;
40
- length: number;
41
- x: number;
42
- y: number;
43
- }) => {
44
- if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
45
- return {
46
- x,
47
- y,
48
- width: seriesWidth,
49
- height: length,
50
- };
51
- };
52
-
53
- const getBorderRadius = ({
54
- isVertical,
55
- positive,
56
- seriesWidth,
57
- }: {
58
- isVertical: boolean;
59
- positive: boolean;
60
- seriesWidth: number;
61
- }) => {
62
- return isVertical
63
- ? positive
64
- ? '0px ' + seriesWidth + 'px ' + seriesWidth + 'px 0'
65
- : seriesWidth + 'px 0 0 ' + seriesWidth + 'px'
66
- : positive
67
- ? seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px 0 0'
68
- : '0 0 ' + seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px';
69
- };
70
-
71
- export default memo(
72
- ({
73
- triggerClick,
74
- config: {
75
- pattern = {},
76
- seriesIntervalWidth: paddingInner = 0,
77
- paddingInner: paddingOuter = 0,
78
- style,
79
- fill,
80
- highlight: { show: showHighlight, extent, fill: highlightFill },
81
- id
82
- },
83
- bandLength = 0,
84
- data,
85
- xAxis: { scaler: xScaler, step, direction },
86
- yAxis: { scaler: yScaler },
87
- fieldName
88
- }: any) => {
89
- if (!data.length) return null;
90
- const bandwidth = getBandwidth(step, paddingOuter);
91
- const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
92
- width: bandwidth,
93
- paddingInner,
94
- bandLength,
95
- });
96
-
97
- const _data = showHighlight ? getHighlightData(data, extent) : data;
98
-
99
- const offset =
100
- (seriesWidth + paddingInner * seriesStep) * bandLength -
101
- paddingInner * seriesStep;
102
-
103
- const isVertical = direction === 'vertical';
104
-
105
- const highlightColor = parseMultiColorToSVG(highlightFill, "highlight_gradient_" + id + "_" + fieldName);
106
- const color = parseMultiColorToSVG(fill, "gradient_" + id + "_" + fieldName);
107
- return (
108
- <g className='__easyv-band'>
109
- <defs>
110
- <filter id={`filter_front`}>
111
- <feComponentTransfer>
112
- <feFuncR type='linear' slope='0.5' />
113
- <feFuncG type='linear' slope='0.5' />
114
- <feFuncB type='linear' slope='0.5' />
115
- </feComponentTransfer>
116
- </filter>
117
- <filter id={`filter_side`}>
118
- <feComponentTransfer>
119
- <feFuncR type='linear' slope='0.7' />
120
- <feFuncG type='linear' slope='0.7' />
121
- <feFuncB type='linear' slope='0.7' />
122
- </feComponentTransfer>
123
- </filter>
124
- {highlightColor.def}
125
- {color.def}
126
- </defs>
127
- {_data.map(
128
- (
129
- {
130
- flag,
131
- index,
132
- bound: [start, end],
133
- data,
134
- data: { x, y, s },
135
- }: DataWithBoundType,
136
- i: number
137
- ) => {
138
- const y1 = yScaler(isVertical ? end : start);
139
- const y2 = yScaler(isVertical ? start : end);
140
- const positionX = xScaler(x) + seriesStep * index - offset / 2;
141
- if (isNaN(positionX)) return null;
142
- const positionY = y < 0 ? y1 : y2;
143
- const attr = getAttr({
144
- isVertical,
145
- x: positionX,
146
- y: positionY,
147
- length: Math.abs(y1 - y2),
148
- seriesWidth,
149
- });
150
-
151
- return (
152
- <g
153
- key={i}
154
- onClick={triggerClick}
155
- data-data={JSON.stringify(data)}
156
- >
157
- <Column3DSkin
158
- {...attr}
159
- color={extent === flag ? highlightColor : color}
160
- />
161
- </g>
162
- );
163
- }
164
- )}
165
- </g>
166
- );
167
- }
168
- );
169
-
170
-
171
- const Column3DSkin = function (props: any) {
172
- const {
173
- width,
174
- height,
175
- x,
176
- y,
177
- color,
178
- opacity = 1,
179
- } = props;
180
- return (
181
- <g
182
- style={{
183
- transform: `skew(0deg, 23deg)`,
184
- transformOrigin: `${x + width / 2}px ${y + height / 2}px`,
185
- opacity: opacity,
186
- }}
187
- >
188
- {color.defs}
189
- {/* 正面 */}
190
- <rect
191
- width={width / 2}
192
- height={height}
193
- x={x}
194
- y={y}
195
- fill={color.fill}
196
- style={{ filter: `url(#filter_front)` }}
197
- ></rect>
198
- {/* 侧面 */}
199
- <rect
200
- width={width / 2}
201
- height={height}
202
- x={x + width / 2}
203
- y={y}
204
- fill={color.fill}
205
- style={{
206
- transformOrigin: `${x + width / 2}px ${y + height / 2}px`,
207
- transform: 'skew(0deg, -45deg)',
208
- }}
209
- ></rect>
210
- {/* 顶部 */}
211
- <rect
212
- width={width / 2}
213
- height={width / 2}
214
- x={x}
215
- y={y}
216
- fill={color.firstColor ? color.firstColor : color}
217
- style={{
218
- transformOrigin: `${x + (width / 4) * 3}px ${y}px`,
219
- transform: `skew(-45deg) translate(0, -${width / 2}px)`,
220
- }}
221
- ></rect>
222
- </g>
223
- );
224
- };
225
-
226
-
227
- //以下都是为了解析multicolor
228
- function pointRotate(point: any, center: any, angle: any) {
229
- const
230
- x = point[0],
231
- y = point[1],
232
- rx = center[0],
233
- ry = center[1],
234
- cos = Math.cos(angle),
235
- sin = Math.sin(angle);
236
- const x0 = (x - rx) * cos - (y - ry) * sin + rx;
237
- const y0 = (x - rx) * sin + (y - ry) * cos + ry;
238
- return [x0, y0];
239
- }
240
- const AngleTransfromRatio = 180 / Math.PI;
241
- function deg2rad(deg: any) {
242
- return deg / AngleTransfromRatio;
243
- }
244
- function deepCopy(obj: any): any {
245
- if (typeof obj == "object") {
246
- let o: any;
247
- if (Array.isArray(obj)) {
248
- o = [];
249
- for (let i = 0; i < obj.length; i++) {
250
- o.push(deepCopy(obj[i]));
251
- }
252
- } else {
253
- o = {};
254
- for (const k of Object.keys(obj)) {
255
- o[k] = deepCopy(obj[k]);
256
- }
257
- }
258
- return o;
259
- } else {
260
- return obj;
261
- }
262
- }
263
- function parseMultiColorToSVG(config: any, id: any) {
264
- if (config.type == "linear") {
265
- const { stops, opacity } = config.linear;
266
- let start = [0, 0.5], end = [1, 0.5];
267
- const angle = config.linear.angle + 90;
268
- if (angle) {
269
- const center = [0.5, 0.5];
270
- start = pointRotate(start, center, deg2rad(angle));
271
- end = pointRotate(end, center, deg2rad(angle));
272
- }
273
- const _stops = deepCopy(stops); //深度复制再排序防止修改props
274
- _stops.sort((a: any, b: any) => a.offset - b.offset); //必须排序才能渲染出来
275
- return {
276
- fill: `url(#${id})`,
277
- def: React.createElement("linearGradient", {
278
- id,
279
- x2: start[0],
280
- y2: start[1],
281
- x1: end[0],
282
- y1: end[1],
283
- }, _stops.map((e: any) => {
284
- return React.createElement("stop", {
285
- key: e.offset,
286
- offset: e.offset / 100,
287
- stopColor: e.color,
288
- stopOpacity: opacity
289
- });
290
- })),
291
- firstColor: getTopColor(_stops,angle)
292
- }
293
- } else {
294
- return {
295
- fill: config.pure,
296
- firstColor: config.pure
297
- };
298
- }
299
- }
300
-
301
- function getTopColor(stops: any[], angle: number) {
302
- let a = angle % 360;
303
- if (a < 0) {
304
- a = 360 + a;
305
- }
306
- if (a >= 90 && a < 270) {
307
- return stops[stops.length - 1].color;
308
- } else {
309
- return stops[0].color;
310
- }
311
- }
1
+ /**
2
+ * 立体柱状图的柱子
3
+ */
4
+ import React, { memo } from 'react';
5
+ import { min, max } from 'd3v7';
6
+ import { getSeriesInfo } from '../utils';
7
+
8
+ const getHighlightData = (data: Array<DataWithBoundType>, extent: string) => {
9
+ switch (extent) {
10
+ case 'min':
11
+ const minData = min(data, (d: DataWithBoundType) => d.data.y);
12
+ return data.map((item) => ({
13
+ ...item,
14
+ flag: minData == item.data.y ? 'min' : '',
15
+ }));
16
+ case 'max':
17
+ const maxData = max(data, (d: DataWithBoundType) => d.data.y);
18
+ return data.map((item) => ({
19
+ ...item,
20
+ flag: maxData == item.data.y ? 'max' : '',
21
+ }));
22
+ default:
23
+ return data;
24
+ }
25
+ };
26
+
27
+ const getAttr = ({
28
+ isVertical,
29
+ seriesWidth,
30
+ length,
31
+ x,
32
+ y,
33
+ }: {
34
+ isVertical: boolean;
35
+ seriesWidth: number;
36
+ length: number;
37
+ x: number;
38
+ y: number;
39
+ }) => {
40
+ if (isVertical) return { width: length, height: seriesWidth, x: y, y: x };
41
+ return {
42
+ x,
43
+ y,
44
+ width: seriesWidth,
45
+ height: length,
46
+ };
47
+ };
48
+
49
+ const getBorderRadius = ({
50
+ isVertical,
51
+ positive,
52
+ seriesWidth,
53
+ }: {
54
+ isVertical: boolean;
55
+ positive: boolean;
56
+ seriesWidth: number;
57
+ }) => {
58
+ return isVertical
59
+ ? positive
60
+ ? '0px ' + seriesWidth + 'px ' + seriesWidth + 'px 0'
61
+ : seriesWidth + 'px 0 0 ' + seriesWidth + 'px'
62
+ : positive
63
+ ? seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px 0 0'
64
+ : '0 0 ' + seriesWidth / 2 + 'px ' + seriesWidth / 2 + 'px';
65
+ };
66
+
67
+ export default memo(
68
+ ({
69
+ triggerClick,
70
+ config: {
71
+ pattern = {},
72
+ seriesIntervalWidth: paddingInner = 0,
73
+ paddingInner: paddingOuter = 0,
74
+ style,
75
+ fill,
76
+ highlight: { show: showHighlight, extent, fill: highlightFill },
77
+ id,
78
+ },
79
+ bandLength = 0,
80
+ data,
81
+ xAxis: { scaler: xScaler, step, direction },
82
+ yAxis: { scaler: yScaler },
83
+ fieldName,
84
+ }: any) => {
85
+ if (!data.length) return null;
86
+
87
+ const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
88
+ step,
89
+ bandLength,
90
+ paddingInner,
91
+ paddingOuter,
92
+ });
93
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
94
+
95
+ const isVertical = direction === 'vertical';
96
+
97
+ const highlightColor = parseMultiColorToSVG(
98
+ highlightFill,
99
+ 'highlight_gradient_' + id + '_' + fieldName
100
+ );
101
+ const color = parseMultiColorToSVG(
102
+ fill,
103
+ 'gradient_' + id + '_' + fieldName
104
+ );
105
+ return (
106
+ <g className='__easyv-band'>
107
+ <defs>
108
+ <filter id={`filter_front`}>
109
+ <feComponentTransfer>
110
+ <feFuncR type='linear' slope='0.5' />
111
+ <feFuncG type='linear' slope='0.5' />
112
+ <feFuncB type='linear' slope='0.5' />
113
+ </feComponentTransfer>
114
+ </filter>
115
+ <filter id={`filter_side`}>
116
+ <feComponentTransfer>
117
+ <feFuncR type='linear' slope='0.7' />
118
+ <feFuncG type='linear' slope='0.7' />
119
+ <feFuncB type='linear' slope='0.7' />
120
+ </feComponentTransfer>
121
+ </filter>
122
+ {highlightColor.def}
123
+ {color.def}
124
+ </defs>
125
+ {_data.map(
126
+ (
127
+ {
128
+ flag,
129
+ index,
130
+ bound: [start, end],
131
+ data,
132
+ data: { x, y, s },
133
+ }: DataWithBoundType,
134
+ i: number
135
+ ) => {
136
+ const y1 = yScaler(isVertical ? end : start);
137
+ const y2 = yScaler(isVertical ? start : end);
138
+
139
+ const positionX =
140
+ xScaler(x) - step / 2 + seriesStart + index * seriesStep;
141
+ if (isNaN(positionX)) return null;
142
+
143
+ const positionY = y < 0 ? y1 : y2;
144
+ const attr = getAttr({
145
+ isVertical,
146
+ x: positionX,
147
+ y: positionY,
148
+ length: Math.abs(y1 - y2),
149
+ seriesWidth,
150
+ });
151
+
152
+ return (
153
+ <g
154
+ key={i}
155
+ onClick={triggerClick}
156
+ data-data={JSON.stringify(data)}
157
+ >
158
+ <Column3DSkin
159
+ {...attr}
160
+ color={extent === flag ? highlightColor : color}
161
+ />
162
+ </g>
163
+ );
164
+ }
165
+ )}
166
+ </g>
167
+ );
168
+ }
169
+ );
170
+
171
+ const Column3DSkin = function (props: any) {
172
+ const { width, height, x, y, color, opacity = 1 } = props;
173
+ return (
174
+ <g
175
+ style={{
176
+ transform: `skew(0deg, 23deg)`,
177
+ transformOrigin: `${x + width / 2}px ${y + height / 2}px`,
178
+ opacity: opacity,
179
+ }}
180
+ >
181
+ {color.defs}
182
+ {/* 正面 */}
183
+ <rect
184
+ width={width / 2}
185
+ height={height}
186
+ x={x}
187
+ y={y}
188
+ fill={color.fill}
189
+ style={{ filter: `url(#filter_front)` }}
190
+ ></rect>
191
+ {/* 侧面 */}
192
+ <rect
193
+ width={width / 2}
194
+ height={height}
195
+ x={x + width / 2}
196
+ y={y}
197
+ fill={color.fill}
198
+ style={{
199
+ transformOrigin: `${x + width / 2}px ${y + height / 2}px`,
200
+ transform: 'skew(0deg, -45deg)',
201
+ }}
202
+ ></rect>
203
+ {/* 顶部 */}
204
+ <rect
205
+ width={width / 2}
206
+ height={width / 2}
207
+ x={x}
208
+ y={y}
209
+ fill={color.firstColor ? color.firstColor : color}
210
+ style={{
211
+ transformOrigin: `${x + (width / 4) * 3}px ${y}px`,
212
+ transform: `skew(-45deg) translate(0, -${width / 2}px)`,
213
+ }}
214
+ ></rect>
215
+ </g>
216
+ );
217
+ };
218
+
219
+ //以下都是为了解析multicolor
220
+ function pointRotate(point: any, center: any, angle: any) {
221
+ const x = point[0],
222
+ y = point[1],
223
+ rx = center[0],
224
+ ry = center[1],
225
+ cos = Math.cos(angle),
226
+ sin = Math.sin(angle);
227
+ const x0 = (x - rx) * cos - (y - ry) * sin + rx;
228
+ const y0 = (x - rx) * sin + (y - ry) * cos + ry;
229
+ return [x0, y0];
230
+ }
231
+ const AngleTransfromRatio = 180 / Math.PI;
232
+ function deg2rad(deg: any) {
233
+ return deg / AngleTransfromRatio;
234
+ }
235
+ function deepCopy(obj: any): any {
236
+ if (typeof obj == 'object') {
237
+ let o: any;
238
+ if (Array.isArray(obj)) {
239
+ o = [];
240
+ for (let i = 0; i < obj.length; i++) {
241
+ o.push(deepCopy(obj[i]));
242
+ }
243
+ } else {
244
+ o = {};
245
+ for (const k of Object.keys(obj)) {
246
+ o[k] = deepCopy(obj[k]);
247
+ }
248
+ }
249
+ return o;
250
+ } else {
251
+ return obj;
252
+ }
253
+ }
254
+ function parseMultiColorToSVG(config: any, id: any) {
255
+ if (config.type == 'linear') {
256
+ const { stops, opacity } = config.linear;
257
+ let start = [0, 0.5],
258
+ end = [1, 0.5];
259
+ const angle = config.linear.angle + 90;
260
+ if (angle) {
261
+ const center = [0.5, 0.5];
262
+ start = pointRotate(start, center, deg2rad(angle));
263
+ end = pointRotate(end, center, deg2rad(angle));
264
+ }
265
+ const _stops = deepCopy(stops); //深度复制再排序防止修改props
266
+ _stops.sort((a: any, b: any) => a.offset - b.offset); //必须排序才能渲染出来
267
+ return {
268
+ fill: `url(#${id})`,
269
+ def: React.createElement(
270
+ 'linearGradient',
271
+ {
272
+ id,
273
+ x2: start[0],
274
+ y2: start[1],
275
+ x1: end[0],
276
+ y1: end[1],
277
+ },
278
+ _stops.map((e: any) => {
279
+ return React.createElement('stop', {
280
+ key: e.offset,
281
+ offset: e.offset / 100,
282
+ stopColor: e.color,
283
+ stopOpacity: opacity,
284
+ });
285
+ })
286
+ ),
287
+ firstColor: getTopColor(_stops, angle),
288
+ };
289
+ } else {
290
+ return {
291
+ fill: config.pure,
292
+ firstColor: config.pure,
293
+ };
294
+ }
295
+ }
296
+
297
+ function getTopColor(stops: any[], angle: number) {
298
+ let a = angle % 360;
299
+ if (a < 0) {
300
+ a = 360 + a;
301
+ }
302
+ if (a >= 90 && a < 270) {
303
+ return stops[stops.length - 1].color;
304
+ } else {
305
+ return stops[0].color;
306
+ }
307
+ }