@easyv/charts 1.2.6 → 1.2.9

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 (75) 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 +2 -2
  6. package/lib/components/BaseLine.js +19 -10
  7. package/lib/components/Carousel.js +2 -2
  8. package/lib/components/CartesianChart.js +3 -0
  9. package/lib/components/ConicalGradient.js +21 -21
  10. package/lib/components/Indicator.js +2 -2
  11. package/lib/components/Lighter.js +179 -179
  12. package/lib/components/Line.js +38 -32
  13. package/lib/components/LinearGradient.js +2 -2
  14. package/lib/components/Marquee.js +3 -3
  15. package/lib/components/PieChart.js +11 -6
  16. package/lib/components/TextOverflow.js +3 -3
  17. package/lib/css/index.module.css +41 -41
  18. package/lib/css/piechart.module.css +26 -26
  19. package/lib/element/ConicGradient.js +72 -72
  20. package/lib/hooks/useAnimateData.js +5 -5
  21. package/lib/hooks/useAxes.js +5 -5
  22. package/lib/hooks/useCarouselAxisX.js +5 -5
  23. package/lib/hooks/useExtentData.js +6 -6
  24. package/lib/hooks/useFilterData.js +5 -5
  25. package/lib/hooks/useStackData.js +5 -5
  26. package/lib/hooks/useTooltip.js +10 -10
  27. package/lib/utils/index.js +1 -1
  28. package/package.json +53 -53
  29. package/src/components/AnimateData.tsx +24 -24
  30. package/src/components/Axis.tsx +354 -354
  31. package/src/components/Background.tsx +45 -45
  32. package/src/components/Band.tsx +173 -173
  33. package/src/components/BaseLine.js +83 -76
  34. package/src/components/Brush.js +159 -159
  35. package/src/components/Carousel.tsx +144 -144
  36. package/src/components/CartesianChart.js +3 -0
  37. package/src/components/Chart.js +99 -99
  38. package/src/components/ChartContainer.tsx +63 -63
  39. package/src/components/ConicalGradient.js +258 -258
  40. package/src/components/ExtentData.js +17 -17
  41. package/src/components/FilterData.js +23 -23
  42. package/src/components/Indicator.js +13 -13
  43. package/src/components/Label.js +206 -206
  44. package/src/components/Legend.js +158 -158
  45. package/src/components/Lighter.jsx +173 -173
  46. package/src/components/Line.js +145 -144
  47. package/src/components/LinearGradient.js +29 -29
  48. package/src/components/Mapping.js +71 -71
  49. package/src/components/Marquee.js +93 -93
  50. package/src/components/PieChart.js +1278 -1288
  51. package/src/components/StackData.js +20 -20
  52. package/src/components/StereoBar.tsx +310 -310
  53. package/src/components/TextOverflow.js +51 -51
  54. package/src/components/Tooltip.js +169 -169
  55. package/src/components/index.js +55 -55
  56. package/src/context/index.js +2 -2
  57. package/src/css/index.module.css +41 -41
  58. package/src/css/piechart.module.css +26 -26
  59. package/src/element/ConicGradient.jsx +55 -55
  60. package/src/element/Line.tsx +33 -33
  61. package/src/element/index.ts +3 -3
  62. package/src/formatter/index.js +1 -1
  63. package/src/formatter/legend.js +90 -90
  64. package/src/hooks/index.js +17 -17
  65. package/src/hooks/useAnimateData.ts +67 -67
  66. package/src/hooks/useAxes.js +144 -144
  67. package/src/hooks/useCarouselAxisX.js +163 -163
  68. package/src/hooks/useExtentData.js +88 -88
  69. package/src/hooks/useFilterData.js +72 -72
  70. package/src/hooks/useStackData.js +100 -100
  71. package/src/hooks/useTooltip.ts +96 -96
  72. package/src/index.js +6 -6
  73. package/src/types/index.d.ts +67 -67
  74. package/src/utils/index.js +714 -714
  75. package/tsconfig.json +22 -22
