@easyv/charts 1.6.13 → 1.6.15

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 (62) 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/Background.js +2 -2
  6. package/lib/components/Band.js +3 -3
  7. package/lib/components/Brush.js +2 -2
  8. package/lib/components/Chart.js +2 -2
  9. package/lib/components/ChartContainer.js +2 -2
  10. package/lib/components/ConicalGradient.js +21 -21
  11. package/lib/components/ExtentData.js +2 -2
  12. package/lib/components/Indicator.js +2 -2
  13. package/lib/components/Label.js +7 -5
  14. package/lib/components/Legend.js +70 -20
  15. package/lib/components/Lighter.js +2 -2
  16. package/lib/components/Line.js +2 -2
  17. package/lib/components/LinearGradient.js +2 -2
  18. package/lib/components/StereoBar.js +2 -2
  19. package/lib/css/index.module.css +42 -42
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/formatter/legend.js +3 -2
  22. package/lib/hooks/useAnimateData.js +6 -6
  23. package/lib/hooks/useAxes.js +1 -2
  24. package/lib/hooks/useFilterData.js +5 -5
  25. package/lib/hooks/useStackData.js +5 -5
  26. package/lib/hooks/useTooltip.js +11 -11
  27. package/package.json +55 -55
  28. package/src/components/Background.tsx +61 -61
  29. package/src/components/Band.tsx +271 -271
  30. package/src/components/Brush.js +159 -159
  31. package/src/components/Chart.js +154 -154
  32. package/src/components/ChartContainer.tsx +71 -71
  33. package/src/components/ConicalGradient.js +258 -258
  34. package/src/components/Control.jsx +241 -241
  35. package/src/components/ExtentData.js +18 -18
  36. package/src/components/Indicator.js +58 -58
  37. package/src/components/Label.js +247 -246
  38. package/src/components/Legend.js +189 -166
  39. package/src/components/Lighter.jsx +173 -173
  40. package/src/components/Line.js +153 -153
  41. package/src/components/LinearGradient.js +29 -29
  42. package/src/components/PieTooltip.jsx +160 -160
  43. package/src/components/StereoBar.tsx +307 -307
  44. package/src/components/index.js +59 -59
  45. package/src/context/index.js +2 -2
  46. package/src/css/index.module.css +42 -42
  47. package/src/css/piechart.module.css +26 -26
  48. package/src/element/ConicGradient.jsx +55 -55
  49. package/src/element/Line.tsx +33 -33
  50. package/src/element/index.ts +3 -3
  51. package/src/formatter/index.js +1 -1
  52. package/src/formatter/legend.js +114 -112
  53. package/src/hooks/index.js +20 -20
  54. package/src/hooks/useAnimateData.ts +68 -68
  55. package/src/hooks/useAxes.js +1 -2
  56. package/src/hooks/useFilterData.js +78 -78
  57. package/src/hooks/useStackData.js +102 -102
  58. package/src/hooks/useTooltip.ts +104 -104
  59. package/src/index.js +6 -6
  60. package/src/types/index.d.ts +68 -68
  61. package/src/utils/index.js +782 -782
  62. package/tsconfig.json +23 -23
