@easyv/charts 1.4.28 → 1.4.30

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 (91) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/commitlint.config.js +1 -1
  5. package/lib/components/AnimateData.js +16 -8
  6. package/lib/components/Axis.js +134 -87
  7. package/lib/components/Background.js +26 -18
  8. package/lib/components/Band.js +98 -72
  9. package/lib/components/BaseLine.js +46 -33
  10. package/lib/components/Brush.js +46 -29
  11. package/lib/components/Carousel.js +40 -13
  12. package/lib/components/CartesianChart.js +147 -98
  13. package/lib/components/Chart.js +45 -28
  14. package/lib/components/ChartContainer.js +27 -18
  15. package/lib/components/ConicalGradient.js +89 -56
  16. package/lib/components/Control.js +28 -12
  17. package/lib/components/ExtentData.js +17 -9
  18. package/lib/components/FilterData.js +27 -16
  19. package/lib/components/Indicator.js +30 -23
  20. package/lib/components/Label.js +126 -96
  21. package/lib/components/Legend.js +66 -41
  22. package/lib/components/Lighter.js +50 -21
  23. package/lib/components/Line.js +59 -39
  24. package/lib/components/LinearGradient.js +22 -16
  25. package/lib/components/Mapping.js +34 -9
  26. package/lib/components/Marquee.js +30 -14
  27. package/lib/components/PieChart.js +427 -325
  28. package/lib/components/StackData.js +18 -8
  29. package/lib/components/StereoBar.js +105 -65
  30. package/lib/components/TextOverflow.js +21 -8
  31. package/lib/components/Tooltip.js +55 -41
  32. package/lib/components/index.js +29 -0
  33. package/lib/components/pieTooltip.js +101 -44
  34. package/lib/context/index.js +2 -0
  35. package/lib/css/index.module.css +42 -42
  36. package/lib/css/piechart.module.css +26 -26
  37. package/lib/element/ConicGradient.js +35 -29
  38. package/lib/element/Line.js +13 -9
  39. package/lib/element/index.js +2 -0
  40. package/lib/formatter/index.js +2 -0
  41. package/lib/formatter/legend.js +41 -30
  42. package/lib/hooks/index.js +9 -0
  43. package/lib/hooks/useAiData.js +20 -12
  44. package/lib/hooks/useAnimateData.js +21 -8
  45. package/lib/hooks/useAxes.js +117 -67
  46. package/lib/hooks/useCarouselAxisX.js +59 -26
  47. package/lib/hooks/useExtentData.js +47 -15
  48. package/lib/hooks/useFilterData.js +34 -13
  49. package/lib/hooks/useStackData.js +35 -12
  50. package/lib/hooks/useTooltip.js +53 -36
  51. package/lib/index.js +15 -0
  52. package/lib/utils/index.js +247 -95
  53. package/package.json +55 -55
  54. package/src/components/Axis.tsx +1 -1
  55. package/src/components/Background.tsx +61 -61
  56. package/src/components/Band.tsx +274 -274
  57. package/src/components/Brush.js +159 -159
  58. package/src/components/CartesianChart.js +2 -1
  59. package/src/components/Chart.js +101 -99
  60. package/src/components/ChartContainer.tsx +71 -71
  61. package/src/components/ConicalGradient.js +258 -258
  62. package/src/components/Control.jsx +51 -51
  63. package/src/components/ExtentData.js +17 -17
  64. package/src/components/Indicator.js +61 -61
  65. package/src/components/Label.js +275 -275
  66. package/src/components/Legend.js +165 -165
  67. package/src/components/Lighter.jsx +173 -173
  68. package/src/components/Line.js +150 -150
  69. package/src/components/LinearGradient.js +29 -29
  70. package/src/components/PieChart.js +19 -12
  71. package/src/components/PieTooltip.jsx +160 -133
  72. package/src/components/StereoBar.tsx +307 -307
  73. package/src/components/index.js +59 -59
  74. package/src/context/index.js +2 -2
  75. package/src/css/index.module.css +42 -42
  76. package/src/css/piechart.module.css +26 -26
  77. package/src/element/ConicGradient.jsx +55 -55
  78. package/src/element/Line.tsx +33 -33
  79. package/src/element/index.ts +3 -3
  80. package/src/formatter/index.js +1 -1
  81. package/src/formatter/legend.js +92 -92
  82. package/src/hooks/index.js +20 -20
  83. package/src/hooks/useAnimateData.ts +67 -67
  84. package/src/hooks/useExtentData.js +1 -1
  85. package/src/hooks/useFilterData.js +72 -72
  86. package/src/hooks/useStackData.js +101 -101
  87. package/src/hooks/useTooltip.ts +100 -100
  88. package/src/index.js +6 -6
  89. package/src/types/index.d.ts +67 -67
  90. package/src/utils/index.js +757 -757
  91. package/tsconfig.json +23 -23