@@ -1,45 +1,45 @@
1
- /**
2
- * 轴类图背景
3
- */
4
- import React from 'react';
5
- import { getBandwidth } from '../utils';
6
-
7
- export default ({
8
- axis: { ticks, scaler, step, direction },
9
- config: { background, paddingInner: paddingOuter },
10
- length,
11
- }: {
12
- axis: {
13
- ticks: Array<string>;
14
- scaler: Function;
15
- step: number;
16
- direction: string;
17
- };
18
- config: { background: string; paddingInner: number };
19
- length: number;
20
- }) => {
21
- const isVertical: boolean = direction === 'vertical';
22
- const bandwidth = getBandwidth(step, paddingOuter);
23
- const size = isVertical
24
- ? {
25
- width: length,
26
- height: bandwidth,
27
- }
28
- : {
29
- width: bandwidth,
30
- height: length,
31
- };
32
-
33
- return ticks.map((tick, index: number) => {
34
- return (
35
- <rect
36
- key={index}
37
- {...size}
38
- x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
39
- y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
40
- fill={background}
41
- stroke='none'
42
- />
43
- );
44
- });
45
- };
1
+ /**
2
+ * 轴类图背景
3
+ */
4
+ import React from 'react';
5
+ import { getBandwidth } from '../utils';
6
+
7
+ export default ({
8
+ axis: { ticks, scaler, step, direction },
9
+ config: { background, paddingInner: paddingOuter },
10
+ length,
11
+ }: {
12
+ axis: {
13
+ ticks: Array<string>;
14
+ scaler: Function;
15
+ step: number;
16
+ direction: string;
17
+ };
18
+ config: { background: string; paddingInner: number };
19
+ length: number;
20
+ }) => {
21
+ const isVertical: boolean = direction === 'vertical';
22
+ const bandwidth = getBandwidth(step, paddingOuter);
23
+ const size = isVertical
24
+ ? {
25
+ width: length,
26
+ height: bandwidth,
27
+ }
28
+ : {
29
+ width: bandwidth,
30
+ height: length,
31
+ };
32
+
33
+ return ticks.map((tick, index: number) => {
34
+ return (
35
+ <rect
36
+ key={index}
37
+ {...size}
38
+ x={isVertical ? 0 : scaler(tick) - bandwidth / 2}
39
+ y={isVertical ? scaler(tick) - bandwidth / 2 : 0}
40
+ fill={background}
41
+ stroke='none'
42
+ />
43
+ );
44
+ });
45
+ };
@@ -1,173 +1,173 @@
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
- fillType,
80
- url,
81
- size,
82
- fill,
83
- opacity,
84
- highlight: { show: showHighlight, extent, fill: highlightFill },
85
- },
86
- bandLength = 0,
87
- data,
88
- xAxis: { scaler: xScaler, step, direction },
89
- yAxis: { scaler: yScaler },
90
- }: any) => {
91
- if (!data.length) return null;
92
- const bandwidth = getBandwidth(step, paddingOuter);
93
- const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
94
- width: bandwidth,
95
- paddingInner,
96
- bandLength,
97
- });
98
-
99
- const _data = showHighlight ? getHighlightData(data, extent) : data;
100
-
101
- const offset =
102
- (seriesWidth + paddingInner * seriesStep) * bandLength -
103
- paddingInner * seriesStep;
104
-
105
- const isVertical = direction === 'vertical';
106
- return (
107
- <g className='__easyv-band'>
108
- {_data.map(
109
- (
110
- {
111
- flag,
112
- index,
113
- bound: [start, end],
114
- data,
115
- data: { x, y, s },
116
- }: DataWithBoundType,
117
- i: number
118
- ) => {
119
- const y1 = yScaler(isVertical ? end : start);
120
- const y2 = yScaler(isVertical ? start : end);
121
- const positionX = xScaler(x) + seriesStep * index - offset / 2;
122
- if (isNaN(positionX)) return null;
123
- const positionY = y < 0 ? y1 : y2;
124
- const attr = getAttr({
125
- isVertical,
126
- x: positionX,
127
- y: positionY,
128
- length: Math.abs(y1 - y2),
129
- seriesWidth,
130
- });
131
-
132
- return (
133
- <foreignObject
134
- key={i}
135
- {...attr}
136
- onClick={triggerClick}
137
- data-data={JSON.stringify(data)}
138
- >
139
- <div
140
- style={{
141
- width: '100%',
142
- height: '100%',
143
- /** Safari Bug **/
144
- position: 'fixed',
145
- opacity: fillType == 'pattern' ? opacity : 1,
146
- background:
147
- fillType == 'pattern'
148
- ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
149
- 'url(' +
150
- url +
151
- ')'
152
- : getBandBackground(
153
- pattern,
154
- extent === flag ? highlightFill : fill
155
- ),
156
- borderRadius:
157
- style == 'square'
158
- ? '0 0 0 0'
159
- : getBorderRadius({
160
- isVertical,
161
- positive: y > 0,
162
- seriesWidth,
163
- }),
164
- }}
165
- />
166
- </foreignObject>
167
- );
168
- }
169
- )}
170
- </g>
171
- );
172
- }
173
- );
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
+ fillType,
80
+ url,
81
+ size,
82
+ fill,
83
+ opacity,
84
+ highlight: { show: showHighlight, extent, fill: highlightFill },
85
+ },
86
+ bandLength = 0,
87
+ data,
88
+ xAxis: { scaler: xScaler, step, direction },
89
+ yAxis: { scaler: yScaler },
90
+ }: any) => {
91
+ if (!data.length) return null;
92
+ const bandwidth = getBandwidth(step, paddingOuter);
93
+ const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
94
+ width: bandwidth,
95
+ paddingInner,
96
+ bandLength,
97
+ });
98
+
99
+ const _data = showHighlight ? getHighlightData(data, extent) : data;
100
+
101
+ const offset =
102
+ (seriesWidth + paddingInner * seriesStep) * bandLength -
103
+ paddingInner * seriesStep;
104
+
105
+ const isVertical = direction === 'vertical';
106
+ return (
107
+ <g className='__easyv-band'>
108
+ {_data.map(
109
+ (
110
+ {
111
+ flag,
112
+ index,
113
+ bound: [start, end],
114
+ data,
115
+ data: { x, y, s },
116
+ }: DataWithBoundType,
117
+ i: number
118
+ ) => {
119
+ const y1 = yScaler(isVertical ? end : start);
120
+ const y2 = yScaler(isVertical ? start : end);
121
+ const positionX = xScaler(x) + seriesStep * index - offset / 2;
122
+ if (isNaN(positionX)) return null;
123
+ const positionY = y < 0 ? y1 : y2;
124
+ const attr = getAttr({
125
+ isVertical,
126
+ x: positionX,
127
+ y: positionY,
128
+ length: Math.abs(y1 - y2),
129
+ seriesWidth,
130
+ });
131
+
132
+ return (
133
+ <foreignObject
134
+ key={i}
135
+ {...attr}
136
+ onClick={triggerClick}
137
+ data-data={JSON.stringify(data)}
138
+ >
139
+ <div
140
+ style={{
141
+ width: '100%',
142
+ height: '100%',
143
+ /** Safari Bug **/
144
+ position: 'fixed',
145
+ opacity: fillType == 'pattern' ? opacity : 1,
146
+ background:
147
+ fillType == 'pattern'
148
+ ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
149
+ 'url(' +
150
+ url +
151
+ ')'
152
+ : getBandBackground(
153
+ pattern,
154
+ extent === flag ? highlightFill : fill
155
+ ),
156
+ borderRadius:
157
+ style == 'square'
158
+ ? '0 0 0 0'
159
+ : getBorderRadius({
160
+ isVertical,
161
+ positive: y > 0,
162
+ seriesWidth,
163
+ }),
164
+ }}
165
+ />
166
+ </foreignObject>
167
+ );
168
+ }
169
+ )}
170
+ </g>
171
+ );
172
+ }
173
+ );
@@ -1,76 +1,83 @@
1
- /**
2
- * 参考线
3
- */
4
- import React, { memo } from 'react';
5
-
6
-
7
- export default memo(
8
- ({
9
- width,
10
- config: {
11
- dataStyle: {
12
- data: {
13
- show: dataShow,
14
- dataStyle,
15
- translate: dataTranslate
16
- },
17
- label: {
18
- label,
19
- show: labelShow,
20
- textStyle,
21
- translate: labelTranslate,
22
- }
23
- },
24
- line: {
25
- color,
26
- lineType,
27
- lineWidth,
28
- margin: {
29
- marginLeft,
30
- marginRight
31
- },
32
- strokeDasharray,
33
- },
34
- },
35
- yAxis: { scaler: yScaler },
36
- data
37
- }) => {
38
- if (!data.value) return null;
39
- return (
40
- <>
41
- <g className='__easyv-baseLine' >
42
- <line
43
- x1={marginLeft}
44
- x2={width - marginRight}
45
- y1={yScaler(data.value)}
46
- y2={yScaler(data.value)}
47
- stroke={color}
48
- fill='none'
49
- strokeDasharray={lineType === 'dash' ? strokeDasharray : null}
50
- strokeWidth={lineWidth}
51
- />
52
- </g>
53
- {labelShow &&
54
- <foreignObject
55
- width={100}
56
- height={100}
57
- x={width - marginRight + labelTranslate.x}
58
- y={yScaler(data.value) - textStyle.fontSize + labelTranslate.y}>
59
- <div>
60
- <span style={{ ...textStyle }}>{label}</span>
61
- </div>
62
- </foreignObject>}
63
- {dataShow &&
64
- <foreignObject
65
- width={100}
66
- height={100}
67
- x={width - marginRight + dataTranslate.x}
68
- y={yScaler(data.value) + dataTranslate.y}>
69
- <div>
70
- <span style={{ ...dataStyle }}>{data.value}</span>
71
- </div>
72
- </foreignObject>}
73
- </>
74
- );
75
- }
76
- );
1
+ /**
2
+ * 参考线
3
+ */
4
+ import React, { memo } from 'react';
5
+ import { getFontStyle } from '../utils';
6
+
7
+ export default memo(
8
+ ({
9
+ width,
10
+ height,
11
+ baseLineOri: orientation,
12
+ config: {
13
+ dataStyle: {
14
+ data: {
15
+ show: dataShow,
16
+ dataStyle,
17
+ translate: dataTranslate
18
+ },
19
+ label: {
20
+ label,
21
+ show: labelShow,
22
+ textStyle,
23
+ translate: labelTranslate,
24
+ }
25
+ },
26
+ line: {
27
+ color,
28
+ lineType,
29
+ lineWidth,
30
+ margin: {
31
+ marginLeft,
32
+ marginRight
33
+ },
34
+ strokeDasharray,
35
+ },
36
+ },
37
+ yAxis: { scaler: yScaler },
38
+ data
39
+ }) => {
40
+ if (!data.value) return null;
41
+ console.log(orientation, 'orientation')
42
+ const x1 = orientation == 'left' ? yScaler(data.value) : marginLeft,
43
+ x2 = orientation == 'left' ? yScaler(data.value) : width - marginRight,
44
+ y1 = orientation == 'left' ? marginLeft : yScaler(data.value),
45
+ y2 = orientation == 'left' ? height - marginRight : yScaler(data.value);
46
+ return (
47
+ <>
48
+ <g className='__easyv-baseLine' >
49
+ <line
50
+ x1={x1}
51
+ x2={x2}
52
+ y1={y1}
53
+ y2={y2}
54
+ stroke={color}
55
+ fill='none'
56
+ strokeDasharray={lineType === 'dash' ? strokeDasharray : null}
57
+ strokeWidth={lineWidth}
58
+ />
59
+ </g>
60
+ {labelShow &&
61
+ <foreignObject
62
+ width={100}
63
+ height={100}
64
+ x={x2 + labelTranslate.x}
65
+ y={y2 - textStyle.fontSize + labelTranslate.y}>
66
+ <div>
67
+ <span style={{ ...getFontStyle(textStyle) }}>{label}</span>
68
+ </div>
69
+ </foreignObject>}
70
+ {dataShow &&
71
+ <foreignObject
72
+ width={100}
73
+ height={100}
74
+ x={x2 + dataTranslate.x}
75
+ y={y2 + dataTranslate.y}>
76
+ <div>
77
+ <span style={{ ...getFontStyle(dataStyle) }}>{data.value}</span>
78
+ </div>
79
+ </foreignObject>}
80
+ </>
81
+ );
82
+ }
83
+ );