@@ -1,271 +1,271 @@
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?length:0.01,
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
- isControlChart = false,
73
- setCtlTip,
74
- config: {
75
- pattern = {},
76
- seriesIntervalWidth: paddingInner = 0,
77
- paddingInner: paddingOuter = 0,
78
- style,
79
- fillType,
80
- url,
81
- size,
82
- fill,
83
- border,
84
- opacity,
85
- highlight: { show: showHighlight, extent, fill: highlightFill },
86
- headDecorate,
87
- },
88
- bandLength = 0,
89
- data,
90
- xAxis: { scaler: normalScaler, step:normalStep, controlStep, direction, controlDragScaler },
91
- yAxis: { scaler: yScaler, isClipAxis, clipValue, reverse },
92
- }: any) => {
93
- if (!data.length) return null;
94
- const step = isControlChart?controlStep:normalStep;
95
- const xScaler = isControlChart?controlDragScaler:normalScaler;
96
- const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
97
- step,
98
- bandLength,
99
- paddingInner,
100
- paddingOuter,
101
- });
102
- const _data = showHighlight ? getHighlightData(data, extent) : data;
103
- const isVertical = direction === "vertical";
104
- const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
105
- return (
106
- <g className="__easyv-band">
107
- {_data.map(
108
- (
109
- {
110
- flag,
111
- index,
112
- bound: [start, end],
113
- data,
114
- data: { x, y, s },
115
- }: DataWithBoundType,
116
- i: number
117
- ) => {
118
- let y1: number, y2: number;
119
- //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
120
- if (isClipAxis) {
121
- if (end > +clipValue) {
122
- y1 = yScaler[1](start);
123
- y2 = yScaler[0](end);
124
- } else {
125
- y1 = yScaler[1](start);
126
- y2 = yScaler[1](end);
127
- }
128
- } else {
129
- y1 = yScaler(isVertical ? end : start);
130
- y2 = yScaler(isVertical ? start : end);
131
- }
132
- const positionX = 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 = reverse?
158
- y > 0 ? y1 : y2:
159
- y < 0 ? y1 : y2;
160
- const attr = getAttr({
161
- isVertical,
162
- x: positionX,
163
- y: positionY,
164
- length: Math.abs(y1 - y2),
165
- seriesWidth,
166
- });
167
- return (
168
- <foreignObject
169
- key={i}
170
- style={{
171
- overflow: "visible",
172
- position: "relative",
173
- cursor: "pointer",
174
- }}
175
- {...attr}
176
- onClick={triggerClick}
177
- //enter和leave事件,用于控制图的提示框
178
- onMouseEnter={() => {
179
- if(isControlChart){
180
- setCtlTip((pre:any)=>({
181
- show:true,
182
- x:xScaler(x),
183
- xName:data.x,
184
- indicatorList:pre.indicatorList.map((item:any)=>{
185
- if (item.tick === data.x) {
186
- return { ...item, isShow: true };
187
- } else {
188
- return item;
189
- }
190
- })
191
- }))
192
- }
193
- }}
194
- onMouseLeave={() => {
195
- if(isControlChart){
196
- setCtlTip((pre:any)=>({
197
- show:false,
198
- x:undefined,
199
- xName:undefined,
200
- indicatorList:pre.indicatorList.map((item:any)=>{
201
- return { ...item, isShow:false }
202
- })
203
- }))
204
- }
205
- }}
206
- data-data={JSON.stringify(data)}
207
- >
208
- {headUrl && showHead && (
209
- <div
210
- style={{
211
- position: "absolute",
212
- background: `url(${
213
- //@ts-ignore
214
- window.appConfig.ASSETS_URL + headUrl
215
- }) 0 0/100% 100%`,
216
- width: headWidth,
217
- height: headHeight,
218
- left: isVertical ? "100%" : "50%",
219
- top: isVertical ? "50%" : "0",
220
- zIndex: 1,
221
- transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
222
- }}
223
- ></div>
224
- )}
225
- <div
226
- style={{
227
- width: "100%",
228
- height: "100%",
229
- /** Safari Bug **/
230
- // position: "fixed",
231
- clipPath: setClipPath(),
232
- opacity: fillType == "pattern" ? opacity : 1,
233
- background:
234
- fillType == "pattern"
235
- ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
236
- "url(" +
237
- url +
238
- ")"
239
- : getBandBackground(
240
- pattern,
241
- extent === flag ? highlightFill : fill
242
- ),
243
- borderRadius:
244
- style == "square"
245
- ? "0 0 0 0"
246
- : getBorderRadius({
247
- isVertical,
248
- positive: y > 0,
249
- seriesWidth,
250
- }),
251
- ...(isVertical
252
- ? {
253
- borderTop: borderStr,
254
- borderRight: borderStr,
255
- borderBottom: borderStr,
256
- }
257
- : {
258
- borderTop: borderStr,
259
- borderRight: borderStr,
260
- borderLeft: borderStr,
261
- }),
262
- }}
263
- />
264
- </foreignObject>
265
- );
266
- }
267
- )}
268
- </g>
269
- );
270
- }
271
- );
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?length:0.1,
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
+ isControlChart = false,
73
+ setCtlTip,
74
+ config: {
75
+ pattern = {},
76
+ seriesIntervalWidth: paddingInner = 0,
77
+ paddingInner: paddingOuter = 0,
78
+ style,
79
+ fillType,
80
+ url,
81
+ size,
82
+ fill,
83
+ border,
84
+ opacity,
85
+ highlight: { show: showHighlight, extent, fill: highlightFill },
86
+ headDecorate,
87
+ },
88
+ bandLength = 0,
89
+ data,
90
+ xAxis: { scaler: normalScaler, step:normalStep, controlStep, direction, controlDragScaler },
91
+ yAxis: { scaler: yScaler, isClipAxis, clipValue, reverse },
92
+ }: any) => {
93
+ if (!data.length) return null;
94
+ const step = isControlChart?controlStep:normalStep;
95
+ const xScaler = isControlChart?controlDragScaler:normalScaler;
96
+ const { seriesWidth, seriesStep, seriesStart } = getSeriesInfo({
97
+ step,
98
+ bandLength,
99
+ paddingInner,
100
+ paddingOuter,
101
+ });
102
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
103
+ const isVertical = direction === "vertical";
104
+ const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
105
+ return (
106
+ <g className="__easyv-band">
107
+ {_data.map(
108
+ (
109
+ {
110
+ flag,
111
+ index,
112
+ bound: [start, end],
113
+ data,
114
+ data: { x, y, s },
115
+ }: DataWithBoundType,
116
+ i: number
117
+ ) => {
118
+ let y1: number, y2: number;
119
+ //断轴图相关,断轴图的scaler是一个数组,内含上断轴下断轴的scaler
120
+ if (isClipAxis) {
121
+ if (end > +clipValue) {
122
+ y1 = yScaler[1](start);
123
+ y2 = yScaler[0](end);
124
+ } else {
125
+ y1 = yScaler[1](start);
126
+ y2 = yScaler[1](end);
127
+ }
128
+ } else {
129
+ y1 = yScaler(isVertical ? end : start);
130
+ y2 = yScaler(isVertical ? start : end);
131
+ }
132
+ const positionX = 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 = reverse?
158
+ y > 0 ? y1 : y2:
159
+ y < 0 ? y1 : y2;
160
+ const attr = getAttr({
161
+ isVertical,
162
+ x: positionX,
163
+ y: positionY,
164
+ length: Math.abs(y1 - y2),
165
+ seriesWidth,
166
+ });
167
+ return (
168
+ <foreignObject
169
+ key={i}
170
+ style={{
171
+ overflow: "visible",
172
+ position: "relative",
173
+ cursor: "pointer",
174
+ }}
175
+ {...attr}
176
+ onClick={triggerClick}
177
+ //enter和leave事件,用于控制图的提示框
178
+ onMouseEnter={() => {
179
+ if(isControlChart){
180
+ setCtlTip((pre:any)=>({
181
+ show:true,
182
+ x:xScaler(x),
183
+ xName:data.x,
184
+ indicatorList:pre.indicatorList.map((item:any)=>{
185
+ if (item.tick === data.x) {
186
+ return { ...item, isShow: true };
187
+ } else {
188
+ return item;
189
+ }
190
+ })
191
+ }))
192
+ }
193
+ }}
194
+ onMouseLeave={() => {
195
+ if(isControlChart){
196
+ setCtlTip((pre:any)=>({
197
+ show:false,
198
+ x:undefined,
199
+ xName:undefined,
200
+ indicatorList:pre.indicatorList.map((item:any)=>{
201
+ return { ...item, isShow:false }
202
+ })
203
+ }))
204
+ }
205
+ }}
206
+ data-data={JSON.stringify(data)}
207
+ >
208
+ {headUrl && showHead && (
209
+ <div
210
+ style={{
211
+ position: "absolute",
212
+ background: `url(${
213
+ //@ts-ignore
214
+ window.appConfig.ASSETS_URL + headUrl
215
+ }) 0 0/100% 100%`,
216
+ width: headWidth,
217
+ height: headHeight,
218
+ left: isVertical ? "100%" : "50%",
219
+ top: isVertical ? "50%" : "0",
220
+ zIndex: 1,
221
+ transform: `translate(calc(-50% + ${headTranslate.x}px), calc(-50% + ${headTranslate.y}px))`,
222
+ }}
223
+ ></div>
224
+ )}
225
+ <div
226
+ style={{
227
+ width: "100%",
228
+ height: "100%",
229
+ /** Safari Bug **/
230
+ // position: "fixed",
231
+ clipPath: setClipPath(),
232
+ opacity: fillType == "pattern" ? opacity : 1,
233
+ background:
234
+ fillType == "pattern"
235
+ ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
236
+ "url(" +
237
+ url +
238
+ ")"
239
+ : getBandBackground(
240
+ pattern,
241
+ extent === flag ? highlightFill : fill
242
+ ),
243
+ borderRadius:
244
+ style == "square"
245
+ ? "0 0 0 0"
246
+ : getBorderRadius({
247
+ isVertical,
248
+ positive: y > 0,
249
+ seriesWidth,
250
+ }),
251
+ ...(isVertical
252
+ ? {
253
+ borderTop: borderStr,
254
+ borderRight: borderStr,
255
+ borderBottom: borderStr,
256
+ }
257
+ : {
258
+ borderTop: borderStr,
259
+ borderRight: borderStr,
260
+ borderLeft: borderStr,
261
+ }),
262
+ }}
263
+ />
264
+ </foreignObject>
265
+ );
266
+ }
267
+ )}
268
+ </g>
269
+ );
270
+ }
271
+ );