@easyv/charts 1.0.60 → 1.0.61

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 (63) hide show
  1. package/.babelrc +8 -8
  2. package/lib/components/AnimateData.js +2 -2
  3. package/lib/components/Axis.js +12 -12
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Carousel.js +2 -2
  6. package/lib/components/Chart.js +2 -2
  7. package/lib/components/ConicalGradient.js +21 -21
  8. package/lib/components/Indicator.js +2 -2
  9. package/lib/components/LinearGradient.js +2 -2
  10. package/lib/components/Tooltip.js +24 -4
  11. package/lib/css/index.module.css +41 -41
  12. package/lib/css/piechart.module.css +26 -26
  13. package/lib/hooks/useAnimateData.js +5 -5
  14. package/lib/hooks/useAxes.js +5 -5
  15. package/lib/hooks/useCarouselAxisX.js +5 -5
  16. package/lib/hooks/useExtentData.js +6 -6
  17. package/lib/hooks/useFilterData.js +5 -5
  18. package/lib/hooks/useStackData.js +5 -5
  19. package/lib/hooks/useTooltip.js +10 -10
  20. package/package.json +34 -34
  21. package/src/components/AnimateData.tsx +24 -24
  22. package/src/components/Axis.tsx +333 -333
  23. package/src/components/Background.tsx +45 -45
  24. package/src/components/Band.tsx +160 -160
  25. package/src/components/Brush.js +159 -159
  26. package/src/components/Carousel.tsx +144 -144
  27. package/src/components/Chart.js +99 -99
  28. package/src/components/ChartContainer.tsx +63 -63
  29. package/src/components/ConicalGradient.js +258 -258
  30. package/src/components/ExtentData.js +17 -17
  31. package/src/components/FilterData.js +23 -23
  32. package/src/components/Indicator.js +13 -13
  33. package/src/components/Label.js +193 -193
  34. package/src/components/Legend.js +158 -158
  35. package/src/components/Lighter.jsx +162 -162
  36. package/src/components/Line.js +126 -126
  37. package/src/components/LinearGradient.js +29 -29
  38. package/src/components/Mapping.js +71 -71
  39. package/src/components/PieChart.js +1092 -1092
  40. package/src/components/StackData.js +20 -20
  41. package/src/components/StereoBar.tsx +298 -298
  42. package/src/components/Tooltip.js +134 -117
  43. package/src/components/index.js +49 -49
  44. package/src/context/index.js +2 -2
  45. package/src/css/index.module.css +41 -41
  46. package/src/css/piechart.module.css +26 -26
  47. package/src/element/ConicGradient.jsx +55 -55
  48. package/src/element/Line.tsx +33 -33
  49. package/src/element/index.ts +3 -3
  50. package/src/formatter/index.js +1 -1
  51. package/src/formatter/legend.js +87 -87
  52. package/src/hooks/index.js +17 -17
  53. package/src/hooks/useAnimateData.ts +62 -62
  54. package/src/hooks/useAxes.js +143 -143
  55. package/src/hooks/useCarouselAxisX.js +163 -163
  56. package/src/hooks/useExtentData.js +88 -88
  57. package/src/hooks/useFilterData.js +72 -72
  58. package/src/hooks/useStackData.js +100 -100
  59. package/src/hooks/useTooltip.ts +96 -96
  60. package/src/index.js +6 -6
  61. package/src/types/index.d.ts +59 -59
  62. package/src/utils/index.js +640 -640
  63. package/tsconfig.json +22 -22
