@easyv/charts 1.4.22 → 1.4.24

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