@redsift/charts 9.2.3 → 9.2.4
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/index.js → index.js} +2 -1
- package/index.js.map +1 -0
- package/package.json +3 -2
- package/coverage/clover.xml +0 -1096
- package/coverage/coverage-final.json +0 -60
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/components/Arc/Arc.tsx.html +0 -304
- package/coverage/lcov-report/components/Arc/index.html +0 -146
- package/coverage/lcov-report/components/Arc/index.ts.html +0 -94
- package/coverage/lcov-report/components/Arc/styles.ts.html +0 -208
- package/coverage/lcov-report/components/Arcs/Arcs.tsx.html +0 -409
- package/coverage/lcov-report/components/Arcs/index.html +0 -146
- package/coverage/lcov-report/components/Arcs/index.ts.html +0 -94
- package/coverage/lcov-report/components/Arcs/styles.ts.html +0 -106
- package/coverage/lcov-report/components/Axis/Axis.tsx.html +0 -754
- package/coverage/lcov-report/components/Axis/computeTicks.ts.html +0 -481
- package/coverage/lcov-report/components/Axis/index.html +0 -176
- package/coverage/lcov-report/components/Axis/index.ts.html +0 -94
- package/coverage/lcov-report/components/Axis/styles.ts.html +0 -148
- package/coverage/lcov-report/components/Axis/types.ts.html +0 -253
- package/coverage/lcov-report/components/Bar/Bar.tsx.html +0 -421
- package/coverage/lcov-report/components/Bar/index.html +0 -161
- package/coverage/lcov-report/components/Bar/index.ts.html +0 -94
- package/coverage/lcov-report/components/Bar/styles.ts.html +0 -247
- package/coverage/lcov-report/components/Bar/types.ts.html +0 -178
- package/coverage/lcov-report/components/BarChart/BarChart.tsx.html +0 -352
- package/coverage/lcov-report/components/BarChart/EmptyBarChart.tsx.html +0 -259
- package/coverage/lcov-report/components/BarChart/LoadingBarChart.tsx.html +0 -145
- package/coverage/lcov-report/components/BarChart/RenderedBarChart.tsx.html +0 -430
- package/coverage/lcov-report/components/BarChart/index.html +0 -206
- package/coverage/lcov-report/components/BarChart/index.ts.html +0 -94
- package/coverage/lcov-report/components/BarChart/styles.ts.html +0 -190
- package/coverage/lcov-report/components/BarChart/utils.ts.html +0 -145
- package/coverage/lcov-report/components/BottomAxis/BottomAxis.tsx.html +0 -247
- package/coverage/lcov-report/components/BottomAxis/index.html +0 -146
- package/coverage/lcov-report/components/BottomAxis/index.ts.html +0 -94
- package/coverage/lcov-report/components/BottomAxis/styles.ts.html +0 -139
- package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +0 -361
- package/coverage/lcov-report/components/ChartContainer/index.html +0 -146
- package/coverage/lcov-report/components/ChartContainer/index.ts.html +0 -94
- package/coverage/lcov-report/components/ChartContainer/intl/index.html +0 -116
- package/coverage/lcov-report/components/ChartContainer/intl/index.ts.html +0 -106
- package/coverage/lcov-report/components/ChartContainer/styles.ts.html +0 -208
- package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +0 -391
- package/coverage/lcov-report/components/DataPoint/index.html +0 -146
- package/coverage/lcov-report/components/DataPoint/index.ts.html +0 -94
- package/coverage/lcov-report/components/DataPoint/styles.ts.html +0 -109
- package/coverage/lcov-report/components/Dot/Dot.tsx.html +0 -232
- package/coverage/lcov-report/components/Dot/index.html +0 -146
- package/coverage/lcov-report/components/Dot/index.ts.html +0 -94
- package/coverage/lcov-report/components/Dot/styles.ts.html +0 -184
- package/coverage/lcov-report/components/HorizontalBar/HorizontalBar.tsx.html +0 -541
- package/coverage/lcov-report/components/HorizontalBar/index.html +0 -161
- package/coverage/lcov-report/components/HorizontalBar/index.ts.html +0 -94
- package/coverage/lcov-report/components/HorizontalBar/styles.ts.html +0 -187
- package/coverage/lcov-report/components/HorizontalBar/types.ts.html +0 -301
- package/coverage/lcov-report/components/HorizontalBarChart/HorizontalBarChart.tsx.html +0 -691
- package/coverage/lcov-report/components/HorizontalBarChart/index.html +0 -146
- package/coverage/lcov-report/components/HorizontalBarChart/index.ts.html +0 -94
- package/coverage/lcov-report/components/HorizontalBarChart/styles.ts.html +0 -196
- package/coverage/lcov-report/components/HorizontalBarChart/types.ts.html +0 -301
- package/coverage/lcov-report/components/Legend/Legend.tsx.html +0 -268
- package/coverage/lcov-report/components/Legend/index.html +0 -146
- package/coverage/lcov-report/components/Legend/index.ts.html +0 -94
- package/coverage/lcov-report/components/Legend/styles.ts.html +0 -130
- package/coverage/lcov-report/components/LegendItem/LegendItem.tsx.html +0 -325
- package/coverage/lcov-report/components/LegendItem/index.html +0 -146
- package/coverage/lcov-report/components/LegendItem/index.ts.html +0 -94
- package/coverage/lcov-report/components/LegendItem/styles.ts.html +0 -205
- package/coverage/lcov-report/components/PieChart/EmptyPieChart.tsx.html +0 -343
- package/coverage/lcov-report/components/PieChart/LoadingPieChart.tsx.html +0 -145
- package/coverage/lcov-report/components/PieChart/PieChart.tsx.html +0 -385
- package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +0 -607
- package/coverage/lcov-report/components/PieChart/index.html +0 -221
- package/coverage/lcov-report/components/PieChart/index.ts.html +0 -94
- package/coverage/lcov-report/components/PieChart/styles.ts.html +0 -370
- package/coverage/lcov-report/components/PieChart/types.ts.html +0 -367
- package/coverage/lcov-report/components/PieChart/utils.ts.html +0 -199
- package/coverage/lcov-report/components/ScatterPlot/EmptyScatterPlot.tsx.html +0 -295
- package/coverage/lcov-report/components/ScatterPlot/LoadingScatterPlot.tsx.html +0 -145
- package/coverage/lcov-report/components/ScatterPlot/RenderedScatterPlot.tsx.html +0 -1048
- package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +0 -367
- package/coverage/lcov-report/components/ScatterPlot/index.html +0 -221
- package/coverage/lcov-report/components/ScatterPlot/index.ts.html +0 -94
- package/coverage/lcov-report/components/ScatterPlot/styles.ts.html +0 -190
- package/coverage/lcov-report/components/ScatterPlot/types.ts.html +0 -394
- package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +0 -388
- package/coverage/lcov-report/core/Arc/Arc.tsx.html +0 -304
- package/coverage/lcov-report/core/Arc/index.html +0 -146
- package/coverage/lcov-report/core/Arc/index.ts.html +0 -94
- package/coverage/lcov-report/core/Arc/styles.ts.html +0 -202
- package/coverage/lcov-report/core/Arcs/Arcs.tsx.html +0 -421
- package/coverage/lcov-report/core/Arcs/index.html +0 -146
- package/coverage/lcov-report/core/Arcs/index.ts.html +0 -94
- package/coverage/lcov-report/core/Arcs/styles.ts.html +0 -106
- package/coverage/lcov-report/core/Axis/Axis.tsx.html +0 -754
- package/coverage/lcov-report/core/Axis/computeTicks.ts.html +0 -481
- package/coverage/lcov-report/core/Axis/index.html +0 -176
- package/coverage/lcov-report/core/Axis/index.ts.html +0 -94
- package/coverage/lcov-report/core/Axis/styles.ts.html +0 -145
- package/coverage/lcov-report/core/Axis/types.ts.html +0 -253
- package/coverage/lcov-report/core/Bar/Bar.tsx.html +0 -421
- package/coverage/lcov-report/core/Bar/index.html +0 -161
- package/coverage/lcov-report/core/Bar/index.ts.html +0 -94
- package/coverage/lcov-report/core/Bar/styles.ts.html +0 -190
- package/coverage/lcov-report/core/Bar/types.ts.html +0 -178
- package/coverage/lcov-report/core/BottomAxis/BottomAxis.tsx.html +0 -277
- package/coverage/lcov-report/core/BottomAxis/index.html +0 -146
- package/coverage/lcov-report/core/BottomAxis/index.ts.html +0 -94
- package/coverage/lcov-report/core/BottomAxis/styles.ts.html +0 -139
- package/coverage/lcov-report/core/ChartConfig/ChartConfig.ts.html +0 -97
- package/coverage/lcov-report/core/ChartConfig/index.html +0 -131
- package/coverage/lcov-report/core/ChartConfig/index.ts.html +0 -88
- package/coverage/lcov-report/core/ChartContainer/ChartContainer.tsx.html +0 -421
- package/coverage/lcov-report/core/ChartContainer/index.html +0 -146
- package/coverage/lcov-report/core/ChartContainer/index.ts.html +0 -94
- package/coverage/lcov-report/core/ChartContainer/intl/index.html +0 -116
- package/coverage/lcov-report/core/ChartContainer/intl/index.ts.html +0 -106
- package/coverage/lcov-report/core/ChartContainer/styles.ts.html +0 -205
- package/coverage/lcov-report/core/DataPoint/DataPoint.tsx.html +0 -442
- package/coverage/lcov-report/core/DataPoint/index.html +0 -146
- package/coverage/lcov-report/core/DataPoint/index.ts.html +0 -94
- package/coverage/lcov-report/core/DataPoint/styles.ts.html +0 -109
- package/coverage/lcov-report/core/Dot/Dot.tsx.html +0 -232
- package/coverage/lcov-report/core/Dot/index.html +0 -146
- package/coverage/lcov-report/core/Dot/index.ts.html +0 -94
- package/coverage/lcov-report/core/Dot/styles.ts.html +0 -184
- package/coverage/lcov-report/core/Legend/Legend.tsx.html +0 -277
- package/coverage/lcov-report/core/Legend/index.html +0 -146
- package/coverage/lcov-report/core/Legend/index.ts.html +0 -94
- package/coverage/lcov-report/core/Legend/styles.ts.html +0 -172
- package/coverage/lcov-report/core/Point/Point.tsx.html +0 -484
- package/coverage/lcov-report/core/Point/index.html +0 -146
- package/coverage/lcov-report/core/Point/index.ts.html +0 -94
- package/coverage/lcov-report/core/Point/styles.ts.html +0 -169
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/HorizontalBarChart.tsx.html +0 -706
- package/coverage/lcov-report/gallery/HorizontalBarChart/index.html +0 -161
- package/coverage/lcov-report/gallery/HorizontalBarChart/index.ts.html +0 -94
- package/coverage/lcov-report/gallery/HorizontalBarChart/styles.ts.html +0 -316
- package/coverage/lcov-report/gallery/HorizontalBarChart/types.ts.html +0 -310
- package/coverage/lcov-report/gallery/PieChart/PieChart.tsx.html +0 -1252
- package/coverage/lcov-report/gallery/PieChart/index.html +0 -161
- package/coverage/lcov-report/gallery/PieChart/index.ts.html +0 -94
- package/coverage/lcov-report/gallery/PieChart/styles.ts.html +0 -517
- package/coverage/lcov-report/gallery/PieChart/types.ts.html +0 -388
- package/coverage/lcov-report/gallery/ScatterPlot/index.html +0 -146
- package/coverage/lcov-report/gallery/ScatterPlot/index.ts.html +0 -94
- package/coverage/lcov-report/gallery/ScatterPlot/styles.ts.html +0 -343
- package/coverage/lcov-report/gallery/ScatterPlot/types.ts.html +0 -433
- package/coverage/lcov-report/hooks/index.html +0 -176
- package/coverage/lcov-report/hooks/index.ts.html +0 -97
- package/coverage/lcov-report/hooks/useBrush.tsx.html +0 -430
- package/coverage/lcov-report/hooks/useColor.tsx.html +0 -163
- package/coverage/lcov-report/hooks/useFormatCategoricalData.tsx.html +0 -289
- package/coverage/lcov-report/hooks/useIsEmpty.tsx.html +0 -118
- package/coverage/lcov-report/hooks/useZoom.tsx.html +0 -235
- package/coverage/lcov-report/index.html +0 -311
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -2345
- package/coverage/storybook/coverage-storybook.json +0 -79382
- package/dist/index.js.map +0 -1
- package/dist/package.json +0 -98
- package/index.ts +0 -1
- package/jest.config.js +0 -3
- package/rollup.config.js +0 -13
- package/src/components/Arc/Arc.test.tsx +0 -80
- package/src/components/Arc/Arc.tsx +0 -73
- package/src/components/Arc/index.ts +0 -3
- package/src/components/Arc/styles.ts +0 -41
- package/src/components/Arc/types.ts +0 -18
- package/src/components/Arcs/Arcs.stories.tsx +0 -177
- package/src/components/Arcs/Arcs.tsx +0 -108
- package/src/components/Arcs/index.ts +0 -3
- package/src/components/Arcs/styles.ts +0 -7
- package/src/components/Arcs/types.ts +0 -26
- package/src/components/Axis/Axis.stories.tsx +0 -297
- package/src/components/Axis/Axis.tsx +0 -223
- package/src/components/Axis/computeTicks.ts +0 -132
- package/src/components/Axis/index.ts +0 -3
- package/src/components/Axis/styles.ts +0 -21
- package/src/components/Axis/types.ts +0 -56
- package/src/components/Bar/Bar.stories.tsx +0 -152
- package/src/components/Bar/Bar.test.tsx +0 -156
- package/src/components/Bar/Bar.tsx +0 -112
- package/src/components/Bar/index.ts +0 -3
- package/src/components/Bar/styles.ts +0 -54
- package/src/components/Bar/types.ts +0 -31
- package/src/components/BarChart/BarChart.stories.tsx +0 -74
- package/src/components/BarChart/BarChart.test.tsx +0 -178
- package/src/components/BarChart/BarChart.tsx +0 -89
- package/src/components/BarChart/EmptyBarChart.tsx +0 -58
- package/src/components/BarChart/LoadingBarChart.tsx +0 -20
- package/src/components/BarChart/RenderedBarChart.tsx +0 -115
- package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +0 -7028
- package/src/components/BarChart/index.ts +0 -3
- package/src/components/BarChart/styles.ts +0 -35
- package/src/components/BarChart/types.ts +0 -58
- package/src/components/BarChart/utils.ts +0 -20
- package/src/components/ChartContainer/ChartContainer.stories.tsx +0 -81
- package/src/components/ChartContainer/ChartContainer.test.tsx +0 -71
- package/src/components/ChartContainer/ChartContainer.tsx +0 -92
- package/src/components/ChartContainer/index.ts +0 -3
- package/src/components/ChartContainer/intl/en-US.json +0 -3
- package/src/components/ChartContainer/intl/fr-FR.json +0 -3
- package/src/components/ChartContainer/intl/index.ts +0 -7
- package/src/components/ChartContainer/styles.ts +0 -41
- package/src/components/ChartContainer/types.ts +0 -26
- package/src/components/DataPoint/DataPoint.tsx +0 -102
- package/src/components/DataPoint/index.ts +0 -3
- package/src/components/DataPoint/styles.ts +0 -8
- package/src/components/DataPoint/types.ts +0 -33
- package/src/components/Dot/Dot.stories.tsx +0 -157
- package/src/components/Dot/Dot.test.tsx +0 -136
- package/src/components/Dot/Dot.tsx +0 -49
- package/src/components/Dot/index.ts +0 -3
- package/src/components/Dot/styles.ts +0 -33
- package/src/components/Dot/types.ts +0 -16
- package/src/components/Legend/Legend.stories.tsx +0 -108
- package/src/components/Legend/Legend.tsx +0 -61
- package/src/components/Legend/index.ts +0 -3
- package/src/components/Legend/styles.ts +0 -15
- package/src/components/Legend/types.ts +0 -27
- package/src/components/LegendItem/LegendItem.test.tsx +0 -69
- package/src/components/LegendItem/LegendItem.tsx +0 -80
- package/src/components/LegendItem/index.ts +0 -3
- package/src/components/LegendItem/styles.ts +0 -40
- package/src/components/LegendItem/types.ts +0 -30
- package/src/components/PieChart/EmptyPieChart.tsx +0 -86
- package/src/components/PieChart/LoadingPieChart.tsx +0 -20
- package/src/components/PieChart/PieChart.stories.tsx +0 -85
- package/src/components/PieChart/PieChart.test.tsx +0 -183
- package/src/components/PieChart/PieChart.tsx +0 -100
- package/src/components/PieChart/RenderedPieChart.tsx +0 -174
- package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +0 -21020
- package/src/components/PieChart/index.ts +0 -3
- package/src/components/PieChart/styles.ts +0 -95
- package/src/components/PieChart/types.ts +0 -94
- package/src/components/PieChart/utils.ts +0 -38
- package/src/components/ScatterPlot/EmptyScatterPlot.tsx +0 -70
- package/src/components/ScatterPlot/LoadingScatterPlot.tsx +0 -20
- package/src/components/ScatterPlot/RenderedScatterPlot.tsx +0 -321
- package/src/components/ScatterPlot/ScatterPlot.stories.tsx +0 -101
- package/src/components/ScatterPlot/ScatterPlot.test.tsx +0 -61
- package/src/components/ScatterPlot/ScatterPlot.tsx +0 -94
- package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +0 -91712
- package/src/components/ScatterPlot/index.ts +0 -3
- package/src/components/ScatterPlot/styles.ts +0 -35
- package/src/components/ScatterPlot/types.ts +0 -103
- package/src/components/ScatterPlot/utils.ts +0 -101
- package/src/config.ts +0 -10
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useBrush.tsx +0 -115
- package/src/hooks/useColor.tsx +0 -26
- package/src/hooks/useFormatCategoricalData.tsx +0 -68
- package/src/hooks/useZoom.tsx +0 -50
- package/src/index.ts +0 -15
- package/src/scheme.ts +0 -213
- package/src/types/data.ts +0 -52
- package/src/types/index.ts +0 -5
- package/src/types/legend.ts +0 -19
- package/src/types/scale.ts +0 -79
- package/src/types/size.ts +0 -17
- package/src/types/theme.ts +0 -27
- package/tsconfig.json +0 -3
- /package/{dist/CONTRIBUTING.md → CONTRIBUTING.md} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
|
|
5
|
-
import { composeStory } from '@storybook/react';
|
|
6
|
-
import Meta, { Controls } from './BarChart.stories';
|
|
7
|
-
|
|
8
|
-
import { BarChart } from './BarChart';
|
|
9
|
-
import { ChartSize, ChartTheme, ColorTheme, TooltipVariant } from '../../types';
|
|
10
|
-
import { PresentationColorPalette } from '@redsift/design-system';
|
|
11
|
-
|
|
12
|
-
jest.mock('@redsift/design-system', () => ({
|
|
13
|
-
...jest.requireActual('@redsift/design-system'),
|
|
14
|
-
useId: () => ['123'],
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const themes = {
|
|
18
|
-
...ColorTheme,
|
|
19
|
-
'success-warning-danger': {
|
|
20
|
-
success: 'Bread',
|
|
21
|
-
warning: 'Tea',
|
|
22
|
-
danger: 'Coffee',
|
|
23
|
-
},
|
|
24
|
-
'success-warning-danger-neutral': {
|
|
25
|
-
success: 'Bread',
|
|
26
|
-
warning: 'Tea',
|
|
27
|
-
danger: 'Coffee',
|
|
28
|
-
neutral: 'Pastry',
|
|
29
|
-
},
|
|
30
|
-
custom: {
|
|
31
|
-
Coffee: PresentationColorPalette.purple,
|
|
32
|
-
Bread: PresentationColorPalette.pink,
|
|
33
|
-
Tea: PresentationColorPalette.aqua,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const data = [
|
|
38
|
-
{ key: 'Dogs', value: 350 },
|
|
39
|
-
{ key: 'Cats', value: 500 },
|
|
40
|
-
{ key: 'Fish', value: 150 },
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
describe('BarChart', () => {
|
|
44
|
-
const onClickSpy = jest.fn();
|
|
45
|
-
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
onClickSpy.mockClear();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should match snapshot', () => {
|
|
51
|
-
const ComposedStory = composeStory(Controls, Meta);
|
|
52
|
-
const tree = render(
|
|
53
|
-
<>
|
|
54
|
-
{Object.values(ChartSize).map((size, i) =>
|
|
55
|
-
Object.values(TooltipVariant).map((tooltipVariant, j) => (
|
|
56
|
-
<ComposedStory
|
|
57
|
-
key={`${size}-${tooltipVariant}`}
|
|
58
|
-
tooltipVariant={tooltipVariant}
|
|
59
|
-
size={size}
|
|
60
|
-
theme={
|
|
61
|
-
Object.keys(themes)[
|
|
62
|
-
(i * Object.values(TooltipVariant).length + j) % Object.keys(themes).length
|
|
63
|
-
] as ChartTheme
|
|
64
|
-
}
|
|
65
|
-
/>
|
|
66
|
-
))
|
|
67
|
-
)}
|
|
68
|
-
</>
|
|
69
|
-
);
|
|
70
|
-
expect(tree).toMatchSnapshot();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('supports custom className', () => {
|
|
74
|
-
const tree = render(<BarChart aria-label="Chart" data={data} className="test" />);
|
|
75
|
-
const component = tree.asFragment().firstChild;
|
|
76
|
-
|
|
77
|
-
expect(component).toHaveAttribute('class', expect.stringContaining('test'));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('supports custom data attributes', () => {
|
|
81
|
-
const tree = render(<BarChart aria-label="Chart" data={data} data-testid="test" />);
|
|
82
|
-
const component = tree.asFragment().firstChild;
|
|
83
|
-
expect(component).toHaveAttribute('data-testid', 'test');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('can be labelled using a title', () => {
|
|
87
|
-
const { getByLabelText } = render(<BarChart data={data} title="Label" />);
|
|
88
|
-
const component = getByLabelText('Label');
|
|
89
|
-
expect(component).toHaveAttribute('aria-labelledby', 'id123__title');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('can be labelled using an aria-label', () => {
|
|
93
|
-
const { getByLabelText } = render(<BarChart data={data} aria-label="Label" />);
|
|
94
|
-
const component = getByLabelText('Label');
|
|
95
|
-
expect(component).toHaveAttribute('aria-label', 'Label');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('can be labelled using an aria-labelledby', () => {
|
|
99
|
-
const { getByLabelText } = render(
|
|
100
|
-
<>
|
|
101
|
-
<h1 id="123">Label</h1>
|
|
102
|
-
<BarChart data={data} aria-labelledby="123" />
|
|
103
|
-
</>
|
|
104
|
-
);
|
|
105
|
-
const component = getByLabelText('Label');
|
|
106
|
-
expect(component).toHaveAttribute('aria-labelledby', '123');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('supports click on the bars', async () => {
|
|
110
|
-
const user = userEvent.setup();
|
|
111
|
-
const { getAllByRole } = render(<BarChart aria-label="Chart" data={data} onBarClick={onClickSpy} />);
|
|
112
|
-
|
|
113
|
-
const bars = getAllByRole('button');
|
|
114
|
-
expect(bars.length).toBe(3);
|
|
115
|
-
|
|
116
|
-
await user.click(bars[0]);
|
|
117
|
-
await user.click(bars[1]);
|
|
118
|
-
await user.click(bars[2]);
|
|
119
|
-
|
|
120
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
121
|
-
data: { key: 'Cats', value: 500, percent: 0.5 },
|
|
122
|
-
});
|
|
123
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
124
|
-
data: { key: 'Dogs', value: 350, percent: 0.35 },
|
|
125
|
-
});
|
|
126
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
127
|
-
data: { key: 'Fish', value: 150, percent: 0.15 },
|
|
128
|
-
});
|
|
129
|
-
expect(onClickSpy).toHaveBeenCalledTimes(3);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('supports keydown on the bars', async () => {
|
|
133
|
-
const { getAllByRole } = render(<BarChart aria-label="Chart" data={data} onBarClick={onClickSpy} />);
|
|
134
|
-
|
|
135
|
-
const bars = getAllByRole('button');
|
|
136
|
-
expect(bars.length).toBe(3);
|
|
137
|
-
|
|
138
|
-
userEvent.keyboard('[Tab]');
|
|
139
|
-
userEvent.keyboard('[Enter]');
|
|
140
|
-
userEvent.keyboard('[Tab]');
|
|
141
|
-
userEvent.keyboard('[Space]');
|
|
142
|
-
userEvent.keyboard('[Tab]');
|
|
143
|
-
userEvent.keyboard('[Enter]');
|
|
144
|
-
|
|
145
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
146
|
-
data: { key: 'Cats', value: 500, percent: 0.5 },
|
|
147
|
-
});
|
|
148
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
149
|
-
data: { key: 'Dogs', value: 350, percent: 0.35 },
|
|
150
|
-
});
|
|
151
|
-
expect(onClickSpy).toHaveBeenCalledWith({
|
|
152
|
-
data: { key: 'Fish', value: 150, percent: 0.15 },
|
|
153
|
-
});
|
|
154
|
-
expect(onClickSpy).toHaveBeenCalledTimes(3);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('shows a tooltip when hovering on the bars ', async () => {
|
|
158
|
-
const user = userEvent.setup();
|
|
159
|
-
const { getAllByRole } = render(
|
|
160
|
-
<BarChart
|
|
161
|
-
aria-label="Chart"
|
|
162
|
-
data={data}
|
|
163
|
-
// The onBarClick gives the bar the role "button" which is then used to access the bars.
|
|
164
|
-
onBarClick={onClickSpy}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const bars = getAllByRole('button');
|
|
169
|
-
expect(bars.length).toBe(3);
|
|
170
|
-
|
|
171
|
-
await user.hover(bars[0]);
|
|
172
|
-
await waitFor(() => {
|
|
173
|
-
expect(screen.getByRole('tooltip', { exact: true })).toBeInTheDocument();
|
|
174
|
-
});
|
|
175
|
-
const tooltip = screen.getByRole('tooltip');
|
|
176
|
-
expect(tooltip.textContent).toContain('Cats');
|
|
177
|
-
});
|
|
178
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
|
|
4
|
-
import { Comp, useId } from '@redsift/design-system';
|
|
5
|
-
|
|
6
|
-
import { ChartSize, ColorTheme, TooltipVariant } from '../../types';
|
|
7
|
-
import { BarChartProps } from './types';
|
|
8
|
-
import { EmptyBarChart } from './EmptyBarChart';
|
|
9
|
-
import { LoadingBarChart } from './LoadingBarChart';
|
|
10
|
-
import { RenderedBarChart } from './RenderedBarChart';
|
|
11
|
-
|
|
12
|
-
const COMPONENT_NAME = 'BarChart';
|
|
13
|
-
const CLASSNAME = 'redsift-barchart';
|
|
14
|
-
const DEFAULT_PROPS: Partial<BarChartProps> = {
|
|
15
|
-
isBarSelected: () => true,
|
|
16
|
-
others: true,
|
|
17
|
-
size: ChartSize.medium,
|
|
18
|
-
theme: ColorTheme.default,
|
|
19
|
-
tooltipVariant: TooltipVariant.value,
|
|
20
|
-
localeText: {
|
|
21
|
-
emptyChartText: 'No Data',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const BarChart: Comp<BarChartProps, HTMLDivElement> = forwardRef((props, ref) => {
|
|
26
|
-
const {
|
|
27
|
-
areXLabelsRotated,
|
|
28
|
-
caping,
|
|
29
|
-
chartRef,
|
|
30
|
-
className,
|
|
31
|
-
data: propsData,
|
|
32
|
-
emptyComponent,
|
|
33
|
-
id: propsId,
|
|
34
|
-
isBarSelected,
|
|
35
|
-
labelDecorator,
|
|
36
|
-
localeText,
|
|
37
|
-
onBarClick,
|
|
38
|
-
others,
|
|
39
|
-
size,
|
|
40
|
-
barRole,
|
|
41
|
-
theme,
|
|
42
|
-
tooltipVariant,
|
|
43
|
-
...forwardedProps
|
|
44
|
-
} = props;
|
|
45
|
-
const [_id] = useId();
|
|
46
|
-
const id = propsId ?? _id;
|
|
47
|
-
|
|
48
|
-
if (propsData === undefined || propsData === null) {
|
|
49
|
-
return <LoadingBarChart id={id} {...forwardedProps} ref={ref} />;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (propsData.length === 0) {
|
|
53
|
-
return (
|
|
54
|
-
<EmptyBarChart
|
|
55
|
-
data={propsData}
|
|
56
|
-
emptyComponent={emptyComponent}
|
|
57
|
-
id={id}
|
|
58
|
-
localeText={localeText}
|
|
59
|
-
size={size}
|
|
60
|
-
{...forwardedProps}
|
|
61
|
-
ref={ref}
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<RenderedBarChart
|
|
68
|
-
areXLabelsRotated={areXLabelsRotated}
|
|
69
|
-
barRole={barRole}
|
|
70
|
-
caping={caping}
|
|
71
|
-
chartRef={chartRef}
|
|
72
|
-
className={classNames(BarChart.className, className)}
|
|
73
|
-
data={propsData}
|
|
74
|
-
id={id}
|
|
75
|
-
isBarSelected={isBarSelected}
|
|
76
|
-
labelDecorator={labelDecorator}
|
|
77
|
-
onBarClick={onBarClick}
|
|
78
|
-
others={others}
|
|
79
|
-
size={size}
|
|
80
|
-
theme={theme}
|
|
81
|
-
tooltipVariant={tooltipVariant}
|
|
82
|
-
{...forwardedProps}
|
|
83
|
-
ref={ref}
|
|
84
|
-
/>
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
BarChart.className = CLASSNAME;
|
|
88
|
-
BarChart.defaultProps = DEFAULT_PROPS;
|
|
89
|
-
BarChart.displayName = COMPONENT_NAME;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, RefObject, useRef } from 'react';
|
|
2
|
-
import { scaleLinear as d3scaleLinear, ScaleLinear as d3ScaleLinear } from 'd3';
|
|
3
|
-
|
|
4
|
-
import { AnyScale } from '../../types';
|
|
5
|
-
import { BarChartProps } from './types';
|
|
6
|
-
import { StyledBarChart, StyledBarChartEmptyText } from './styles';
|
|
7
|
-
import { Axis } from '../Axis';
|
|
8
|
-
import { sizeToDimension } from './utils';
|
|
9
|
-
|
|
10
|
-
export const EmptyBarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
11
|
-
(props, ref) => {
|
|
12
|
-
const { className, emptyComponent, size, localeText, ...forwardedProps } =
|
|
13
|
-
props;
|
|
14
|
-
|
|
15
|
-
const chartDimensions = sizeToDimension(size!);
|
|
16
|
-
const width = chartDimensions.width;
|
|
17
|
-
const height = chartDimensions.height;
|
|
18
|
-
const margins = { top: 16, left: 16, right: 16, bottom: 32 };
|
|
19
|
-
const chartHeight = height - margins.top - margins.bottom;
|
|
20
|
-
const chartWidth = width - margins.left - margins.right;
|
|
21
|
-
|
|
22
|
-
const scaleRef = useRef<d3ScaleLinear<number, number>>();
|
|
23
|
-
if (!scaleRef.current) {
|
|
24
|
-
scaleRef.current = d3scaleLinear().domain([]).range([0, chartWidth]);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<StyledBarChart
|
|
29
|
-
{...forwardedProps}
|
|
30
|
-
className={className}
|
|
31
|
-
ref={ref as RefObject<HTMLDivElement>}
|
|
32
|
-
>
|
|
33
|
-
{emptyComponent ?? (
|
|
34
|
-
<>
|
|
35
|
-
<StyledBarChartEmptyText
|
|
36
|
-
$maxWidth={width}
|
|
37
|
-
$textSize={chartDimensions.fontSize / 2}
|
|
38
|
-
>
|
|
39
|
-
<span>{localeText?.emptyChartText}</span>
|
|
40
|
-
</StyledBarChartEmptyText>
|
|
41
|
-
<svg width={width} height={height}>
|
|
42
|
-
<g transform={`translate(${margins.left},${margins.top})`}>
|
|
43
|
-
<Axis
|
|
44
|
-
position="bottom"
|
|
45
|
-
length={chartWidth}
|
|
46
|
-
scale={scaleRef.current as AnyScale}
|
|
47
|
-
x={0}
|
|
48
|
-
y={chartHeight}
|
|
49
|
-
tickValues={4}
|
|
50
|
-
/>
|
|
51
|
-
</g>
|
|
52
|
-
</svg>
|
|
53
|
-
</>
|
|
54
|
-
)}
|
|
55
|
-
</StyledBarChart>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
import { BarChartProps } from './types';
|
|
4
|
-
import { StyledBarChart } from './styles';
|
|
5
|
-
|
|
6
|
-
export const LoadingBarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
7
|
-
(props, ref) => {
|
|
8
|
-
const { className, ...forwardedProps } = props;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<StyledBarChart
|
|
12
|
-
{...forwardedProps}
|
|
13
|
-
className={className}
|
|
14
|
-
ref={ref as RefObject<HTMLDivElement>}
|
|
15
|
-
>
|
|
16
|
-
Loading...
|
|
17
|
-
</StyledBarChart>
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
);
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, RefObject, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { scaleLinear as d3scaleLinear, ScaleLinear as d3ScaleLinear, sum as d3sum } from 'd3';
|
|
3
|
-
|
|
4
|
-
import { AnyScale, CategoryData } from '../../types';
|
|
5
|
-
import { BarChartProps } from './types';
|
|
6
|
-
import { StyledBarChart } from './styles';
|
|
7
|
-
import { Bar } from '../Bar';
|
|
8
|
-
import { Axis } from '../Axis';
|
|
9
|
-
import { useFormatCategoricalData } from '../../hooks';
|
|
10
|
-
import { sizeToDimension } from './utils';
|
|
11
|
-
|
|
12
|
-
interface RenderedBarChartProps extends Required<Pick<BarChartProps, 'data'>>, Omit<BarChartProps, 'data'> {}
|
|
13
|
-
|
|
14
|
-
export const RenderedBarChart = forwardRef<HTMLDivElement, RenderedBarChartProps>((props, ref) => {
|
|
15
|
-
const {
|
|
16
|
-
areXLabelsRotated,
|
|
17
|
-
barProps,
|
|
18
|
-
caping,
|
|
19
|
-
className,
|
|
20
|
-
data: propsData,
|
|
21
|
-
id,
|
|
22
|
-
isBarSelected,
|
|
23
|
-
labelDecorator,
|
|
24
|
-
onBarClick,
|
|
25
|
-
others,
|
|
26
|
-
size,
|
|
27
|
-
barRole,
|
|
28
|
-
theme,
|
|
29
|
-
tooltipVariant,
|
|
30
|
-
...forwardedProps
|
|
31
|
-
} = props;
|
|
32
|
-
|
|
33
|
-
const cache = useRef<CategoryData>();
|
|
34
|
-
|
|
35
|
-
const { data, colorScale } = useFormatCategoricalData({
|
|
36
|
-
data: propsData,
|
|
37
|
-
theme: theme!,
|
|
38
|
-
caping,
|
|
39
|
-
others,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
cache.current = data;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const chartDimensions = sizeToDimension(size!);
|
|
47
|
-
const width = chartDimensions.width;
|
|
48
|
-
const height = chartDimensions.height;
|
|
49
|
-
const margins = { top: 16, left: 16, right: 16, bottom: 32 };
|
|
50
|
-
const chartHeight = height - margins.top - margins.bottom;
|
|
51
|
-
const chartWidth = width - margins.left - margins.right;
|
|
52
|
-
const numberOfRows = data.filter((datum) => datum.value).length;
|
|
53
|
-
const gap = 5;
|
|
54
|
-
|
|
55
|
-
const scale = useMemo<d3ScaleLinear<number, number>>(
|
|
56
|
-
() =>
|
|
57
|
-
d3scaleLinear()
|
|
58
|
-
.domain([0, Math.max(...data.map(({ value }) => value))])
|
|
59
|
-
.range([0, chartWidth]),
|
|
60
|
-
[size]
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const barHeight = (chartHeight - (numberOfRows + 1) * gap) / numberOfRows;
|
|
64
|
-
const total = d3sum(data, (d) => d.value);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<StyledBarChart {...forwardedProps} id={id} className={className} ref={ref as RefObject<HTMLDivElement>}>
|
|
68
|
-
<svg width={width} height={height}>
|
|
69
|
-
<g transform={`translate(${margins.left},${margins.top})`}>
|
|
70
|
-
<Axis
|
|
71
|
-
position="bottom"
|
|
72
|
-
length={chartWidth}
|
|
73
|
-
scale={scale as AnyScale}
|
|
74
|
-
x={0}
|
|
75
|
-
y={chartHeight}
|
|
76
|
-
tickValues={4}
|
|
77
|
-
tickRotation={areXLabelsRotated ? -45 : 0}
|
|
78
|
-
/>
|
|
79
|
-
{data
|
|
80
|
-
.filter((datum) => datum.value)
|
|
81
|
-
.map((datum, index) => {
|
|
82
|
-
const percent = datum.value / total;
|
|
83
|
-
const to = {
|
|
84
|
-
data: {
|
|
85
|
-
...datum,
|
|
86
|
-
percent,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
const from = cache.current ? { data: cache.current[index] } : undefined;
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<Bar
|
|
93
|
-
{...barProps}
|
|
94
|
-
color={colorScale?.(to.data.key)!}
|
|
95
|
-
data={to}
|
|
96
|
-
gap={gap}
|
|
97
|
-
height={barHeight}
|
|
98
|
-
id={`id${id}__bar-${index}`}
|
|
99
|
-
index={index}
|
|
100
|
-
isSelected={Boolean(isBarSelected!(to))}
|
|
101
|
-
key={`bar _${index}`}
|
|
102
|
-
labelDecorator={labelDecorator}
|
|
103
|
-
onClick={onBarClick}
|
|
104
|
-
previousData={from!}
|
|
105
|
-
role={barRole}
|
|
106
|
-
scale={scale!}
|
|
107
|
-
tooltipVariant={tooltipVariant}
|
|
108
|
-
/>
|
|
109
|
-
);
|
|
110
|
-
})}
|
|
111
|
-
</g>
|
|
112
|
-
</svg>
|
|
113
|
-
</StyledBarChart>
|
|
114
|
-
);
|
|
115
|
-
});
|