@@ -1,3 +1,3 @@
1
- import Line from './Line';
2
-
3
- export { Line };
1
+ import Line from './Line';
2
+
3
+ export { Line };
@@ -1 +1 @@
1
- export * from './legend';
1
+ export * from './legend';
@@ -1,87 +1,87 @@
1
- import css from '../css/index.module.css';
2
- import { getFontStyle } from '../utils';
3
- export const pieLegendFormatter = (
4
- { displayName, value, percent, series: { color: seriesColor, icon="" } },
5
- {
6
- name: { show: showName, font: nameFont },
7
- value: {
8
- show: showValue,
9
- font: valueFont,
10
- sameColor: valueSameColor,
11
- gap: valueGap,
12
- suffix: {
13
- show: showSuffix,
14
- text,
15
- fontSize,
16
- translate: { x, y },
17
- },
18
- },
19
- percent: {
20
- show: showPercent,
21
- font: percentFont,
22
- sameColor: percentSameColor,
23
- gap: percentGap,
24
- },
25
- }
26
- ) => {
27
- const {
28
- type: seriesColorType,
29
- pure,
30
- linear: { stops },
31
- } = seriesColor;
32
-
33
- const _color = seriesColorType == 'pure' ? pure : stops[0].color;
34
- return (
35
- <>
36
- {icon &&<span style={{ ...icon, marginRight: icon.marginRight }} />}
37
- <span
38
- className={
39
- showName && showValue && showPercent
40
- ? css.showAllStyle
41
- : css.notShowAllStyle
42
- }
43
- >
44
- {showName && (
45
- <span style={{ paddingLeft: 5, ...getFontStyle(nameFont), whiteSpace:"nowrap" }}>
46
- {displayName}
47
- </span>
48
- )}
49
- {showValue && (
50
- <span
51
- style={{
52
- ...getFontStyle(valueFont),
53
- marginLeft: valueGap,
54
- display: 'flex',
55
- color: valueSameColor ? _color : valueFont.color,
56
- alignItems: 'center',
57
- justifyContent: 'flex-start',
58
- }}
59
- >
60
- {showValue && <span>{value}</span>}
61
- {showSuffix && (
62
- <span
63
- style={{
64
- fontSize,
65
- transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
66
- }}
67
- >
68
- {text}
69
- </span>
70
- )}
71
- </span>
72
- )}
73
- {showPercent && (
74
- <span
75
- style={{
76
- ...getFontStyle(percentFont),
77
- marginLeft: percentGap,
78
- color: percentSameColor ? _color : percentFont.color,
79
- }}
80
- >
81
- {percent + '%'}
82
- </span>
83
- )}
84
- </span>
85
- </>
86
- );
87
- };
1
+ import css from '../css/index.module.css';
2
+ import { getFontStyle } from '../utils';
3
+ export const pieLegendFormatter = (
4
+ { displayName, value, percent, series: { color: seriesColor, icon="" } },
5
+ {
6
+ name: { show: showName, font: nameFont },
7
+ value: {
8
+ show: showValue,
9
+ font: valueFont,
10
+ sameColor: valueSameColor,
11
+ gap: valueGap,
12
+ suffix: {
13
+ show: showSuffix,
14
+ text,
15
+ fontSize,
16
+ translate: { x, y },
17
+ },
18
+ },
19
+ percent: {
20
+ show: showPercent,
21
+ font: percentFont,
22
+ sameColor: percentSameColor,
23
+ gap: percentGap,
24
+ },
25
+ }
26
+ ) => {
27
+ const {
28
+ type: seriesColorType,
29
+ pure,
30
+ linear: { stops },
31
+ } = seriesColor;
32
+
33
+ const _color = seriesColorType == 'pure' ? pure : stops[0].color;
34
+ return (
35
+ <>
36
+ {icon &&<span style={{ ...icon, marginRight: icon.marginRight }} />}
37
+ <span
38
+ className={
39
+ showName && showValue && showPercent
40
+ ? css.showAllStyle
41
+ : css.notShowAllStyle
42
+ }
43
+ >
44
+ {showName && (
45
+ <span style={{ paddingLeft: 5, ...getFontStyle(nameFont), whiteSpace:"nowrap" }}>
46
+ {displayName}
47
+ </span>
48
+ )}
49
+ {showValue && (
50
+ <span
51
+ style={{
52
+ ...getFontStyle(valueFont),
53
+ marginLeft: valueGap,
54
+ display: 'flex',
55
+ color: valueSameColor ? _color : valueFont.color,
56
+ alignItems: 'center',
57
+ justifyContent: 'flex-start',
58
+ }}
59
+ >
60
+ {showValue && <span>{value}</span>}
61
+ {showSuffix && (
62
+ <span
63
+ style={{
64
+ fontSize,
65
+ transform: 'translate3d(' + x + 'px, ' + y + 'px, 0px)',
66
+ }}
67
+ >
68
+ {text}
69
+ </span>
70
+ )}
71
+ </span>
72
+ )}
73
+ {showPercent && (
74
+ <span
75
+ style={{
76
+ ...getFontStyle(percentFont),
77
+ marginLeft: percentGap,
78
+ color: percentSameColor ? _color : percentFont.color,
79
+ }}
80
+ >
81
+ {percent + '%'}
82
+ </span>
83
+ )}
84
+ </span>
85
+ </>
86
+ );
87
+ };
@@ -1,17 +1,17 @@
1
- import useFilterData from './useFilterData';
2
- import useStackData from './useStackData';
3
- import useAxes from './useAxes';
4
- import useTooltip from './useTooltip';
5
- import useAnimateData from './useAnimateData';
6
- import useCarouselAxisX from './useCarouselAxisX';
7
- import useExtentData from './useExtentData';
8
-
9
- export {
10
- useFilterData,
11
- useStackData,
12
- useAxes,
13
- useTooltip,
14
- useAnimateData,
15
- useCarouselAxisX,
16
- useExtentData,
17
- };
1
+ import useFilterData from './useFilterData';
2
+ import useStackData from './useStackData';
3
+ import useAxes from './useAxes';
4
+ import useTooltip from './useTooltip';
5
+ import useAnimateData from './useAnimateData';
6
+ import useCarouselAxisX from './useCarouselAxisX';
7
+ import useExtentData from './useExtentData';
8
+
9
+ export {
10
+ useFilterData,
11
+ useStackData,
12
+ useAxes,
13
+ useTooltip,
14
+ useAnimateData,
15
+ useCarouselAxisX,
16
+ useExtentData,
17
+ };
@@ -1,62 +1,62 @@
1
- import { useEffect, useState } from 'react';
2
- import { animate, linear } from 'popmotion';
3
-
4
- /**
5
- * 图表数据动画
6
- * @param {Array} data data列表
7
- * @param {boolean} dataAnimation 是否开启数据增长动画
8
- * @returns 改变后的数据
9
- */
10
-
11
- export default (data: DataType[], dataAnimation: boolean) => {
12
- const [animateData, setAnimateData] = useState<DataType[]>([]);
13
-
14
- useEffect(() => {
15
- let animateRef: any = null;
16
- if (dataAnimation && data.length) {
17
- animateRef = animate({
18
- autoplay: true,
19
- repeat: 0,
20
- from: 0,
21
- to: 1,
22
- duration: 500,
23
- ease: linear,
24
- onUpdate: (v: number) => {
25
- setAnimateData((oldData: DataType[]) => {
26
- const oldLength = oldData.length;
27
- const newLength = data.length;
28
- if (oldLength >= newLength) {
29
- return oldData.map(({ y }: DataType, i: number) => {
30
- const current: DataType = data[i] || { y: 0 };
31
- const delta: number = current.y - y;
32
- return {
33
- ...current,
34
- y: Math.floor(y + delta * v),
35
- };
36
- });
37
- } else {
38
- return data.map((current: DataType, i: number) => {
39
- const oldCurrent: DataType = oldData[i] || { y: 0 };
40
- const delta = oldCurrent.y - current.y;
41
- return {
42
- ...current,
43
- y: Math.floor(oldCurrent.y + delta * v),
44
- };
45
- });
46
- }
47
- });
48
- },
49
- onComplete: () => {
50
- setAnimateData(data);
51
- },
52
- });
53
- } else {
54
- setAnimateData(data);
55
- }
56
- return () => {
57
- animateRef && animateRef.stop();
58
- };
59
- }, [data, dataAnimation]);
60
-
61
- return animateData;
62
- };
1
+ import { useEffect, useState } from 'react';
2
+ import { animate, linear } from 'popmotion';
3
+
4
+ /**
5
+ * 图表数据动画
6
+ * @param {Array} data data列表
7
+ * @param {boolean} dataAnimation 是否开启数据增长动画
8
+ * @returns 改变后的数据
9
+ */
10
+
11
+ export default (data: DataType[], dataAnimation: boolean) => {
12
+ const [animateData, setAnimateData] = useState<DataType[]>([]);
13
+
14
+ useEffect(() => {
15
+ let animateRef: any = null;
16
+ if (dataAnimation && data.length) {
17
+ animateRef = animate({
18
+ autoplay: true,
19
+ repeat: 0,
20
+ from: 0,
21
+ to: 1,
22
+ duration: 500,
23
+ ease: linear,
24
+ onUpdate: (v: number) => {
25
+ setAnimateData((oldData: DataType[]) => {
26
+ const oldLength = oldData.length;
27
+ const newLength = data.length;
28
+ if (oldLength >= newLength) {
29
+ return oldData.map(({ y }: DataType, i: number) => {
30
+ const current: DataType = data[i] || { y: 0 };
31
+ const delta: number = current.y - y;
32
+ return {
33
+ ...current,
34
+ y: Math.floor(y + delta * v),
35
+ };
36
+ });
37
+ } else {
38
+ return data.map((current: DataType, i: number) => {
39
+ const oldCurrent: DataType = oldData[i] || { y: 0 };
40
+ const delta = oldCurrent.y - current.y;
41
+ return {
42
+ ...current,
43
+ y: Math.floor(oldCurrent.y + delta * v),
44
+ };
45
+ });
46
+ }
47
+ });
48
+ },
49
+ onComplete: () => {
50
+ setAnimateData(data);
51
+ },
52
+ });
53
+ } else {
54
+ setAnimateData(data);
55
+ }
56
+ return () => {
57
+ animateRef && animateRef.stop();
58
+ };
59
+ }, [data, dataAnimation]);
60
+
61
+ return animateData;
62
+ };
@@ -1,143 +1,143 @@
1
- import { useMemo } from 'react';
2
- import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
3
- import { band } from '../utils';
4
- import {
5
- getYTicksByStep,
6
- getYTicks,
7
- getTicksOfAxis,
8
- } from '@easyv/utils/lib/common/utils';
9
-
10
- const scales = {
11
- linear: scaleLinear,
12
- log: scaleLog,
13
- time: scaleTime,
14
- utc: scaleUtc,
15
- ordinal: band,
16
- };
17
-
18
- /**
19
- * x/y/z轴
20
- * @param {Array} axes 轴列表数组
21
- * @param {Object} context 其中需要包括
22
- * @returns {Map} 返回所有轴
23
- */
24
-
25
- export default ({ axes, context: { width, height } }) => {
26
- const _axes = useMemo(() => {
27
- const tmp = new Map();
28
- const xAxisPositions = [];
29
- axes.forEach((item) => {
30
- const {
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
- const direction =
45
- orientation === 'top' || orientation === 'bottom'
46
- ? 'horizontal'
47
- : orientation === 'left' || orientation === 'right'
48
- ? 'vertical'
49
- : '';
50
-
51
- const length =
52
- direction === 'horizontal'
53
- ? width
54
- : direction === 'vertical'
55
- ? height
56
- : 0;
57
-
58
- const _paddingOuter = paddingOuter * length;
59
- const start = _paddingOuter / 2;
60
- const end = length - start;
61
-
62
- const range =
63
- direction === 'horizontal'
64
- ? [start, end]
65
- : direction === 'vertical'
66
- ? [end, start]
67
- : [0, 0];
68
-
69
- const scaler = scales[type]().domain(domain).range(range);
70
- scaler.type = type;
71
-
72
- if (type !== 'ordinal') scaler.nice().clamp(true);
73
-
74
- const allTicks = ticks
75
- ? ticks
76
- : scaler.ticks
77
- ? scaler.ticks(tickCount)
78
- : scaler.domain();
79
-
80
- let _ticks = allTicks;
81
- if (type === 'ordinal') {
82
- if (carousel === false) {
83
- _ticks = getTicksOfAxis(_ticks, +tickCount);
84
- }
85
- } else {
86
- if (auto === false) {
87
- switch (mode) {
88
- case 'count':
89
- _ticks = getYTicks(
90
- _ticks[_ticks.length - 1],
91
- _ticks[0],
92
- +tickCount
93
- );
94
- break;
95
- case 'step':
96
- _ticks = getYTicksByStep(
97
- _ticks[_ticks.length - 1],
98
- _ticks[0],
99
- +step
100
- );
101
- break;
102
- }
103
- }
104
- }
105
-
106
- const lengthWithoutPaddingOuter = length - _paddingOuter;
107
-
108
- if (type == 'linear' && config.on) {
109
- const zeroPosition = scaler(0);
110
- if (zeroPosition !== range[0]) {
111
- if (direction === 'horizontal') {
112
- xAxisPositions.push({
113
- x: zeroPosition,
114
- y: 0,
115
- });
116
- } else if (direction === 'vertical') {
117
- xAxisPositions.push({
118
- x: 0,
119
- y: zeroPosition,
120
- });
121
- }
122
- }
123
- }
124
-
125
- tmp.set(axisType, {
126
- ...item,
127
- scaler,
128
- length,
129
- direction,
130
- start,
131
- end,
132
- lengthWithoutPaddingOuter,
133
- step: lengthWithoutPaddingOuter / allTicks.length,
134
- allTicks,
135
- ticks: _ticks,
136
- });
137
- });
138
-
139
- tmp.get('x') && (tmp.get('x').positions = xAxisPositions);
140
- return tmp;
141
- }, [axes]);
142
- return _axes;
143
- };
1
+ import { useMemo } from 'react';
2
+ import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
3
+ import { band } from '../utils';
4
+ import {
5
+ getYTicksByStep,
6
+ getYTicks,
7
+ getTicksOfAxis,
8
+ } from '@easyv/utils/lib/common/utils';
9
+
10
+ const scales = {
11
+ linear: scaleLinear,
12
+ log: scaleLog,
13
+ time: scaleTime,
14
+ utc: scaleUtc,
15
+ ordinal: band,
16
+ };
17
+
18
+ /**
19
+ * x/y/z轴
20
+ * @param {Array} axes 轴列表数组
21
+ * @param {Object} context 其中需要包括
22
+ * @returns {Map} 返回所有轴
23
+ */
24
+
25
+ export default ({ axes, context: { width, height } }) => {
26
+ const _axes = useMemo(() => {
27
+ const tmp = new Map();
28
+ const xAxisPositions = [];
29
+ axes.forEach((item) => {
30
+ const {
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
+ const direction =
45
+ orientation === 'top' || orientation === 'bottom'
46
+ ? 'horizontal'
47
+ : orientation === 'left' || orientation === 'right'
48
+ ? 'vertical'
49
+ : '';
50
+
51
+ const length =
52
+ direction === 'horizontal'
53
+ ? width
54
+ : direction === 'vertical'
55
+ ? height
56
+ : 0;
57
+
58
+ const _paddingOuter = paddingOuter * length;
59
+ const start = _paddingOuter / 2;
60
+ const end = length - start;
61
+
62
+ const range =
63
+ direction === 'horizontal'
64
+ ? [start, end]
65
+ : direction === 'vertical'
66
+ ? [end, start]
67
+ : [0, 0];
68
+
69
+ const scaler = scales[type]().domain(domain).range(range);
70
+ scaler.type = type;
71
+
72
+ if (type !== 'ordinal') scaler.nice().clamp(true);
73
+
74
+ const allTicks = ticks
75
+ ? ticks
76
+ : scaler.ticks
77
+ ? scaler.ticks(tickCount)
78
+ : scaler.domain();
79
+
80
+ let _ticks = allTicks;
81
+ if (type === 'ordinal') {
82
+ if (carousel === false) {
83
+ _ticks = getTicksOfAxis(_ticks, +tickCount);
84
+ }
85
+ } else {
86
+ if (auto === false) {
87
+ switch (mode) {
88
+ case 'count':
89
+ _ticks = getYTicks(
90
+ _ticks[_ticks.length - 1],
91
+ _ticks[0],
92
+ +tickCount
93
+ );
94
+ break;
95
+ case 'step':
96
+ _ticks = getYTicksByStep(
97
+ _ticks[_ticks.length - 1],
98
+ _ticks[0],
99
+ +step
100
+ );
101
+ break;
102
+ }
103
+ }
104
+ }
105
+
106
+ const lengthWithoutPaddingOuter = length - _paddingOuter;
107
+
108
+ if (type == 'linear' && config.on) {
109
+ const zeroPosition = scaler(0);
110
+ if (zeroPosition !== range[0]) {
111
+ if (direction === 'horizontal') {
112
+ xAxisPositions.push({
113
+ x: zeroPosition,
114
+ y: 0,
115
+ });
116
+ } else if (direction === 'vertical') {
117
+ xAxisPositions.push({
118
+ x: 0,
119
+ y: zeroPosition,
120
+ });
121
+ }
122
+ }
123
+ }
124
+
125
+ tmp.set(axisType, {
126
+ ...item,
127
+ scaler,
128
+ length,
129
+ direction,
130
+ start,
131
+ end,
132
+ lengthWithoutPaddingOuter,
133
+ step: lengthWithoutPaddingOuter / allTicks.length,
134
+ allTicks,
135
+ ticks: _ticks,
136
+ });
137
+ });
138
+
139
+ tmp.get('x') && (tmp.get('x').positions = xAxisPositions);
140
+ return tmp;
141
+ }, [axes]);
142
+ return _axes;
143
+ };