@easyv/charts 1.7.37 → 1.8.0

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 (61) hide show
  1. package/.babelrc +8 -8
  2. package/CHANGELOG.md +18 -18
  3. package/commitlint.config.js +1 -1
  4. package/lib/components/Background.js +2 -2
  5. package/lib/components/Band.js +2 -2
  6. package/lib/components/Brush.js +2 -2
  7. package/lib/components/Chart.js +2 -2
  8. package/lib/components/ChartContainer.js +2 -2
  9. package/lib/components/ConicalGradient.js +21 -21
  10. package/lib/components/ExtentData.js +2 -2
  11. package/lib/components/Indicator.js +2 -2
  12. package/lib/components/Label.js +2 -2
  13. package/lib/components/Legend.js +5 -8
  14. package/lib/components/Lighter.js +2 -2
  15. package/lib/components/Line.js +2 -2
  16. package/lib/components/LinearGradient.js +2 -2
  17. package/lib/components/PieChart.js +26 -4
  18. package/lib/components/StereoBar.js +2 -2
  19. package/lib/css/index.module.css +39 -39
  20. package/lib/css/piechart.module.css +26 -26
  21. package/lib/hooks/useAnimateData.js +6 -6
  22. package/lib/hooks/useFilterData.js +5 -5
  23. package/lib/hooks/useStackData.js +5 -5
  24. package/lib/hooks/useTooltip.js +11 -11
  25. package/package.json +54 -54
  26. package/src/components/Background.tsx +61 -61
  27. package/src/components/Band.tsx +334 -334
  28. package/src/components/Brush.js +159 -159
  29. package/src/components/Chart.js +157 -157
  30. package/src/components/ChartContainer.tsx +71 -71
  31. package/src/components/ConicalGradient.js +258 -258
  32. package/src/components/Control.jsx +242 -242
  33. package/src/components/ExtentData.js +18 -18
  34. package/src/components/Indicator.js +61 -61
  35. package/src/components/Label.js +262 -262
  36. package/src/components/Legend.js +286 -289
  37. package/src/components/Lighter.jsx +173 -173
  38. package/src/components/Line.js +153 -153
  39. package/src/components/LinearGradient.js +29 -29
  40. package/src/components/PieChart.js +19 -5
  41. package/src/components/PieTooltip.jsx +160 -160
  42. package/src/components/SplitText.tsx +70 -70
  43. package/src/components/StereoBar.tsx +307 -307
  44. package/src/components/index.js +61 -61
  45. package/src/context/index.js +2 -2
  46. package/src/css/index.module.css +39 -39
  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 +122 -122
  53. package/src/hooks/index.js +20 -20
  54. package/src/hooks/useAnimateData.ts +68 -68
  55. package/src/hooks/useFilterData.js +77 -77
  56. package/src/hooks/useStackData.js +140 -140
  57. package/src/hooks/useTooltip.ts +103 -103
  58. package/src/index.js +6 -6
  59. package/src/types/index.d.ts +68 -68
  60. package/src/utils/index.js +812 -812
  61. package/tsconfig.json +23 -23
