@redsift/charts 8.0.1 → 8.0.2

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.
Files changed (217) hide show
  1. package/{dist/index.d.ts → index.d.ts} +8 -0
  2. package/{dist/index.js → index.js} +97 -25
  3. package/index.js.map +1 -0
  4. package/package.json +3 -2
  5. package/coverage/clover.xml +0 -1070
  6. package/coverage/coverage-final.json +0 -60
  7. package/coverage/lcov-report/ChartEmptyState/ChartEmptyState.tsx.html +0 -679
  8. package/coverage/lcov-report/ChartEmptyState/index.html +0 -146
  9. package/coverage/lcov-report/ChartEmptyState/index.ts.html +0 -91
  10. package/coverage/lcov-report/ChartEmptyState/styles.ts.html +0 -184
  11. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChart.tsx.html +0 -775
  12. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartAxisBottom.tsx.html +0 -259
  13. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartBar.tsx.html +0 -421
  14. package/coverage/lcov-report/HorizontalBarChart/index.html +0 -191
  15. package/coverage/lcov-report/HorizontalBarChart/index.ts.html +0 -94
  16. package/coverage/lcov-report/HorizontalBarChart/styles.ts.html +0 -451
  17. package/coverage/lcov-report/HorizontalBarChart/types.ts.html +0 -433
  18. package/coverage/lcov-report/PieChart/PieChart.tsx.html +0 -1105
  19. package/coverage/lcov-report/PieChart/PieChartArc.tsx.html +0 -412
  20. package/coverage/lcov-report/PieChart/index.html +0 -176
  21. package/coverage/lcov-report/PieChart/index.ts.html +0 -94
  22. package/coverage/lcov-report/PieChart/styles.ts.html +0 -616
  23. package/coverage/lcov-report/PieChart/types.ts.html +0 -472
  24. package/coverage/lcov-report/PieChart.tsx.html +0 -1045
  25. package/coverage/lcov-report/PieChartArc.tsx.html +0 -271
  26. package/coverage/lcov-report/StaticPieChart.tsx.html +0 -286
  27. package/coverage/lcov-report/base.css +0 -224
  28. package/coverage/lcov-report/block-navigation.js +0 -87
  29. package/coverage/lcov-report/components/Arc/Arc.tsx.html +0 -304
  30. package/coverage/lcov-report/components/Arc/index.html +0 -146
  31. package/coverage/lcov-report/components/Arc/index.ts.html +0 -94
  32. package/coverage/lcov-report/components/Arc/styles.ts.html +0 -208
  33. package/coverage/lcov-report/components/Arcs/Arcs.tsx.html +0 -427
  34. package/coverage/lcov-report/components/Arcs/index.html +0 -146
  35. package/coverage/lcov-report/components/Arcs/index.ts.html +0 -94
  36. package/coverage/lcov-report/components/Arcs/styles.ts.html +0 -106
  37. package/coverage/lcov-report/components/Axis/Axis.tsx.html +0 -754
  38. package/coverage/lcov-report/components/Axis/computeTicks.ts.html +0 -481
  39. package/coverage/lcov-report/components/Axis/index.html +0 -176
  40. package/coverage/lcov-report/components/Axis/index.ts.html +0 -94
  41. package/coverage/lcov-report/components/Axis/styles.ts.html +0 -148
  42. package/coverage/lcov-report/components/Axis/types.ts.html +0 -253
  43. package/coverage/lcov-report/components/Bar/Bar.tsx.html +0 -421
  44. package/coverage/lcov-report/components/Bar/index.html +0 -161
  45. package/coverage/lcov-report/components/Bar/index.ts.html +0 -94
  46. package/coverage/lcov-report/components/Bar/styles.ts.html +0 -247
  47. package/coverage/lcov-report/components/Bar/types.ts.html +0 -178
  48. package/coverage/lcov-report/components/BarChart/BarChart.tsx.html +0 -355
  49. package/coverage/lcov-report/components/BarChart/EmptyBarChart.tsx.html +0 -259
  50. package/coverage/lcov-report/components/BarChart/LoadingBarChart.tsx.html +0 -145
  51. package/coverage/lcov-report/components/BarChart/RenderedBarChart.tsx.html +0 -496
  52. package/coverage/lcov-report/components/BarChart/index.html +0 -206
  53. package/coverage/lcov-report/components/BarChart/index.ts.html +0 -94
  54. package/coverage/lcov-report/components/BarChart/styles.ts.html +0 -190
  55. package/coverage/lcov-report/components/BarChart/utils.ts.html +0 -145
  56. package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +0 -433
  57. package/coverage/lcov-report/components/ChartContainer/index.html +0 -146
  58. package/coverage/lcov-report/components/ChartContainer/index.ts.html +0 -94
  59. package/coverage/lcov-report/components/ChartContainer/intl/index.html +0 -116
  60. package/coverage/lcov-report/components/ChartContainer/intl/index.ts.html +0 -106
  61. package/coverage/lcov-report/components/ChartContainer/styles.ts.html +0 -211
  62. package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +0 -442
  63. package/coverage/lcov-report/components/DataPoint/index.html +0 -146
  64. package/coverage/lcov-report/components/DataPoint/index.ts.html +0 -94
  65. package/coverage/lcov-report/components/DataPoint/styles.ts.html +0 -109
  66. package/coverage/lcov-report/components/Dot/Dot.tsx.html +0 -232
  67. package/coverage/lcov-report/components/Dot/index.html +0 -146
  68. package/coverage/lcov-report/components/Dot/index.ts.html +0 -94
  69. package/coverage/lcov-report/components/Dot/styles.ts.html +0 -184
  70. package/coverage/lcov-report/components/Legend/Legend.tsx.html +0 -268
  71. package/coverage/lcov-report/components/Legend/index.html +0 -146
  72. package/coverage/lcov-report/components/Legend/index.ts.html +0 -94
  73. package/coverage/lcov-report/components/Legend/styles.ts.html +0 -130
  74. package/coverage/lcov-report/components/LegendItem/LegendItem.tsx.html +0 -403
  75. package/coverage/lcov-report/components/LegendItem/index.html +0 -146
  76. package/coverage/lcov-report/components/LegendItem/index.ts.html +0 -94
  77. package/coverage/lcov-report/components/LegendItem/styles.ts.html +0 -205
  78. package/coverage/lcov-report/components/PieChart/EmptyPieChart.tsx.html +0 -343
  79. package/coverage/lcov-report/components/PieChart/LoadingPieChart.tsx.html +0 -145
  80. package/coverage/lcov-report/components/PieChart/PieChart.tsx.html +0 -388
  81. package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +0 -571
  82. package/coverage/lcov-report/components/PieChart/index.html +0 -221
  83. package/coverage/lcov-report/components/PieChart/index.ts.html +0 -94
  84. package/coverage/lcov-report/components/PieChart/styles.ts.html +0 -376
  85. package/coverage/lcov-report/components/PieChart/types.ts.html +0 -352
  86. package/coverage/lcov-report/components/PieChart/utils.ts.html +0 -199
  87. package/coverage/lcov-report/components/ScatterPlot/EmptyScatterPlot.tsx.html +0 -295
  88. package/coverage/lcov-report/components/ScatterPlot/LoadingScatterPlot.tsx.html +0 -145
  89. package/coverage/lcov-report/components/ScatterPlot/RenderedScatterPlot.tsx.html +0 -910
  90. package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +0 -379
  91. package/coverage/lcov-report/components/ScatterPlot/index.html +0 -221
  92. package/coverage/lcov-report/components/ScatterPlot/index.ts.html +0 -94
  93. package/coverage/lcov-report/components/ScatterPlot/styles.ts.html +0 -196
  94. package/coverage/lcov-report/components/ScatterPlot/types.ts.html +0 -376
  95. package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +0 -388
  96. package/coverage/lcov-report/favicon.png +0 -0
  97. package/coverage/lcov-report/hooks/index.html +0 -176
  98. package/coverage/lcov-report/hooks/index.ts.html +0 -97
  99. package/coverage/lcov-report/hooks/useBrush.tsx.html +0 -430
  100. package/coverage/lcov-report/hooks/useColor.tsx.html +0 -163
  101. package/coverage/lcov-report/hooks/useFormatCategoricalData.tsx.html +0 -289
  102. package/coverage/lcov-report/hooks/useZoom.tsx.html +0 -235
  103. package/coverage/lcov-report/index.html +0 -311
  104. package/coverage/lcov-report/index.ts.html +0 -94
  105. package/coverage/lcov-report/prettify.css +0 -1
  106. package/coverage/lcov-report/prettify.js +0 -2
  107. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  108. package/coverage/lcov-report/sorter.js +0 -196
  109. package/coverage/lcov-report/styles.ts.html +0 -631
  110. package/coverage/lcov-report/types.ts.html +0 -457
  111. package/coverage/lcov.info +0 -2272
  112. package/dist/index.js.map +0 -1
  113. package/dist/package.json +0 -98
  114. package/index.ts +0 -1
  115. package/jest.config.js +0 -3
  116. package/rollup.config.js +0 -13
  117. package/src/components/Arc/Arc.test.tsx +0 -92
  118. package/src/components/Arc/Arc.tsx +0 -73
  119. package/src/components/Arc/index.ts +0 -3
  120. package/src/components/Arc/styles.ts +0 -41
  121. package/src/components/Arc/types.ts +0 -18
  122. package/src/components/Arcs/Arcs.stories.tsx +0 -177
  123. package/src/components/Arcs/Arcs.tsx +0 -114
  124. package/src/components/Arcs/index.ts +0 -3
  125. package/src/components/Arcs/styles.ts +0 -7
  126. package/src/components/Arcs/types.ts +0 -26
  127. package/src/components/Axis/Axis.stories.tsx +0 -297
  128. package/src/components/Axis/Axis.tsx +0 -223
  129. package/src/components/Axis/computeTicks.ts +0 -132
  130. package/src/components/Axis/index.ts +0 -3
  131. package/src/components/Axis/styles.ts +0 -21
  132. package/src/components/Axis/types.ts +0 -56
  133. package/src/components/Bar/Bar.stories.tsx +0 -152
  134. package/src/components/Bar/Bar.test.tsx +0 -158
  135. package/src/components/Bar/Bar.tsx +0 -112
  136. package/src/components/Bar/index.ts +0 -3
  137. package/src/components/Bar/styles.ts +0 -54
  138. package/src/components/Bar/types.ts +0 -31
  139. package/src/components/BarChart/BarChart.stories.tsx +0 -80
  140. package/src/components/BarChart/BarChart.test.tsx +0 -189
  141. package/src/components/BarChart/BarChart.tsx +0 -90
  142. package/src/components/BarChart/EmptyBarChart.tsx +0 -58
  143. package/src/components/BarChart/LoadingBarChart.tsx +0 -20
  144. package/src/components/BarChart/RenderedBarChart.tsx +0 -137
  145. package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +0 -6932
  146. package/src/components/BarChart/index.ts +0 -3
  147. package/src/components/BarChart/styles.ts +0 -35
  148. package/src/components/BarChart/types.ts +0 -58
  149. package/src/components/BarChart/utils.ts +0 -20
  150. package/src/components/ChartContainer/ChartContainer.stories.tsx +0 -81
  151. package/src/components/ChartContainer/ChartContainer.test.tsx +0 -75
  152. package/src/components/ChartContainer/ChartContainer.tsx +0 -116
  153. package/src/components/ChartContainer/index.ts +0 -3
  154. package/src/components/ChartContainer/intl/en-US.json +0 -3
  155. package/src/components/ChartContainer/intl/fr-FR.json +0 -3
  156. package/src/components/ChartContainer/intl/index.ts +0 -7
  157. package/src/components/ChartContainer/styles.ts +0 -42
  158. package/src/components/ChartContainer/types.ts +0 -24
  159. package/src/components/DataPoint/DataPoint.tsx +0 -119
  160. package/src/components/DataPoint/index.ts +0 -3
  161. package/src/components/DataPoint/styles.ts +0 -8
  162. package/src/components/DataPoint/types.ts +0 -33
  163. package/src/components/Dot/Dot.stories.tsx +0 -157
  164. package/src/components/Dot/Dot.test.tsx +0 -136
  165. package/src/components/Dot/Dot.tsx +0 -49
  166. package/src/components/Dot/index.ts +0 -3
  167. package/src/components/Dot/styles.ts +0 -33
  168. package/src/components/Dot/types.ts +0 -16
  169. package/src/components/Legend/Legend.stories.tsx +0 -108
  170. package/src/components/Legend/Legend.tsx +0 -61
  171. package/src/components/Legend/index.ts +0 -3
  172. package/src/components/Legend/styles.ts +0 -15
  173. package/src/components/Legend/types.ts +0 -27
  174. package/src/components/LegendItem/LegendItem.test.tsx +0 -69
  175. package/src/components/LegendItem/LegendItem.tsx +0 -106
  176. package/src/components/LegendItem/index.ts +0 -3
  177. package/src/components/LegendItem/styles.ts +0 -40
  178. package/src/components/LegendItem/types.ts +0 -30
  179. package/src/components/PieChart/EmptyPieChart.tsx +0 -86
  180. package/src/components/PieChart/LoadingPieChart.tsx +0 -20
  181. package/src/components/PieChart/PieChart.stories.tsx +0 -91
  182. package/src/components/PieChart/PieChart.test.tsx +0 -201
  183. package/src/components/PieChart/PieChart.tsx +0 -101
  184. package/src/components/PieChart/RenderedPieChart.tsx +0 -162
  185. package/src/components/PieChart/__snapshots__/PieChart.stories.storyshot +0 -7843
  186. package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +0 -20540
  187. package/src/components/PieChart/index.ts +0 -3
  188. package/src/components/PieChart/styles.ts +0 -97
  189. package/src/components/PieChart/types.ts +0 -89
  190. package/src/components/PieChart/utils.ts +0 -38
  191. package/src/components/ScatterPlot/EmptyScatterPlot.tsx +0 -70
  192. package/src/components/ScatterPlot/LoadingScatterPlot.tsx +0 -20
  193. package/src/components/ScatterPlot/RenderedScatterPlot.tsx +0 -275
  194. package/src/components/ScatterPlot/ScatterPlot.stories.tsx +0 -95
  195. package/src/components/ScatterPlot/ScatterPlot.test.tsx +0 -44
  196. package/src/components/ScatterPlot/ScatterPlot.tsx +0 -98
  197. package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +0 -88352
  198. package/src/components/ScatterPlot/index.ts +0 -3
  199. package/src/components/ScatterPlot/styles.ts +0 -37
  200. package/src/components/ScatterPlot/types.ts +0 -97
  201. package/src/components/ScatterPlot/utils.ts +0 -101
  202. package/src/config.ts +0 -10
  203. package/src/hooks/index.ts +0 -4
  204. package/src/hooks/useBrush.tsx +0 -115
  205. package/src/hooks/useColor.tsx +0 -26
  206. package/src/hooks/useFormatCategoricalData.tsx +0 -68
  207. package/src/hooks/useZoom.tsx +0 -50
  208. package/src/index.ts +0 -15
  209. package/src/scheme.ts +0 -221
  210. package/src/types/data.ts +0 -52
  211. package/src/types/index.ts +0 -5
  212. package/src/types/legend.ts +0 -19
  213. package/src/types/scale.ts +0 -79
  214. package/src/types/size.ts +0 -17
  215. package/src/types/theme.ts +0 -27
  216. package/tsconfig.json +0 -3
  217. /package/{dist/CONTRIBUTING.md → CONTRIBUTING.md} +0 -0
