@wonderflow/charts 12.8.0 → 12.9.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.
- package/dist/components/bar-chart/bar-chart.d.ts +54 -0
- package/dist/components/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/components/bar-chart/bar-chart.js +56 -0
- package/dist/components/bar-chart/bar-chart.test.d.ts +2 -0
- package/dist/components/bar-chart/bar-chart.test.d.ts.map +1 -0
- package/dist/components/bar-chart/bar-chart.test.js +15 -0
- package/dist/components/bar-chart/index.d.ts +3 -0
- package/dist/components/bar-chart/index.d.ts.map +1 -0
- package/dist/components/bar-chart/index.js +16 -0
- package/dist/components/cartesian-base/cartesian-base-axis.js +15 -15
- package/dist/components/cartesian-base/cartesian-base-brush.d.ts +21 -0
- package/dist/components/cartesian-base/cartesian-base-brush.d.ts.map +1 -0
- package/dist/components/cartesian-base/cartesian-base-brush.js +59 -0
- package/dist/components/cartesian-base/cartesian-base-grid.d.ts +1 -1
- package/dist/components/cartesian-base/cartesian-base-grid.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-legend.d.ts +3 -2
- package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-legend.js +9 -8
- package/dist/components/cartesian-base/cartesian-base.d.ts +26 -6
- package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base.js +41 -76
- package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
- package/dist/components/cartesian-base/cartesian-base.test.d.ts +1 -1
- package/dist/components/cartesian-base/cartesian-base.test.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base.test.js +33 -6
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/line-chart/line-chart.d.ts +59 -2
- package/dist/components/line-chart/line-chart.d.ts.map +1 -1
- package/dist/components/line-chart/line-chart.js +16 -41
- package/dist/components/loader/loader.test.js +3 -1
- package/dist/components/shapes/bars/bars.d.ts +3 -0
- package/dist/components/shapes/bars/bars.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars.js +24 -0
- package/dist/components/shapes/bars/bars.module.css +1 -0
- package/dist/components/shapes/bars/bars.test.d.ts +2 -0
- package/dist/components/shapes/bars/bars.test.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars.test.js +71 -0
- package/dist/components/shapes/bars/index.d.ts +2 -0
- package/dist/components/shapes/bars/index.d.ts.map +1 -0
- package/dist/components/shapes/bars/index.js +16 -0
- package/dist/components/shapes/index.d.ts +1 -0
- package/dist/components/shapes/index.d.ts.map +1 -1
- package/dist/components/shapes/index.js +1 -0
- package/dist/components/shapes/lines/lines-average.d.ts +3 -0
- package/dist/components/shapes/lines/lines-average.d.ts.map +1 -0
- package/dist/components/shapes/lines/lines-average.js +69 -0
- package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-marker-labels.js +14 -7
- package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-overlay.js +8 -5
- package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-series.js +10 -7
- package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-tooltip.js +16 -20
- package/dist/components/shapes/lines/lines.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines.js +18 -16
- package/dist/components/shapes/lines/lines.module.css +1 -1
- package/dist/components/shapes/lines/lines.test.js +13 -7
- package/dist/hooks/hooks.test.d.ts +2 -0
- package/dist/hooks/hooks.test.d.ts.map +1 -0
- package/dist/hooks/hooks.test.js +153 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/useBrush.d.ts +74 -0
- package/dist/hooks/useBrush.d.ts.map +1 -0
- package/dist/hooks/useBrush.js +175 -0
- package/dist/hooks/useCartesian.d.ts +73 -0
- package/dist/hooks/useCartesian.d.ts.map +1 -0
- package/dist/hooks/useCartesian.js +143 -0
- package/dist/hooks/useLineChart.d.ts +39 -0
- package/dist/hooks/useLineChart.d.ts.map +1 -0
- package/dist/hooks/useLineChart.js +79 -0
- package/dist/hooks/useSSR.d.ts +5 -0
- package/dist/hooks/useSSR.d.ts.map +1 -0
- package/dist/hooks/useSSR.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/providers/cartesian.d.ts +1 -0
- package/dist/providers/cartesian.d.ts.map +1 -1
- package/dist/providers/cartesian.js +20 -18
- package/dist/providers/data.d.ts +3 -1
- package/dist/providers/data.d.ts.map +1 -1
- package/dist/providers/data.js +19 -17
- package/dist/providers/layout.d.ts.map +1 -1
- package/dist/providers/layout.js +17 -16
- package/dist/providers/style-config.d.ts.map +1 -1
- package/dist/providers/style-config.js +17 -16
- package/dist/providers/theme.d.ts.map +1 -1
- package/dist/providers/theme.js +16 -16
- package/dist/style-config/brush.d.ts +3 -0
- package/dist/style-config/brush.d.ts.map +1 -0
- package/dist/style-config/brush.js +28 -0
- package/dist/style-config/cartesian.d.ts.map +1 -1
- package/dist/style-config/cartesian.js +5 -3
- package/dist/style-config/index.d.ts +1 -0
- package/dist/style-config/index.d.ts.map +1 -1
- package/dist/style-config/index.js +2 -1
- package/dist/style-config/lines.d.ts.map +1 -1
- package/dist/style-config/lines.js +13 -1
- package/dist/style-config/themes.d.ts.map +1 -1
- package/dist/style-config/themes.js +33 -1
- package/dist/types/bar-chart.d.ts +49 -0
- package/dist/types/bar-chart.d.ts.map +1 -0
- package/dist/types/bar-chart.js +54 -0
- package/dist/types/brush.d.ts +14 -0
- package/dist/types/brush.d.ts.map +1 -0
- package/dist/types/brush.js +16 -0
- package/dist/types/cartesian.d.ts +4 -2
- package/dist/types/cartesian.d.ts.map +1 -1
- package/dist/types/cartesian.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/line-chart.d.ts +4 -1
- package/dist/types/line-chart.d.ts.map +1 -1
- package/dist/types/line-chart.js +1 -1
- package/dist/types/lines.d.ts +14 -0
- package/dist/types/lines.d.ts.map +1 -1
- package/dist/types/lines.js +1 -1
- package/dist/types/main.d.ts +9 -1
- package/dist/types/main.d.ts.map +1 -1
- package/dist/types/main.js +1 -1
- package/dist/types/themes.d.ts +16 -0
- package/dist/types/themes.d.ts.map +1 -1
- package/dist/types/themes.js +1 -1
- package/dist/types/viewport.d.ts +4 -4
- package/dist/types/viewport.d.ts.map +1 -1
- package/dist/types/viewport.js +1 -1
- package/dist/utils/axis.js +14 -14
- package/dist/utils/data.d.ts +10 -7
- package/dist/utils/data.d.ts.map +1 -1
- package/dist/utils/data.js +26 -1
- package/dist/utils/data.test.js +109 -1
- package/dist/utils/lines.d.ts +3 -3
- package/dist/utils/lines.d.ts.map +1 -1
- package/dist/utils/lines.js +3 -3
- package/dist/utils/lines.test.js +6 -6
- package/dist/utils/metadata.d.ts +7 -4
- package/dist/utils/metadata.d.ts.map +1 -1
- package/dist/utils/metadata.js +6 -2
- package/dist/utils/metadata.test.js +8 -8
- package/dist/utils/viewport.d.ts +3 -1
- package/dist/utils/viewport.d.ts.map +1 -1
- package/package.json +15 -14
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022-2024 Wonderflow Design Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import _ from 'lodash';
|
|
17
|
+
import { useCallback, useEffect, useMemo, useRef, } from 'react';
|
|
18
|
+
import { useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../providers';
|
|
19
|
+
import { getPrimitiveFromObjectByPath } from '../utils';
|
|
20
|
+
export const useBrush = ({ axisSystem, brushSize = 32, dimension, isVisible, padding = 16, position, onChange, }) => {
|
|
21
|
+
const brushRef = useRef(null);
|
|
22
|
+
const { isHorizontal } = useLayoutContext();
|
|
23
|
+
const { data, metadata } = useDataContext();
|
|
24
|
+
const { brush, themes } = useStyleConfigContext();
|
|
25
|
+
const theme = useThemeContext();
|
|
26
|
+
const { bottom, left } = axisSystem;
|
|
27
|
+
const { maxWidth, maxHeight } = dimension;
|
|
28
|
+
const { top: tPos, left: lPos } = position;
|
|
29
|
+
const initialBrushRange = {
|
|
30
|
+
min: 0.2,
|
|
31
|
+
max: 0.8,
|
|
32
|
+
};
|
|
33
|
+
const initDataRange = useMemo(() => {
|
|
34
|
+
const dataLen = data.length;
|
|
35
|
+
const initialDataClamp = {
|
|
36
|
+
min: _.round(dataLen * initialBrushRange.min),
|
|
37
|
+
max: _.round(dataLen * initialBrushRange.max),
|
|
38
|
+
};
|
|
39
|
+
const { min, max } = initialDataClamp;
|
|
40
|
+
return data.filter((_, i) => i > min && i < max - 1);
|
|
41
|
+
}, [data, initialBrushRange.max, initialBrushRange.min]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
onChange(initDataRange);
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
}, []);
|
|
46
|
+
const initialBrushPosition = {
|
|
47
|
+
start: isHorizontal
|
|
48
|
+
? { x: (maxWidth * initialBrushRange.min) }
|
|
49
|
+
: { y: (maxHeight * initialBrushRange.min) },
|
|
50
|
+
end: isHorizontal
|
|
51
|
+
? { x: (maxWidth * initialBrushRange.max) }
|
|
52
|
+
: { y: (maxHeight * initialBrushRange.max) },
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!isVisible)
|
|
56
|
+
onChange(data);
|
|
57
|
+
if (isVisible)
|
|
58
|
+
onChange(initDataRange);
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
}, [isVisible]);
|
|
61
|
+
const brushDirection = isHorizontal ? 'horizontal' : 'vertical';
|
|
62
|
+
const resizeTriggerAreas = isHorizontal ? ['left', 'right'] : ['top', 'bottom'];
|
|
63
|
+
const brushHeight = isHorizontal ? brushSize : maxHeight;
|
|
64
|
+
const brushWidth = isHorizontal ? maxWidth : brushSize;
|
|
65
|
+
const topPosition = isHorizontal ? tPos + padding : tPos;
|
|
66
|
+
const leftPosition = isHorizontal ? lPos : lPos + padding * 2;
|
|
67
|
+
const margin = isHorizontal
|
|
68
|
+
? {
|
|
69
|
+
top: 0, left: lPos, right: 0, bottom: 0,
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
top: tPos, left: 0, right: 0, bottom: 0,
|
|
73
|
+
};
|
|
74
|
+
const style = useMemo(() => ({
|
|
75
|
+
selectedBox: {
|
|
76
|
+
fill: themes[theme].brush.selectedBox.fill,
|
|
77
|
+
fillOpacity: brush.selectedBox.fillOpacity,
|
|
78
|
+
stroke: themes[theme].brush.selectedBox.stroke,
|
|
79
|
+
strokeWidth: brush.selectedBox.strokeWidth,
|
|
80
|
+
strokeOpacity: brush.selectedBox.strokeOpacity,
|
|
81
|
+
},
|
|
82
|
+
pattern: {
|
|
83
|
+
transform: `scale(.1) rotate(${isHorizontal ? 0 : 90})`,
|
|
84
|
+
strokeWidth: brush.pattern.strokeWidth,
|
|
85
|
+
stroke: themes[theme].brush.pattern.stroke,
|
|
86
|
+
fill: themes[theme].brush.pattern.fill,
|
|
87
|
+
},
|
|
88
|
+
}), [
|
|
89
|
+
brush.pattern.strokeWidth,
|
|
90
|
+
brush.selectedBox.fillOpacity,
|
|
91
|
+
brush.selectedBox.strokeOpacity,
|
|
92
|
+
brush.selectedBox.strokeWidth,
|
|
93
|
+
isHorizontal,
|
|
94
|
+
theme,
|
|
95
|
+
themes,
|
|
96
|
+
]);
|
|
97
|
+
const handleBrushClear = () => {
|
|
98
|
+
if (brushRef?.current) {
|
|
99
|
+
onChange(data);
|
|
100
|
+
brushRef.current.reset();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const handleBrushReset = () => {
|
|
104
|
+
if (brushRef?.current) {
|
|
105
|
+
const updater = (prevBrush) => {
|
|
106
|
+
const newExtent = brushRef.current.getExtent(initialBrushPosition.start, initialBrushPosition.end);
|
|
107
|
+
const newState = {
|
|
108
|
+
...prevBrush,
|
|
109
|
+
start: { y: newExtent.y0, x: newExtent.x0 },
|
|
110
|
+
end: { y: newExtent.y1, x: newExtent.x1 },
|
|
111
|
+
extent: newExtent,
|
|
112
|
+
};
|
|
113
|
+
return newState;
|
|
114
|
+
};
|
|
115
|
+
brushRef.current.updateBrush(updater);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const handleBrushChange = useCallback((domain) => {
|
|
119
|
+
if (!domain)
|
|
120
|
+
return;
|
|
121
|
+
let filteredData = data;
|
|
122
|
+
const { x0, x1, xValues, y0, y1, yValues, } = domain;
|
|
123
|
+
const indexAxis = isHorizontal ? bottom : left;
|
|
124
|
+
const indexScaleType = indexAxis.scaleType;
|
|
125
|
+
const indexDataKey = metadata.index;
|
|
126
|
+
const min = isHorizontal ? x0 : y0;
|
|
127
|
+
const max = isHorizontal ? x1 : y1;
|
|
128
|
+
const domainValues = isHorizontal ? xValues : yValues;
|
|
129
|
+
if (indexScaleType === 'label') {
|
|
130
|
+
filteredData = data.filter((d) => {
|
|
131
|
+
const value = getPrimitiveFromObjectByPath(d, indexDataKey);
|
|
132
|
+
return domainValues.includes(value);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (indexScaleType === 'time') {
|
|
136
|
+
filteredData = data.filter((d) => {
|
|
137
|
+
const value = getPrimitiveFromObjectByPath(d, indexDataKey);
|
|
138
|
+
const toTime = value ? new Date(value).getTime() : 0;
|
|
139
|
+
return toTime >= min && toTime <= max;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (indexScaleType === 'linear') {
|
|
143
|
+
filteredData = data.filter((d) => {
|
|
144
|
+
const value = getPrimitiveFromObjectByPath(d, indexDataKey);
|
|
145
|
+
const v = typeof value === 'number' ? value : (min - 1);
|
|
146
|
+
return v >= min && v <= max;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
onChange(filteredData);
|
|
150
|
+
}, [bottom, left, data, isHorizontal, metadata, onChange]);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
handleBrushReset();
|
|
153
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
154
|
+
}, [isHorizontal]);
|
|
155
|
+
return {
|
|
156
|
+
ref: brushRef,
|
|
157
|
+
brushDirection,
|
|
158
|
+
brushHeight,
|
|
159
|
+
brushWidth,
|
|
160
|
+
initialBrushPosition,
|
|
161
|
+
margin,
|
|
162
|
+
position: {
|
|
163
|
+
left: leftPosition,
|
|
164
|
+
top: topPosition,
|
|
165
|
+
},
|
|
166
|
+
resizeTriggerAreas,
|
|
167
|
+
scale: {
|
|
168
|
+
x: axisSystem?.bottom?.scale,
|
|
169
|
+
y: axisSystem.left?.scale,
|
|
170
|
+
},
|
|
171
|
+
style,
|
|
172
|
+
handleBrushClear,
|
|
173
|
+
handleBrushChange,
|
|
174
|
+
};
|
|
175
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { HeadingsProps } from '../components';
|
|
3
|
+
import { AxisConfig, AxisOrientation, AxisProps, Background, CartesianStyleConfig, CartesianxAxisSystem, DeepPartial, MarginProps } from '../types';
|
|
4
|
+
export declare type UseCartesianProps = {
|
|
5
|
+
axis: Record<AxisOrientation, AxisProps | undefined>;
|
|
6
|
+
axisFiltered: Record<AxisOrientation, AxisProps | undefined>;
|
|
7
|
+
background?: Background;
|
|
8
|
+
headings?: Pick<HeadingsProps, 'top' | 'left' | 'config'>;
|
|
9
|
+
height?: number;
|
|
10
|
+
hideLegend: boolean;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
margin?: MarginProps;
|
|
13
|
+
preventResponsive?: boolean;
|
|
14
|
+
showBrush?: boolean;
|
|
15
|
+
styleConfig?: DeepPartial<CartesianStyleConfig>;
|
|
16
|
+
title?: string;
|
|
17
|
+
width?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const useCartesian: ({ axis, axisFiltered, background, headings, height, hideLegend, isLoading, margin, preventResponsive, showBrush, styleConfig, title, width, }: UseCartesianProps) => {
|
|
20
|
+
axisConfig: AxisConfig;
|
|
21
|
+
axisFilteredSystem: CartesianxAxisSystem;
|
|
22
|
+
axisSystem: CartesianxAxisSystem;
|
|
23
|
+
bgFrom: string;
|
|
24
|
+
bgTo: string;
|
|
25
|
+
brushSize: number;
|
|
26
|
+
brushPadding: number;
|
|
27
|
+
cartesianConfig: CartesianStyleConfig & DeepPartial<CartesianStyleConfig>;
|
|
28
|
+
dimension: {
|
|
29
|
+
loader: {
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
axis: {
|
|
34
|
+
maxWidth: number;
|
|
35
|
+
maxHeight: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
dynamicHeight: number;
|
|
39
|
+
dynamicWidth: number;
|
|
40
|
+
dynamicStyle: CSSProperties;
|
|
41
|
+
hasData: boolean;
|
|
42
|
+
hasLegend: boolean;
|
|
43
|
+
hasBrush: boolean;
|
|
44
|
+
filteredData: import("../types").Data;
|
|
45
|
+
hasEmptyState: boolean;
|
|
46
|
+
hoveredLegendItem: string;
|
|
47
|
+
metadata: import("../types").BarChartMetadata | import("../types").LineChartMetadata | undefined;
|
|
48
|
+
position: {
|
|
49
|
+
headings: {
|
|
50
|
+
top: number;
|
|
51
|
+
left: number;
|
|
52
|
+
};
|
|
53
|
+
loader: {
|
|
54
|
+
top: number;
|
|
55
|
+
left: number;
|
|
56
|
+
};
|
|
57
|
+
axis: {
|
|
58
|
+
top: number;
|
|
59
|
+
right: number;
|
|
60
|
+
bottom: number;
|
|
61
|
+
left: number;
|
|
62
|
+
};
|
|
63
|
+
brush: {
|
|
64
|
+
top: number;
|
|
65
|
+
left: number;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
ref: import("react").RefObject<HTMLDivElement>;
|
|
69
|
+
refLegend: import("react").RefObject<HTMLDivElement>;
|
|
70
|
+
theme: import("../types").ThemeVariants;
|
|
71
|
+
setHoveredLegendItem: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=useCartesian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCartesian.d.ts","sourceRoot":"","sources":["../../src/hooks/useCartesian.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,aAAa,EACd,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EACL,UAAU,EACV,eAAe,EACf,SAAS,EACT,UAAU,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EACjF,MAAM,UAAU,CAAC;AAIlB,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IACrD,YAAY,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IAC7D,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAE,MAAM,GAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,eAAO,MAAM,YAAY,kJAmBtB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6JnB,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022-2024 Wonderflow Design Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { useSize } from 'ahooks';
|
|
17
|
+
import _ from 'lodash';
|
|
18
|
+
import { useMemo, useRef, useState, } from 'react';
|
|
19
|
+
import { useDataContext, useLayoutContext, useThemeContext } from '../providers';
|
|
20
|
+
import { cartesianStyleConfig } from '../style-config';
|
|
21
|
+
import { computeAxisStyleConfig, computeAxisSystemProperties, handleVerticalTickLabelOffset } from '../utils';
|
|
22
|
+
import { useSSR } from './useSSR';
|
|
23
|
+
export const useCartesian = ({ axis, axisFiltered, background, headings, height = 600, hideLegend = false, isLoading = false, margin = {
|
|
24
|
+
top: 24,
|
|
25
|
+
right: 24,
|
|
26
|
+
bottom: 24,
|
|
27
|
+
left: 24,
|
|
28
|
+
}, preventResponsive = false, showBrush = false, styleConfig, title, width = 800, }) => {
|
|
29
|
+
const theme = useThemeContext();
|
|
30
|
+
const { isHorizontal } = useLayoutContext();
|
|
31
|
+
const { metadata, data, filteredData } = useDataContext();
|
|
32
|
+
const { isBrowser } = useSSR();
|
|
33
|
+
const cartesianConfig = useMemo(() => _.merge(cartesianStyleConfig, styleConfig), [styleConfig]);
|
|
34
|
+
const { axis: aStyle, legend: lStyle, themes, headings: hStyle, viewport, } = cartesianConfig;
|
|
35
|
+
const { from: bgFrom, to: bgTo } = useMemo(() => _.merge(themes[theme].background, background), [background, theme, themes]);
|
|
36
|
+
const [hoveredLegendItem, setHoveredLegendItem] = useState('');
|
|
37
|
+
const ref = useRef(null);
|
|
38
|
+
const size = useSize(ref);
|
|
39
|
+
const refLegend = useRef(null);
|
|
40
|
+
const sizeLegend = useSize(refLegend);
|
|
41
|
+
const hasData = !!filteredData.length;
|
|
42
|
+
const hasEmptyState = !isLoading && !hasData;
|
|
43
|
+
const hasLegend = data && !hideLegend && !isLoading;
|
|
44
|
+
const legendHeight = hasLegend ? (sizeLegend?.height ?? 0) : 0;
|
|
45
|
+
const isBrushInViewport = isHorizontal
|
|
46
|
+
? Boolean(size && size.width > viewport.medium.maxWidth)
|
|
47
|
+
: Boolean(size && size.height > viewport.medium.maxHeight);
|
|
48
|
+
const hasBrush = isBrowser && isBrushInViewport && showBrush;
|
|
49
|
+
const brushSize = 32;
|
|
50
|
+
const brushPadding = 16;
|
|
51
|
+
const brushTotalArea = brushSize + brushPadding;
|
|
52
|
+
const brushArea = {
|
|
53
|
+
height: (hasBrush && isHorizontal) ? brushTotalArea : 0,
|
|
54
|
+
width: (hasBrush && !isHorizontal) ? brushTotalArea : 0,
|
|
55
|
+
};
|
|
56
|
+
const hasHeadings = !!title;
|
|
57
|
+
const headingsHeight = hasHeadings ? hStyle.height : 0;
|
|
58
|
+
const w = size ? size.width : width;
|
|
59
|
+
const h = size ? size.height : height;
|
|
60
|
+
const dynamicWidth = preventResponsive ? width : w;
|
|
61
|
+
const dynamicHeight = preventResponsive ? height : h;
|
|
62
|
+
const dynamicStyle = {
|
|
63
|
+
'--static-width': `${dynamicWidth}px`,
|
|
64
|
+
'--static-height': `${dynamicHeight}px`,
|
|
65
|
+
'--legend-width': `calc(100% - ${margin.left + margin.right}px)`,
|
|
66
|
+
'--legend-top': `calc(100% - ${legendHeight + margin.bottom}px)`,
|
|
67
|
+
'--legend-left': `${margin.left}px`,
|
|
68
|
+
'--legend-padding': lStyle.padding,
|
|
69
|
+
};
|
|
70
|
+
const { top, right, bottom, left, } = axis;
|
|
71
|
+
const axisConfig = useMemo(() => computeAxisStyleConfig(axis, aStyle), [aStyle, axis]);
|
|
72
|
+
const { leftAxisOffset: lOff, topAxisOffset: tOff, verticalAxisOffset: vOff, horizontalAxisOffset: hOff, } = axisConfig.offset;
|
|
73
|
+
const mr = margin.right * (right ? 1 : 2);
|
|
74
|
+
const ml = margin.left * (left ? 1 : 2);
|
|
75
|
+
const xMax = dynamicWidth - ml - mr - vOff - brushArea.width;
|
|
76
|
+
const topTickLabelOffset = handleVerticalTickLabelOffset(xMax, cartesianConfig, top);
|
|
77
|
+
const bottomTickLabelOffset = handleVerticalTickLabelOffset(xMax, cartesianConfig, bottom);
|
|
78
|
+
const mt = margin.top * (top ? 1 : 2) + headingsHeight + topTickLabelOffset;
|
|
79
|
+
const mb = margin.bottom * (bottom ? 1 : 2) + legendHeight + bottomTickLabelOffset + brushArea.height;
|
|
80
|
+
const yMax = dynamicHeight - mt - mb - hOff;
|
|
81
|
+
const dimension = {
|
|
82
|
+
loader: {
|
|
83
|
+
width: dynamicWidth - margin.left - margin.right,
|
|
84
|
+
height: dynamicHeight - headingsHeight - margin.top - margin.bottom,
|
|
85
|
+
},
|
|
86
|
+
axis: {
|
|
87
|
+
maxWidth: xMax,
|
|
88
|
+
maxHeight: yMax,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const position = {
|
|
92
|
+
headings: {
|
|
93
|
+
top: headings?.top ?? margin.top,
|
|
94
|
+
left: headings?.left ?? ml,
|
|
95
|
+
},
|
|
96
|
+
loader: {
|
|
97
|
+
top: margin.top + headingsHeight,
|
|
98
|
+
left: margin.left,
|
|
99
|
+
},
|
|
100
|
+
axis: {
|
|
101
|
+
top: mt + tOff,
|
|
102
|
+
right: ml + lOff + xMax,
|
|
103
|
+
bottom: mt + tOff + yMax,
|
|
104
|
+
left: ml + lOff,
|
|
105
|
+
},
|
|
106
|
+
brush: {
|
|
107
|
+
top: isHorizontal
|
|
108
|
+
? mt + tOff + bottomTickLabelOffset + dimension.axis.maxHeight + brushArea.height
|
|
109
|
+
: mt + tOff,
|
|
110
|
+
left: isHorizontal
|
|
111
|
+
? ml + lOff
|
|
112
|
+
: ml + lOff + xMax,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
const axisSystem = useMemo(() => computeAxisSystemProperties(axis, dimension.axis, position.axis), [axis, dimension.axis, position.axis]);
|
|
116
|
+
const axisFilteredSystem = useMemo(() => computeAxisSystemProperties(axisFiltered, dimension.axis, position.axis), [axisFiltered, dimension.axis, position.axis]);
|
|
117
|
+
return {
|
|
118
|
+
axisConfig,
|
|
119
|
+
axisFilteredSystem,
|
|
120
|
+
axisSystem,
|
|
121
|
+
bgFrom,
|
|
122
|
+
bgTo,
|
|
123
|
+
brushSize,
|
|
124
|
+
brushPadding,
|
|
125
|
+
cartesianConfig,
|
|
126
|
+
dimension,
|
|
127
|
+
dynamicHeight,
|
|
128
|
+
dynamicWidth,
|
|
129
|
+
dynamicStyle,
|
|
130
|
+
hasData,
|
|
131
|
+
hasLegend,
|
|
132
|
+
hasBrush,
|
|
133
|
+
filteredData,
|
|
134
|
+
hasEmptyState,
|
|
135
|
+
hoveredLegendItem,
|
|
136
|
+
metadata,
|
|
137
|
+
position,
|
|
138
|
+
ref,
|
|
139
|
+
refLegend,
|
|
140
|
+
theme,
|
|
141
|
+
setHoveredLegendItem,
|
|
142
|
+
};
|
|
143
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Except } from 'type-fest';
|
|
3
|
+
import { LineChartProps } from '../components';
|
|
4
|
+
import { CartesianChartLayout, Charts, Data, MarginProps } from '../types';
|
|
5
|
+
export declare type UseLineChartProps = Except<LineChartProps, 'otherProps'>;
|
|
6
|
+
export declare const useLineChart: ({ theme, layout, renderAs, data, index, series, overlay, tooltip, showAverage, hideMissingDataConnection, showMarker, showMarkerLabel, hidePadding, }: UseLineChartProps) => {
|
|
7
|
+
axis: Record<CartesianChartLayout, Record<import("../types").AxisOrientation, import("../types").AxisProps | undefined>>;
|
|
8
|
+
axisFiltered: Record<CartesianChartLayout, Record<import("../types").AxisOrientation, import("../types").AxisProps | undefined>>;
|
|
9
|
+
isHorizontal: boolean;
|
|
10
|
+
metadata: {
|
|
11
|
+
type: Charts;
|
|
12
|
+
renderAs: import("../types").LineChartRenderType;
|
|
13
|
+
index: string;
|
|
14
|
+
series: {
|
|
15
|
+
dataKey: string[];
|
|
16
|
+
names: string[];
|
|
17
|
+
colors: (string | undefined)[];
|
|
18
|
+
style: (import("../types").LineStyle | undefined)[] | undefined;
|
|
19
|
+
average: import("../types").AverageType;
|
|
20
|
+
};
|
|
21
|
+
overlay: {
|
|
22
|
+
dataKey: string | undefined;
|
|
23
|
+
name: string;
|
|
24
|
+
color: string;
|
|
25
|
+
style: import("../types").LineStyle | undefined;
|
|
26
|
+
average: import("../types").AverageType;
|
|
27
|
+
};
|
|
28
|
+
tooltip: import("../types").LineChartTooltip | undefined;
|
|
29
|
+
showAverage: boolean;
|
|
30
|
+
hideMissingDataConnection: boolean;
|
|
31
|
+
showMarker: boolean;
|
|
32
|
+
showMarkerLabel: boolean;
|
|
33
|
+
hidePadding: boolean;
|
|
34
|
+
};
|
|
35
|
+
zeroPadding: MarginProps | undefined;
|
|
36
|
+
brushFilteredData: Data;
|
|
37
|
+
setBrushFilteredData: import("react").Dispatch<import("react").SetStateAction<Data>>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=useLineChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLineChart.d.ts","sourceRoot":"","sources":["../../src/hooks/useLineChart.ts"],"names":[],"mappings":";AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EACL,oBAAoB,EAAE,MAAM,EAAE,IAAI,EAClC,WAAW,EACZ,MAAM,UAAU,CAAC;AAWlB,oBAAY,iBAAiB,GAAG,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;AAEpE,eAAO,MAAM,YAAY,0JActB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2EnB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022-2024 Wonderflow Design Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { useMemo, useState } from 'react';
|
|
17
|
+
import { defaultLineChartPalette } from '../style-config';
|
|
18
|
+
import { CartesianChartLayout, Charts, } from '../types';
|
|
19
|
+
import { computeAverage, handleChartAxisLayout, handleChartDomainAndScaleType, handleLineChartOverlayColor, handleLineChartSeriesColors, handleOverlayName, handleSeriesNames, } from '../utils';
|
|
20
|
+
export const useLineChart = ({ theme = 'light', layout = CartesianChartLayout.HORIZONTAL, renderAs = 'curves', data = [], index, series, overlay, tooltip, showAverage = false, hideMissingDataConnection = false, showMarker = false, showMarkerLabel = false, hidePadding = false, }) => {
|
|
21
|
+
const [brushFilteredData, setBrushFilteredData] = useState(data);
|
|
22
|
+
const isHorizontal = layout === CartesianChartLayout.HORIZONTAL;
|
|
23
|
+
const zeroPadding = hidePadding
|
|
24
|
+
? {
|
|
25
|
+
top: 0, right: 12, bottom: 0, left: 0,
|
|
26
|
+
}
|
|
27
|
+
: undefined;
|
|
28
|
+
const { index: i, series: s, overlay: o } = useMemo(() => handleChartDomainAndScaleType(data, index, series, overlay), [data, index, overlay, series]);
|
|
29
|
+
const { index: iFiltered, series: sFiltered, overlay: oFiltered } = useMemo(() => handleChartDomainAndScaleType(brushFilteredData, index, series, overlay), [brushFilteredData, index, overlay, series]);
|
|
30
|
+
const axis = useMemo(() => handleChartAxisLayout(i, s, o), [i, s, o]);
|
|
31
|
+
const axisFiltered = useMemo(() => handleChartAxisLayout(iFiltered, sFiltered, oFiltered), [iFiltered, sFiltered, oFiltered]);
|
|
32
|
+
const palette = defaultLineChartPalette[theme];
|
|
33
|
+
const metadata = useMemo(() => ({
|
|
34
|
+
type: Charts.LINE_CHART,
|
|
35
|
+
renderAs,
|
|
36
|
+
index: index.dataKey,
|
|
37
|
+
series: {
|
|
38
|
+
dataKey: series.dataKey,
|
|
39
|
+
names: handleSeriesNames(series),
|
|
40
|
+
colors: handleLineChartSeriesColors(series, palette.series),
|
|
41
|
+
style: series.style,
|
|
42
|
+
average: computeAverage(data, series.dataKey),
|
|
43
|
+
},
|
|
44
|
+
overlay: {
|
|
45
|
+
dataKey: overlay?.dataKey,
|
|
46
|
+
name: handleOverlayName(overlay),
|
|
47
|
+
color: handleLineChartOverlayColor(overlay, palette.overlay),
|
|
48
|
+
style: overlay?.style,
|
|
49
|
+
average: overlay?.dataKey ? computeAverage(data, [overlay.dataKey]) : undefined,
|
|
50
|
+
},
|
|
51
|
+
tooltip,
|
|
52
|
+
showAverage,
|
|
53
|
+
hideMissingDataConnection,
|
|
54
|
+
showMarker,
|
|
55
|
+
showMarkerLabel,
|
|
56
|
+
hidePadding,
|
|
57
|
+
}), [data,
|
|
58
|
+
hideMissingDataConnection,
|
|
59
|
+
hidePadding,
|
|
60
|
+
index.dataKey,
|
|
61
|
+
overlay,
|
|
62
|
+
palette.overlay,
|
|
63
|
+
palette.series,
|
|
64
|
+
renderAs,
|
|
65
|
+
series,
|
|
66
|
+
showAverage,
|
|
67
|
+
showMarker,
|
|
68
|
+
showMarkerLabel,
|
|
69
|
+
tooltip]);
|
|
70
|
+
return {
|
|
71
|
+
axis,
|
|
72
|
+
axisFiltered,
|
|
73
|
+
isHorizontal,
|
|
74
|
+
metadata,
|
|
75
|
+
zeroPadding,
|
|
76
|
+
brushFilteredData,
|
|
77
|
+
setBrushFilteredData,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSSR.d.ts","sourceRoot":"","sources":["../../src/hooks/useSSR.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,MAAM;;;CASlB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export const useSSR = () => {
|
|
17
|
+
const isBrowser = typeof window !== 'undefined'
|
|
18
|
+
&& window.document
|
|
19
|
+
&& window.document.documentElement;
|
|
20
|
+
return {
|
|
21
|
+
isBrowser: !!isBrowser,
|
|
22
|
+
isServer: !isBrowser,
|
|
23
|
+
};
|
|
24
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright 2022-
|
|
2
|
+
* Copyright 2022-2024 Wonderflow Design Team
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export * from './components';
|
|
17
|
+
export * from './hooks';
|
|
18
|
+
export * from './providers';
|
|
17
19
|
export * from './style-config';
|
|
18
20
|
export * from './types';
|
|
19
21
|
export * from './utils';
|
|
@@ -12,6 +12,7 @@ export declare type CartesianContextProps = {
|
|
|
12
12
|
maxHeight: number;
|
|
13
13
|
};
|
|
14
14
|
axis?: CartesianxAxisSystem;
|
|
15
|
+
hoveredLegendItem: string;
|
|
15
16
|
};
|
|
16
17
|
export declare type CartesianProviderProps = CartesianContextProps;
|
|
17
18
|
export declare const CartesianContext: import("react").Context<CartesianContextProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian.d.ts","sourceRoot":"","sources":["../../src/providers/cartesian.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,qBAAqB,GAAG;IAClC,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,IAAI,CAAC,EAAE,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"cartesian.d.ts","sourceRoot":"","sources":["../../src/providers/cartesian.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,qBAAqB,GAAG;IAClC,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,oBAAY,sBAAsB,GAAG,qBAAqB,CAAA;AAiB1D,eAAO,MAAM,gBAAgB,gDAAuD,CAAC;AAErF,eAAO,MAAM,iBAAiB,EAAE,UAAU,CAAC,sBAAsB,CAahE,CAAC;AAEF,eAAO,MAAM,mBAAmB,6BAS/B,CAAC"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
3
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
17
|
import { createContext, useContext } from 'react';
|
|
18
18
|
const defaultSetting = {
|
|
19
19
|
position: {
|
|
@@ -27,17 +27,19 @@ const defaultSetting = {
|
|
|
27
27
|
maxHeight: 600,
|
|
28
28
|
},
|
|
29
29
|
axis: undefined,
|
|
30
|
+
hoveredLegendItem: '',
|
|
30
31
|
};
|
|
31
32
|
export const CartesianContext = createContext(defaultSetting);
|
|
32
|
-
export const CartesianProvider = ({ children, position, dimension, axis, }) => (_jsx(CartesianContext.Provider, { value: {
|
|
33
|
-
position, dimension, axis,
|
|
33
|
+
export const CartesianProvider = ({ children, position, dimension, axis, hoveredLegendItem, }) => (_jsx(CartesianContext.Provider, { value: {
|
|
34
|
+
position, dimension, axis, hoveredLegendItem,
|
|
34
35
|
}, children: children }));
|
|
35
36
|
export const useCartesianContext = () => {
|
|
36
37
|
const context = useContext(CartesianContext);
|
|
37
38
|
if (!context) {
|
|
38
|
-
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.error('useCartesianContext() must be used inside CartesianProvider to access context data.');
|
|
39
41
|
}
|
|
40
|
-
return context;
|
|
42
|
+
return context ?? defaultSetting;
|
|
41
43
|
};
|
|
42
44
|
CartesianContext.displayName = 'CartesianContext';
|
|
43
45
|
CartesianProvider.displayName = 'CartesianProvider';
|
package/dist/providers/data.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Data, LineChartMetadata } from '../types';
|
|
3
|
+
import { BarChartMetadata } from '../types/bar-chart';
|
|
3
4
|
export declare type DataContextProps = {
|
|
4
5
|
data: Data;
|
|
5
|
-
|
|
6
|
+
filteredData: Data;
|
|
7
|
+
metadata?: LineChartMetadata | BarChartMetadata;
|
|
6
8
|
};
|
|
7
9
|
export declare type DataProviderProps = DataContextProps;
|
|
8
10
|
export declare const DataContext: import("react").Context<DataContextProps>;
|