@@ -1,274 +1,274 @@
1
- /**
2
- * (柱状/条形)图柱子
3
- */
4
- import React, { memo } from "react";
5
- import { min, max } from "d3v7";
6
- import { getBandBackground, 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
- //控制图部分,主要是为了控制图的指示器,在悬浮的时候显示
70
- triggerClick,
71
- indicatorWidth,
72
- setControlChartTooltipShow,
73
- setControlChartTooltipX,
74
- setControlChartTooltipXName,
75
- isControlChart = false,
76
- setControlChartIndicatorList,
77
-
78
- config: {
79
- pattern = {},
80
- seriesIntervalWidth: paddingInner = 0,
81
- paddingInner: paddingOuter = 0,
82
- style,
83
- fillType,
84
- url,
85
- size,
86
- fill,
87
- border,
88
- opacity,
89
- highlight: { show: showHighlight, extent, fill: highlightFill },
90
- headDecorate,
91
- },
92
- bandLength = 0,
93
- data,
94
- xAxis: { scaler: xScaler, step, direction },
95
- xAxis,
96
- yAxis: { scaler: yScaler, isClipAxis, clipValue },
97
- }: any) => {
98
- if (!data.length) return null;
99
-
100
- const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
101
- step,
102
- bandLength,
103
- paddingInner,
104
- paddingOuter,
105
- });
106
-
107
- const _data = showHighlight ? getHighlightData(data, extent) : data;
108
-
109
- const isVertical = direction === "vertical";
110
- const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
111
- return (
112
- <g className="__easyv-band">
113
- {_data.map(
114
- (
115
- {
116
- flag,
117
- index,
118
- bound: [start, end],
119
- data,
120
- data: { x, y, s },
121
- }: DataWithBoundType,
122
- i: number
123
- ) => {
124
- let y1: number, y2: number;
125
- //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
126
- if (isClipAxis) {
127
- if (end > +clipValue) {
128
- y1 = yScaler[1](start);
129
- y2 = yScaler[0](end);
130
- } else {
131
- y1 = yScaler[1](start);
132
- y2 = yScaler[1](end);
133
- }
134
- } else {
135
- y1 = yScaler(isVertical ? end : start);
136
- y2 = yScaler(isVertical ? start : end);
137
- }
138
-
139
- const positionX =
140
- xScaler(x) - step / 2 + seriesStart + index * seriesStep;
141
-
142
- let showHead, headUrl, headWidth, headHeight, headTranslate;
143
- if (headDecorate) {
144
- (showHead = headDecorate.show),
145
- (headUrl = headDecorate.url),
146
- (headWidth = headDecorate.size.width),
147
- (headHeight = headDecorate.size.height),
148
- (headTranslate = headDecorate.translate);
149
- }
150
- //断轴图相关,将柱形在断轴处切开
151
- const setClipPath = () => {
152
- if (isClipAxis && end > +clipValue) {
153
- let clipValueY2 = yScaler[0](clipValue); //上方
154
- let clipValueY1 = yScaler[1](clipValue); //下方
155
- let top = Math.abs((y2 - clipValueY2) / (y1 - y2)) * 100;
156
- let bottom = Math.abs((y2 - clipValueY1) / (y1 - y2)) * 100;
157
-
158
- //clip path属性
159
- return `polygon(0% 0%, 0% 100%, 0 100%, 0 ${top}%, 100% ${top}%, 100% ${bottom}%, 0 ${bottom}%, 0 100%, 100% 100%, 100% 0%)`;
160
- } else {
161
- return "none";
162
- }
163
- };
164
- if (isNaN(positionX)) return null;
165
- const positionY = y < 0 ? y1 : y2;
166
- const attr = getAttr({
167
- isVertical,
168
- x: positionX,
169
- y: positionY,
170
- length: Math.abs(y1 - y2),
171
- seriesWidth,
172
- });
173
- return (
174
- <foreignObject
175
- key={i}
176
- style={{
177
- overflow: "visible",
178
- position: "relative",
179
- cursor: "pointer",
180
- }}
181
- {...attr}
182
- onClick={triggerClick}
183
- //enter和leave事件,用于控制图的提示框
184
- onMouseEnter={() => {
185
- if (isControlChart) {
186
- setControlChartIndicatorList((v: any) => {
187
- return v.map((item: any) => {
188
- if (item.tick === data.x) {
189
- return { ...item, isShow: true };
190
- } else {
191
- return item;
192
- }
193
- });
194
- });
195
- setControlChartTooltipShow(true);
196
- setControlChartTooltipX(xScaler(x) - indicatorWidth / 2);
197
- setControlChartTooltipXName(data.x);
198
- }
199
- }}
200
- onMouseLeave={() => {
201
- if (isControlChart) {
202
- setControlChartIndicatorList((v: any) =>
203
- v.map((item: any) => ({ ...item, isShow: false }))
204
- );
205
- setControlChartTooltipShow(false);
206
- setControlChartTooltipXName(undefined);
207
- setControlChartTooltipX(undefined);
208
- }
209
- }}
210
- data-data={JSON.stringify(data)}
211
- >
212
- {headUrl && showHead && (
213
- <div
214
- style={{
215
- position: "absolute",
216
- background: `url(${
217
- window.appConfig.ASSETS_URL + headUrl
218
- }) 0 0/100% 100%`,
219
- width: headWidth,
220
- height: headHeight,
221
- left: isVertical ? "100%" : "50%",
222
- top: isVertical ? "50%" : "0",
223
- zIndex: 1,
224
- transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
225
- }}
226
- ></div>
227
- )}
228
- <div
229
- style={{
230
- width: "100%",
231
- height: "100%",
232
- /** Safari Bug **/
233
- position: "fixed",
234
- clipPath: setClipPath(),
235
- opacity: fillType == "pattern" ? opacity : 1,
236
- background:
237
- fillType == "pattern"
238
- ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
239
- "url(" +
240
- url +
241
- ")"
242
- : getBandBackground(
243
- pattern,
244
- extent === flag ? highlightFill : fill
245
- ),
246
- borderRadius:
247
- style == "square"
248
- ? "0 0 0 0"
249
- : getBorderRadius({
250
- isVertical,
251
- positive: y > 0,
252
- seriesWidth,
253
- }),
254
- ...(isVertical
255
- ? {
256
- borderTop: borderStr,
257
- borderRight: borderStr,
258
- borderBottom: borderStr,
259
- }
260
- : {
261
- borderTop: borderStr,
262
- borderRight: borderStr,
263
- borderLeft: borderStr,
264
- }),
265
- }}
266
- />
267
- </foreignObject>
268
- );
269
- }
270
- )}
271
- </g>
272
- );
273
- }
274
- );
1
+ /**
2
+ * (柱状/条形)图柱子
3
+ */
4
+ import React, { memo } from "react";
5
+ import { min, max } from "d3v7";
6
+ import { getBandBackground, 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
+ //控制图部分,主要是为了控制图的指示器,在悬浮的时候显示
70
+ triggerClick,
71
+ indicatorWidth,
72
+ setControlChartTooltipShow,
73
+ setControlChartTooltipX,
74
+ setControlChartTooltipXName,
75
+ isControlChart = false,
76
+ setControlChartIndicatorList,
77
+
78
+ config: {
79
+ pattern = {},
80
+ seriesIntervalWidth: paddingInner = 0,
81
+ paddingInner: paddingOuter = 0,
82
+ style,
83
+ fillType,
84
+ url,
85
+ size,
86
+ fill,
87
+ border,
88
+ opacity,
89
+ highlight: { show: showHighlight, extent, fill: highlightFill },
90
+ headDecorate,
91
+ },
92
+ bandLength = 0,
93
+ data,
94
+ xAxis: { scaler: xScaler, step, direction },
95
+ xAxis,
96
+ yAxis: { scaler: yScaler, isClipAxis, clipValue },
97
+ }: any) => {
98
+ if (!data.length) return null;
99
+
100
+ const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
101
+ step,
102
+ bandLength,
103
+ paddingInner,
104
+ paddingOuter,
105
+ });
106
+
107
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
108
+
109
+ const isVertical = direction === "vertical";
110
+ const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
111
+ return (
112
+ <g className="__easyv-band">
113
+ {_data.map(
114
+ (
115
+ {
116
+ flag,
117
+ index,
118
+ bound: [start, end],
119
+ data,
120
+ data: { x, y, s },
121
+ }: DataWithBoundType,
122
+ i: number
123
+ ) => {
124
+ let y1: number, y2: number;
125
+ //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
126
+ if (isClipAxis) {
127
+ if (end > +clipValue) {
128
+ y1 = yScaler[1](start);
129
+ y2 = yScaler[0](end);
130
+ } else {
131
+ y1 = yScaler[1](start);
132
+ y2 = yScaler[1](end);
133
+ }
134
+ } else {
135
+ y1 = yScaler(isVertical ? end : start);
136
+ y2 = yScaler(isVertical ? start : end);
137
+ }
138
+
139
+ const positionX =
140
+ xScaler(x) - step / 2 + seriesStart + index * seriesStep;
141
+
142
+ let showHead, headUrl, headWidth, headHeight, headTranslate;
143
+ if (headDecorate) {
144
+ (showHead = headDecorate.show),
145
+ (headUrl = headDecorate.url),
146
+ (headWidth = headDecorate.size.width),
147
+ (headHeight = headDecorate.size.height),
148
+ (headTranslate = headDecorate.translate);
149
+ }
150
+ //断轴图相关,将柱形在断轴处切开
151
+ const setClipPath = () => {
152
+ if (isClipAxis && end > +clipValue) {
153
+ let clipValueY2 = yScaler[0](clipValue); //上方
154
+ let clipValueY1 = yScaler[1](clipValue); //下方
155
+ let top = Math.abs((y2 - clipValueY2) / (y1 - y2)) * 100;
156
+ let bottom = Math.abs((y2 - clipValueY1) / (y1 - y2)) * 100;
157
+
158
+ //clip path属性
159
+ return `polygon(0% 0%, 0% 100%, 0 100%, 0 ${top}%, 100% ${top}%, 100% ${bottom}%, 0 ${bottom}%, 0 100%, 100% 100%, 100% 0%)`;
160
+ } else {
161
+ return "none";
162
+ }
163
+ };
164
+ if (isNaN(positionX)) return null;
165
+ const positionY = y < 0 ? y1 : y2;
166
+ const attr = getAttr({
167
+ isVertical,
168
+ x: positionX,
169
+ y: positionY,
170
+ length: Math.abs(y1 - y2),
171
+ seriesWidth,
172
+ });
173
+ return (
174
+ <foreignObject
175
+ key={i}
176
+ style={{
177
+ overflow: "visible",
178
+ position: "relative",
179
+ cursor: "pointer",
180
+ }}
181
+ {...attr}
182
+ onClick={triggerClick}
183
+ //enter和leave事件,用于控制图的提示框
184
+ onMouseEnter={() => {
185
+ if (isControlChart) {
186
+ setControlChartIndicatorList((v: any) => {
187
+ return v.map((item: any) => {
188
+ if (item.tick === data.x) {
189
+ return { ...item, isShow: true };
190
+ } else {
191
+ return item;
192
+ }
193
+ });
194
+ });
195
+ setControlChartTooltipShow(true);
196
+ setControlChartTooltipX(xScaler(x) - indicatorWidth / 2);
197
+ setControlChartTooltipXName(data.x);
198
+ }
199
+ }}
200
+ onMouseLeave={() => {
201
+ if (isControlChart) {
202
+ setControlChartIndicatorList((v: any) =>
203
+ v.map((item: any) => ({ ...item, isShow: false }))
204
+ );
205
+ setControlChartTooltipShow(false);
206
+ setControlChartTooltipXName(undefined);
207
+ setControlChartTooltipX(undefined);
208
+ }
209
+ }}
210
+ data-data={JSON.stringify(data)}
211
+ >
212
+ {headUrl && showHead && (
213
+ <div
214
+ style={{
215
+ position: "absolute",
216
+ background: `url(${
217
+ window.appConfig.ASSETS_URL + headUrl
218
+ }) 0 0/100% 100%`,
219
+ width: headWidth,
220
+ height: headHeight,
221
+ left: isVertical ? "100%" : "50%",
222
+ top: isVertical ? "50%" : "0",
223
+ zIndex: 1,
224
+ transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
225
+ }}
226
+ ></div>
227
+ )}
228
+ <div
229
+ style={{
230
+ width: "100%",
231
+ height: "100%",
232
+ /** Safari Bug **/
233
+ position: "fixed",
234
+ clipPath: setClipPath(),
235
+ opacity: fillType == "pattern" ? opacity : 1,
236
+ background:
237
+ fillType == "pattern"
238
+ ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
239
+ "url(" +
240
+ url +
241
+ ")"
242
+ : getBandBackground(
243
+ pattern,
244
+ extent === flag ? highlightFill : fill
245
+ ),
246
+ borderRadius:
247
+ style == "square"
248
+ ? "0 0 0 0"
249
+ : getBorderRadius({
250
+ isVertical,
251
+ positive: y > 0,
252
+ seriesWidth,
253
+ }),
254
+ ...(isVertical
255
+ ? {
256
+ borderTop: borderStr,
257
+ borderRight: borderStr,
258
+ borderBottom: borderStr,
259
+ }
260
+ : {
261
+ borderTop: borderStr,
262
+ borderRight: borderStr,
263
+ borderLeft: borderStr,
264
+ }),
265
+ }}
266
+ />
267
+ </foreignObject>
268
+ );
269
+ }
270
+ )}
271
+ </g>
272
+ );
273
+ }
274
+ );