@@ -1,3 +0,0 @@
1
- export * from './BarChart';
2
- export * from './types';
3
- export * from './styles';
@@ -1,35 +0,0 @@
1
- import styled from 'styled-components';
2
- import { StyledBarChartProps } from './types';
3
- import { ChartContainer } from '../ChartContainer';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledBarChart = styled(ChartContainer)<StyledBarChartProps>``;
9
-
10
- export const StyledBarChartEmptyText = styled.div<{
11
- $maxWidth: number;
12
- $textSize: number;
13
- }>`
14
- position: absolute;
15
- top: 0;
16
- left: 0;
17
- height: 100%;
18
- width: 100%;
19
- display: flex;
20
- flex-direction: column;
21
- justify-content: center;
22
- align-items: center;
23
- pointer-events: none;
24
-
25
- > * {
26
- max-width: ${({ $maxWidth }) => $maxWidth}px;
27
- }
28
-
29
- > span {
30
- font-family: var(--redsift-typography-font-family-raleway);
31
- color: var(--redsift-color-neutral-black);
32
- font-size: ${({ $textSize }) => $textSize}px;
33
- line-height: ${({ $textSize }) => $textSize}px;
34
- }
35
- `;
@@ -1,58 +0,0 @@
1
- import { ComponentProps, ReactNode } from 'react';
2
- import {
3
- ChartDimensions,
4
- ChartSize,
5
- ChartTheme,
6
- BarDatum,
7
- TooltipVariant,
8
- CategoryData,
9
- } from '../../types';
10
- import { ChartContainerProps } from '../ChartContainer';
11
- import { BarProps } from '../Bar';
12
-
13
- interface LocaleText {
14
- emptyChartText: string;
15
- }
16
-
17
- export type BarChartDimensions = ChartDimensions & {
18
- fontSize: number;
19
- };
20
-
21
- /**
22
- * Component props.
23
- */
24
- export interface BarChartProps extends ChartContainerProps {
25
- /** Whether the x axis labels are rotated or not. */
26
- areXLabelsRotated?: boolean;
27
- /** Native HTML props to forward to each bar. */
28
- barProps?: Omit<
29
- ComponentProps<'g'>,
30
- 'onClick' | 'orientation' | 'ref' | 'scale' | 'width'
31
- >;
32
- /** Number of categories to use, the rest being put into a new category called "Others". */
33
- caping?: number;
34
- /** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */
35
- data?: CategoryData;
36
- /** Component to use if the chart is empty (replacing the default one). */
37
- emptyComponent?: ReactNode;
38
- /** Method to determine whether a slice is selected or not. */
39
- isBarSelected?: (datum: BarDatum) => void;
40
- /** Method to override the data labels. */
41
- labelDecorator?: (datum: BarDatum) => string;
42
- /** Labels and texts. */
43
- localeText?: LocaleText;
44
- /** Method to be called on a click on a bar. */
45
- onBarClick?: (datum: BarDatum) => void;
46
- /** Whether a category should be displayed for categories that has been removed by the caping option. Optionaly, this prop can be used to change the label of this category. */
47
- others?: boolean | string;
48
- /** BarChart size. */
49
- size?: ChartSize | BarChartDimensions;
50
- /** Bar role. Used to indicate that bars are to be considered buttons or links. If an onClick is provided, the bars will have the role `button` unless specifically set to `link` with this prop. */
51
- barRole?: BarProps['role'];
52
- /** Color palette to use. You can choose among the list of available color palette or also choose to use the success/warning/danger theme for which you have to specify which key corresponds to which status. */
53
- theme?: ChartTheme;
54
- /** Tooltip variant. */
55
- tooltipVariant?: TooltipVariant;
56
- }
57
-
58
- export type StyledBarChartProps = BarChartProps & {};
@@ -1,20 +0,0 @@
1
- import { ChartSize } from '../../types';
2
- import { BarChartDimensions } from './types';
3
-
4
- export const sizeToDimension = (
5
- size: ChartSize | BarChartDimensions
6
- ): BarChartDimensions => {
7
- if (typeof size !== 'string') {
8
- return size;
9
- }
10
-
11
- switch (size) {
12
- case ChartSize.small:
13
- return { width: 300, height: 200, fontSize: 30 };
14
- case ChartSize.large:
15
- return { width: 500, height: 400, fontSize: 38 };
16
- case ChartSize.medium:
17
- default:
18
- return { width: 400, height: 300, fontSize: 34 };
19
- }
20
- };
@@ -1,81 +0,0 @@
1
- import React from 'react';
2
- // @ts-ignore
3
- import type { StoryObj } from '@storybook/react';
4
-
5
- import { monochrome } from '../../scheme';
6
-
7
- import { ChartContainer, ChartContainerProps } from '.';
8
- import { Heading } from '@redsift/design-system';
9
-
10
- const meta = {
11
- title: 'Charts/Core/Chart Container',
12
- component: ChartContainer,
13
- };
14
-
15
- export default meta;
16
- type Story = StoryObj<ChartContainerProps>;
17
-
18
- const Svg = (
19
- <svg width="100" height="100">
20
- <circle cx={50} cy={50} r={40} fill={monochrome} />
21
- </svg>
22
- );
23
-
24
- export const Empty: Story = {
25
- args: {
26
- 'aria-label': 'Chart',
27
- width: '500px',
28
- },
29
- };
30
-
31
- export const Simple: Story = {
32
- args: {
33
- 'aria-label': 'Chart',
34
- children: Svg,
35
- width: '500px',
36
- },
37
- };
38
-
39
- export const WithTitle: Story = {
40
- args: {
41
- children: Svg,
42
- title: 'Title',
43
- width: '500px',
44
- },
45
- };
46
-
47
- export const WithCustomTitle: Story = {
48
- args: {
49
- children: Svg,
50
- title: <Heading as="h2">Title</Heading>,
51
- width: '500px',
52
- },
53
- };
54
-
55
- export const WithCaption: Story = {
56
- args: {
57
- children: Svg,
58
- title: 'Title',
59
- caption:
60
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec rhoncus accumsan massa. Morbi suscipit erat diam, sit amet euismod dolor lacinia et.',
61
- width: '500px',
62
- },
63
- };
64
-
65
- export const WithResetButton: Story = {
66
- args: {
67
- 'aria-label': 'Chart',
68
- children: Svg,
69
- onReset: () => console.log('reset'),
70
- width: '500px',
71
- },
72
- };
73
-
74
- export const WithTitleAndResetButton: Story = {
75
- args: {
76
- children: Svg,
77
- onReset: () => console.log('reset'),
78
- title: 'Title',
79
- width: '500px',
80
- },
81
- };
@@ -1,75 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
-
4
- import { ChartContainer } from './ChartContainer';
5
-
6
- jest.mock('react', () => ({
7
- ...jest.requireActual('react'),
8
- useId: () => '123',
9
- }));
10
-
11
- describe('ChartContainer', () => {
12
- it('supports custom className', () => {
13
- const tree = render(
14
- <ChartContainer aria-label="Chart" className="test">
15
- Chart content
16
- </ChartContainer>
17
- );
18
- const component = tree.asFragment().firstChild;
19
-
20
- expect(component).toHaveAttribute('class', expect.stringContaining('test'));
21
- });
22
-
23
- it('supports custom id', () => {
24
- const tree = render(
25
- <ChartContainer id="456" aria-label="Chart">
26
- Chart content
27
- </ChartContainer>
28
- );
29
- const component = tree.asFragment().firstChild;
30
- expect(component).toHaveAttribute('id', '456');
31
- });
32
-
33
- it('supports custom data attributes', () => {
34
- const tree = render(
35
- <ChartContainer aria-label="Chart" data-testid="test">
36
- Chart content
37
- </ChartContainer>
38
- );
39
- const component = tree.asFragment().firstChild;
40
- expect(component).toHaveAttribute('data-testid', 'test');
41
- });
42
-
43
- it('can be labelled using a title', () => {
44
- const { getByLabelText } = render(
45
- <ChartContainer title="Title">Chart content</ChartContainer>
46
- );
47
- const component = getByLabelText('Title');
48
- expect(component).toHaveAttribute('aria-labelledby', 'id123__title');
49
- });
50
-
51
- it('can be labelled using an aria-label', () => {
52
- const { getByLabelText } = render(
53
- <ChartContainer aria-label="Label">Chart content</ChartContainer>
54
- );
55
- const component = getByLabelText('Label');
56
- expect(component).toHaveAttribute('aria-label', 'Label');
57
- });
58
-
59
- it('can be labelled using an aria-labelledby', () => {
60
- const { getByLabelText } = render(
61
- <>
62
- <h1 id="123">Label</h1>
63
- <ChartContainer aria-labelledby="123">Chart content</ChartContainer>
64
- </>
65
- );
66
- const component = getByLabelText('Label');
67
- expect(component).toHaveAttribute('aria-labelledby', '123');
68
- });
69
-
70
- it('warns if there is no label for accessibility', () => {
71
- const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
72
- render(<ChartContainer>Chart content</ChartContainer>);
73
- expect(spy).toHaveBeenCalled();
74
- });
75
- });
@@ -1,116 +0,0 @@
1
- import React, { ComponentProps, forwardRef, RefObject, useId } from 'react';
2
- import classNames from 'classnames';
3
-
4
- import { useLocalizedStringFormatter } from 'react-aria';
5
- import intlMessages from './intl';
6
-
7
- import {
8
- Button,
9
- Comp,
10
- Heading,
11
- warnIfNoAccessibleLabelFound,
12
- } from '@redsift/design-system';
13
-
14
- import { ChartContainerProps } from './types';
15
- import {
16
- StyledChartContainer,
17
- StyledChartContainerCaption,
18
- StyledChartContainerTitle,
19
- } from './styles';
20
-
21
- const COMPONENT_NAME = 'ChartContainer';
22
- const CLASSNAME = 'redsift-chart-container';
23
- const DEFAULT_PROPS: Partial<ChartContainerProps> = {};
24
-
25
- export const ChartContainer: Comp<ChartContainerProps, HTMLDivElement> =
26
- forwardRef((props, ref) => {
27
- const {
28
- 'aria-label': propsAriaLabel,
29
- 'aria-labelledby': propsAriaLabelledby,
30
- caption,
31
- chartProps,
32
- chartRef,
33
- children,
34
- className,
35
- id: propsId,
36
- title,
37
- onReset,
38
- ...forwardedProps
39
- } = props;
40
- const id = propsId ?? useId();
41
-
42
- warnIfNoAccessibleLabelFound(
43
- props as ComponentProps<keyof JSX.IntrinsicElements>,
44
- [title]
45
- );
46
-
47
- const stringFormatter = useLocalizedStringFormatter(intlMessages);
48
-
49
- const ariaLabel = propsAriaLabel
50
- ? propsAriaLabel
51
- : propsAriaLabelledby || title
52
- ? undefined
53
- : undefined;
54
- const ariaLabelledby = propsAriaLabelledby
55
- ? propsAriaLabelledby
56
- : title
57
- ? `id${id}__title`
58
- : undefined;
59
-
60
- return (
61
- <StyledChartContainer
62
- {...forwardedProps}
63
- ref={ref as RefObject<HTMLDivElement>}
64
- className={classNames(ChartContainer.className, className)}
65
- id={id}
66
- >
67
- {title || onReset ? (
68
- <StyledChartContainerTitle
69
- alignItems="center"
70
- justifyContent="space-between"
71
- className={`${ChartContainer.className}__title`}
72
- id={`id${id}__title`}
73
- >
74
- {typeof title === 'string' ? (
75
- <Heading as="h3">{title}</Heading>
76
- ) : title ? (
77
- title
78
- ) : null}
79
-
80
- {onReset ? (
81
- <Button
82
- className={`${ChartContainer.className}-title__reset-button`}
83
- color="question"
84
- variant="unstyled"
85
- onClick={onReset}
86
- >
87
- {stringFormatter.format('reset')}
88
- </Button>
89
- ) : null}
90
- </StyledChartContainerTitle>
91
- ) : null}
92
-
93
- {children ? (
94
- <div
95
- {...chartProps}
96
- ref={chartRef}
97
- className={`${ChartContainer.className}__content`}
98
- aria-label={ariaLabel}
99
- aria-labelledby={ariaLabelledby}
100
- >
101
- {children}
102
- </div>
103
- ) : null}
104
- {caption ? (
105
- <StyledChartContainerCaption
106
- className={`${ChartContainer.className}__caption`}
107
- >
108
- {caption}
109
- </StyledChartContainerCaption>
110
- ) : null}
111
- </StyledChartContainer>
112
- );
113
- });
114
- ChartContainer.className = CLASSNAME;
115
- ChartContainer.defaultProps = DEFAULT_PROPS;
116
- ChartContainer.displayName = COMPONENT_NAME;
@@ -1,3 +0,0 @@
1
- export * from './ChartContainer';
2
- export * from './types';
3
- export * from './styles';
@@ -1,3 +0,0 @@
1
- {
2
- "reset": "Reset"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "reset": "Réinitialiser"
3
- }
@@ -1,7 +0,0 @@
1
- import enUS from './en-US.json';
2
- import frFR from './fr-FR.json';
3
-
4
- export default {
5
- 'en-US': enUS,
6
- 'fr-FR': frFR,
7
- };
@@ -1,42 +0,0 @@
1
- import styled from 'styled-components';
2
- import { Flexbox, baseStyling, focusRing } from '@redsift/design-system';
3
- import { StyledChartContainerProps } from './types';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledChartContainer = styled.div<StyledChartContainerProps>`
9
- ${baseStyling}
10
-
11
- margin: 8px;
12
- padding: 8px;
13
- color: var(--redsift-color-neutral-black);
14
-
15
- .redsift-chart-container__content {
16
- display: flex;
17
- align-items: center;
18
- gap: 16px;
19
- font-family: var(--redsift-typography-font-family-source-code-pro);
20
- font-size: 11px;
21
- justify-content: center;
22
- margin: 8px 0;
23
- position: relative;
24
-
25
- ${focusRing}
26
- }
27
-
28
- svg {
29
- display: block;
30
- }
31
- `;
32
-
33
- export const StyledChartContainerTitle = styled(
34
- Flexbox
35
- )<StyledChartContainerProps>``;
36
-
37
- export const StyledChartContainerCaption = styled.p<StyledChartContainerProps>`
38
- font-family: var(--redsift-typography-caption-font-family);
39
- font-size: var(--redsift-typography-caption-font-size);
40
- font-weight: var(--redsift-typography-caption-font-weight);
41
- line-height: var(--redsift-typography-caption-line-height);
42
- `;
@@ -1,24 +0,0 @@
1
- import { StylingProps } from '@redsift/design-system';
2
- import { ComponentProps, ReactElement, RefObject } from 'react';
3
-
4
- /**
5
- * Component props.
6
- */
7
- export interface ChartContainerProps
8
- extends Omit<ComponentProps<'div'>, 'title'>,
9
- StylingProps {
10
- /** Caption. */
11
- caption?: string;
12
- /** Native HTML props to pass to the chart. */
13
- chartProps?: ComponentProps<'div'>;
14
- /** Ref to the chart. */
15
- chartRef?: RefObject<HTMLDivElement>;
16
- /** Id. */
17
- id?: string;
18
- /** Method called when the Reset button is displayed (defines whether or not the button should be displayed). */
19
- onReset?: () => void;
20
- /** Title. */
21
- title?: string | ReactElement;
22
- }
23
-
24
- export type StyledChartContainerProps = ChartContainerProps & {};
@@ -1,119 +0,0 @@
1
- import React, {
2
- forwardRef,
3
- KeyboardEventHandler,
4
- RefObject,
5
- useId,
6
- } from 'react';
7
- import classNames from 'classnames';
8
-
9
- import { Comp, Number, Text } from '@redsift/design-system';
10
- import { Tooltip } from '@redsift/popovers';
11
-
12
- import { DataPointProps } from './types';
13
- import { StyledDataPoint } from './styles';
14
- import { TooltipVariant } from '../../types';
15
-
16
- export const DataPoint: Comp<DataPointProps<any>, SVGGElement> = forwardRef(
17
- (props, ref) => {
18
- const {
19
- children,
20
- className,
21
- data,
22
- id: propsId,
23
- index,
24
- isSelected: propsIsSelected,
25
- labelDecorator,
26
- onClick,
27
- role,
28
- tooltipVariant,
29
- ...forwardedProps
30
- } = props;
31
- const id = propsId ?? useId();
32
-
33
- const text = labelDecorator ? labelDecorator(data) : data.data.key;
34
- const hasText = text && tooltipVariant !== TooltipVariant.none;
35
- const tooltipValue =
36
- tooltipVariant === TooltipVariant.value
37
- ? data.data.value
38
- : tooltipVariant === TooltipVariant.percent && data.data.percent
39
- ? data.data.percent
40
- : undefined;
41
- const hasValue =
42
- tooltipValue &&
43
- [TooltipVariant.value, TooltipVariant.percent].includes(tooltipVariant!);
44
- const showTooltip =
45
- tooltipVariant !== TooltipVariant.none && (hasText || hasValue);
46
-
47
- const isEmpty = data.data.value === 0;
48
-
49
- const isSelectable = role === 'option';
50
- const isSelected = isSelectable && propsIsSelected === true;
51
- const isDeselected = isSelectable && propsIsSelected === false;
52
-
53
- const onKeyDown: KeyboardEventHandler<SVGElement> = (event) => {
54
- if (onClick) {
55
- event.stopPropagation();
56
-
57
- if (event.code === 'Enter' || event.code === 'Space') {
58
- event.preventDefault();
59
- onClick(data);
60
- }
61
- }
62
- };
63
-
64
- const DataPointComponent = (
65
- <StyledDataPoint
66
- tabIndex={onClick ? 0 : undefined}
67
- {...forwardedProps}
68
- className={classNames(className, `_${index}`, {
69
- selected: isSelected,
70
- deselected: isDeselected,
71
- })}
72
- ref={ref as RefObject<SVGGElement>}
73
- aria-label={
74
- showTooltip && !isEmpty ? `${text}: ${data.data.value}` : undefined
75
- }
76
- aria-labelledby={!showTooltip && !isEmpty ? `${id}-title` : undefined}
77
- aria-selected={isSelected ? true : isDeselected ? false : undefined}
78
- id={id}
79
- onClick={onClick ? () => onClick(data) : undefined}
80
- onKeyDown={onClick ? (e) => onKeyDown(e) : undefined}
81
- role={role ? role : onClick ? 'button' : undefined}
82
- $clickable={Boolean(onClick)}
83
- >
84
- {children}
85
- {!showTooltip && !isEmpty ? (
86
- <title id={`${id}-title`}>{`${text}: ${data.data.value}`}</title>
87
- ) : null}
88
- </StyledDataPoint>
89
- );
90
-
91
- if (showTooltip) {
92
- return (
93
- <Tooltip placement="right">
94
- <Tooltip.Trigger>{DataPointComponent}</Tooltip.Trigger>
95
- <Tooltip.Content>
96
- <Text variant="caption">
97
- {text}
98
- {hasText && hasValue ? ' - ' : null}
99
- {hasValue ? (
100
- <Number
101
- value={tooltipValue!}
102
- type={
103
- tooltipVariant === TooltipVariant.percent
104
- ? 'percent'
105
- : 'decimal'
106
- }
107
- variant="caption"
108
- maximumFractionDigits={2}
109
- />
110
- ) : null}
111
- </Text>
112
- </Tooltip.Content>
113
- </Tooltip>
114
- );
115
- }
116
-
117
- return DataPointComponent;
118
- }
119
- );
@@ -1,3 +0,0 @@
1
- export * from './DataPoint';
2
- export * from './types';
3
- export * from './styles';
@@ -1,8 +0,0 @@
1
- import styled from 'styled-components';
2
- import { animated } from '@react-spring/web';
3
- import { StyledDataPointProps } from './types';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledDataPoint = styled(animated.g)<StyledDataPointProps>``;
@@ -1,33 +0,0 @@
1
- import { ComponentProps } from 'react';
2
- import { TooltipVariant } from '../../types';
3
-
4
- /**
5
- * Component props.
6
- */
7
- export interface DataPointProps<T>
8
- extends Omit<ComponentProps<'g'>, 'onClick' | 'scale'> {
9
- /** Color of the DataPoint. */
10
- color?: string;
11
- /** Data. Also state to which the component should end the animation, if any. */
12
- data: T;
13
- /** Id. Used for accessibility. */
14
- id?: string;
15
- /** Position in the list of siblings. Used for placement and selection. */
16
- index?: number;
17
- /** Whether the component is selected or not. Used only if the component is selectable. Set to `undefined` to make nor selected nor unselected. */
18
- isSelected?: boolean;
19
- /** Method modifying the label before displaying it. */
20
- labelDecorator?: (data: T) => string;
21
- /** Method called when a click or keydown occurs on the component. */
22
- onClick?: (data: T) => void;
23
- /** State from which the component should start the animation, if any. */
24
- previousData?: T;
25
- /** Role. Will be set to 'button' if onClick is provided. If 'option', then the component becomes selectable. */
26
- role?: 'button' | 'link' | 'option';
27
- /** Tooltip variant. */
28
- tooltipVariant?: TooltipVariant;
29
- }
30
-
31
- export type StyledDataPointProps = Omit<DataPointProps<any>, 'data'> & {
32
- $clickable: boolean;
33
- };