@easyv/charts 1.2.4 → 1.2.7

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 (92) hide show
  1. package/.babelrc +8 -8
  2. package/.husky/commit-msg +3 -3
  3. package/CHANGELOG.md +18 -18
  4. package/lib/components/AnimateData.js +7 -11
  5. package/lib/components/Axis.js +14 -18
  6. package/lib/components/Background.js +2 -2
  7. package/lib/components/Band.js +4 -8
  8. package/lib/components/BaseLine.js +74 -0
  9. package/lib/components/Brush.js +2 -2
  10. package/lib/components/Carousel.js +8 -15
  11. package/lib/components/CartesianChart.js +22 -11
  12. package/lib/components/Chart.js +6 -9
  13. package/lib/components/ChartContainer.js +4 -8
  14. package/lib/components/ConicalGradient.js +23 -27
  15. package/lib/components/ExtentData.js +4 -7
  16. package/lib/components/FilterData.js +4 -7
  17. package/lib/components/Indicator.js +2 -2
  18. package/lib/components/Label.js +2 -2
  19. package/lib/components/Legend.js +5 -11
  20. package/lib/components/Lighter.js +179 -179
  21. package/lib/components/Line.js +5 -11
  22. package/lib/components/LinearGradient.js +2 -2
  23. package/lib/components/Mapping.js +5 -8
  24. package/lib/components/Marquee.js +5 -5
  25. package/lib/components/PieChart.js +12 -22
  26. package/lib/components/StackData.js +4 -7
  27. package/lib/components/StereoBar.js +4 -8
  28. package/lib/components/TextOverflow.js +5 -5
  29. package/lib/components/Tooltip.js +2 -2
  30. package/lib/components/index.js +53 -45
  31. package/lib/css/index.module.css +41 -41
  32. package/lib/css/piechart.module.css +26 -26
  33. package/lib/element/ConicGradient.js +72 -72
  34. package/lib/formatter/legend.js +2 -2
  35. package/lib/hooks/index.js +14 -14
  36. package/lib/hooks/useAnimateData.js +7 -7
  37. package/lib/hooks/useAxes.js +7 -7
  38. package/lib/hooks/useCarouselAxisX.js +7 -7
  39. package/lib/hooks/useExtentData.js +8 -8
  40. package/lib/hooks/useFilterData.js +8 -8
  41. package/lib/hooks/useStackData.js +8 -10
  42. package/lib/hooks/useTooltip.js +10 -10
  43. package/lib/index.js +2 -6
  44. package/lib/utils/index.js +28 -11
  45. package/package.json +53 -53
  46. package/src/components/AnimateData.tsx +24 -24
  47. package/src/components/Axis.tsx +354 -354
  48. package/src/components/Background.tsx +45 -45
  49. package/src/components/Band.tsx +173 -173
  50. package/src/components/BaseLine.js +76 -0
  51. package/src/components/Brush.js +159 -159
  52. package/src/components/Carousel.tsx +144 -144
  53. package/src/components/CartesianChart.js +22 -5
  54. package/src/components/Chart.js +99 -99
  55. package/src/components/ChartContainer.tsx +63 -63
  56. package/src/components/ConicalGradient.js +258 -258
  57. package/src/components/ExtentData.js +17 -17
  58. package/src/components/FilterData.js +23 -23
  59. package/src/components/Indicator.js +13 -13
  60. package/src/components/Label.js +206 -206
  61. package/src/components/Legend.js +158 -158
  62. package/src/components/Lighter.jsx +173 -173
  63. package/src/components/Line.js +144 -144
  64. package/src/components/LinearGradient.js +29 -29
  65. package/src/components/Mapping.js +71 -71
  66. package/src/components/Marquee.js +93 -93
  67. package/src/components/PieChart.js +1287 -1288
  68. package/src/components/StackData.js +20 -20
  69. package/src/components/StereoBar.tsx +310 -310
  70. package/src/components/TextOverflow.js +51 -51
  71. package/src/components/Tooltip.js +169 -169
  72. package/src/components/index.js +55 -53
  73. package/src/context/index.js +2 -2
  74. package/src/css/index.module.css +41 -41
  75. package/src/css/piechart.module.css +26 -26
  76. package/src/element/ConicGradient.jsx +55 -55
  77. package/src/element/Line.tsx +33 -33
  78. package/src/element/index.ts +3 -3
  79. package/src/formatter/index.js +1 -1
  80. package/src/formatter/legend.js +90 -90
  81. package/src/hooks/index.js +17 -17
  82. package/src/hooks/useAnimateData.ts +67 -67
  83. package/src/hooks/useAxes.js +144 -144
  84. package/src/hooks/useCarouselAxisX.js +163 -163
  85. package/src/hooks/useExtentData.js +88 -88
  86. package/src/hooks/useFilterData.js +72 -72
  87. package/src/hooks/useStackData.js +100 -100
  88. package/src/hooks/useTooltip.ts +96 -96
  89. package/src/index.js +6 -6
  90. package/src/types/index.d.ts +67 -67
  91. package/src/utils/index.js +714 -696
  92. package/tsconfig.json +22 -22