@@ -1,140 +1,140 @@
1
- import { useMemo } from 'react';
2
- import { group } from 'd3v7';
3
- import {
4
- dataYOrZ,
5
- seriesYOrZ,
6
- getCurrentStack,
7
- getStacks,
8
- resetStacks,
9
- } from '../utils';
10
-
11
- const getSeriesMap = (series) => {
12
- const seriesMap = new Map();
13
- series.forEach(({ name, ...rest }) => {
14
- seriesMap.set(name, {
15
- ...rest,
16
- name,
17
- data: [],
18
- });
19
- });
20
- return seriesMap;
21
- };
22
- const resetStackData = (series) => {
23
- series.forEach((series) => {
24
- series.data = [];
25
- });
26
- };
27
-
28
- const setStackData = (data, series, stacks) => {
29
- const dataMap = group(data, (d) => d.x);
30
- dataMap.forEach((value) => {
31
- resetStacks(stacks);
32
- for (let i = 0, j = value.length; i < j; i++) {
33
- const d = value[i];
34
- const currentSeries = series.get(d.s);
35
- if(currentSeries){
36
- const type = currentSeries.type;
37
- const currentStack = getCurrentStack(currentSeries, stacks);
38
- if (d && d.y !== undefined && (type!="band" || type=="band" && !isNaN(d.y))) {
39
- if (currentStack) {
40
- if (d.y >= 0) {
41
- currentSeries.data.push({
42
- data: d,
43
- index: currentStack.index,
44
- bound: [currentStack.positive, currentStack.positive + d.y],
45
- });
46
- currentStack.positive += d.y;
47
- } else {
48
- currentSeries.data.push({
49
- data: d,
50
- index: currentStack.index,
51
- bound: [currentStack.negative, currentStack.negative + d.y],
52
- });
53
- currentStack.negative += d.y;
54
- }
55
- } else {
56
- currentSeries.data.push({
57
- data: d,
58
- bound: [0, d.y],
59
- index: 0,
60
- });
61
- }
62
- }
63
- }
64
-
65
- }
66
- });
67
- dataMap.clear();
68
- return series;
69
- };
70
- const mergeDataAndSeries=(data, _series) =>{
71
- // 创建一个映射,键为系列名称,值为数据点数组
72
- const dataMap = new Map();
73
-
74
- // 遍历 data 数组,按系列名称分组数据点
75
- data.forEach(item => {
76
- const seriesName = item.s;
77
- if (!dataMap.has(seriesName)) {
78
- dataMap.set(seriesName, []);
79
- }
80
- // 构建符合目标格式的数据点对象
81
- const dataPoint = {
82
- data: {
83
- s: item.s,
84
- x: item.x,
85
- y: item.y,
86
- showY: item.showY
87
- },
88
- index: 0,
89
- bound: [0, item.y]
90
- };
91
- dataMap.get(seriesName).push(dataPoint);
92
- });
93
-
94
- // 遍历 _series 数组,为每个系列添加对应的数据
95
- return _series.map(series => {
96
- const seriesName = series.name || series.fieldName;
97
- // 查找对应系列的数据
98
- const seriesData = dataMap.get(seriesName) || [];
99
- // 返回合并后完整的系列对象,包含原始配置和新添加的数据
100
- return {
101
- ...series,
102
- data: seriesData
103
- };
104
- });
105
- }
106
- /**
107
- * 计算堆叠数据
108
- * @param {Array} data 数据
109
- * @param {Map} series 系列
110
- * @returns {Array} 返回堆叠后的数据,由一开始的{x, y, s}变成{data: {x, y, s}, bound: [start, end], index}
111
- */
112
-
113
- export default ({ data, series }) => {
114
- const _series = useMemo(() => {
115
- const stacks = getStacks(series);
116
- const _series = getSeriesMap(series);
117
- return { stacks, series: seriesYOrZ(_series) };
118
- }, [series]);
119
-
120
- const _data = useMemo(() => dataYOrZ(data, _series.series), [data, _series]);
121
- const tmp = useMemo(() => {
122
- const seriesdata=mergeDataAndSeries(data,Array.from(series.values()))
123
- const { y: dataY, z: dataZ } = _data;
124
- const {
125
- stacks,
126
- series: { z: seriesZ,y: seriesY },
127
- } = _series;
128
- resetStackData(seriesY);
129
- resetStackData(seriesZ);
130
- setStackData(dataY, seriesY, stacks);
131
- setStackData(dataZ, seriesZ, stacks);
132
- return {
133
- bandLength: stacks.filter((item) => item.type == 'band').length,
134
- // series: mergeDataAndSeries(data,Array.from(series.values())),
135
- series: [...seriesY.values(), ...seriesZ.values()],
136
- seriesdata:seriesdata
137
- };
138
- }, [_data, _series]);
139
- return tmp;
140
- };
1
+ import { useMemo } from 'react';
2
+ import { group } from 'd3v7';
3
+ import {
4
+ dataYOrZ,
5
+ seriesYOrZ,
6
+ getCurrentStack,
7
+ getStacks,
8
+ resetStacks,
9
+ } from '../utils';
10
+
11
+ const getSeriesMap = (series) => {
12
+ const seriesMap = new Map();
13
+ series.forEach(({ name, ...rest }) => {
14
+ seriesMap.set(name, {
15
+ ...rest,
16
+ name,
17
+ data: [],
18
+ });
19
+ });
20
+ return seriesMap;
21
+ };
22
+ const resetStackData = (series) => {
23
+ series.forEach((series) => {
24
+ series.data = [];
25
+ });
26
+ };
27
+
28
+ const setStackData = (data, series, stacks) => {
29
+ const dataMap = group(data, (d) => d.x);
30
+ dataMap.forEach((value) => {
31
+ resetStacks(stacks);
32
+ for (let i = 0, j = value.length; i < j; i++) {
33
+ const d = value[i];
34
+ const currentSeries = series.get(d.s);
35
+ if(currentSeries){
36
+ const type = currentSeries.type;
37
+ const currentStack = getCurrentStack(currentSeries, stacks);
38
+ if (d && d.y !== undefined && (type!="band" || type=="band" && !isNaN(d.y))) {
39
+ if (currentStack) {
40
+ if (d.y >= 0) {
41
+ currentSeries.data.push({
42
+ data: d,
43
+ index: currentStack.index,
44
+ bound: [currentStack.positive, currentStack.positive + d.y],
45
+ });
46
+ currentStack.positive += d.y;
47
+ } else {
48
+ currentSeries.data.push({
49
+ data: d,
50
+ index: currentStack.index,
51
+ bound: [currentStack.negative, currentStack.negative + d.y],
52
+ });
53
+ currentStack.negative += d.y;
54
+ }
55
+ } else {
56
+ currentSeries.data.push({
57
+ data: d,
58
+ bound: [0, d.y],
59
+ index: 0,
60
+ });
61
+ }
62
+ }
63
+ }
64
+
65
+ }
66
+ });
67
+ dataMap.clear();
68
+ return series;
69
+ };
70
+ const mergeDataAndSeries=(data, _series) =>{
71
+ // 创建一个映射,键为系列名称,值为数据点数组
72
+ const dataMap = new Map();
73
+
74
+ // 遍历 data 数组,按系列名称分组数据点
75
+ data.forEach(item => {
76
+ const seriesName = item.s;
77
+ if (!dataMap.has(seriesName)) {
78
+ dataMap.set(seriesName, []);
79
+ }
80
+ // 构建符合目标格式的数据点对象
81
+ const dataPoint = {
82
+ data: {
83
+ s: item.s,
84
+ x: item.x,
85
+ y: item.y,
86
+ showY: item.showY
87
+ },
88
+ index: 0,
89
+ bound: [0, item.y]
90
+ };
91
+ dataMap.get(seriesName).push(dataPoint);
92
+ });
93
+
94
+ // 遍历 _series 数组,为每个系列添加对应的数据
95
+ return _series.map(series => {
96
+ const seriesName = series.name || series.fieldName;
97
+ // 查找对应系列的数据
98
+ const seriesData = dataMap.get(seriesName) || [];
99
+ // 返回合并后完整的系列对象,包含原始配置和新添加的数据
100
+ return {
101
+ ...series,
102
+ data: seriesData
103
+ };
104
+ });
105
+ }
106
+ /**
107
+ * 计算堆叠数据
108
+ * @param {Array} data 数据
109
+ * @param {Map} series 系列
110
+ * @returns {Array} 返回堆叠后的数据,由一开始的{x, y, s}变成{data: {x, y, s}, bound: [start, end], index}
111
+ */
112
+
113
+ export default ({ data, series }) => {
114
+ const _series = useMemo(() => {
115
+ const stacks = getStacks(series);
116
+ const _series = getSeriesMap(series);
117
+ return { stacks, series: seriesYOrZ(_series) };
118
+ }, [series]);
119
+
120
+ const _data = useMemo(() => dataYOrZ(data, _series.series), [data, _series]);
121
+ const tmp = useMemo(() => {
122
+ const seriesdata=mergeDataAndSeries(data,Array.from(series.values()))
123
+ const { y: dataY, z: dataZ } = _data;
124
+ const {
125
+ stacks,
126
+ series: { z: seriesZ,y: seriesY },
127
+ } = _series;
128
+ resetStackData(seriesY);
129
+ resetStackData(seriesZ);
130
+ setStackData(dataY, seriesY, stacks);
131
+ setStackData(dataZ, seriesZ, stacks);
132
+ return {
133
+ bandLength: stacks.filter((item) => item.type == 'band').length,
134
+ // series: mergeDataAndSeries(data,Array.from(series.values())),
135
+ series: [...seriesY.values(), ...seriesZ.values()],
136
+ seriesdata:seriesdata
137
+ };
138
+ }, [_data, _series]);
139
+ return tmp;
140
+ };
@@ -1,103 +1,103 @@
1
- import { useCallback, useState, useEffect } from "react";
2
- import { getMousePos } from "../utils";
3
- const callback = () => {};
4
-
5
- /**
6
- * 主要用于轴类图表,返回当前选中的是哪一个x
7
- * @param {Array} svg svg的dom实例
8
- * @param {Number} marginLeft 左间距
9
- * @param {Number} marginTop 上间距
10
- * @param {Number} width 宽
11
- * @param {Number} height 高
12
- * @param {Number} axisX 类目轴
13
- * @param {Object} config 轮播动画参数
14
- * @param {Boolean} active 组件是否处于活跃状态
15
- * @returns {Object} 返回被选中的名称,坐标,选中方法
16
- */
17
- type Props = {
18
- svg: any;
19
- marginLeft: number;
20
- marginTop: number;
21
- width: number;
22
- height: number;
23
- axisX: any;
24
- isHover: boolean;
25
- config: { auto?: boolean; interval?: number; manual?: boolean };
26
- active:boolean
27
- };
28
-
29
- export default ({
30
- svg,
31
- marginLeft,
32
- marginTop,
33
- width,
34
- height,
35
- axisX,
36
- isHover,
37
- config: { auto, interval = 0, manual } = {},
38
- active
39
- }: Props) => {
40
- const [currentIndex, setCurrentIndex] = useState<number>(-1);
41
- const tickLength = axisX.allTicks.length;
42
- const setIndex = useCallback(
43
- (e: any) => {
44
- if (svg) {
45
- const {
46
- x: mouseX,
47
- y: mouseY,
48
- w: boundWidth,
49
- h: boundHeight,
50
- } = getMousePos(e, svg.current);
51
- const { carousel, allTicks, ticks, scaler, direction } = axisX;
52
- const _ticks = carousel ? ticks : allTicks;
53
- const ratioX = parseInt(svg.current.style.width) / boundWidth;
54
- const ratioY = parseInt(svg.current.style.height) / boundHeight;
55
- const resetX = mouseX * ratioX;
56
- const resetY = mouseY * ratioY;
57
- const x = resetX - marginLeft;
58
- const y = resetY - marginTop;
59
- if (x > 0 && x < width && y > 0 && y < height && _ticks.length) {
60
- const position = direction === "vertical" ? y : x;
61
- const name = _ticks.reduce((prev: string, current: string) =>
62
- Math.abs(scaler(prev) - position) >
63
- Math.abs(scaler(current) - position)
64
- ? current
65
- : prev
66
- );
67
- setCurrentIndex(allTicks.findIndex((tick: string) => tick == name));
68
- } else {
69
- // 鼠标划出后,如果开启了自动轮播,就不需要让提示框消失了
70
- if (!auto) {
71
- setCurrentIndex(-1);
72
- }
73
- }
74
- }
75
- },
76
- [svg, marginLeft, axisX, auto]
77
- );
78
- useEffect(() => {
79
- const on = auto && tickLength && !isHover && active;
80
- // if (!!on) setCurrentIndex(0);
81
- const intervalHandler = on
82
- ? setInterval(() => {
83
- setCurrentIndex((index) => {
84
- const currentIndex = index + 1;
85
- if (currentIndex >= tickLength) {
86
- return 0;
87
- }
88
- return currentIndex;
89
- });
90
- }, interval * 1000)
91
- : null;
92
- return () => {
93
- intervalHandler && clearInterval(intervalHandler);
94
- };
95
- }, [auto, tickLength, interval, isHover, active]);
96
- const name = currentIndex === -1 ? null : axisX.allTicks[currentIndex];
97
-
98
- return {
99
- name,
100
- x: axisX.scaler(name),
101
- setIndex: manual ? setIndex : callback,
102
- };
103
- };
1
+ import { useCallback, useState, useEffect } from "react";
2
+ import { getMousePos } from "../utils";
3
+ const callback = () => {};
4
+
5
+ /**
6
+ * 主要用于轴类图表,返回当前选中的是哪一个x
7
+ * @param {Array} svg svg的dom实例
8
+ * @param {Number} marginLeft 左间距
9
+ * @param {Number} marginTop 上间距
10
+ * @param {Number} width 宽
11
+ * @param {Number} height 高
12
+ * @param {Number} axisX 类目轴
13
+ * @param {Object} config 轮播动画参数
14
+ * @param {Boolean} active 组件是否处于活跃状态
15
+ * @returns {Object} 返回被选中的名称,坐标,选中方法
16
+ */
17
+ type Props = {
18
+ svg: any;
19
+ marginLeft: number;
20
+ marginTop: number;
21
+ width: number;
22
+ height: number;
23
+ axisX: any;
24
+ isHover: boolean;
25
+ config: { auto?: boolean; interval?: number; manual?: boolean };
26
+ active:boolean
27
+ };
28
+
29
+ export default ({
30
+ svg,
31
+ marginLeft,
32
+ marginTop,
33
+ width,
34
+ height,
35
+ axisX,
36
+ isHover,
37
+ config: { auto, interval = 0, manual } = {},
38
+ active
39
+ }: Props) => {
40
+ const [currentIndex, setCurrentIndex] = useState<number>(-1);
41
+ const tickLength = axisX.allTicks.length;
42
+ const setIndex = useCallback(
43
+ (e: any) => {
44
+ if (svg) {
45
+ const {
46
+ x: mouseX,
47
+ y: mouseY,
48
+ w: boundWidth,
49
+ h: boundHeight,
50
+ } = getMousePos(e, svg.current);
51
+ const { carousel, allTicks, ticks, scaler, direction } = axisX;
52
+ const _ticks = carousel ? ticks : allTicks;
53
+ const ratioX = parseInt(svg.current.style.width) / boundWidth;
54
+ const ratioY = parseInt(svg.current.style.height) / boundHeight;
55
+ const resetX = mouseX * ratioX;
56
+ const resetY = mouseY * ratioY;
57
+ const x = resetX - marginLeft;
58
+ const y = resetY - marginTop;
59
+ if (x > 0 && x < width && y > 0 && y < height && _ticks.length) {
60
+ const position = direction === "vertical" ? y : x;
61
+ const name = _ticks.reduce((prev: string, current: string) =>
62
+ Math.abs(scaler(prev) - position) >
63
+ Math.abs(scaler(current) - position)
64
+ ? current
65
+ : prev
66
+ );
67
+ setCurrentIndex(allTicks.findIndex((tick: string) => tick == name));
68
+ } else {
69
+ // 鼠标划出后,如果开启了自动轮播,就不需要让提示框消失了
70
+ if (!auto) {
71
+ setCurrentIndex(-1);
72
+ }
73
+ }
74
+ }
75
+ },
76
+ [svg, marginLeft, axisX, auto]
77
+ );
78
+ useEffect(() => {
79
+ const on = auto && tickLength && !isHover && active;
80
+ // if (!!on) setCurrentIndex(0);
81
+ const intervalHandler = on
82
+ ? setInterval(() => {
83
+ setCurrentIndex((index) => {
84
+ const currentIndex = index + 1;
85
+ if (currentIndex >= tickLength) {
86
+ return 0;
87
+ }
88
+ return currentIndex;
89
+ });
90
+ }, interval * 1000)
91
+ : null;
92
+ return () => {
93
+ intervalHandler && clearInterval(intervalHandler);
94
+ };
95
+ }, [auto, tickLength, interval, isHover, active]);
96
+ const name = currentIndex === -1 ? null : axisX.allTicks[currentIndex];
97
+
98
+ return {
99
+ name,
100
+ x: axisX.scaler(name),
101
+ setIndex: manual ? setIndex : callback,
102
+ };
103
+ };
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from './components';
2
- export * from './hooks';
3
- export * from './context';
4
- export * from './formatter';
5
- export * as utils from './utils';
6
- export * from '@easyv/utils';
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from './context';
4
+ export * from './formatter';
5
+ export * as utils from './utils';
6
+ export * from '@easyv/utils';
@@ -1,68 +1,68 @@
1
- declare module 'd3v7' {
2
- export * from 'd3-timer';
3
- export * from 'd3-array';
4
- }
5
-
6
- type DataAnimation = {
7
- show: boolean;
8
- duration: number;
9
- };
10
-
11
- type DataType = {
12
- x: string;
13
- y: number;
14
- s: string;
15
- };
16
- type DataWithBoundType = {
17
- index: number;
18
- data: DataType;
19
- bound: Array<number>;
20
- flag: boolean;
21
- };
22
- type Context = {
23
- width: number;
24
- height: number;
25
- id: string;
26
- triggerOnRelative: Function;
27
- svg: Object;
28
- onEmit: Function;
29
- };
30
-
31
- type ChartLine = {
32
- show: boolean;
33
- color: string;
34
- lineWidth: number;
35
- strokeDasharray?: string;
36
- };
37
-
38
- type Orientation = 'top' | 'bottom' | 'left' | 'right';
39
- type TextAlign = "left" | "center" | "right" | "justify";
40
-
41
- type Translate = {
42
- x: number;
43
- y: number;
44
- };
45
- type Size = {
46
- width: number;
47
- height: number;
48
- };
49
- type Font = {
50
- bold: boolean;
51
- color: string;
52
- fontFamily: string;
53
- fontSize: number;
54
- italic: boolean;
55
- letterSpacing: number;
56
- };
57
-
58
- type Align = { textAnchor: string; dominantBaseline: string };
59
-
60
- type Tick = { show: boolean; tick: string };
61
-
62
- type AxisX = {
63
- carousel: boolean;
64
- allTicks: Array<string>;
65
- ticks: Array<string>;
66
- scaler: Function;
67
- direction: 'vertical' | 'horizontal';
68
- };
1
+ declare module 'd3v7' {
2
+ export * from 'd3-timer';
3
+ export * from 'd3-array';
4
+ }
5
+
6
+ type DataAnimation = {
7
+ show: boolean;
8
+ duration: number;
9
+ };
10
+
11
+ type DataType = {
12
+ x: string;
13
+ y: number;
14
+ s: string;
15
+ };
16
+ type DataWithBoundType = {
17
+ index: number;
18
+ data: DataType;
19
+ bound: Array<number>;
20
+ flag: boolean;
21
+ };
22
+ type Context = {
23
+ width: number;
24
+ height: number;
25
+ id: string;
26
+ triggerOnRelative: Function;
27
+ svg: Object;
28
+ onEmit: Function;
29
+ };
30
+
31
+ type ChartLine = {
32
+ show: boolean;
33
+ color: string;
34
+ lineWidth: number;
35
+ strokeDasharray?: string;
36
+ };
37
+
38
+ type Orientation = 'top' | 'bottom' | 'left' | 'right';
39
+ type TextAlign = "left" | "center" | "right" | "justify";
40
+
41
+ type Translate = {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ type Size = {
46
+ width: number;
47
+ height: number;
48
+ };
49
+ type Font = {
50
+ bold: boolean;
51
+ color: string;
52
+ fontFamily: string;
53
+ fontSize: number;
54
+ italic: boolean;
55
+ letterSpacing: number;
56
+ };
57
+
58
+ type Align = { textAnchor: string; dominantBaseline: string };
59
+
60
+ type Tick = { show: boolean; tick: string };
61
+
62
+ type AxisX = {
63
+ carousel: boolean;
64
+ allTicks: Array<string>;
65
+ ticks: Array<string>;
66
+ scaler: Function;
67
+ direction: 'vertical' | 'horizontal';
68
+ };