@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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
2
4
|
import { render, screen } from '@testing-library/react';
|
|
3
5
|
import { CartesianBase } from './cartesian-base';
|
|
6
|
+
import { BrushHandle } from './cartesian-base-brush';
|
|
7
|
+
import { CartesianBaseLegend } from './cartesian-base-legend';
|
|
4
8
|
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
5
9
|
observe: jest.fn(),
|
|
6
10
|
unobserve: jest.fn(),
|
|
@@ -28,24 +32,47 @@ const mockedAxis = {
|
|
|
28
32
|
orientation: 'left',
|
|
29
33
|
},
|
|
30
34
|
};
|
|
31
|
-
describe('<
|
|
35
|
+
describe('<CartesianBase>', () => {
|
|
32
36
|
it('should render the component', () => {
|
|
33
|
-
render(_jsx(CartesianBase, { axis: mockedAxis }));
|
|
37
|
+
render(_jsx(CartesianBase, { axis: mockedAxis, axisFiltered: mockedAxis, onBrushChange: () => ({}) }));
|
|
34
38
|
const element = screen.getByTestId('cartesian');
|
|
35
39
|
expect(element).toBeDefined();
|
|
36
40
|
});
|
|
37
41
|
it('should render the component w/o R/B axis', () => {
|
|
38
|
-
render(_jsx(CartesianBase, { axis: { ...mockedAxis, right: undefined, bottom: undefined }, title: "Title", preventResponsive: true, margin: {
|
|
42
|
+
render(_jsx(CartesianBase, { axis: { ...mockedAxis, right: undefined, bottom: undefined }, axisFiltered: { ...mockedAxis, right: undefined, bottom: undefined }, title: "Title", preventResponsive: true, margin: {
|
|
39
43
|
top: 0, right: 0, bottom: 0, left: 0,
|
|
40
|
-
} }));
|
|
44
|
+
}, onBrushChange: () => ({}) }));
|
|
41
45
|
const element = screen.getByTestId('cartesian');
|
|
42
46
|
expect(element).toBeDefined();
|
|
43
47
|
});
|
|
44
48
|
it('should render the component w props', () => {
|
|
45
|
-
render(_jsx(CartesianBase, { axis: { ...mockedAxis, left: undefined }, title: "Title", preventResponsive: true, margin: {
|
|
49
|
+
render(_jsx(CartesianBase, { axis: { ...mockedAxis, left: undefined }, axisFiltered: { ...mockedAxis, left: undefined }, title: "Title", preventResponsive: true, margin: {
|
|
46
50
|
top: 12, right: 12, bottom: 12, left: 12,
|
|
47
|
-
} }));
|
|
51
|
+
}, showBrush: true, onBrushChange: () => ({}) }));
|
|
48
52
|
const element = screen.getByTestId('cartesian');
|
|
49
53
|
expect(element).toBeDefined();
|
|
50
54
|
});
|
|
55
|
+
it('should render the component w/o legend', () => {
|
|
56
|
+
render(_jsx(CartesianBase, { axis: { ...mockedAxis }, axisFiltered: { ...mockedAxis }, title: "Title", hideLegend: true, onBrushChange: () => ({}) }));
|
|
57
|
+
const element = screen.getByTestId('cartesian');
|
|
58
|
+
expect(element).toBeDefined();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('<CartesianBaseLegend>', () => {
|
|
62
|
+
it('should render the custom legend if provided', () => {
|
|
63
|
+
const onMouseOverSpy = jest.fn();
|
|
64
|
+
const customLegend = _jsx("div", { children: "Custom legend content" });
|
|
65
|
+
render(_jsx(CartesianBaseLegend, { customLegend: customLegend, onMouseOver: onMouseOverSpy, isVisible: true }));
|
|
66
|
+
expect(screen.getByRole('presentation')).toBeDefined();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('<BrushHandle>', () => {
|
|
70
|
+
it('should render the handle', () => {
|
|
71
|
+
const { getByTestId } = render(_jsx(BrushHandle, { x: 0, y: 0, width: 100, height: 30, isBrushActive: true, className: "" }));
|
|
72
|
+
expect(getByTestId('brush-handle')).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
it('should not render when inactive', () => {
|
|
75
|
+
const { container } = render(_jsx(BrushHandle, { x: 0, y: 0, width: 100, height: 30, isBrushActive: false, className: "" }));
|
|
76
|
+
expect(container.innerHTML).toBe('');
|
|
77
|
+
});
|
|
51
78
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAgBA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAgBA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -32,6 +32,10 @@ export declare type LineChartProps = {
|
|
|
32
32
|
* Set the properties associated with the Overlay Axis.
|
|
33
33
|
*/
|
|
34
34
|
overlay?: LineChartOverlay;
|
|
35
|
+
/**
|
|
36
|
+
* Display an average line and label when true.
|
|
37
|
+
*/
|
|
38
|
+
showAverage?: boolean;
|
|
35
39
|
/**
|
|
36
40
|
* Set extra data or custom content to be displayed in the tooltip.
|
|
37
41
|
*/
|
|
@@ -52,6 +56,59 @@ export declare type LineChartProps = {
|
|
|
52
56
|
* Remove the padding from the chart container.
|
|
53
57
|
*/
|
|
54
58
|
hidePadding?: boolean;
|
|
55
|
-
} & Except<CartesianBaseProps, 'axis'>;
|
|
56
|
-
export declare const LineChart:
|
|
59
|
+
} & Except<CartesianBaseProps, 'axis' | 'axisFiltered' | 'onBrushChange'>;
|
|
60
|
+
export declare const LineChart: import("react").ForwardRefExoticComponent<{
|
|
61
|
+
/**
|
|
62
|
+
* Set the theme of the chart. This is set to `light` by default.
|
|
63
|
+
*/
|
|
64
|
+
theme?: ThemeVariants | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Set the layout of the chart. `Index`, `Series` and eventually `Overlay` will be automatically rearranged.
|
|
67
|
+
*/
|
|
68
|
+
layout?: CartesianChartLayout | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Set the data structure that will be used to render the chart.
|
|
71
|
+
*/
|
|
72
|
+
data: Data;
|
|
73
|
+
/**
|
|
74
|
+
* Set the type of render function used to draw any chart line.
|
|
75
|
+
*/
|
|
76
|
+
renderAs?: LineChartRenderType | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Set the properties associated with the Index Axis.
|
|
79
|
+
*/
|
|
80
|
+
index: LineChartIndex;
|
|
81
|
+
/**
|
|
82
|
+
* Set the properties associated with any Series of lines.
|
|
83
|
+
*/
|
|
84
|
+
series: LineChartSeries;
|
|
85
|
+
/**
|
|
86
|
+
* Set the properties associated with the Overlay Axis.
|
|
87
|
+
*/
|
|
88
|
+
overlay?: LineChartOverlay | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Display an average line and label when true.
|
|
91
|
+
*/
|
|
92
|
+
showAverage?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Set extra data or custom content to be displayed in the tooltip.
|
|
95
|
+
*/
|
|
96
|
+
tooltip?: LineChartTooltip | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Prevent showing a connecting line between points when data is missing.
|
|
99
|
+
*/
|
|
100
|
+
hideMissingDataConnection?: boolean | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Show a marker for every single data point.
|
|
103
|
+
*/
|
|
104
|
+
showMarker?: boolean | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Show a label and a marker for every single data point.
|
|
107
|
+
*/
|
|
108
|
+
showMarkerLabel?: boolean | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Remove the padding from the chart container.
|
|
111
|
+
*/
|
|
112
|
+
hidePadding?: boolean | undefined;
|
|
113
|
+
} & Except<CartesianBaseProps, "axis" | "axisFiltered" | "onBrushChange"> & import("react").RefAttributes<HTMLElement>>;
|
|
57
114
|
//# sourceMappingURL=line-chart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/components/line-chart/line-chart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAOnC,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/components/line-chart/line-chart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAOnC,OAAO,EACL,oBAAoB,EACpB,IAAI,EACJ,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EACzE,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAiB,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAErF,oBAAY,cAAc,GAAG;IAC3B;;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,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IACtB;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,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,SAAS;IAtDpB;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;WACI,cAAc;IACrB;;OAEG;YACK,eAAe;IACvB;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;uHAgEH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
3
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,55 +14,30 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { forwardRef } from 'react';
|
|
18
|
+
import { useLineChart } from '../../hooks';
|
|
18
19
|
import { DataProvider, LayoutProvider, ThemeProvider, } from '../../providers';
|
|
19
|
-
import {
|
|
20
|
-
import { CartesianChartLayout, Charts, } from '../../types';
|
|
21
|
-
import { handleChartAxisLayout, handleChartDomainAndScaleType, handleOverlayColor, handleOverlayName, handleSeriesColors, handleSeriesNames, } from '../../utils';
|
|
20
|
+
import { CartesianChartLayout, } from '../../types';
|
|
22
21
|
import { CartesianBase } from '../cartesian-base/cartesian-base';
|
|
23
|
-
export const LineChart = ({ theme = 'light', layout = CartesianChartLayout.HORIZONTAL, renderAs = 'curves', data = [], index, series, overlay, tooltip, hideMissingDataConnection = false, showMarker = false, showMarkerLabel = false, hidePadding = false, ...otherProps }) => {
|
|
24
|
-
const isHorizontal
|
|
25
|
-
|
|
26
|
-
|
|
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.LINE_CHART,
|
|
22
|
+
export const LineChart = forwardRef(({ theme = 'light', layout = CartesianChartLayout.HORIZONTAL, renderAs = 'curves', data = [], index, series, overlay, tooltip, showAverage = false, hideMissingDataConnection = false, showMarker = false, showMarkerLabel = false, hidePadding = false, ...otherProps }, forwardedRef) => {
|
|
23
|
+
const { axis, axisFiltered, isHorizontal, metadata, zeroPadding, brushFilteredData, setBrushFilteredData, } = useLineChart({
|
|
24
|
+
theme,
|
|
25
|
+
layout,
|
|
33
26
|
renderAs,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
dataKey: series.dataKey,
|
|
37
|
-
names: handleSeriesNames(series),
|
|
38
|
-
colors: handleSeriesColors(series, palette.series),
|
|
39
|
-
style: series.style,
|
|
40
|
-
},
|
|
41
|
-
overlay: {
|
|
42
|
-
dataKey: overlay?.dataKey,
|
|
43
|
-
name: handleOverlayName(overlay),
|
|
44
|
-
color: handleOverlayColor(overlay, palette.overlay),
|
|
45
|
-
style: overlay?.style,
|
|
46
|
-
},
|
|
47
|
-
tooltip,
|
|
48
|
-
hideMissingDataConnection,
|
|
49
|
-
showMarker,
|
|
50
|
-
showMarkerLabel,
|
|
51
|
-
hidePadding,
|
|
52
|
-
}), [renderAs,
|
|
53
|
-
index.dataKey,
|
|
27
|
+
data,
|
|
28
|
+
index,
|
|
54
29
|
series,
|
|
55
|
-
palette.series,
|
|
56
|
-
palette.overlay,
|
|
57
30
|
overlay,
|
|
58
31
|
tooltip,
|
|
32
|
+
showAverage,
|
|
59
33
|
hideMissingDataConnection,
|
|
60
34
|
showMarker,
|
|
61
35
|
showMarkerLabel,
|
|
62
|
-
hidePadding
|
|
63
|
-
|
|
36
|
+
hidePadding,
|
|
37
|
+
});
|
|
38
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(LayoutProvider, { layout: layout, children: _jsx(DataProvider, { data: data, metadata: metadata, filteredData: brushFilteredData, children: _jsx(CartesianBase, { ...otherProps, axis: axis[layout], axisFiltered: axisFiltered[layout], grid: {
|
|
64
39
|
hideRows: !isHorizontal,
|
|
65
40
|
hideColumns: isHorizontal,
|
|
66
|
-
}, margin: zeroPadding,
|
|
67
|
-
};
|
|
41
|
+
}, margin: zeroPadding, onBrushChange: setBrushFilteredData, ref: forwardedRef }) }) }) }));
|
|
42
|
+
});
|
|
68
43
|
LineChart.displayName = 'LineChart';
|
|
@@ -12,10 +12,12 @@ const mockMetadata = {
|
|
|
12
12
|
dataKey: ['a', 'b'],
|
|
13
13
|
names: ['A', 'B'],
|
|
14
14
|
colors: ['ca', 'cb'],
|
|
15
|
+
average: undefined,
|
|
15
16
|
},
|
|
16
17
|
overlay: {
|
|
17
18
|
name: '',
|
|
18
19
|
color: '',
|
|
20
|
+
average: undefined,
|
|
19
21
|
},
|
|
20
22
|
hidePadding: true,
|
|
21
23
|
};
|
|
@@ -30,7 +32,7 @@ describe('<Loader>', () => {
|
|
|
30
32
|
expect(container.firstChild).toBeNull();
|
|
31
33
|
});
|
|
32
34
|
it('should render w context', () => {
|
|
33
|
-
const { container } = render(_jsx(DataProvider, { data: [{}, {}], metadata: mockMetadata, children: _jsx(Loader, {}) }));
|
|
35
|
+
const { container } = render(_jsx(DataProvider, { data: [{}, {}], filteredData: [{}, {}], metadata: mockMetadata, children: _jsx(Loader, {}) }));
|
|
34
36
|
expect(container.firstChild).toBeNull();
|
|
35
37
|
});
|
|
36
38
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars.tsx"],"names":[],"mappings":";AAuBA,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAiBxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
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
|
+
*/
|
|
17
|
+
import { Group } from '@visx/group';
|
|
18
|
+
import { useCartesianContext } from '../../../providers/cartesian';
|
|
19
|
+
import { BarsItemGroup, } from './bars.module.css';
|
|
20
|
+
export const Bars = () => {
|
|
21
|
+
const { position } = useCartesianContext();
|
|
22
|
+
return (_jsx(Group, { top: position.top, left: position.left, children: _jsx(Group, { className: BarsItemGroup, "data-testid": "bars" }) }));
|
|
23
|
+
};
|
|
24
|
+
Bars.displayName = 'Bars';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.BarsItemGroup{filter:saturate(100%)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars.test.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars.test.tsx"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { render, screen, } from '@testing-library/react';
|
|
4
|
+
import { CartesianProvider, DataProvider, LayoutProvider, ThemeProvider, } from '../../../providers';
|
|
5
|
+
import { CartesianChartLayout, Charts, } from '../../../types';
|
|
6
|
+
import { Bars } from './bars';
|
|
7
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
8
|
+
observe: jest.fn(),
|
|
9
|
+
unobserve: jest.fn(),
|
|
10
|
+
disconnect: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
const mockMetadata = {
|
|
13
|
+
type: Charts.BAR_CHART,
|
|
14
|
+
index: 'date',
|
|
15
|
+
isStacked: false,
|
|
16
|
+
sortBy: 'as-is',
|
|
17
|
+
series: {
|
|
18
|
+
dataKey: ['a'],
|
|
19
|
+
names: ['A'],
|
|
20
|
+
colors: ['ca'],
|
|
21
|
+
},
|
|
22
|
+
overlay: {
|
|
23
|
+
dataKey: 'b',
|
|
24
|
+
name: 'B',
|
|
25
|
+
color: 'ob',
|
|
26
|
+
},
|
|
27
|
+
hidePadding: true,
|
|
28
|
+
};
|
|
29
|
+
const mockedAxisSystem = {
|
|
30
|
+
top: {
|
|
31
|
+
domain: [0, 1],
|
|
32
|
+
scaleType: 'linear',
|
|
33
|
+
orientation: 'top',
|
|
34
|
+
top: 0,
|
|
35
|
+
left: 0,
|
|
36
|
+
scale: jest.fn(),
|
|
37
|
+
},
|
|
38
|
+
right: {
|
|
39
|
+
domain: ['a', 'b'],
|
|
40
|
+
scaleType: 'label',
|
|
41
|
+
orientation: 'right',
|
|
42
|
+
top: 0,
|
|
43
|
+
left: 800,
|
|
44
|
+
scale: jest.fn(),
|
|
45
|
+
},
|
|
46
|
+
bottom: {
|
|
47
|
+
domain: ['01-01-2020', '01-01-2024'],
|
|
48
|
+
scaleType: 'time',
|
|
49
|
+
orientation: 'bottom',
|
|
50
|
+
top: 600,
|
|
51
|
+
left: 0,
|
|
52
|
+
scale: jest.fn(),
|
|
53
|
+
},
|
|
54
|
+
left: {
|
|
55
|
+
domain: [0, 1],
|
|
56
|
+
scaleType: 'linear',
|
|
57
|
+
orientation: 'left',
|
|
58
|
+
top: 0,
|
|
59
|
+
left: 0,
|
|
60
|
+
scale: jest.fn(),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
describe('<Bars>', () => {
|
|
64
|
+
it('should render the component', () => {
|
|
65
|
+
render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], filteredData: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { position: {
|
|
66
|
+
top: 24, right: 24, bottom: 24, left: 24,
|
|
67
|
+
}, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, hoveredLegendItem: "", children: _jsx(Bars, {}) }) }) }) }));
|
|
68
|
+
const element = screen.getByTestId('bars');
|
|
69
|
+
expect(element).toBeDefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 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 { Bars } from './bars';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/shapes/index.ts"],"names":[],"mappings":"AAgBA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/shapes/index.ts"],"names":[],"mappings":"AAgBA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines-average.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-average.tsx"],"names":[],"mappings":";AA0BA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EA2IhC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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 { Label } from '@visx/annotation';
|
|
18
|
+
import { Group } from '@visx/group';
|
|
19
|
+
import { Line } from '@visx/shape';
|
|
20
|
+
import { useMemo } from 'react';
|
|
21
|
+
import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
|
|
22
|
+
export const LinesAverage = () => {
|
|
23
|
+
const theme = useThemeContext();
|
|
24
|
+
const { lines: defaultStyle, themes, viewport } = useStyleConfigContext();
|
|
25
|
+
const { metadata } = useDataContext();
|
|
26
|
+
const { isHorizontal } = useLayoutContext();
|
|
27
|
+
const { axis, dimension } = useCartesianContext();
|
|
28
|
+
const { top, right, bottom, left, } = axis;
|
|
29
|
+
const seriesAxis = isHorizontal ? left : bottom;
|
|
30
|
+
const overlayAxis = isHorizontal ? right : top;
|
|
31
|
+
const { showAverage, series, overlay } = metadata;
|
|
32
|
+
const { maxHeight, maxWidth } = dimension;
|
|
33
|
+
const { backgroundPadding, backgroundProps, maxLabelWidth, opacity, pointerEvents, strokeDasharray, strokeWidth, titleFontSize, titleFontWeight, titleProps, } = defaultStyle.average;
|
|
34
|
+
const averageSeries = series.average?.average;
|
|
35
|
+
const averageOverlay = overlay.average?.average;
|
|
36
|
+
const averageSeriesScale = seriesAxis.scale(averageSeries) ?? 0;
|
|
37
|
+
const averageOverlayScale = (overlayAxis && averageOverlay) ? overlayAxis.scale(averageOverlay) : 0;
|
|
38
|
+
const hasAverageSeries = Boolean(showAverage && averageSeries);
|
|
39
|
+
const hasAverageOverlay = Boolean(showAverage && averageOverlay);
|
|
40
|
+
const hasLabel = dimension.maxWidth > viewport.small.maxWidth;
|
|
41
|
+
const coordinates = useMemo(() => (isHorizontal
|
|
42
|
+
? {
|
|
43
|
+
series: {
|
|
44
|
+
from: { x: 0, y: averageSeriesScale },
|
|
45
|
+
to: { x: maxWidth, y: averageSeriesScale },
|
|
46
|
+
label: { x: 4, y: averageSeriesScale },
|
|
47
|
+
},
|
|
48
|
+
overlay: {
|
|
49
|
+
from: { x: 0, y: averageOverlayScale },
|
|
50
|
+
to: { x: maxWidth, y: averageOverlayScale },
|
|
51
|
+
label: { x: maxWidth - 4, y: averageOverlayScale },
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
: {
|
|
55
|
+
series: {
|
|
56
|
+
from: { x: averageSeriesScale, y: 0 },
|
|
57
|
+
to: { x: averageSeriesScale, y: maxHeight },
|
|
58
|
+
label: { x: averageSeriesScale, y: maxHeight - 16 },
|
|
59
|
+
},
|
|
60
|
+
overlay: {
|
|
61
|
+
from: { x: averageOverlayScale ?? 0, y: 0 },
|
|
62
|
+
to: { x: averageOverlayScale ?? 0, y: maxHeight },
|
|
63
|
+
label: { x: averageOverlayScale, y: 16 },
|
|
64
|
+
},
|
|
65
|
+
}), [isHorizontal, averageSeriesScale, maxWidth, averageOverlayScale, maxHeight]);
|
|
66
|
+
const formatAverage = (value) => value.toFixed(2);
|
|
67
|
+
return (_jsxs(_Fragment, { children: [hasAverageSeries && (_jsxs(Group, { children: [_jsx(Line, { from: coordinates.series.from, to: coordinates.series.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }), hasLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.series.label.x, y: coordinates.series.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${formatAverage(averageSeries)}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'start' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth }))] })), hasAverageOverlay && (_jsxs(Group, { children: [_jsx(Line, { from: coordinates.overlay.from, to: coordinates.overlay.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }), hasLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.overlay.label.x, y: coordinates.overlay.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${formatAverage(averageOverlay)}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'end' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth }))] }))] }));
|
|
68
|
+
};
|
|
69
|
+
LinesAverage.displayName = 'LinesAverage';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines-marker-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-marker-labels.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"lines-marker-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-marker-labels.tsx"],"names":[],"mappings":";AAmCA,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAsJrC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
3
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,20 +16,22 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
16
16
|
*/
|
|
17
17
|
import { Label } from '@visx/annotation';
|
|
18
18
|
import { Group } from '@visx/group';
|
|
19
|
+
import { useCallback } from 'react';
|
|
19
20
|
import { v4 as uuid } from 'uuid';
|
|
20
|
-
import { useCartesianContext, useDataContext, useLayoutContext, useThemeContext, } from '../../../providers';
|
|
21
|
-
import { themes } from '../../../style-config';
|
|
21
|
+
import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
|
|
22
22
|
import { getCoordinates, getMarkerLabelProps, getPrimitiveFromObjectByPath, isMarkerLabelVisible, } from '../../../utils';
|
|
23
|
-
import { LinesItem, } from './lines.module.css';
|
|
23
|
+
import { LinesItem, LinesItemBlurred, } from './lines.module.css';
|
|
24
24
|
export const LinesMarkerLabels = () => {
|
|
25
25
|
const theme = useThemeContext();
|
|
26
26
|
const { data, metadata } = useDataContext();
|
|
27
27
|
const { isHorizontal } = useLayoutContext();
|
|
28
|
-
const { axis, dimension } = useCartesianContext();
|
|
28
|
+
const { axis, dimension, hoveredLegendItem: overLegend } = useCartesianContext();
|
|
29
|
+
const { themes, viewport } = useStyleConfigContext();
|
|
29
30
|
const { index, showMarkerLabel, series, overlay, } = metadata;
|
|
30
31
|
const indexAxis = isHorizontal ? axis.bottom : axis.left;
|
|
31
32
|
const seriesAxis = isHorizontal ? axis.left : axis.bottom;
|
|
32
33
|
const overlayAxis = isHorizontal ? axis?.right : axis?.top;
|
|
34
|
+
const hasMarkerLabel = dimension.maxWidth > viewport.small.maxWidth;
|
|
33
35
|
const hasOverlay = Boolean(overlayAxis && overlay.dataKey);
|
|
34
36
|
const themeConfig = themes[theme];
|
|
35
37
|
const totalLabels = data.length;
|
|
@@ -49,7 +51,12 @@ export const LinesMarkerLabels = () => {
|
|
|
49
51
|
otherDataKey: dataKey,
|
|
50
52
|
isHorizontal,
|
|
51
53
|
});
|
|
52
|
-
|
|
54
|
+
const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
|
|
55
|
+
? LinesItem
|
|
56
|
+
: LinesItemBlurred), []);
|
|
57
|
+
if (!hasMarkerLabel)
|
|
58
|
+
return null;
|
|
59
|
+
return (_jsxs(_Fragment, { children: [series.dataKey.map((k, i) => (_jsx(Group, { className: dynamicClassName(overLegend, k), children: (showMarkerLabel || series.style?.[i]?.showMarkerLabel)
|
|
53
60
|
&& data.map((d, di) => {
|
|
54
61
|
const isVisible = isMarkerLabelVisible(di, totalLabels);
|
|
55
62
|
const title = `${getPrimitiveFromObjectByPath(d, k) ?? ''}`;
|
|
@@ -66,7 +73,7 @@ export const LinesMarkerLabels = () => {
|
|
|
66
73
|
const markerLabelProps = getMarkerLabelProps(coordinates, dimension, isHorizontal, themeConfig);
|
|
67
74
|
const { background, fontColor, fontSize, fontWeight, titleProps, anchor, verticalAnchor, padding, backgroundProps, } = markerLabelProps;
|
|
68
75
|
return (isVisible
|
|
69
|
-
? (_jsx(Label, { backgroundFill: background, x: coordinates.x, y: coordinates.y, fontColor: fontColor, title: title, titleFontSize: fontSize, titleFontWeight: fontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: anchor, verticalAnchor: verticalAnchor, showBackground: true, backgroundPadding: padding, backgroundProps: backgroundProps }, uuid())) : null);
|
|
76
|
+
? (_jsx(Label, { className: dynamicClassName(overLegend, overlay.dataKey), backgroundFill: background, x: coordinates.x, y: coordinates.y, fontColor: fontColor, title: title, titleFontSize: fontSize, titleFontWeight: fontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: anchor, verticalAnchor: verticalAnchor, showBackground: true, backgroundPadding: padding, backgroundProps: backgroundProps }, uuid())) : null);
|
|
70
77
|
})] }));
|
|
71
78
|
};
|
|
72
79
|
LinesMarkerLabels.displayName = 'LinesMarkerLabels';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-overlay.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"lines-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-overlay.tsx"],"names":[],"mappings":";AAkCA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAqFhC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
3
|
+
* Copyright 2023-2024 Wonderflow Design Team
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,17 +17,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
17
17
|
import { Group } from '@visx/group';
|
|
18
18
|
import { LinePath } from '@visx/shape';
|
|
19
19
|
import _ from 'lodash';
|
|
20
|
-
import { useMemo } from 'react';
|
|
20
|
+
import { useCallback, useMemo } from 'react';
|
|
21
21
|
import { v4 as uuid } from 'uuid';
|
|
22
22
|
import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
|
|
23
23
|
import { createSubPaths, getCoordinates, getLinesRenderer, getValueFromObjectByPath, } from '../../../utils';
|
|
24
|
-
import { LinesItem, } from './lines.module.css';
|
|
24
|
+
import { LinesItem, LinesItemBlurred, } from './lines.module.css';
|
|
25
25
|
export const LinesOverlay = () => {
|
|
26
26
|
const theme = useThemeContext();
|
|
27
27
|
const { lines: defaultStyle, themes } = useStyleConfigContext();
|
|
28
28
|
const { data, metadata } = useDataContext();
|
|
29
29
|
const { isHorizontal } = useLayoutContext();
|
|
30
|
-
const { axis } = useCartesianContext();
|
|
30
|
+
const { axis, hoveredLegendItem: overLegend } = useCartesianContext();
|
|
31
31
|
const { index, renderAs, showMarker, showMarkerLabel, overlay, hideMissingDataConnection, } = metadata;
|
|
32
32
|
const indexAxis = isHorizontal ? axis.bottom : axis.left;
|
|
33
33
|
const overlayAxis = isHorizontal ? axis?.right : axis?.top;
|
|
@@ -47,6 +47,9 @@ export const LinesOverlay = () => {
|
|
|
47
47
|
|| overlay.style?.showMarker
|
|
48
48
|
|| overlay.style?.showMarkerLabel);
|
|
49
49
|
const segmentStroke = hideMissingDataConnection ? 'transparent' : themes[theme].lines.noData;
|
|
50
|
-
|
|
50
|
+
const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
|
|
51
|
+
? LinesItem
|
|
52
|
+
: LinesItemBlurred), []);
|
|
53
|
+
return (_jsx(_Fragment, { children: hasOverlay && (subPaths.map((subPathData, si) => (_jsxs(Group, { className: dynamicClassName(overLegend, overlay.dataKey), children: [_jsx(LinePath, { "data-testid": "lines-overlay", data: subPathData, curve: renderer, x: datum => getOverlayCoordinates(datum, overlay.dataKey, isHorizontal).x, y: datum => getOverlayCoordinates(datum, overlay.dataKey, isHorizontal).y, stroke: si % 2 === 0 ? overlay.color : segmentStroke, strokeWidth: overlay.style?.strokeWidth ?? defaultStyle.path.strokeWidth, strokeOpacity: overlay.style?.strokeOpacity ?? defaultStyle.path.strokeOpacity, strokeDasharray: si % 2 === 0 ? overlay.style?.strokeDasharray : defaultStyle.segment.strokeDashArray }), hasMarker && subPathData.map((d) => (_jsx("circle", { r: defaultStyle.marker.radius, cx: getOverlayCoordinates(d, overlay.dataKey, isHorizontal).x, cy: getOverlayCoordinates(d, overlay.dataKey, isHorizontal).y, stroke: overlay.color, fill: themes[theme].marker.fill, strokeWidth: overlay.style?.strokeWidth ?? defaultStyle.marker.strokeWidth, strokeOpacity: overlay.style?.strokeOpacity ?? defaultStyle.marker.strokeOpacity }, uuid())))] }, uuid())))) }));
|
|
51
54
|
};
|
|
52
55
|
LinesOverlay.displayName = 'LinesOverlay';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-series.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"lines-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-series.tsx"],"names":[],"mappings":";AAkCA,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EA6F/B,CAAC"}
|