@@ -1,144 +1,144 @@
1
- import { useMemo } from 'react';
2
- import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
3
- import { band, getTicksOfAxis } from '../utils';
4
- import {
5
- getYTicksByStep,
6
- getYTicks,
7
- } from '@easyv/utils/lib/common/utils';
8
-
9
- const scales = {
10
- linear: scaleLinear,
11
- log: scaleLog,
12
- time: scaleTime,
13
- utc: scaleUtc,
14
- ordinal: band,
15
- };
16
-
17
- /**
18
- * x/y/z轴
19
- * @param {Array} axes 轴列表数组
20
- * @param {Object} context 其中需要包括
21
- * @returns {Map} 返回所有轴
22
- */
23
-
24
- export default ({ axes, context: { width, height } }) => {
25
- const _axes = useMemo(() => {
26
- const tmp = new Map();
27
- const xAxisPositions = [];
28
- axes.forEach((item) => {
29
- const {
30
- config: { label: { showLast = false } },
31
- type,
32
- orientation,
33
- ticks,
34
- tickCount = 1,
35
- step = 1,
36
- domain,
37
- axisType,
38
- paddingOuter = 0,
39
- auto,
40
- mode,
41
- carousel,
42
- config,
43
- } = item;
44
-
45
- const direction =
46
- orientation === 'top' || orientation === 'bottom'
47
- ? 'horizontal'
48
- : orientation === 'left' || orientation === 'right'
49
- ? 'vertical'
50
- : '';
51
-
52
- const length =
53
- direction === 'horizontal'
54
- ? width
55
- : direction === 'vertical'
56
- ? height
57
- : 0;
58
-
59
- const _paddingOuter = paddingOuter * length;
60
- const start = _paddingOuter / 2;
61
- const end = length - start;
62
-
63
- const range =
64
- direction === 'horizontal'
65
- ? [start, end]
66
- : direction === 'vertical'
67
- ? [end, start]
68
- : [0, 0];
69
-
70
- const scaler = scales[type]().domain(domain).range(range);
71
- scaler.type = type;
72
-
73
- if (type !== 'ordinal') scaler.nice().clamp(true);
74
-
75
- const allTicks = ticks
76
- ? ticks
77
- : scaler.ticks
78
- ? scaler.ticks(tickCount)
79
- : scaler.domain();
80
-
81
- let _ticks = allTicks;
82
- if (type === 'ordinal') {
83
- if (carousel === false) {
84
- _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
85
- }
86
- } else {
87
- if (auto === false) {
88
- switch (mode) {
89
- case 'count':
90
- _ticks = getYTicks(
91
- _ticks[_ticks.length - 1],
92
- _ticks[0],
93
- +tickCount
94
- );
95
- break;
96
- case 'step':
97
- _ticks = getYTicksByStep(
98
- _ticks[_ticks.length - 1],
99
- _ticks[0],
100
- +step
101
- );
102
- break;
103
- }
104
- }
105
- }
106
-
107
- const lengthWithoutPaddingOuter = length - _paddingOuter;
108
-
109
- if (type == 'linear' && config.on) {
110
- const zeroPosition = scaler(0);
111
- if (zeroPosition !== range[0]) {
112
- if (direction === 'horizontal') {
113
- xAxisPositions.push({
114
- x: zeroPosition,
115
- y: 0,
116
- });
117
- } else if (direction === 'vertical') {
118
- xAxisPositions.push({
119
- x: 0,
120
- y: zeroPosition,
121
- });
122
- }
123
- }
124
- }
125
-
126
- tmp.set(axisType, {
127
- ...item,
128
- scaler,
129
- length,
130
- direction,
131
- start,
132
- end,
133
- lengthWithoutPaddingOuter,
134
- step: lengthWithoutPaddingOuter / allTicks.length,
135
- allTicks,
136
- ticks: _ticks,
137
- });
138
- });
139
-
140
- tmp.get('x') && (tmp.get('x').positions = xAxisPositions);
141
- return tmp;
142
- }, [axes]);
143
- return _axes;
144
- };
1
+ import { useMemo } from 'react';
2
+ import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
3
+ import { band, getTicksOfAxis } from '../utils';
4
+ import {
5
+ getYTicksByStep,
6
+ getYTicks,
7
+ } from '@easyv/utils/lib/common/utils';
8
+
9
+ const scales = {
10
+ linear: scaleLinear,
11
+ log: scaleLog,
12
+ time: scaleTime,
13
+ utc: scaleUtc,
14
+ ordinal: band,
15
+ };
16
+
17
+ /**
18
+ * x/y/z轴
19
+ * @param {Array} axes 轴列表数组
20
+ * @param {Object} context 其中需要包括
21
+ * @returns {Map} 返回所有轴
22
+ */
23
+
24
+ export default ({ axes, context: { width, height } }) => {
25
+ const _axes = useMemo(() => {
26
+ const tmp = new Map();
27
+ const xAxisPositions = [];
28
+ axes.forEach((item) => {
29
+ const {
30
+ config: { label: { showLast = false } },
31
+ type,
32
+ orientation,
33
+ ticks,
34
+ tickCount = 1,
35
+ step = 1,
36
+ domain,
37
+ axisType,
38
+ paddingOuter = 0,
39
+ auto,
40
+ mode,
41
+ carousel,
42
+ config,
43
+ } = item;
44
+
45
+ const direction =
46
+ orientation === 'top' || orientation === 'bottom'
47
+ ? 'horizontal'
48
+ : orientation === 'left' || orientation === 'right'
49
+ ? 'vertical'
50
+ : '';
51
+
52
+ const length =
53
+ direction === 'horizontal'
54
+ ? width
55
+ : direction === 'vertical'
56
+ ? height
57
+ : 0;
58
+
59
+ const _paddingOuter = paddingOuter * length;
60
+ const start = _paddingOuter / 2;
61
+ const end = length - start;
62
+
63
+ const range =
64
+ direction === 'horizontal'
65
+ ? [start, end]
66
+ : direction === 'vertical'
67
+ ? [end, start]
68
+ : [0, 0];
69
+
70
+ const scaler = scales[type]().domain(domain).range(range);
71
+ scaler.type = type;
72
+
73
+ if (type !== 'ordinal') scaler.nice().clamp(true);
74
+
75
+ const allTicks = ticks
76
+ ? ticks
77
+ : scaler.ticks
78
+ ? scaler.ticks(tickCount)
79
+ : scaler.domain();
80
+
81
+ let _ticks = allTicks;
82
+ if (type === 'ordinal') {
83
+ if (carousel === false) {
84
+ _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
85
+ }
86
+ } else {
87
+ if (auto === false) {
88
+ switch (mode) {
89
+ case 'count':
90
+ _ticks = getYTicks(
91
+ _ticks[_ticks.length - 1],
92
+ _ticks[0],
93
+ +tickCount
94
+ );
95
+ break;
96
+ case 'step':
97
+ _ticks = getYTicksByStep(
98
+ _ticks[_ticks.length - 1],
99
+ _ticks[0],
100
+ +step
101
+ );
102
+ break;
103
+ }
104
+ }
105
+ }
106
+
107
+ const lengthWithoutPaddingOuter = length - _paddingOuter;
108
+
109
+ if (type == 'linear' && config.on) {
110
+ const zeroPosition = scaler(0);
111
+ if (zeroPosition !== range[0]) {
112
+ if (direction === 'horizontal') {
113
+ xAxisPositions.push({
114
+ x: zeroPosition,
115
+ y: 0,
116
+ });
117
+ } else if (direction === 'vertical') {
118
+ xAxisPositions.push({
119
+ x: 0,
120
+ y: zeroPosition,
121
+ });
122
+ }
123
+ }
124
+ }
125
+
126
+ tmp.set(axisType, {
127
+ ...item,
128
+ scaler,
129
+ length,
130
+ direction,
131
+ start,
132
+ end,
133
+ lengthWithoutPaddingOuter,
134
+ step: lengthWithoutPaddingOuter / allTicks.length,
135
+ allTicks,
136
+ ticks: _ticks,
137
+ });
138
+ });
139
+
140
+ tmp.get('x') && (tmp.get('x').positions = xAxisPositions);
141
+ return tmp;
142
+ }, [axes]);
143
+ return _axes;
144
+ };
@@ -1,163 +1,163 @@
1
- import { useEffect, useState } from 'react';
2
- import { animate, linear } from 'popmotion';
3
-
4
- const initialState = {
5
- currentIndex: null,
6
- flag: false,
7
- };
8
-
9
- /**
10
- * x轴滚动逻辑
11
- * @param {Object} axis x轴配置项
12
- * @param {Object} config x轴轮播动画的配置项
13
- * @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
14
- */
15
-
16
- export default (axis, config) => {
17
- const { show, interval, duration } = config;
18
- const time = duration + interval;
19
-
20
- const {
21
- tickCount,
22
- allTicks,
23
- scaler,
24
- start,
25
- end,
26
- step,
27
- ticks,
28
- lengthWithoutPaddingOuter,
29
- } = axis;
30
- const tickLength = ticks.length;
31
-
32
- const [state, setState] = useState({
33
- scaler,
34
- step,
35
- ticks,
36
- });
37
- const [status, setStatus] = useState(initialState);
38
-
39
- useEffect(() => {
40
- let handler;
41
- if (show && time && tickLength > tickCount) {
42
- setStatus({
43
- currentIndex: 0,
44
- flag: true,
45
- });
46
- handler = setInterval(() => {
47
- setStatus(({ currentIndex }) => {
48
- const tmp = +currentIndex + 1;
49
- return {
50
- currentIndex: tmp >= tickLength ? 0 : tmp,
51
- flag: false,
52
- };
53
- });
54
- }, time * 1000);
55
- } else {
56
- setStatus(initialState);
57
- }
58
- return () => {
59
- handler && clearInterval(handler);
60
- };
61
- }, [show, time, tickCount, tickLength]);
62
-
63
- useEffect(() => {
64
- let animation;
65
- const { currentIndex, flag } = status;
66
- if (currentIndex !== null) {
67
- const step = lengthWithoutPaddingOuter / tickCount;
68
- if (flag) {
69
- const _ticks = allTicks.slice(currentIndex, tickCount);
70
- setState({
71
- step,
72
- ticks: _ticks,
73
- scaler: scaler.copy().domain(_ticks).range([start, end]),
74
- });
75
- } else {
76
- animation = animate({
77
- from: 0,
78
- to: -1,
79
- duration: duration * 1000,
80
- ease: linear,
81
- onPlay: () => {
82
- setState((axis) => {
83
- const { ticks, scaler } = axis;
84
- const [tick] = ticks;
85
- const _ticks = [
86
- tick,
87
- ...getTicks(allTicks, currentIndex, tickCount),
88
- ];
89
- return {
90
- ...axis,
91
- ticks: _ticks,
92
- scaler: scaler
93
- .copy()
94
- .range([start, end + step])
95
- .domain(_ticks),
96
- };
97
- });
98
- },
99
- onUpdate: (v) => {
100
- setState((axis) => {
101
- const { scaler, step } = axis;
102
- return {
103
- ...axis,
104
- scaler: scaler
105
- .copy()
106
- .range([start + step * v, end + step + step * v]),
107
- };
108
- });
109
- },
110
- onComplete: () => {
111
- setState((axis) => {
112
- const { scaler, ticks } = axis;
113
- const _ticks = ticks.slice(1, ticks.length);
114
- return {
115
- ...axis,
116
- ticks: _ticks,
117
- scaler: scaler.copy().range([start, end]).domain(_ticks),
118
- };
119
- });
120
- },
121
- });
122
- }
123
- } else {
124
- const _ticks = scaler.type == 'linear' ? scaler.domain() : allTicks;
125
- setState({
126
- step,
127
- scaler: scaler.copy().domain(_ticks).range([start, end]),
128
- ticks,
129
- });
130
- }
131
- return () => {
132
- animation && animation.stop();
133
- };
134
- }, [
135
- tickCount,
136
- allTicks,
137
- scaler,
138
- start,
139
- end,
140
- step,
141
- ticks,
142
- lengthWithoutPaddingOuter,
143
- status,
144
- duration,
145
- ]);
146
- return {
147
- ...axis,
148
- ...state,
149
- };
150
- };
151
-
152
- const getTicks = (ticks, currentIndex, length) => {
153
- const _currentIndex = +currentIndex;
154
- const ticksLength = ticks.length;
155
- if (ticksLength <= length) return ticks;
156
- const end = _currentIndex + length;
157
- if (ticksLength < end) {
158
- const prev = ticks.slice(_currentIndex, ticksLength);
159
- const next = ticks.slice(0, end - ticksLength);
160
- return [...prev, ...next];
161
- }
162
- return ticks.slice(_currentIndex, end);
163
- };
1
+ import { useEffect, useState } from 'react';
2
+ import { animate, linear } from 'popmotion';
3
+
4
+ const initialState = {
5
+ currentIndex: null,
6
+ flag: false,
7
+ };
8
+
9
+ /**
10
+ * x轴滚动逻辑
11
+ * @param {Object} axis x轴配置项
12
+ * @param {Object} config x轴轮播动画的配置项
13
+ * @returns {Map} 返回经过改变后的x轴,主要是ticks和scaler的range发生了改变
14
+ */
15
+
16
+ export default (axis, config) => {
17
+ const { show, interval, duration } = config;
18
+ const time = duration + interval;
19
+
20
+ const {
21
+ tickCount,
22
+ allTicks,
23
+ scaler,
24
+ start,
25
+ end,
26
+ step,
27
+ ticks,
28
+ lengthWithoutPaddingOuter,
29
+ } = axis;
30
+ const tickLength = ticks.length;
31
+
32
+ const [state, setState] = useState({
33
+ scaler,
34
+ step,
35
+ ticks,
36
+ });
37
+ const [status, setStatus] = useState(initialState);
38
+
39
+ useEffect(() => {
40
+ let handler;
41
+ if (show && time && tickLength > tickCount) {
42
+ setStatus({
43
+ currentIndex: 0,
44
+ flag: true,
45
+ });
46
+ handler = setInterval(() => {
47
+ setStatus(({ currentIndex }) => {
48
+ const tmp = +currentIndex + 1;
49
+ return {
50
+ currentIndex: tmp >= tickLength ? 0 : tmp,
51
+ flag: false,
52
+ };
53
+ });
54
+ }, time * 1000);
55
+ } else {
56
+ setStatus(initialState);
57
+ }
58
+ return () => {
59
+ handler && clearInterval(handler);
60
+ };
61
+ }, [show, time, tickCount, tickLength]);
62
+
63
+ useEffect(() => {
64
+ let animation;
65
+ const { currentIndex, flag } = status;
66
+ if (currentIndex !== null) {
67
+ const step = lengthWithoutPaddingOuter / tickCount;
68
+ if (flag) {
69
+ const _ticks = allTicks.slice(currentIndex, tickCount);
70
+ setState({
71
+ step,
72
+ ticks: _ticks,
73
+ scaler: scaler.copy().domain(_ticks).range([start, end]),
74
+ });
75
+ } else {
76
+ animation = animate({
77
+ from: 0,
78
+ to: -1,
79
+ duration: duration * 1000,
80
+ ease: linear,
81
+ onPlay: () => {
82
+ setState((axis) => {
83
+ const { ticks, scaler } = axis;
84
+ const [tick] = ticks;
85
+ const _ticks = [
86
+ tick,
87
+ ...getTicks(allTicks, currentIndex, tickCount),
88
+ ];
89
+ return {
90
+ ...axis,
91
+ ticks: _ticks,
92
+ scaler: scaler
93
+ .copy()
94
+ .range([start, end + step])
95
+ .domain(_ticks),
96
+ };
97
+ });
98
+ },
99
+ onUpdate: (v) => {
100
+ setState((axis) => {
101
+ const { scaler, step } = axis;
102
+ return {
103
+ ...axis,
104
+ scaler: scaler
105
+ .copy()
106
+ .range([start + step * v, end + step + step * v]),
107
+ };
108
+ });
109
+ },
110
+ onComplete: () => {
111
+ setState((axis) => {
112
+ const { scaler, ticks } = axis;
113
+ const _ticks = ticks.slice(1, ticks.length);
114
+ return {
115
+ ...axis,
116
+ ticks: _ticks,
117
+ scaler: scaler.copy().range([start, end]).domain(_ticks),
118
+ };
119
+ });
120
+ },
121
+ });
122
+ }
123
+ } else {
124
+ const _ticks = scaler.type == 'linear' ? scaler.domain() : allTicks;
125
+ setState({
126
+ step,
127
+ scaler: scaler.copy().domain(_ticks).range([start, end]),
128
+ ticks,
129
+ });
130
+ }
131
+ return () => {
132
+ animation && animation.stop();
133
+ };
134
+ }, [
135
+ tickCount,
136
+ allTicks,
137
+ scaler,
138
+ start,
139
+ end,
140
+ step,
141
+ ticks,
142
+ lengthWithoutPaddingOuter,
143
+ status,
144
+ duration,
145
+ ]);
146
+ return {
147
+ ...axis,
148
+ ...state,
149
+ };
150
+ };
151
+
152
+ const getTicks = (ticks, currentIndex, length) => {
153
+ const _currentIndex = +currentIndex;
154
+ const ticksLength = ticks.length;
155
+ if (ticksLength <= length) return ticks;
156
+ const end = _currentIndex + length;
157
+ if (ticksLength < end) {
158
+ const prev = ticks.slice(_currentIndex, ticksLength);
159
+ const next = ticks.slice(0, end - ticksLength);
160
+ return [...prev, ...next];
161
+ }
162
+ return ticks.slice(_currentIndex, end);
163
+ };