@wonderflow/charts 12.11.0 → 14.0.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 +35 -7
- package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/components/bar-chart/bar-chart.js +21 -46
- package/dist/components/bar-chart/bar-chart.test.js +7 -1
- package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-axis.js +10 -11
- package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-legend.js +3 -3
- package/dist/components/cartesian-base/cartesian-base.d.ts +32 -0
- package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base.js +8 -3
- package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
- package/dist/components/headings/headings.d.ts +19 -2
- package/dist/components/headings/headings.d.ts.map +1 -1
- package/dist/components/headings/headings.js +72 -6
- package/dist/components/headings/headings.module.css +1 -0
- package/dist/components/headings/headings.test.d.ts +1 -1
- package/dist/components/headings/headings.test.d.ts.map +1 -1
- package/dist/components/headings/headings.test.js +37 -3
- package/dist/components/line-chart/line-chart.d.ts +31 -15
- package/dist/components/line-chart/line-chart.d.ts.map +1 -1
- package/dist/components/line-chart/line-chart.js +5 -3
- package/dist/components/line-chart/line-chart.test.js +2 -2
- package/dist/components/loader/bar-chart-loader.d.ts.map +1 -1
- package/dist/components/loader/bar-chart-loader.js +1 -1
- package/dist/components/loader/loader.js +2 -2
- package/dist/components/loader/loader.test.js +4 -2
- package/dist/components/shapes/bars/bars-average.d.ts +3 -0
- package/dist/components/shapes/bars/bars-average.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-average.js +30 -0
- package/dist/components/shapes/bars/bars-label.d.ts +22 -0
- package/dist/components/shapes/bars/bars-label.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-label.js +35 -0
- package/dist/components/shapes/bars/bars-layout.d.ts +3 -0
- package/dist/components/shapes/bars/bars-layout.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-layout.js +36 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay-labels.js +62 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay.js +59 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series-labels.js +62 -0
- package/dist/components/shapes/bars/bars-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series.js +56 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series.js +48 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts +3 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-tooltip.js +96 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts +3 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-trendline.js +43 -0
- package/dist/components/shapes/bars/bars.d.ts.map +1 -1
- package/dist/components/shapes/bars/bars.js +27 -18
- package/dist/components/shapes/bars/bars.module.css +1 -1
- package/dist/components/shapes/bars/bars.test.js +132 -8
- package/dist/components/shapes/bars/index.d.ts +13 -0
- package/dist/components/shapes/bars/index.d.ts.map +1 -1
- package/dist/components/shapes/bars/index.js +14 -1
- package/dist/components/shapes/lines/lines-average.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-average.js +8 -46
- package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-marker-labels.js +16 -12
- package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-overlay.js +21 -26
- package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-series.js +6 -19
- package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-tooltip.js +21 -28
- package/dist/components/shapes/lines/lines-trendline.d.ts +3 -0
- package/dist/components/shapes/lines/lines-trendline.d.ts.map +1 -0
- package/dist/components/shapes/lines/lines-trendline.js +43 -0
- package/dist/components/shapes/lines/lines.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines.js +2 -1
- package/dist/components/shapes/lines/lines.test.js +29 -8
- package/dist/hooks/hooks.test.d.ts.map +1 -1
- package/dist/hooks/hooks.test.js +162 -5
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useAverage.d.ts +82 -0
- package/dist/hooks/useAverage.d.ts.map +1 -0
- package/dist/hooks/useAverage.js +83 -0
- package/dist/hooks/useBarChart.d.ts +17 -0
- package/dist/hooks/useBarChart.d.ts.map +1 -0
- package/dist/hooks/useBarChart.js +110 -0
- package/dist/hooks/useBars.d.ts +66 -0
- package/dist/hooks/useBars.d.ts.map +1 -0
- package/dist/hooks/useBars.js +121 -0
- package/dist/hooks/useCartesian.d.ts +12 -2
- package/dist/hooks/useCartesian.d.ts.map +1 -1
- package/dist/hooks/useCartesian.js +19 -7
- package/dist/hooks/useLineChart.d.ts +3 -27
- package/dist/hooks/useLineChart.d.ts.map +1 -1
- package/dist/hooks/useLineChart.js +27 -16
- package/dist/hooks/useLines.d.ts +51 -0
- package/dist/hooks/useLines.d.ts.map +1 -0
- package/dist/hooks/useLines.js +70 -0
- package/dist/hooks/useTrendline.d.ts +60 -0
- package/dist/hooks/useTrendline.d.ts.map +1 -0
- package/dist/hooks/useTrendline.js +84 -0
- package/dist/providers/cartesian.d.ts +5 -1
- package/dist/providers/cartesian.d.ts.map +1 -1
- package/dist/providers/cartesian.js +19 -3
- package/dist/providers/data.d.ts +6 -7
- package/dist/providers/data.d.ts.map +1 -1
- package/dist/providers/data.js +4 -3
- package/dist/style-config/axis.js +3 -3
- package/dist/style-config/bars.d.ts +3 -0
- package/dist/style-config/bars.d.ts.map +1 -0
- package/dist/style-config/bars.js +43 -0
- package/dist/style-config/cartesian.d.ts.map +1 -1
- package/dist/style-config/cartesian.js +2 -0
- package/dist/style-config/colors.d.ts +1 -4
- package/dist/style-config/colors.d.ts.map +1 -1
- package/dist/style-config/colors.js +30 -36
- package/dist/style-config/headings.d.ts.map +1 -1
- package/dist/style-config/headings.js +16 -1
- package/dist/style-config/lines.d.ts.map +1 -1
- package/dist/style-config/lines.js +6 -0
- package/dist/style-config/themes.d.ts.map +1 -1
- package/dist/style-config/themes.js +18 -0
- package/dist/types/bar-chart.d.ts +26 -22
- package/dist/types/bar-chart.d.ts.map +1 -1
- package/dist/types/bar-chart.js +1 -39
- package/dist/types/bars.d.ts +68 -0
- package/dist/types/bars.d.ts.map +1 -0
- package/dist/types/bars.js +16 -0
- package/dist/types/cartesian.d.ts +7 -0
- package/dist/types/cartesian.d.ts.map +1 -1
- package/dist/types/headings.d.ts +15 -0
- package/dist/types/headings.d.ts.map +1 -1
- package/dist/types/headings.js +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/line-chart.d.ts +17 -19
- package/dist/types/line-chart.d.ts.map +1 -1
- package/dist/types/lines.d.ts +6 -0
- package/dist/types/lines.d.ts.map +1 -1
- package/dist/types/main.d.ts +15 -2
- package/dist/types/main.d.ts.map +1 -1
- package/dist/types/themes.d.ts +9 -0
- package/dist/types/themes.d.ts.map +1 -1
- package/dist/utils/axis.d.ts +12 -2
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +52 -15
- package/dist/utils/axis.test.js +72 -8
- package/dist/utils/bars.d.ts +63 -0
- package/dist/utils/bars.d.ts.map +1 -0
- package/dist/utils/bars.js +316 -0
- package/dist/utils/bars.test.d.ts +2 -0
- package/dist/utils/bars.test.d.ts.map +1 -0
- package/dist/utils/bars.test.js +388 -0
- package/dist/utils/data.d.ts +14 -6
- package/dist/utils/data.d.ts.map +1 -1
- package/dist/utils/data.js +128 -21
- package/dist/utils/data.test.js +195 -86
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +2 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/lines.d.ts +3 -3
- package/dist/utils/lines.d.ts.map +1 -1
- package/dist/utils/lines.js +3 -1
- package/dist/utils/lines.test.js +26 -1
- package/dist/utils/metadata.d.ts +5 -8
- package/dist/utils/metadata.d.ts.map +1 -1
- package/dist/utils/metadata.js +8 -20
- package/dist/utils/metadata.test.js +5 -58
- package/dist/utils/viewport.test.js +8 -0
- package/package.json +13 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Except } from 'type-fest';
|
|
3
3
|
import { CartesianChartLayout, Data, SortingType, ThemeVariants } from '../../types';
|
|
4
|
-
import { BarChartIndex,
|
|
4
|
+
import { BarChartIndex, BarChartSeries } from '../../types/bar-chart';
|
|
5
5
|
import { CartesianBaseProps } from '../cartesian-base/cartesian-base';
|
|
6
6
|
export declare type BarChartProps = {
|
|
7
7
|
/**
|
|
@@ -10,6 +10,7 @@ export declare type BarChartProps = {
|
|
|
10
10
|
theme?: ThemeVariants;
|
|
11
11
|
/**
|
|
12
12
|
* Set the layout of the chart. `Index`, `Series` and eventually `Overlay` will be automatically rearranged.
|
|
13
|
+
* Layout is Horizontal when Index is on the bottom axis, and is Vertical when index is on the left one.
|
|
13
14
|
*/
|
|
14
15
|
layout?: CartesianChartLayout;
|
|
15
16
|
/**
|
|
@@ -17,16 +18,18 @@ export declare type BarChartProps = {
|
|
|
17
18
|
*/
|
|
18
19
|
data: Data;
|
|
19
20
|
/**
|
|
20
|
-
* If true bars get stacked one upon
|
|
21
|
+
* If true bars get stacked one upon the other.
|
|
21
22
|
*/
|
|
22
23
|
isStacked?: boolean;
|
|
23
24
|
/**
|
|
24
|
-
* Set
|
|
25
|
+
* Set how data should be sorted by:
|
|
25
26
|
* 'descending-key': dataKey alphabetical order;
|
|
26
|
-
* 'ascending-key': reverse
|
|
27
|
+
* 'ascending-key': dataKey reverse alphabetical order;
|
|
27
28
|
* 'descending-value': by data value;
|
|
28
29
|
* 'ascending-value': by reverse data value;
|
|
29
30
|
* 'as-is': as set in series/overlay dataKey;
|
|
31
|
+
* Values organized on different axis will be independent one from another
|
|
32
|
+
* and will be treated like independent groups sorted by the same logic.
|
|
30
33
|
*/
|
|
31
34
|
sortBy?: SortingType;
|
|
32
35
|
/**
|
|
@@ -40,15 +43,40 @@ export declare type BarChartProps = {
|
|
|
40
43
|
/**
|
|
41
44
|
* Set the properties associated with the Overlay Axis.
|
|
42
45
|
*/
|
|
43
|
-
overlay?:
|
|
46
|
+
overlay?: BarChartSeries;
|
|
44
47
|
/**
|
|
45
|
-
*
|
|
48
|
+
* Display an average line and label when `true`.
|
|
46
49
|
*/
|
|
47
|
-
|
|
50
|
+
showAverage?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Display a trend line for every single series of bars when `true`.
|
|
53
|
+
*/
|
|
54
|
+
showTrendline?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Display a background color behind the bars to highlight the entire possible occupancy area.
|
|
57
|
+
*/
|
|
58
|
+
showBackground?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Set custom content to be displayed in the tooltip below the default information.
|
|
61
|
+
*/
|
|
62
|
+
tooltipExtraContent?: React.ReactNode;
|
|
63
|
+
/**
|
|
64
|
+
* Prevent from displaying the tooltip on the chart when `true`.
|
|
65
|
+
*/
|
|
66
|
+
preventTooltipDisplay?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Show a label for every single bar.
|
|
69
|
+
*/
|
|
70
|
+
showLabel?: boolean;
|
|
48
71
|
/**
|
|
49
72
|
* Remove the padding from the chart container.
|
|
50
73
|
*/
|
|
51
74
|
hidePadding?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* If set to `true`, in the horizontal layout the bars resize up to the maximum thickness (default 24px),
|
|
77
|
+
* while in the vertical layout they have a fixed thickness, forcing the graph to resize in height.
|
|
78
|
+
*/
|
|
79
|
+
fixedBarSize?: boolean;
|
|
52
80
|
} & Except<CartesianBaseProps, 'axis' | 'axisFiltered' | 'onBrushChange'>;
|
|
53
81
|
export declare const BarChart: React.FC<BarChartProps>;
|
|
54
82
|
//# sourceMappingURL=bar-chart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/components/bar-chart/bar-chart.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/components/bar-chart/bar-chart.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAOnC,OAAO,EACL,oBAAoB,EACpB,IAAI,EACJ,WAAW,EAAE,aAAa,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAiB,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAErF,oBAAY,aAAa,GAAG;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;OASG;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,cAAc,CAAC;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,mBAAmB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACtC;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,MAAM,CAAC,kBAAkB,EAAE,MAAM,GAAG,cAAc,GAAG,eAAe,CAAC,CAAA;AAEzE,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAuE5C,CAAC"}
|
|
@@ -1,56 +1,31 @@
|
|
|
1
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';
|
|
2
|
+
import { useBarChart } from '../../hooks/useBarChart';
|
|
18
3
|
import { DataProvider, LayoutProvider, ThemeProvider, } from '../../providers';
|
|
19
|
-
import {
|
|
20
|
-
import { CartesianChartLayout, Charts, } from '../../types';
|
|
21
|
-
import { handleBarChartOverlayColor, handleBarChartSeriesColors, handleChartAxisLayout, handleChartDomainAndScaleType, handleOverlayName, handleSeriesNames, } from '../../utils';
|
|
4
|
+
import { CartesianChartLayout, } from '../../types';
|
|
22
5
|
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,
|
|
24
|
-
const isHorizontal
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const zeroPadding = hidePadding ? {
|
|
29
|
-
top: 0, right: 12, bottom: 0, left: 0,
|
|
30
|
-
} : undefined;
|
|
31
|
-
const metadata = useMemo(() => ({
|
|
32
|
-
type: Charts.BAR_CHART,
|
|
6
|
+
export const BarChart = ({ theme = 'light', layout = CartesianChartLayout.HORIZONTAL, height, isStacked = false, sortBy = 'as-is', data = [], index, series, overlay, tooltipExtraContent, preventTooltipDisplay = false, showAverage = false, showTrendline = false, showLabel = false, showBackground = false, hidePadding = false, fixedBarSize = false, ...otherProps }) => {
|
|
7
|
+
const { axis, axisFiltered, barChartLabelsMaxSize, brushFilteredData, fixedHeight, isHorizontal, metadata, zeroPadding, setBrushFilteredData, } = useBarChart({
|
|
8
|
+
theme,
|
|
9
|
+
layout,
|
|
10
|
+
height,
|
|
33
11
|
isStacked,
|
|
34
12
|
sortBy,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
color: handleBarChartOverlayColor(overlay, palette.overlay),
|
|
46
|
-
style: overlay?.style,
|
|
47
|
-
},
|
|
48
|
-
tooltip,
|
|
13
|
+
data,
|
|
14
|
+
index,
|
|
15
|
+
series,
|
|
16
|
+
overlay,
|
|
17
|
+
tooltipExtraContent,
|
|
18
|
+
preventTooltipDisplay,
|
|
19
|
+
showAverage,
|
|
20
|
+
showTrendline,
|
|
21
|
+
showLabel,
|
|
22
|
+
showBackground,
|
|
49
23
|
hidePadding,
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
fixedBarSize,
|
|
25
|
+
});
|
|
26
|
+
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: {
|
|
52
27
|
hideRows: !isHorizontal,
|
|
53
28
|
hideColumns: isHorizontal,
|
|
54
|
-
}, margin: zeroPadding, onBrushChange:
|
|
29
|
+
}, margin: zeroPadding, onBrushChange: setBrushFilteredData, overrideInnerHeight: fixedHeight, barChartLabelsMaxSize: barChartLabelsMaxSize }) }) }) }));
|
|
55
30
|
};
|
|
56
31
|
BarChart.displayName = 'BarChart';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { CartesianChartLayout } from '../../types/cartesian';
|
|
3
4
|
import { BarChart } from './bar-chart';
|
|
4
5
|
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
5
6
|
observe: jest.fn(),
|
|
@@ -8,7 +9,12 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
|
8
9
|
}));
|
|
9
10
|
describe('<BarChart>', () => {
|
|
10
11
|
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
|
+
render(_jsx(BarChart, { data: [{ date: 'a', value: 1 }, { date: 'b', value: 2 }], index: { dataKey: 'date' }, series: { dataKey: ['value'] }, overlay: { dataKey: ['value'] }, title: "Title", subtitle: "test", sortBy: "as-is", showAverage: true, showTrendline: true, fixedBarSize: true, layout: CartesianChartLayout.HORIZONTAL }));
|
|
13
|
+
const element = screen.getByTestId('cartesian');
|
|
14
|
+
expect(element).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
it('should render the component with props', () => {
|
|
17
|
+
render(_jsx(BarChart, { data: [{ date: 'a', value: 1 }, { date: 'b', value: 2 }], index: { dataKey: 'date' }, series: { dataKey: ['value'] }, overlay: { dataKey: ['value'] }, title: "Title", subtitle: "test", theme: "dark", sortBy: "descending-value", layout: CartesianChartLayout.VERTICAL }));
|
|
12
18
|
const element = screen.getByTestId('cartesian');
|
|
13
19
|
expect(element).toBeDefined();
|
|
14
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cartesian-base-axis.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-axis.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAEL,aAAa,EACd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cartesian-base-axis.d.ts","sourceRoot":"","sources":["../../../src/components/cartesian-base/cartesian-base-axis.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAEL,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAAE,UAAU,EAAiB,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AASnF,oBAAY,sBAAsB,GAAG;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAA;AAED,oBAAY,UAAU,GAAG,aAAa,CAAC,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;AAEhF,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAgF9D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2023-2024 Wonderflow Design Team
|
|
5
5
|
*
|
|
@@ -17,6 +17,7 @@ import { createElement as _createElement } from "react";
|
|
|
17
17
|
*/
|
|
18
18
|
import { Axis, } from '@visx/axis';
|
|
19
19
|
import { Group } from '@visx/group';
|
|
20
|
+
import { Text } from '@visx/text';
|
|
20
21
|
import { v4 as uuid } from 'uuid';
|
|
21
22
|
import { useStyleConfigContext, useThemeContext } from '../../providers';
|
|
22
23
|
import { handleNumberOfTicks, handleTickFormat, handleVerticalTickLabelOffset, handleVerticalTickLabelTransform, hasVerticalTickLabel, } from '../../utils/axis';
|
|
@@ -35,19 +36,17 @@ export const CartesianBaseAxis = ({ axis, axisConfig, dimension, }) => {
|
|
|
35
36
|
const numTicks = handleNumberOfTicks(xMax, yMax, a, viewport);
|
|
36
37
|
const labelOffset = orientation.labelOffset + handleVerticalTickLabelOffset(xMax, styleConfig, a);
|
|
37
38
|
const tickFormat = handleTickFormat(a);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
stroke: tick,
|
|
46
|
-
}, tickFormat: tickFormat, label: a.label, labelOffset: labelOffset, labelProps: {
|
|
39
|
+
const getTickLabelProps = (v) => ({
|
|
40
|
+
...tickLabelProps,
|
|
41
|
+
...orientation.tickLabelProps,
|
|
42
|
+
...handleVerticalTickLabelTransform(v, isVertical, a),
|
|
43
|
+
fill: tickLabel,
|
|
44
|
+
});
|
|
45
|
+
return (_createElement(Axis, { ...a, key: uuid(), numTicks: numTicks, tickLength: tickLineProps.length, tickLabelProps: getTickLabelProps, tickLineProps: { ...tickLineProps, stroke: tick }, tickFormat: tickFormat, label: a.label, labelOffset: labelOffset, labelProps: {
|
|
47
46
|
...labelProps,
|
|
48
47
|
...orientation.labelProps,
|
|
49
48
|
fill: label,
|
|
50
|
-
}, stroke: line, strokeDasharray: axisLineProps.strokeDasharray, strokeWidth: axisLineProps.strokeWidth }));
|
|
49
|
+
}, stroke: line, strokeDasharray: axisLineProps.strokeDasharray, strokeWidth: axisLineProps.strokeWidth, tickComponent: t => (_jsx(Text, { x: t.x, y: t.y, transform: `rotate(${isVertical ? 90 : 0} ${t.x} ${t.y})`, fontFamily: t.fontFamily, fontSize: t.fontSize, fontWeight: t.fontWeight, textAnchor: t.textAnchor, verticalAnchor: t.verticalAnchor, fill: t.fill, dominantBaseline: t.dominantBaseline, dx: t.dx, dy: t.dy, width: 160, children: t.formattedValue })) }));
|
|
51
50
|
}) }));
|
|
52
51
|
};
|
|
53
52
|
CartesianBaseAxis.displayName = 'CartesianBaseAxis';
|
|
@@ -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,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAA;AAED,eAAO,MAAM,mBAAmB,
|
|
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,qHAsF9B,CAAC"}
|
|
@@ -27,9 +27,9 @@ export const CartesianBaseLegend = forwardRef(({ customLegend, isVisible = true,
|
|
|
27
27
|
return (_jsx("div", { ref: forwardedRef, className: styles.Legend, role: "presentation", children: _jsx("div", { className: styles.LegendContent, children: customLegend }) }));
|
|
28
28
|
}
|
|
29
29
|
if (metadata) {
|
|
30
|
-
const { names, colors, dataKey: sdk } = metadata.series;
|
|
31
|
-
const {
|
|
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":
|
|
30
|
+
const { names: sn, colors: sc, dataKey: sdk } = metadata.series;
|
|
31
|
+
const { names: on, colors: oc, dataKey: odk } = metadata.overlay;
|
|
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": sn[i], "aria-live": "polite", "data-testid": "legend-item", onMouseOver: () => onMouseOver(s), onMouseLeave: () => onMouseOver(''), onMouseOut: () => onMouseOver(''), onFocus: () => ({}), onBlur: () => ({}), children: _jsxs("div", { children: [_jsx(Placeholder, { color: sc[i] }), _jsx("span", { children: sn[i] })] }) }, uuid()))), odk?.map((s, i) => (_jsx("li", { "aria-label": on[i], "aria-live": "polite", "data-testid": "overlay-legend-item", onMouseOver: () => onMouseOver(s), onMouseLeave: () => onMouseOver(''), onMouseOut: () => onMouseOver(''), onFocus: () => ({}), onBlur: () => ({}), children: _jsxs("div", { children: [_jsx(Placeholder, { color: oc[i] }), _jsx("span", { children: on[i] })] }) }, uuid())))] }) }) }));
|
|
33
33
|
}
|
|
34
34
|
return null;
|
|
35
35
|
});
|
|
@@ -17,6 +17,10 @@ export declare type CartesianBaseProps = {
|
|
|
17
17
|
* Set headings custom position and style.
|
|
18
18
|
*/
|
|
19
19
|
headings?: Pick<HeadingsProps, 'top' | 'left' | 'config'>;
|
|
20
|
+
/**
|
|
21
|
+
* Set the content for the popup menu.
|
|
22
|
+
*/
|
|
23
|
+
menu?: React.ReactNode;
|
|
20
24
|
/**
|
|
21
25
|
* Set the Cartesian component width. 800px is the default value.
|
|
22
26
|
*/
|
|
@@ -73,6 +77,34 @@ export declare type CartesianBaseProps = {
|
|
|
73
77
|
* Set a custom `Legend` content.
|
|
74
78
|
*/
|
|
75
79
|
customLegend?: React.ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* By default, the data will grow from the lower left Cartesian
|
|
82
|
+
* origin ({x:0, y:0}) in both the horizontal and vertical
|
|
83
|
+
* layouts, so that the values will increase upward and
|
|
84
|
+
* rightward. By setting this parameter `true`, the order of the
|
|
85
|
+
* index will be reversed, but only in the vertical layout (left
|
|
86
|
+
* axis).
|
|
87
|
+
*/
|
|
88
|
+
reverseIndex?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* When set to 'true' zero will be in the middle of the axis and
|
|
91
|
+
* the positive and negative domain value will equal to +/- the
|
|
92
|
+
* max absolute value (eg. [10, -100] will be [100, -100]).
|
|
93
|
+
*/
|
|
94
|
+
mirrorDomains?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* This value is used to override the dynamic height of the
|
|
97
|
+
* chart, intended as the dimension of axis and grid. It is
|
|
98
|
+
* different from the height property which computes all the
|
|
99
|
+
* subcomponents dimension and is equal to the total external
|
|
100
|
+
* chart height.
|
|
101
|
+
*/
|
|
102
|
+
overrideInnerHeight?: number;
|
|
103
|
+
/**
|
|
104
|
+
* This value is used to compute the space necessary to store the labels
|
|
105
|
+
* on the far right side of the grid, when the bar chart has a vertical layout.
|
|
106
|
+
*/
|
|
107
|
+
barChartLabelsMaxSize?: number;
|
|
76
108
|
/**
|
|
77
109
|
* Set custom styling properties.
|
|
78
110
|
*/
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB;;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;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,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,wFAqPxB,CAAC"}
|
|
@@ -42,8 +42,8 @@ export const CartesianBase = forwardRef(({ width = 800, height = 600, preventRes
|
|
|
42
42
|
}, grid = {
|
|
43
43
|
hideColumns: false,
|
|
44
44
|
hideRows: false,
|
|
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({
|
|
45
|
+
}, title, subtitle, headings, menu, axis, axisFiltered, showBrush = false, hideLegend = false, emptyState, emptyStateMessage, customLegend, reverseIndex, mirrorDomains, overrideInnerHeight, barChartLabelsMaxSize, styleConfig, className, style, otherProps, onBrushChange, }, forwardedRef) => {
|
|
46
|
+
const { axisConfig, axisFilteredSystem, axisSystem, bgFrom, bgTo, brushSize, brushPadding, cartesianConfig, dimension, dynamicHeight, dynamicWidth, dynamicStyle, hasBrush, hasData, hasLegend, hasReversedIndex, hasMirroredDomainsHorizontal, hasMirroredDomainsVertical, filteredData, hasEmptyState, hoveredLegendItem, isMenuOpen, metadata, position, ref, refLegend, theme, setHoveredLegendItem, setIsMenuOpen, } = useCartesian({
|
|
47
47
|
axis,
|
|
48
48
|
axisFiltered,
|
|
49
49
|
background,
|
|
@@ -53,11 +53,16 @@ export const CartesianBase = forwardRef(({ width = 800, height = 600, preventRes
|
|
|
53
53
|
isLoading,
|
|
54
54
|
margin,
|
|
55
55
|
preventResponsive,
|
|
56
|
+
reverseIndex,
|
|
57
|
+
mirrorDomains,
|
|
58
|
+
overrideInnerHeight,
|
|
59
|
+
barChartLabelsMaxSize,
|
|
56
60
|
showBrush,
|
|
57
61
|
styleConfig,
|
|
58
62
|
title,
|
|
63
|
+
menu,
|
|
59
64
|
width,
|
|
60
65
|
});
|
|
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, {
|
|
66
|
+
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("defs", { children: _jsx("filter", { id: "filter_multiply", filterUnits: "objectBoundingBox", x: "0%", y: "0%", width: "100%", height: "100%", children: _jsx("feBlend", { in: "SourceGraphic", mode: "multiply" }) }) }), _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, width: dynamicWidth, margin: margin, menu: menu, config: headings?.config, onMenuOpen: setIsMenuOpen, "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, preventTooltipOpening: isMenuOpen, hasReversedIndex: hasReversedIndex, hasMirroredDomainsHorizontal: hasMirroredDomainsHorizontal, hasMirroredDomainsVertical: hasMirroredDomainsVertical, children: _jsx(DataProvider, { data: filteredData, metadata: metadata, filteredData: filteredData, children: _jsxs(Group, { 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
67
|
});
|
|
63
68
|
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:.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
|
+
.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;flex-grow:1;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,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { HeadingsStyleConfig } from '../../types';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeadingsStyleConfig, MarginProps } from '../../types';
|
|
3
3
|
import { DeepPartial } from '../../types/main';
|
|
4
4
|
export declare type HeadingsProps = {
|
|
5
5
|
/**
|
|
@@ -18,10 +18,27 @@ export declare type HeadingsProps = {
|
|
|
18
18
|
* Set the position from left (X axis).
|
|
19
19
|
*/
|
|
20
20
|
left?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Set margin using an object with `top`, `right`, `bottom` and `left` position.
|
|
23
|
+
*/
|
|
24
|
+
margin?: MarginProps;
|
|
25
|
+
/**
|
|
26
|
+
* Set the max width of the component.
|
|
27
|
+
*/
|
|
28
|
+
width?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Set the content of the menu popup.
|
|
31
|
+
*/
|
|
32
|
+
menu?: React.ReactNode;
|
|
21
33
|
/**
|
|
22
34
|
* Set custom headings style attributes.
|
|
23
35
|
*/
|
|
24
36
|
config?: DeepPartial<HeadingsStyleConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* This callback is used to inform about the menu state
|
|
39
|
+
* in order to prevent both menu and tooltip to be open at the same time
|
|
40
|
+
*/
|
|
41
|
+
onMenuOpen: (isOpen: boolean) => void;
|
|
25
42
|
};
|
|
26
43
|
export declare const Headings: React.FC<HeadingsProps>;
|
|
27
44
|
//# sourceMappingURL=headings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headings.d.ts","sourceRoot":"","sources":["../../../src/components/headings/headings.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"headings.d.ts","sourceRoot":"","sources":["../../../src/components/headings/headings.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAEN,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,oBAAY,aAAa,GAAG;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC;IAC1C;;;OAGG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAiM5C,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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.
|
|
@@ -16,16 +16,82 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
16
16
|
*/
|
|
17
17
|
import { Group } from '@visx/group';
|
|
18
18
|
import { Text } from '@visx/text';
|
|
19
|
+
import { defaultStyles, useTooltip, useTooltipInPortal } from '@visx/tooltip';
|
|
20
|
+
import { useClickAway, useKeyPress } from 'ahooks';
|
|
19
21
|
import _ from 'lodash';
|
|
20
|
-
import { useMemo } from 'react';
|
|
22
|
+
import { useCallback, useMemo, useRef, useState, } from 'react';
|
|
23
|
+
import { v4 as uuid } from 'uuid';
|
|
24
|
+
import { useSSR } from '../../hooks/useSSR';
|
|
21
25
|
import { useStyleConfigContext, useThemeContext } from '../../providers';
|
|
22
|
-
|
|
26
|
+
import styles from './headings.module.css';
|
|
27
|
+
export const Headings = ({ title, subtitle, top = 0, left = 0, width = 800, margin, menu, config, onMenuOpen, }) => {
|
|
23
28
|
const theme = useThemeContext();
|
|
24
29
|
const { headings, themes } = useStyleConfigContext();
|
|
30
|
+
const { isBrowser } = useSSR();
|
|
31
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
32
|
+
const menuRef = useRef(null);
|
|
33
|
+
const menuStyle = { ...defaultStyles, ...headings.menu };
|
|
25
34
|
const mergeStyle = useMemo(() => (_.merge(headings, config)), [headings, config]);
|
|
26
35
|
const { title: t, subtitle: s } = mergeStyle;
|
|
27
|
-
|
|
36
|
+
const hasMenu = Boolean(menu && isBrowser);
|
|
37
|
+
const hasMarginRight = (margin && margin.right >= 24);
|
|
38
|
+
const buttonSize = 24;
|
|
39
|
+
const padding = hasMarginRight ? margin.right : 0;
|
|
40
|
+
const buttonLeft = width - buttonSize - padding;
|
|
41
|
+
const { foreground: fg, background: bg, hover } = themes[theme].headings.button;
|
|
42
|
+
const { showTooltip } = useTooltip();
|
|
43
|
+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
|
|
44
|
+
detectBounds: true,
|
|
45
|
+
scroll: true,
|
|
46
|
+
debounce: 500,
|
|
47
|
+
zIndex: 4,
|
|
48
|
+
});
|
|
49
|
+
const tLeft = width + (hasMarginRight ? 0 : buttonSize);
|
|
50
|
+
const tTop = top + buttonSize * 1.5;
|
|
51
|
+
const handleTooltip = useCallback(() => {
|
|
52
|
+
showTooltip({
|
|
53
|
+
tooltipLeft: tLeft,
|
|
54
|
+
tooltipTop: tTop,
|
|
55
|
+
tooltipData: menu,
|
|
56
|
+
});
|
|
57
|
+
}, [menu, showTooltip, tLeft, tTop]);
|
|
58
|
+
const handleTooltipToggle = () => {
|
|
59
|
+
handleTooltip();
|
|
60
|
+
setIsOpen(prev => !prev);
|
|
61
|
+
onMenuOpen(!isOpen);
|
|
62
|
+
};
|
|
63
|
+
const handleTooltipOpen = () => {
|
|
64
|
+
handleTooltip();
|
|
65
|
+
setIsOpen(true);
|
|
66
|
+
onMenuOpen(true);
|
|
67
|
+
};
|
|
68
|
+
const handleTooltipClose = () => {
|
|
69
|
+
handleTooltip();
|
|
70
|
+
setIsOpen(false);
|
|
71
|
+
onMenuOpen(false);
|
|
72
|
+
};
|
|
73
|
+
const handleKeyDown = (event) => {
|
|
74
|
+
if (hasMenu
|
|
75
|
+
&& !isOpen
|
|
76
|
+
&& (event.key === 'Enter' || event.key === 'ArrowDown'))
|
|
77
|
+
handleTooltipOpen();
|
|
78
|
+
};
|
|
79
|
+
useKeyPress('Esc', () => {
|
|
80
|
+
if (hasMenu && isOpen)
|
|
81
|
+
handleTooltipClose();
|
|
82
|
+
});
|
|
83
|
+
const counter = useRef(0);
|
|
84
|
+
useClickAway(() => {
|
|
85
|
+
if (counter.current) {
|
|
86
|
+
handleTooltipClose();
|
|
87
|
+
counter.current = 0;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
counter.current = 1;
|
|
91
|
+
}
|
|
92
|
+
}, menuRef);
|
|
93
|
+
if (!title && !menu)
|
|
28
94
|
return null;
|
|
29
|
-
return (_jsxs(Group, { top: top, left: left, children: [_jsx(Text, { "data-testid": "headings", fontFamily: mergeStyle.fontFamily, fill: themes[theme].headings.title, fontSize: t.fontSize, fontWeight: t.fontWeight, lineHeight: t.lineHeight, textAnchor: t.textAnchor, verticalAnchor: t.verticalAnchor, x: t.x, y: t.y, dy: 4, children: title }), _jsx(Text, { fontFamily: mergeStyle.fontFamily, fill: themes[theme].headings.subtitle, fontSize: s.fontSize, fontWeight: s.fontWeight, lineHeight: s.lineHeight, textAnchor: s.textAnchor, verticalAnchor: s.verticalAnchor, x: s.x, y: s.y, dy: 4, children: subtitle })] }));
|
|
95
|
+
return (_jsxs(_Fragment, { children: [title && (_jsxs(Group, { top: top, left: left, children: [_jsx(Text, { "data-testid": "headings", fontFamily: mergeStyle.fontFamily, fill: themes[theme].headings.title, fontSize: t.fontSize, fontWeight: t.fontWeight, lineHeight: t.lineHeight, textAnchor: t.textAnchor, verticalAnchor: t.verticalAnchor, x: t.x, y: t.y, dy: 4, children: title }), _jsx(Text, { fontFamily: mergeStyle.fontFamily, fill: themes[theme].headings.subtitle, fontSize: s.fontSize, fontWeight: s.fontWeight, lineHeight: s.lineHeight, textAnchor: s.textAnchor, verticalAnchor: s.verticalAnchor, x: s.x, y: s.y, dy: 4, children: subtitle })] })), hasMenu && (_jsx(Group, { top: top, left: buttonLeft, className: styles.Menu, ref: containerRef, onClick: handleTooltipToggle, focusable: true, tabIndex: 0, onKeyDown: e => handleKeyDown(e), "data-testid": "menu-button", children: _jsxs("svg", { width: buttonSize, height: buttonSize, viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", "aria-label": "Chart Menu", children: [_jsx("circle", { cx: buttonSize / 2, cy: buttonSize / 2, r: buttonSize / 2, fill: bg }), _jsx("circle", { cx: buttonSize / 2, cy: buttonSize / 2, r: buttonSize / 2, fill: hover, className: styles.ActiveArea }), _jsx("g", { transform: "scale(0.75 0.75) translate(4 4)", children: _jsx("path", { d: "M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2Zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Z", fill: fg }) })] }) })), hasMenu && isOpen && (_jsx(TooltipInPortal, { left: tLeft, top: tTop, style: menuStyle, "aria-expanded": isOpen, children: _jsx("div", { className: "ChartMenu", "data-inner-component": "ChartMenu", role: "menu", "aria-live": "polite", ref: menuRef, "data-testid": "menu", children: menu }) }, uuid()))] }));
|
|
30
96
|
};
|
|
31
97
|
Headings.displayName = 'ChartHeadings';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.Menu{.ActiveArea{visibility:hidden}}.Menu:active{outline:none}.Menu:hover{cursor:pointer}.Menu:hover .ActiveArea{visibility:visible}@media print{.ActiveArea,.ChartMenu,.Menu{visibility:hidden}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
2
|
//# sourceMappingURL=headings.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headings.test.d.ts","sourceRoot":"","sources":["../../../src/components/headings/headings.test.tsx"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"headings.test.d.ts","sourceRoot":"","sources":["../../../src/components/headings/headings.test.tsx"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -1,14 +1,48 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { fireEvent, render, screen, } from '@testing-library/react';
|
|
3
4
|
import { Headings } from './headings';
|
|
5
|
+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
6
|
+
observe: jest.fn(),
|
|
7
|
+
unobserve: jest.fn(),
|
|
8
|
+
disconnect: jest.fn(),
|
|
9
|
+
}));
|
|
4
10
|
describe('<Headings>', () => {
|
|
5
11
|
it('should render the component', () => {
|
|
6
|
-
render(_jsx(Headings, { title: "Title" }));
|
|
12
|
+
render(_jsx(Headings, { title: "Title", onMenuOpen: () => ({}) }));
|
|
7
13
|
const element = screen.getByTestId('headings');
|
|
8
14
|
expect(element).toBeDefined();
|
|
9
15
|
});
|
|
10
16
|
it('should NOT render the component w/o title', () => {
|
|
11
|
-
const { container } = render(_jsx(Headings, {}));
|
|
17
|
+
const { container } = render(_jsx(Headings, { onMenuOpen: () => ({}) }));
|
|
12
18
|
expect(container.firstChild).toBeNull();
|
|
13
19
|
});
|
|
20
|
+
it('should render menu button and open menu on click and close at key down', () => {
|
|
21
|
+
const spyOnMenu = jest.fn();
|
|
22
|
+
const { getByTestId, queryByTestId } = render(_jsx(Headings, { onMenuOpen: spyOnMenu, menu: "some content here" }));
|
|
23
|
+
expect(getByTestId('menu-button')).toBeDefined();
|
|
24
|
+
fireEvent.click(getByTestId('menu-button'));
|
|
25
|
+
expect(spyOnMenu).toHaveBeenCalledTimes(1);
|
|
26
|
+
expect(getByTestId('menu')).toBeDefined();
|
|
27
|
+
fireEvent.keyDown(document, {
|
|
28
|
+
key: 'Escape',
|
|
29
|
+
code: 'Escape',
|
|
30
|
+
keyCode: 27,
|
|
31
|
+
charCode: 27,
|
|
32
|
+
});
|
|
33
|
+
expect(queryByTestId('menu')).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
it('should open when hit Enter on focus and close on click away', () => {
|
|
36
|
+
const { queryByTestId } = render(_jsx(Headings, { onMenuOpen: () => ({}), menu: "some content here" }));
|
|
37
|
+
expect(queryByTestId('menu')).toBeNull();
|
|
38
|
+
fireEvent.keyDown(document, {
|
|
39
|
+
key: 'Enter',
|
|
40
|
+
code: 'Enter',
|
|
41
|
+
keyCode: 13,
|
|
42
|
+
charCode: 13,
|
|
43
|
+
});
|
|
44
|
+
expect(queryByTestId('menu')).toBeDefined();
|
|
45
|
+
fireEvent.click(document);
|
|
46
|
+
expect(queryByTestId('menu')).toBeNull();
|
|
47
|
+
});
|
|
14
48
|
});
|