@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,54 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Except } from 'type-fest';
|
|
3
|
+
import { CartesianChartLayout, Data, SortingType, ThemeVariants } from '../../types';
|
|
4
|
+
import { BarChartIndex, BarChartOverlay, BarChartSeries, BarChartTooltip } from '../../types/bar-chart';
|
|
5
|
+
import { CartesianBaseProps } from '../cartesian-base/cartesian-base';
|
|
6
|
+
export declare type BarChartProps = {
|
|
7
|
+
/**
|
|
8
|
+
* Set the theme of the chart. This is set to `light` by default.
|
|
9
|
+
*/
|
|
10
|
+
theme?: ThemeVariants;
|
|
11
|
+
/**
|
|
12
|
+
* Set the layout of the chart. `Index`, `Series` and eventually `Overlay` will be automatically rearranged.
|
|
13
|
+
*/
|
|
14
|
+
layout?: CartesianChartLayout;
|
|
15
|
+
/**
|
|
16
|
+
* Set the data structure that will be used to render the chart.
|
|
17
|
+
*/
|
|
18
|
+
data: Data;
|
|
19
|
+
/**
|
|
20
|
+
* If true bars get stacked one upon each other.
|
|
21
|
+
*/
|
|
22
|
+
isStacked?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Set the order data should be sorted by:
|
|
25
|
+
* 'descending-key': dataKey alphabetical order;
|
|
26
|
+
* 'ascending-key': reverse dataKey alphabetical order;
|
|
27
|
+
* 'descending-value': by data value;
|
|
28
|
+
* 'ascending-value': by reverse data value;
|
|
29
|
+
* 'as-is': as set in series/overlay dataKey;
|
|
30
|
+
*/
|
|
31
|
+
sortBy?: SortingType;
|
|
32
|
+
/**
|
|
33
|
+
* Set the properties associated with the Index Axis.
|
|
34
|
+
*/
|
|
35
|
+
index: BarChartIndex;
|
|
36
|
+
/**
|
|
37
|
+
* Set the properties associated with any Series of lines.
|
|
38
|
+
*/
|
|
39
|
+
series: BarChartSeries;
|
|
40
|
+
/**
|
|
41
|
+
* Set the properties associated with the Overlay Axis.
|
|
42
|
+
*/
|
|
43
|
+
overlay?: BarChartOverlay;
|
|
44
|
+
/**
|
|
45
|
+
* Set extra data or custom content to be displayed in the tooltip.
|
|
46
|
+
*/
|
|
47
|
+
tooltip?: BarChartTooltip;
|
|
48
|
+
/**
|
|
49
|
+
* Remove the padding from the chart container.
|
|
50
|
+
*/
|
|
51
|
+
hidePadding?: boolean;
|
|
52
|
+
} & Except<CartesianBaseProps, 'axis' | 'axisFiltered' | 'onBrushChange'>;
|
|
53
|
+
export declare const BarChart: React.FC<BarChartProps>;
|
|
54
|
+
//# sourceMappingURL=bar-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/components/bar-chart/bar-chart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAOnC,OAAO,EACL,oBAAoB,EAAU,IAAI,EAAe,WAAW,EAAE,aAAa,EAC5E,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EAAoB,eAAe,EAAE,cAAc,EAAE,eAAe,EAClF,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EAAiB,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAErF,oBAAY,aAAa,GAAG;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;OAEG;IACH,MAAM,EAAE,cAAc,CAAC;IACvB;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,MAAM,CAAC,kBAAkB,EAAE,MAAM,GAAG,cAAc,GAAG,eAAe,CAAC,CAAA;AAEzE,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAmE5C,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
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
|
+
import { useMemo } from 'react';
|
|
18
|
+
import { DataProvider, LayoutProvider, ThemeProvider, } from '../../providers';
|
|
19
|
+
import { defaultLineChartPalette } from '../../style-config';
|
|
20
|
+
import { CartesianChartLayout, Charts, } from '../../types';
|
|
21
|
+
import { handleBarChartOverlayColor, handleBarChartSeriesColors, handleChartAxisLayout, handleChartDomainAndScaleType, handleOverlayName, handleSeriesNames, } from '../../utils';
|
|
22
|
+
import { CartesianBase } from '../cartesian-base/cartesian-base';
|
|
23
|
+
export const BarChart = ({ theme = 'light', layout = CartesianChartLayout.HORIZONTAL, isStacked = false, sortBy = 'as-is', data = [], index, series, overlay, tooltip, hidePadding = false, ...otherProps }) => {
|
|
24
|
+
const isHorizontal = layout === CartesianChartLayout.HORIZONTAL;
|
|
25
|
+
const { index: i, series: s, overlay: o } = useMemo(() => handleChartDomainAndScaleType(data, index, series, overlay), [data, index, overlay, series]);
|
|
26
|
+
const axis = useMemo(() => handleChartAxisLayout(i, s, o), [i, s, o]);
|
|
27
|
+
const palette = useMemo(() => defaultLineChartPalette[theme], [theme]);
|
|
28
|
+
const zeroPadding = hidePadding ? {
|
|
29
|
+
top: 0, right: 12, bottom: 0, left: 0,
|
|
30
|
+
} : undefined;
|
|
31
|
+
const metadata = useMemo(() => ({
|
|
32
|
+
type: Charts.BAR_CHART,
|
|
33
|
+
isStacked,
|
|
34
|
+
sortBy,
|
|
35
|
+
index: index.dataKey,
|
|
36
|
+
series: {
|
|
37
|
+
dataKey: series.dataKey,
|
|
38
|
+
names: handleSeriesNames(series),
|
|
39
|
+
colors: handleBarChartSeriesColors(series, palette.series),
|
|
40
|
+
style: series.style,
|
|
41
|
+
},
|
|
42
|
+
overlay: {
|
|
43
|
+
dataKey: overlay?.dataKey,
|
|
44
|
+
name: handleOverlayName(overlay),
|
|
45
|
+
color: handleBarChartOverlayColor(overlay, palette.overlay),
|
|
46
|
+
style: overlay?.style,
|
|
47
|
+
},
|
|
48
|
+
tooltip,
|
|
49
|
+
hidePadding,
|
|
50
|
+
}), [isStacked, sortBy, index.dataKey, series, palette.series, palette.overlay, overlay, tooltip, hidePadding]);
|
|
51
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(LayoutProvider, { layout: layout, children: _jsx(DataProvider, { data: data, metadata: metadata, filteredData: data, children: _jsx(CartesianBase, { ...otherProps, axis: axis[layout], axisFiltered: axis[layout], grid: {
|
|
52
|
+
hideRows: !isHorizontal,
|
|
53
|
+
hideColumns: isHorizontal,
|
|
54
|
+
}, margin: zeroPadding, onBrushChange: () => ({}) }) }) }) }));
|
|
55
|
+
};
|
|
56
|
+
BarChart.displayName = 'BarChart';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bar-chart.test.d.ts","sourceRoot":"","sources":["../../../src/components/bar-chart/bar-chart.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { BarChart } from './bar-chart';
|
|
4
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
5
|
+
observe: jest.fn(),
|
|
6
|
+
unobserve: jest.fn(),
|
|
7
|
+
disconnect: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
describe('<BarChart>', () => {
|
|
10
|
+
it('should render the component', () => {
|
|
11
|
+
render(_jsx(BarChart, { data: [{ date: 'a', value: 1 }, { date: 'b', value: 2 }], index: { dataKey: 'date' }, series: { dataKey: ['value'] }, overlay: { dataKey: 'value' }, title: "Title" }));
|
|
12
|
+
const element = screen.getByTestId('cartesian');
|
|
13
|
+
expect(element).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/bar-chart/index.ts"],"names":[],"mappings":"AAgBA,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022-2023 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 { BarChart } from './bar-chart';
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
3
|
/*
|
|
4
|
-
* Copyright 2023 Wonderflow Design Team
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
4
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
18
|
import { Axis, } from '@visx/axis';
|
|
19
19
|
import { Group } from '@visx/group';
|
|
20
20
|
import { v4 as uuid } from 'uuid';
|
|
@@ -25,7 +25,7 @@ export const CartesianBaseAxis = ({ axis, axisConfig, dimension, }) => {
|
|
|
25
25
|
const styleConfig = useStyleConfigContext();
|
|
26
26
|
const { viewport, themes } = styleConfig;
|
|
27
27
|
const { maxWidth: xMax, maxHeight: yMax } = dimension;
|
|
28
|
-
return (_jsx(Group, { children: Object.values(axis)
|
|
28
|
+
return (_jsx(Group, { role: "group", children: Object.values(axis)
|
|
29
29
|
.filter((a) => !!a)
|
|
30
30
|
.map((a) => {
|
|
31
31
|
const orientation = axisConfig[a.orientation];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BrushHandleRenderProps } from '@visx/brush/lib/BrushHandle';
|
|
3
|
+
import { CartesianxAxisSystem, Data } from '../../types';
|
|
4
|
+
export declare type CartesianBaseBrushProps = {
|
|
5
|
+
axisSystem: CartesianxAxisSystem;
|
|
6
|
+
brushSize?: number;
|
|
7
|
+
padding?: number;
|
|
8
|
+
position: {
|
|
9
|
+
top: number;
|
|
10
|
+
left: number;
|
|
11
|
+
};
|
|
12
|
+
dimension: {
|
|
13
|
+
maxWidth: number;
|
|
14
|
+
maxHeight: number;
|
|
15
|
+
};
|
|
16
|
+
isVisible?: boolean;
|
|
17
|
+
onChange: (filteredData: Data) => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const BrushHandle: ({ x, y, height, isBrushActive, }: BrushHandleRenderProps) => JSX.Element | null;
|
|
20
|
+
export declare const CartesianBaseBrush: React.FC<CartesianBaseBrushProps>;
|
|
21
|
+
//# sourceMappingURL=cartesian-base-brush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cartesian-base-brush.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-brush.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAOrE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEzD,oBAAY,uBAAuB,GAAG;IACpC,UAAU,EAAE,oBAAoB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,CAAC;CACxC,CAAA;AAED,eAAO,MAAM,WAAW,qCAErB,sBAAsB,uBA2CxB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAiFhE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
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
|
+
import { Brush } from '@visx/brush';
|
|
18
|
+
import { Group } from '@visx/group';
|
|
19
|
+
import { useBrush } from '../../hooks';
|
|
20
|
+
import { useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../providers';
|
|
21
|
+
export const BrushHandle = ({ x, y, height, isBrushActive, }) => {
|
|
22
|
+
const { isHorizontal } = useLayoutContext();
|
|
23
|
+
const { brush, themes } = useStyleConfigContext();
|
|
24
|
+
const theme = useThemeContext();
|
|
25
|
+
const pathWidth = 8;
|
|
26
|
+
const pathHeight = 16;
|
|
27
|
+
const lPos = isHorizontal ? (x + pathWidth / 2) : (x + pathHeight * 1.75);
|
|
28
|
+
const tPos = isHorizontal ? (height - pathHeight) / 2 : (y + pathWidth / 2);
|
|
29
|
+
const style = {
|
|
30
|
+
stroke: themes[theme].brush.handle.stroke,
|
|
31
|
+
strokeWidth: brush.handle.strokeWidth,
|
|
32
|
+
fill: themes[theme].brush.handle.fill,
|
|
33
|
+
cursor: isHorizontal
|
|
34
|
+
? { cursor: 'col-resize' }
|
|
35
|
+
: { cursor: 'row-resize' },
|
|
36
|
+
transform: isHorizontal
|
|
37
|
+
? 'rotate(0)'
|
|
38
|
+
: 'rotate(90)',
|
|
39
|
+
};
|
|
40
|
+
if (!isBrushActive) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return (_jsx(Group, { left: lPos, top: tPos, "data-testid": "brush-handle", children: _jsx("path", { fill: style.fill, d: "M -4.5 0.5 L 3.5 0.5 L 3.5 15.5 L -4.5 15.5 L -4.5 0.5 M -1.5 4 L -1.5 12 M 0.5 4 L 0.5 12", stroke: style.stroke, strokeWidth: style.strokeWidth, style: style.cursor, transform: style.transform }) }));
|
|
44
|
+
};
|
|
45
|
+
export const CartesianBaseBrush = ({ axisSystem, brushSize = 32, dimension, isVisible = false, padding = 16, position, onChange, }) => {
|
|
46
|
+
const { ref, brushDirection, brushHeight, brushWidth, initialBrushPosition, margin, position: pos, resizeTriggerAreas, scale, style, handleBrushClear, handleBrushChange, } = useBrush({
|
|
47
|
+
axisSystem,
|
|
48
|
+
brushSize,
|
|
49
|
+
dimension,
|
|
50
|
+
isVisible,
|
|
51
|
+
padding,
|
|
52
|
+
position,
|
|
53
|
+
onChange,
|
|
54
|
+
});
|
|
55
|
+
if (!isVisible)
|
|
56
|
+
return null;
|
|
57
|
+
return (_jsxs(Group, { left: pos.left, top: pos.top, "aria-hidden": "false", "data-testid": "brush", children: [_jsx("defs", { children: _jsxs("pattern", { id: "brush_pattern_lines", patternUnits: "userSpaceOnUse", width: "20", height: "20", patternTransform: style.pattern.transform, children: [_jsx("rect", { x: "0", y: "0", width: "100%", height: "100%", fill: "url(#cartesian-grid-background)" }), _jsx("path", { d: "M0 10h20z", strokeWidth: style.pattern.strokeWidth, stroke: style.pattern.stroke, fill: style.pattern.fill })] }) }), _jsx("rect", { x: 0, y: 0, width: brushWidth, height: brushHeight, fill: "url(#brush_pattern_lines)", style: { pointerEvents: 'all', cursor: 'move' } }), _jsx(Brush, { brushDirection: brushDirection, brushRegion: "chart", handleSize: 8, innerRef: ref, initialBrushPosition: initialBrushPosition, margin: margin, onBrushStart: undefined, onBrushEnd: undefined, onChange: handleBrushChange, onClick: handleBrushClear, resizeTriggerAreas: resizeTriggerAreas, selectedBoxStyle: style.selectedBox, xAxisOrientation: "bottom", yAxisOrientation: "left", xScale: scale.x, yScale: scale.y, renderBrushHandle: (props) => _jsx(BrushHandle, { ...props }), useWindowMoveEvents: true, width: brushWidth, height: brushHeight })] }));
|
|
58
|
+
};
|
|
59
|
+
CartesianBaseBrush.displayName = 'CartesianBaseBrush';
|
|
@@ -17,7 +17,7 @@ export declare type CartesianBaseGridProps = {
|
|
|
17
17
|
tickRows?: number;
|
|
18
18
|
tickColumns?: number;
|
|
19
19
|
background?: Background;
|
|
20
|
-
otherProps?: Record<string,
|
|
20
|
+
otherProps?: Record<string, unknown>;
|
|
21
21
|
};
|
|
22
22
|
export declare const CartesianBaseGrid: React.FC<CartesianBaseGridProps>;
|
|
23
23
|
//# sourceMappingURL=cartesian-base-grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian-base-grid.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-grid.tsx"],"names":[],"mappings":";AAsBA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE/D,oBAAY,sBAAsB,GAAG;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,QAAQ,EAAE;QACR,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"cartesian-base-grid.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-grid.tsx"],"names":[],"mappings":";AAsBA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE/D,oBAAY,sBAAsB,GAAG;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,QAAQ,EAAE;QACR,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA0E9D,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare type CartesianBaseLegendProps = {
|
|
3
3
|
customLegend?: React.ReactNode;
|
|
4
|
-
|
|
4
|
+
isVisible?: boolean;
|
|
5
|
+
onMouseOver: (key: string) => void;
|
|
5
6
|
};
|
|
6
|
-
export declare const CartesianBaseLegend:
|
|
7
|
+
export declare const CartesianBaseLegend: import("react").ForwardRefExoticComponent<CartesianBaseLegendProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
7
8
|
//# sourceMappingURL=cartesian-base-legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian-base-legend.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-legend.tsx"],"names":[],"mappings":";AAyBA,oBAAY,wBAAwB,GAAG;IACrC,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B,
|
|
1
|
+
{"version":3,"file":"cartesian-base-legend.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-legend.tsx"],"names":[],"mappings":";AAyBA,oBAAY,wBAAwB,GAAG;IACrC,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAA;AAED,eAAO,MAAM,mBAAmB,qHAgF9B,CAAC"}
|
|
@@ -15,21 +15,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { forwardRef, } from 'react';
|
|
18
|
+
import { v4 as uuid } from 'uuid';
|
|
18
19
|
import { useDataContext } from '../../providers/data';
|
|
19
20
|
import { Placeholder } from '../placeholder';
|
|
20
21
|
import styles from './cartesian-base.module.css';
|
|
21
|
-
const
|
|
22
|
+
export const CartesianBaseLegend = forwardRef(({ customLegend, isVisible = true, onMouseOver, }, forwardedRef) => {
|
|
23
|
+
const { metadata } = useDataContext();
|
|
24
|
+
if (!isVisible)
|
|
25
|
+
return null;
|
|
26
|
+
if (customLegend) {
|
|
27
|
+
return (_jsx("div", { ref: forwardedRef, className: styles.Legend, role: "presentation", children: _jsx("div", { className: styles.LegendContent, children: customLegend }) }));
|
|
28
|
+
}
|
|
22
29
|
if (metadata) {
|
|
23
30
|
const { names, colors, dataKey: sdk } = metadata.series;
|
|
24
31
|
const { name, color, dataKey: odk } = metadata.overlay;
|
|
25
|
-
return (_jsxs("ul", { children: [sdk.map((s, i) => (_jsx("li", { children: _jsxs("div", { children: [_jsx(Placeholder, { color: colors[i] }), _jsx("span", { children: names[i] })] }) },
|
|
32
|
+
return (_jsx("div", { "aria-hidden": !isVisible, "data-testid": "legend", className: styles.Legend, ref: forwardedRef, role: "presentation", children: _jsx("div", { className: styles.LegendContent, onMouseOut: () => onMouseOver(''), onBlur: () => ({}), children: _jsxs("ul", { children: [sdk.map((s, i) => (_jsx("li", { "aria-label": names[i], "aria-live": "polite", "data-testid": "legend-item", onMouseOver: () => onMouseOver(s), onMouseLeave: () => onMouseOver(''), onFocus: () => ({}), children: _jsxs("div", { children: [_jsx(Placeholder, { color: colors[i] }), _jsx("span", { children: names[i] })] }) }, uuid()))), odk && (_jsx("li", { onMouseOver: () => onMouseOver(odk), onMouseLeave: () => onMouseOver(''), onMouseOut: () => onMouseOver(''), onFocus: () => ({}), onBlur: () => ({}), children: _jsxs("div", { children: [_jsx(Placeholder, { color: color }), _jsx("span", { children: name })] }) }))] }) }) }));
|
|
26
33
|
}
|
|
27
34
|
return null;
|
|
28
|
-
};
|
|
29
|
-
export const CartesianBaseLegend = forwardRef(({ customLegend, hideLegend = false, }, forwardedRef) => {
|
|
30
|
-
const { metadata } = useDataContext();
|
|
31
|
-
if (hideLegend)
|
|
32
|
-
return null;
|
|
33
|
-
return (_jsx("div", { ref: forwardedRef, className: styles.Legend, children: _jsx("div", { className: styles.LegendContent, children: customLegend ?? renderLegendItems(metadata) }) }));
|
|
34
35
|
});
|
|
35
36
|
CartesianBaseLegend.displayName = 'CartesianBaseLegend';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { SVGProps } from 'react';
|
|
2
2
|
import { AxisOrientation } from '../../types';
|
|
3
3
|
import { AxisProps, CartesianStyleConfig, GridProps, MarginProps } from '../../types/cartesian';
|
|
4
4
|
import { Background } from '../../types/linear-gradient';
|
|
5
|
-
import { DeepPartial } from '../../types/main';
|
|
5
|
+
import { Data, DeepPartial } from '../../types/main';
|
|
6
6
|
import { HeadingsProps } from '../headings';
|
|
7
7
|
export declare type CartesianBaseProps = {
|
|
8
8
|
/**
|
|
@@ -18,7 +18,7 @@ export declare type CartesianBaseProps = {
|
|
|
18
18
|
*/
|
|
19
19
|
headings?: Pick<HeadingsProps, 'top' | 'left' | 'config'>;
|
|
20
20
|
/**
|
|
21
|
-
* Set the Cartesian component width. 800px is the default value
|
|
21
|
+
* Set the Cartesian component width. 800px is the default value.
|
|
22
22
|
*/
|
|
23
23
|
width?: number;
|
|
24
24
|
/**
|
|
@@ -49,6 +49,14 @@ export declare type CartesianBaseProps = {
|
|
|
49
49
|
* Set `Axis System` properties.
|
|
50
50
|
*/
|
|
51
51
|
axis: Record<AxisOrientation, AxisProps | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Set `Axis System` properties used by the `Brush` component.
|
|
54
|
+
*/
|
|
55
|
+
axisFiltered: Record<AxisOrientation, AxisProps | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Set the `Brush` visibility.
|
|
58
|
+
*/
|
|
59
|
+
showBrush?: boolean;
|
|
52
60
|
/**
|
|
53
61
|
* Hide `Legend` when set to `true`.
|
|
54
62
|
*/
|
|
@@ -70,9 +78,21 @@ export declare type CartesianBaseProps = {
|
|
|
70
78
|
*/
|
|
71
79
|
styleConfig?: DeepPartial<CartesianStyleConfig>;
|
|
72
80
|
/**
|
|
73
|
-
* Set
|
|
81
|
+
* Set SVG custom properties.
|
|
82
|
+
*/
|
|
83
|
+
otherProps?: SVGProps<SVGSVGElement>;
|
|
84
|
+
/**
|
|
85
|
+
* Set extra class
|
|
86
|
+
*/
|
|
87
|
+
className?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Add some inline style
|
|
90
|
+
*/
|
|
91
|
+
style?: Record<string, any>;
|
|
92
|
+
/**
|
|
93
|
+
* A callback to retrieve data filtered from the brush.
|
|
74
94
|
*/
|
|
75
|
-
|
|
95
|
+
onBrushChange: (filteredData: Data) => void;
|
|
76
96
|
};
|
|
77
|
-
export declare const CartesianBase: React.
|
|
97
|
+
export declare const CartesianBase: React.ForwardRefExoticComponent<CartesianBaseProps & React.RefAttributes<HTMLElement>>;
|
|
78
98
|
//# sourceMappingURL=cartesian-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian-base.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cartesian-base.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,EAAc,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOpD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,SAAS,EAAE,oBAAoB,EAAE,SAAS,EAAE,WAAW,EACxD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAEL,IAAI,EACJ,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAY,aAAa,EAAE,MAAM,aAAa,CAAC;AAStD,oBAAY,kBAAkB,GAAG;IAC/B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAE,MAAM,GAAE,QAAQ,CAAC,CAAC;IACxD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IACrD;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IAC7D;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;IAChD;;OAEG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACrC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B;;OAEG;IACH,aAAa,EAAE,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,CAAC;CAC7C,CAAA;AAED,eAAO,MAAM,aAAa,wFAwNxB,CAAC"}
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } 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 { RectClipPath } from '@visx/clip-path';
|
|
18
18
|
import { LinearGradient } from '@visx/gradient';
|
|
19
19
|
import { Group } from '@visx/group';
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
20
|
+
import clsx from 'clsx';
|
|
21
|
+
import { forwardRef } from 'react';
|
|
22
|
+
import { mergeRefs } from 'react-merge-refs';
|
|
23
|
+
import { useCartesian } from '../../hooks';
|
|
23
24
|
import { StyleConfigProvider } from '../../providers';
|
|
24
25
|
import { CartesianProvider } from '../../providers/cartesian';
|
|
25
|
-
import {
|
|
26
|
-
import { useThemeContext } from '../../providers/theme';
|
|
27
|
-
import { cartesianStyleConfig, headingsStyleConfig as hStyle } from '../../style-config';
|
|
26
|
+
import { DataProvider } from '../../providers/data';
|
|
28
27
|
import { Charts, } from '../../types/main';
|
|
29
|
-
import { computeAxisStyleConfig, computeAxisSystemProperties, handleVerticalTickLabelOffset, } from '../../utils/axis';
|
|
30
28
|
import { EmptyState } from '../empty-state';
|
|
31
29
|
import { Headings } from '../headings';
|
|
32
30
|
import { Loader } from '../loader';
|
|
33
|
-
import { Lines } from '../shapes';
|
|
34
|
-
import styles from './cartesian-base.module.css';
|
|
31
|
+
import { Bars, Lines } from '../shapes';
|
|
32
|
+
import styles, { Unselectable } from './cartesian-base.module.css';
|
|
35
33
|
import { CartesianBaseAxis } from './cartesian-base-axis';
|
|
34
|
+
import { CartesianBaseBrush } from './cartesian-base-brush';
|
|
36
35
|
import { CartesianBaseGrid } from './cartesian-base-grid';
|
|
37
36
|
import { CartesianBaseLegend } from './cartesian-base-legend';
|
|
38
|
-
export const CartesianBase = ({ width = 800, height = 600, preventResponsive, isLoading = false, background, margin = {
|
|
37
|
+
export const CartesianBase = forwardRef(({ width = 800, height = 600, preventResponsive, isLoading = false, background, margin = {
|
|
39
38
|
top: 24,
|
|
40
39
|
right: 24,
|
|
41
40
|
bottom: 24,
|
|
@@ -43,56 +42,22 @@ export const CartesianBase = ({ width = 800, height = 600, preventResponsive, is
|
|
|
43
42
|
}, grid = {
|
|
44
43
|
hideColumns: false,
|
|
45
44
|
hideRows: false,
|
|
46
|
-
}, title, subtitle, headings, axis, hideLegend = false, emptyState, emptyStateMessage, customLegend, styleConfig, otherProps, }) => {
|
|
47
|
-
const theme =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const dynamicWidth = preventResponsive ? width : w;
|
|
65
|
-
const dynamicHeight = preventResponsive ? height : h;
|
|
66
|
-
const dynamicStyle = {
|
|
67
|
-
'--static-width': `${dynamicWidth}px`,
|
|
68
|
-
'--static-height': `${dynamicHeight}px`,
|
|
69
|
-
'--legend-width': `calc(100% - ${margin.left + margin.right}px)`,
|
|
70
|
-
'--legend-top': `calc(100% - ${legendHeight + margin.bottom}px)`,
|
|
71
|
-
'--legend-left': `${margin.left}px`,
|
|
72
|
-
'--legend-padding': lStyle.padding,
|
|
73
|
-
};
|
|
74
|
-
const { top, right, bottom, left, } = axis;
|
|
75
|
-
const axisConfig = useMemo(() => computeAxisStyleConfig(axis, aStyle), [aStyle, axis]);
|
|
76
|
-
const { leftAxisOffset: lOff, topAxisOffset: tOff, verticalAxisOffset: vOff, horizontalAxisOffset: hOff, } = axisConfig.offset;
|
|
77
|
-
const mr = margin.right * (right ? 1 : 2);
|
|
78
|
-
const ml = margin.left * (left ? 1 : 2);
|
|
79
|
-
const xMax = dynamicWidth - ml - mr - vOff;
|
|
80
|
-
const topTickLabelOffset = handleVerticalTickLabelOffset(xMax, cartesianConfig, top);
|
|
81
|
-
const bottomTickLabelOffset = handleVerticalTickLabelOffset(xMax, cartesianConfig, bottom);
|
|
82
|
-
const mt = margin.top * (top ? 1 : 2) + headingsHeight + topTickLabelOffset;
|
|
83
|
-
const mb = margin.bottom * (bottom ? 1 : 2) + legendHeight + bottomTickLabelOffset;
|
|
84
|
-
const yMax = dynamicHeight - mt - mb - hOff;
|
|
85
|
-
const dimension = {
|
|
86
|
-
maxWidth: xMax,
|
|
87
|
-
maxHeight: yMax,
|
|
88
|
-
};
|
|
89
|
-
const position = {
|
|
90
|
-
top: mt + tOff,
|
|
91
|
-
right: ml + lOff + xMax,
|
|
92
|
-
bottom: mt + tOff + yMax,
|
|
93
|
-
left: ml + lOff,
|
|
94
|
-
};
|
|
95
|
-
const axisSystem = computeAxisSystemProperties(axis, dimension, position);
|
|
96
|
-
return (_jsx("div", { className: styles.Wrapper, "data-theme": theme, "data-responsive": !preventResponsive, ref: ref, style: dynamicStyle, "data-testid": "cartesian", children: _jsxs(StyleConfigProvider, { styleConfig: cartesianConfig, children: [_jsxs("svg", { width: dynamicWidth, height: dynamicHeight, viewBox: `0 0 ${dynamicWidth} ${dynamicHeight}`, ...otherProps, children: [_jsx(RectClipPath, { id: "clip-path-cartesian-container", x: 0, y: 0, width: dynamicWidth, height: dynamicHeight }), _jsx(RectClipPath, { id: "clip-path-cartesian-chart", x: position.left, y: position.top, width: dimension.maxWidth, height: dimension.maxHeight }), _jsx(LinearGradient, { id: "cartesian-container", from: from, to: to }), _jsx("rect", { x: 0, y: 0, width: dynamicWidth, height: dynamicHeight, fill: "url(#cartesian-container)", rx: 0, strokeWidth: 0, stroke: "none" }), _jsx(Headings, { title: title, subtitle: subtitle, top: headings?.top ?? margin.top, left: headings?.left ?? ml, config: headings?.config }), _jsx(Loader, { isLoading: isLoading, top: margin.top + headingsHeight, left: margin.left, width: dynamicWidth - margin.left - margin.right, height: dynamicHeight - headingsHeight - margin.top - margin.bottom }), !isLoading && (_jsxs(Group, { clipPath: "url(#clip-path-cartesian-container)", children: [_jsx(CartesianBaseGrid, { position: position, dimension: dimension, axis: axisSystem, hideRows: !hasData || grid.hideRows, hideColumns: !hasData || grid.hideColumns, tickRows: grid.tickRows, tickColumns: grid.tickColumns, background: grid.background, otherProps: grid.otherProps }), _jsx(CartesianBaseAxis, { dimension: dimension, axis: axisSystem, axisConfig: axisConfig }), _jsx(EmptyState, { position: position, dimension: dimension, customEmptyState: emptyState, message: emptyStateMessage, isVisible: hasEmptyState }), hasData && (_jsx(CartesianProvider, { position: position, dimension: dimension, axis: axisSystem, children: _jsx(Group, { clipPath: "url(#clip-path-cartesian-chart)", children: metadata?.type === Charts.LINE_CHART && _jsx(Lines, {}) }) }))] }))] }), hasLegend && (_jsx(CartesianBaseLegend, { customLegend: customLegend, hideLegend: hideLegend, ref: refLegend }))] }) }));
|
|
97
|
-
};
|
|
45
|
+
}, title, subtitle, headings, axis, axisFiltered, showBrush = false, hideLegend = false, emptyState, emptyStateMessage, customLegend, styleConfig, className, style, otherProps, onBrushChange, }, forwardedRef) => {
|
|
46
|
+
const { axisConfig, axisFilteredSystem, axisSystem, bgFrom, bgTo, brushSize, brushPadding, cartesianConfig, dimension, dynamicHeight, dynamicWidth, dynamicStyle, hasBrush, hasData, hasLegend, filteredData, hasEmptyState, hoveredLegendItem, metadata, position, ref, refLegend, theme, setHoveredLegendItem, } = useCartesian({
|
|
47
|
+
axis,
|
|
48
|
+
axisFiltered,
|
|
49
|
+
background,
|
|
50
|
+
headings,
|
|
51
|
+
height,
|
|
52
|
+
hideLegend,
|
|
53
|
+
isLoading,
|
|
54
|
+
margin,
|
|
55
|
+
preventResponsive,
|
|
56
|
+
showBrush,
|
|
57
|
+
styleConfig,
|
|
58
|
+
title,
|
|
59
|
+
width,
|
|
60
|
+
});
|
|
61
|
+
return (_jsx("div", { "aria-atomic": "true", "aria-hidden": "false", "aria-label": "Cartesian Chart", className: clsx([styles.Wrapper, className]), "data-testid": "cartesian", "data-responsive": !preventResponsive, "data-theme": theme, ref: mergeRefs([ref, forwardedRef]), role: "img", style: { ...style, ...dynamicStyle }, children: _jsxs(StyleConfigProvider, { styleConfig: cartesianConfig, children: [_jsxs("svg", { ...otherProps, width: dynamicWidth, height: dynamicHeight, viewBox: `0 0 ${dynamicWidth} ${dynamicHeight}`, className: Unselectable, onMouseOver: () => setHoveredLegendItem(''), children: [_jsx(RectClipPath, { id: "clip-path-cartesian-container", x: 0, y: 0, width: dynamicWidth, height: dynamicHeight }), _jsx(RectClipPath, { id: "clip-path-cartesian-chart", x: position.axis.left, y: position.axis.top, width: dimension.axis.maxWidth, height: dimension.axis.maxHeight }), _jsx(LinearGradient, { id: "cartesian-container", from: bgFrom, to: bgTo }), _jsx("rect", { x: 0, y: 0, width: dynamicWidth, height: dynamicHeight, fill: "url(#cartesian-container)", rx: 0, strokeWidth: 0, stroke: "none" }), _jsx(Headings, { title: title, subtitle: subtitle, top: position.headings.top, left: position.headings.left, config: headings?.config, "data-inner-element": "Headings" }), _jsx(Loader, { isLoading: isLoading, top: position.loader.top, left: position.loader.left, width: dimension.loader.width, height: dimension.loader.height, "data-inner-element": "Loader" }), !isLoading && (_jsxs(Group, { clipPath: "url(#clip-path-cartesian-container)", children: [_jsx(CartesianBaseGrid, { position: position.axis, dimension: dimension.axis, axis: axisFilteredSystem, hideRows: !hasData || grid.hideRows, hideColumns: !hasData || grid.hideColumns, tickRows: grid.tickRows, tickColumns: grid.tickColumns, background: grid.background, otherProps: grid.otherProps, "data-inner-element": "CartesianBaseGrid" }), _jsx(CartesianBaseAxis, { dimension: dimension.axis, axis: axisFilteredSystem, axisConfig: axisConfig, "data-inner-element": "CartesianBaseAxis" }), _jsx(EmptyState, { position: position.axis, dimension: dimension.axis, customEmptyState: emptyState, message: emptyStateMessage, isVisible: hasEmptyState, "data-inner-element": "EmptyState" }), hasData && (_jsx(CartesianProvider, { position: position.axis, dimension: dimension.axis, axis: axisFilteredSystem, hoveredLegendItem: hoveredLegendItem, children: _jsx(DataProvider, { data: filteredData, metadata: metadata, filteredData: filteredData, children: _jsxs(Group, { clipPath: "url(#clip-path-cartesian-chart)", children: [metadata?.type === Charts.LINE_CHART && _jsx(Lines, {}), metadata?.type === Charts.BAR_CHART && _jsx(Bars, {})] }) }) })), _jsx(CartesianBaseBrush, { axisSystem: axisSystem, brushSize: brushSize, dimension: dimension.axis, isVisible: hasBrush, padding: brushPadding, position: position.brush, onChange: onBrushChange, "data-inner-element": "CartesianBaseBrush" })] }))] }), _jsx(CartesianBaseLegend, { customLegend: customLegend, isVisible: hasLegend, ref: refLegend, onMouseOver: (dataKey) => setHoveredLegendItem(dataKey), "data-inner-element": "CartesianBaseLegend" })] }) }));
|
|
62
|
+
});
|
|
98
63
|
CartesianBase.displayName = 'CartesianBase';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.Wrapper{align-items:center;display:block;height:var(--static-height);justify-content:center;overflow:hidden;position:relative;resize:none;width:var(--static-width)}.Wrapper[data-responsive=true]{display:flex;height:inherit;justify-content:center;width:inherit}.Legend{left:var(--legend-left);overflow:hidden;padding:var(--legend-padding);position:absolute;top:var(--legend-top);width:var(--legend-width)}.LegendContent{display:flex;flex-direction:column;width:100%}.LegendContent ul{flex-flow:row wrap;gap
|
|
1
|
+
.Wrapper{align-items:center;display:block;height:var(--static-height);justify-content:center;overflow:hidden;position:relative;resize:none;width:var(--static-width)}.Wrapper[data-responsive=true]{display:flex;height:inherit;justify-content:center;width:inherit}.Legend{left:var(--legend-left);overflow:hidden;padding:var(--legend-padding);position:absolute;top:var(--legend-top);width:var(--legend-width)}.LegendContent{display:flex;flex-direction:column;width:100%}.LegendContent ul{flex-flow:row wrap;gap:.5rem 1rem;list-style:none;padding:0;width:100%}.LegendContent li>div,.LegendContent ul{align-items:center;display:flex;justify-content:flex-start}.LegendContent li>div{flex-direction:row;gap:4px}.LegendContent li>div span{font-size:12px;line-height:1rem}.LegendContent li:hover{cursor:pointer}.Unselectable{-webkit-touch-callout:none;-webkit-user-select:none;user-select:none}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
2
|
//# sourceMappingURL=cartesian-base.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian-base.test.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base.test.tsx"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"cartesian-base.test.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base.test.tsx"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAC"}
|