@easyv/charts 1.0.57 → 1.0.61

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 (66) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +12 -12
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Carousel.js +2 -2
  6. package/lib/components/Chart.js +2 -2
  7. package/lib/components/ConicalGradient.js +21 -21
  8. package/lib/components/Indicator.js +2 -2
  9. package/lib/components/Label.js +2 -1
  10. package/lib/components/LinearGradient.js +2 -2
  11. package/lib/components/PieChart.js +39 -2
  12. package/lib/components/Tooltip.js +25 -5
  13. package/lib/css/index.module.css +41 -41
  14. package/lib/css/piechart.module.css +26 -26
  15. package/lib/formatter/legend.js +4 -2
  16. package/lib/hooks/useAnimateData.js +5 -5
  17. package/lib/hooks/useAxes.js +5 -5
  18. package/lib/hooks/useCarouselAxisX.js +5 -5
  19. package/lib/hooks/useExtentData.js +6 -6
  20. package/lib/hooks/useFilterData.js +11 -6
  21. package/lib/hooks/useStackData.js +5 -5
  22. package/lib/hooks/useTooltip.js +10 -10
  23. package/package.json +34 -34
  24. package/src/components/AnimateData.tsx +24 -24
  25. package/src/components/Axis.tsx +333 -333
  26. package/src/components/Background.tsx +45 -45
  27. package/src/components/Band.tsx +160 -160
  28. package/src/components/Brush.js +159 -159
  29. package/src/components/Carousel.tsx +144 -144
  30. package/src/components/Chart.js +99 -99
  31. package/src/components/ChartContainer.tsx +63 -63
  32. package/src/components/ConicalGradient.js +258 -258
  33. package/src/components/ExtentData.js +17 -17
  34. package/src/components/FilterData.js +23 -23
  35. package/src/components/Indicator.js +13 -13
  36. package/src/components/Label.js +193 -194
  37. package/src/components/Legend.js +158 -158
  38. package/src/components/Lighter.jsx +162 -162
  39. package/src/components/Line.js +126 -126
  40. package/src/components/LinearGradient.js +29 -29
  41. package/src/components/Mapping.js +71 -71
  42. package/src/components/PieChart.js +1092 -1092
  43. package/src/components/StackData.js +20 -20
  44. package/src/components/StereoBar.tsx +298 -298
  45. package/src/components/Tooltip.js +134 -117
  46. package/src/components/index.js +49 -49
  47. package/src/context/index.js +2 -2
  48. package/src/css/index.module.css +41 -41
  49. package/src/css/piechart.module.css +26 -26
  50. package/src/element/ConicGradient.jsx +56 -0
  51. package/src/element/Line.tsx +33 -33
  52. package/src/element/index.ts +3 -3
  53. package/src/formatter/index.js +1 -1
  54. package/src/formatter/legend.js +87 -87
  55. package/src/hooks/index.js +17 -17
  56. package/src/hooks/useAnimateData.ts +62 -62
  57. package/src/hooks/useAxes.js +143 -143
  58. package/src/hooks/useCarouselAxisX.js +163 -163
  59. package/src/hooks/useExtentData.js +88 -88
  60. package/src/hooks/useFilterData.js +72 -65
  61. package/src/hooks/useStackData.js +100 -100
  62. package/src/hooks/useTooltip.ts +96 -96
  63. package/src/index.js +6 -6
  64. package/src/types/index.d.ts +59 -59
  65. package/src/utils/index.js +640 -640
  66. package/tsconfig.json +22 -22
@@ -1,20 +1,20 @@
1
- /**
2
- * 堆叠类,具体逻辑在useStackData(HOC)
3
- */
4
- import { memo } from 'react';
5
- import { useStackData } from '../hooks';
6
- export default (Component) => {
7
- return memo(({ config: { series, ...config }, data, ...props }) => {
8
- const _series = useStackData({
9
- series,
10
- data,
11
- });
12
- return (
13
- <Component
14
- {...props}
15
- config={{ ...config, series: _series }}
16
- data={data}
17
- />
18
- );
19
- });
20
- };
1
+ /**
2
+ * 堆叠类,具体逻辑在useStackData(HOC)
3
+ */
4
+ import { memo } from 'react';
5
+ import { useStackData } from '../hooks';
6
+ export default (Component) => {
7
+ return memo(({ config: { series, ...config }, data, ...props }) => {
8
+ const _series = useStackData({
9
+ series,
10
+ data,
11
+ });
12
+ return (
13
+ <Component
14
+ {...props}
15
+ config={{ ...config, series: _series }}
16
+ data={data}
17
+ />
18
+ );
19
+ });
20
+ };
@@ -1,299 +1,299 @@
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: _stops[_stops.length - 1].color
292
- }
293
- } else {
294
- return {
295
- fill: config.pure,
296
- firstColor: config.pure
297
- };
298
- }
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: _stops[_stops.length - 1].color
292
+ }
293
+ } else {
294
+ return {
295
+ fill: config.pure,
296
+ firstColor: config.pure
297
+ };
298
+ }
299
299
  }