@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,106 +0,0 @@
1
- import React, { KeyboardEventHandler, forwardRef, useId } from 'react';
2
- import classNames from 'classnames';
3
-
4
- import { Comp, Number, Text } from '@redsift/design-system';
5
-
6
- import { LegendItemProps } from './types';
7
- import { StyledLegendItem } from './styles';
8
- import { monochrome } from '../../scheme';
9
- import { LabelVariant } from '../../types';
10
-
11
- const COMPONENT_NAME = 'LegendItem';
12
- const CLASSNAME = 'redsift-legend-item';
13
- const DEFAULT_PROPS: Partial<LegendItemProps> = {
14
- color: monochrome,
15
- index: 0,
16
- };
17
-
18
- export const LegendItem: Comp<LegendItemProps, HTMLLIElement> = forwardRef(
19
- (props, ref) => {
20
- const {
21
- index,
22
- isSelected: propsIsSelected,
23
- labelDecorator,
24
- onClick,
25
- role,
26
- } = props;
27
-
28
- const {
29
- className,
30
- color,
31
- data,
32
- id: propsId,
33
- total,
34
- variant,
35
- ...forwardedProps
36
- } = props;
37
- const id = propsId ?? useId();
38
-
39
- const text = labelDecorator ? labelDecorator(data) : data.data.key;
40
- const isEmpty = data.data.value === 0;
41
-
42
- const isSelectable = role === 'option';
43
- const isSelected = isSelectable && propsIsSelected === true;
44
- const isDeselected = isSelectable && propsIsSelected === false;
45
-
46
- const onKeyDown: KeyboardEventHandler<HTMLLIElement> = (event) => {
47
- if (onClick) {
48
- event.stopPropagation();
49
-
50
- if (event.code === 'Enter' || event.code === 'Space') {
51
- event.preventDefault();
52
- onClick(data);
53
- }
54
- }
55
- };
56
-
57
- return (
58
- <StyledLegendItem
59
- {...forwardedProps}
60
- className={classNames(LegendItem.className, className, `_${index}`, {
61
- selected: isSelected,
62
- deselected: isDeselected,
63
- })}
64
- color={isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color}
65
- ref={ref}
66
- aria-labelledby={!isEmpty ? `${id}-title` : undefined}
67
- aria-selected={isSelected ? true : isDeselected ? false : undefined}
68
- id={id}
69
- onClick={onClick ? () => onClick(data) : undefined}
70
- onKeyDown={onClick ? (e) => onKeyDown(e) : undefined}
71
- role={role ? role : onClick ? 'button' : undefined}
72
- tabIndex={onClick ? 0 : undefined}
73
- $clickable={Boolean(onClick)}
74
- >
75
- <div />
76
- {variant === LabelVariant.value ? (
77
- <>
78
- <Number
79
- as="b"
80
- maximumFractionDigits={2}
81
- value={data.data.value}
82
- variant="inherit"
83
- />
84
- <Text variant="caption">{text}</Text>
85
- </>
86
- ) : variant === LabelVariant.percent && total ? (
87
- <>
88
- <Number
89
- as="b"
90
- maximumFractionDigits={2}
91
- type="percent"
92
- value={data.data.value / total}
93
- variant="inherit"
94
- />
95
- <Text variant="caption">{text}</Text>
96
- </>
97
- ) : (
98
- <Text variant="caption">{text}</Text>
99
- )}
100
- </StyledLegendItem>
101
- );
102
- }
103
- );
104
- LegendItem.className = CLASSNAME;
105
- LegendItem.defaultProps = DEFAULT_PROPS;
106
- LegendItem.displayName = COMPONENT_NAME;
@@ -1,3 +0,0 @@
1
- export * from './LegendItem';
2
- export * from './types';
3
- export * from './styles';
@@ -1,40 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
- import { StyledLegendItemProps } from './types';
3
-
4
- /**
5
- * Component style.
6
- */
7
- export const StyledLegendItem = styled.li<StyledLegendItemProps>`
8
- display: flex;
9
- align-items: center;
10
- gap: 8px;
11
- font-size: var(--redsift-typography-caption-font-size);
12
-
13
- > div {
14
- height: 16px;
15
- width: 16px;
16
- min-width: 16px;
17
- background-color: ${({ color }) => color};
18
- }
19
-
20
- ${({ $clickable }) =>
21
- $clickable
22
- ? css`
23
- cursor: pointer;
24
-
25
- &:hover,
26
- &:focus {
27
- outline: none;
28
- > div {
29
- opacity: 0.7;
30
- }
31
- }
32
-
33
- &:focus-visible {
34
- > div {
35
- outline: 4px solid var(--redsift-color-default-primary);
36
- }
37
- }
38
- `
39
- : ''}}
40
- `;
@@ -1,30 +0,0 @@
1
- import { ComponentProps } from 'react';
2
- import { LabelVariant, LegendItemDatum } from '../../types';
3
- import { DataPointProps, StyledDataPointProps } from '../DataPoint';
4
-
5
- /**
6
- * Component props.
7
- */
8
- export interface LegendItemProps
9
- extends Pick<
10
- DataPointProps<LegendItemDatum>,
11
- | 'color'
12
- | 'data'
13
- | 'id'
14
- | 'index'
15
- | 'isSelected'
16
- | 'labelDecorator'
17
- | 'onClick'
18
- | 'previousData'
19
- | 'role'
20
- | 'tooltipVariant'
21
- >,
22
- Omit<ComponentProps<'li'>, 'onClick' | 'role'> {
23
- /** Total used to compute percentage. */
24
- total?: number;
25
- /** Variant. */
26
- variant?: LabelVariant;
27
- }
28
-
29
- export type StyledLegendItemProps = Pick<StyledDataPointProps, '$clickable'> &
30
- Omit<LegendItemProps, 'data'>;
@@ -1,86 +0,0 @@
1
- import React, { forwardRef, RefObject } from 'react';
2
- import { arc as d3arc } from 'd3';
3
-
4
- import { ArcDatum } from '../../types';
5
- import { PieChartProps, PieChartVariant } from './types';
6
- import { StyledPieChart, StyledPieChartEmptyText } from './styles';
7
- import { Arcs } from '../Arcs';
8
- import { empty } from '../../scheme';
9
- import { sizeToDimension } from './utils';
10
-
11
- export const EmptyPieChart = forwardRef<HTMLDivElement, PieChartProps>(
12
- (props, ref) => {
13
- const {
14
- className,
15
- emptyComponent,
16
- localeText,
17
- size,
18
- variant,
19
- ...forwardedProps
20
- } = props;
21
-
22
- const isDonut =
23
- variant === PieChartVariant.donut ||
24
- variant === PieChartVariant.spacedDonut;
25
-
26
- const { width, height, fontSize, innerRadius } = sizeToDimension(size!);
27
- const externalRadiusPadding = 8;
28
-
29
- const createArc = d3arc<ArcDatum>()
30
- .innerRadius(isDonut ? innerRadius : 0)
31
- .outerRadius(width / 2 - externalRadiusPadding);
32
-
33
- return (
34
- <StyledPieChart
35
- {...forwardedProps}
36
- className={className}
37
- ref={ref as RefObject<HTMLDivElement>}
38
- >
39
- {emptyComponent ?? (
40
- <>
41
- <StyledPieChartEmptyText
42
- $maxWidth={innerRadius * 2}
43
- $textSize={fontSize / 2}
44
- $isDonut={isDonut}
45
- >
46
- <span>{localeText?.emptyChartText}</span>
47
- </StyledPieChartEmptyText>
48
- <svg width={width} height={height}>
49
- <Arcs
50
- arcs={[
51
- {
52
- createArc,
53
- previousData: {
54
- data: {
55
- key: '',
56
- value: 0,
57
- },
58
- startAngle: 0,
59
- endAngle: 0,
60
- padAngle: 0,
61
- value: 0,
62
- index: 0,
63
- },
64
- data: {
65
- data: {
66
- key: 'No Data',
67
- value: 0,
68
- },
69
- index: 0,
70
- value: 0,
71
- startAngle: 0,
72
- endAngle: 2 * Math.PI,
73
- padAngle: 0,
74
- },
75
- color: empty,
76
- },
77
- ]}
78
- transform={`translate(${width / 2} ${height / 2})`}
79
- />
80
- </svg>
81
- </>
82
- )}
83
- </StyledPieChart>
84
- );
85
- }
86
- );
@@ -1,20 +0,0 @@
1
- import React, { forwardRef, RefObject } from 'react';
2
-
3
- import { PieChartProps } from './types';
4
- import { StyledPieChart } from './styles';
5
-
6
- export const LoadingPieChart = forwardRef<HTMLDivElement, PieChartProps>(
7
- (props, ref) => {
8
- const { className, ...forwardedProps } = props;
9
-
10
- return (
11
- <StyledPieChart
12
- {...forwardedProps}
13
- className={className}
14
- ref={ref as RefObject<HTMLDivElement>}
15
- >
16
- Loading...
17
- </StyledPieChart>
18
- );
19
- }
20
- );
@@ -1,91 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
-
3
- import { DataVizColorPalette } from '@redsift/design-system';
4
- import { PieChart } from '.';
5
- import { PieChartLabelVariant, PieChartVariant } from './types';
6
- import {
7
- CategoryData,
8
- ChartSize,
9
- ChartTheme,
10
- ColorTheme,
11
- TooltipVariant,
12
- } from '../../types';
13
-
14
- const themes = {
15
- ...ColorTheme,
16
- 'success-warning-danger': {
17
- success: 'Bread',
18
- warning: 'Tea',
19
- danger: 'Coffee',
20
- },
21
- 'success-warning-danger-neutral': {
22
- success: 'Bread',
23
- warning: 'Tea',
24
- danger: 'Coffee',
25
- neutral: 'Pastry',
26
- },
27
- custom: {
28
- Coffee: DataVizColorPalette.purple,
29
- Bread: DataVizColorPalette.pink,
30
- Tea: DataVizColorPalette.aqua,
31
- },
32
- };
33
-
34
- const meta: Meta<typeof PieChart> = {
35
- title: 'Charts/PieChart',
36
- component: PieChart as any,
37
- argTypes: {
38
- variant: {
39
- options: Object.values(PieChartVariant),
40
- control: { type: 'select' },
41
- },
42
- labelVariant: {
43
- options: Object.values(PieChartLabelVariant),
44
- control: { type: 'select' },
45
- },
46
- tooltipVariant: {
47
- options: Object.values(TooltipVariant),
48
- control: { type: 'select' },
49
- },
50
- size: {
51
- options: Object.values(ChartSize),
52
- control: { type: 'select' },
53
- },
54
- theme: {
55
- options: Object.keys(themes),
56
- mapping: themes,
57
- control: {
58
- type: 'select',
59
- },
60
- },
61
- },
62
- };
63
- export default meta;
64
- type Story = StoryObj<typeof PieChart>;
65
-
66
- const data: CategoryData = [
67
- { key: 'Cookies', value: 540 },
68
- { key: 'Coffee', value: 5471 },
69
- { key: 'Bread', value: 3325 },
70
- { key: 'Tea', value: 1435 },
71
- { key: 'Pastry', value: 856 },
72
- { key: 'Sandwich', value: 771 },
73
- { key: 'Croissant', value: 771 },
74
- { key: 'Hot chocolate', value: 588 },
75
- { key: 'Toast', value: 318 },
76
- ];
77
-
78
- export const Controls: Story = {
79
- args: {
80
- title: 'Pie Chart',
81
- variant: 'spacedDonut',
82
- labelVariant: 'externalLabelValue',
83
- tooltipVariant: 'value',
84
- size: 'medium',
85
- theme: 'success-warning-danger-neutral' as ChartTheme,
86
- caping: 4,
87
- others: true,
88
- onSliceClick: (datum) => console.log(datum),
89
- data: data,
90
- },
91
- };
@@ -1,201 +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 './PieChart.stories';
7
-
8
- import { PieChart } from './PieChart';
9
- import { PieChartLabelVariant, PieChartVariant } from './types';
10
- import { ChartSize, ChartTheme, ColorTheme, TooltipVariant } from '../../types';
11
- import { DataVizColorPalette } from '@redsift/design-system';
12
-
13
- jest.mock('react', () => ({
14
- ...jest.requireActual('react'),
15
- useId: () => '123',
16
- }));
17
-
18
- const themes = {
19
- ...ColorTheme,
20
- 'success-warning-danger': {
21
- success: 'Bread',
22
- warning: 'Tea',
23
- danger: 'Coffee',
24
- },
25
- 'success-warning-danger-neutral': {
26
- success: 'Bread',
27
- warning: 'Tea',
28
- danger: 'Coffee',
29
- neutral: 'Pastry',
30
- },
31
- custom: {
32
- Coffee: DataVizColorPalette.purple,
33
- Bread: DataVizColorPalette.pink,
34
- Tea: DataVizColorPalette.aqua,
35
- },
36
- };
37
-
38
- const data = [
39
- { key: 'Dogs', value: 300 },
40
- { key: 'Cats', value: 500 },
41
- { key: 'Fish', value: 150 },
42
- ];
43
-
44
- describe('PieChart', () => {
45
- const onClickSpy = jest.fn();
46
-
47
- afterEach(() => {
48
- onClickSpy.mockClear();
49
- });
50
-
51
- it('should match snapshot', () => {
52
- const ComposedStory = composeStory(Controls, Meta);
53
- const tree = render(
54
- <>
55
- {Object.values(PieChartVariant).map((variant, i) =>
56
- Object.values(ChartSize).map((size, j) =>
57
- Object.values(PieChartLabelVariant).map((labelVariant, k) => (
58
- <ComposedStory
59
- key={`${variant}-${size}-${labelVariant}-${
60
- Object.values(TooltipVariant)[k]
61
- }`}
62
- variant={variant}
63
- labelVariant={labelVariant}
64
- tooltipVariant={Object.values(TooltipVariant)[k]}
65
- size={size}
66
- theme={
67
- Object.keys(themes)[
68
- (i * Object.values(ChartSize).length +
69
- j * Object.values(PieChartLabelVariant).length +
70
- k) %
71
- Object.keys(themes).length
72
- ] as ChartTheme
73
- }
74
- />
75
- ))
76
- )
77
- )}
78
- </>
79
- );
80
- expect(tree).toMatchSnapshot();
81
- });
82
-
83
- it('handles default', () => {
84
- const { queryByText } = render(<PieChart aria-label="Chart" data={data} />);
85
-
86
- expect(queryByText('Cats')).toBe(null);
87
- expect(queryByText('Dogs')).toBe(null);
88
- expect(queryByText('Fish')).toBe(null);
89
- });
90
-
91
- it('handles internal labels', () => {
92
- const { getByText } = render(
93
- <PieChart
94
- aria-label="Chart"
95
- data={data}
96
- labelVariant={PieChartLabelVariant.internal}
97
- />
98
- );
99
-
100
- expect(getByText('Cats')).toBeVisible();
101
- expect(getByText('Dogs')).toBeVisible();
102
- });
103
-
104
- it('supports custom className', () => {
105
- const tree = render(
106
- <PieChart aria-label="Chart" data={data} className="test" />
107
- );
108
- const component = tree.asFragment().firstChild;
109
-
110
- expect(component).toHaveAttribute('class', expect.stringContaining('test'));
111
- });
112
-
113
- it('supports custom data attributes', () => {
114
- const tree = render(
115
- <PieChart aria-label="Chart" data={data} data-testid="test" />
116
- );
117
- const component = tree.asFragment().firstChild;
118
- expect(component).toHaveAttribute('data-testid', 'test');
119
- });
120
-
121
- it('can be labelled using a title', () => {
122
- const { getByLabelText } = render(<PieChart data={data} title="Label" />);
123
- const component = getByLabelText('Label');
124
- expect(component).toHaveAttribute('aria-labelledby', 'id123__title');
125
- });
126
-
127
- it('can be labelled using an aria-label', () => {
128
- const { getByLabelText } = render(
129
- <PieChart data={data} aria-label="Label" />
130
- );
131
- const component = getByLabelText('Label');
132
- expect(component).toHaveAttribute('aria-label', 'Label');
133
- });
134
-
135
- it('can be labelled using an aria-labelledby', () => {
136
- const { getByLabelText } = render(
137
- <>
138
- <h1 id="123">Label</h1>
139
- <PieChart data={data} aria-labelledby="123" />
140
- </>
141
- );
142
- const component = getByLabelText('Label');
143
- expect(component).toHaveAttribute('aria-labelledby', '123');
144
- });
145
-
146
- it('supports click on the pie slices', async () => {
147
- const user = userEvent.setup();
148
- const { getAllByRole } = render(
149
- <PieChart aria-label="Chart" data={data} onSliceClick={onClickSpy} />
150
- );
151
-
152
- const slices = getAllByRole('button');
153
- expect(slices.length).toBe(3);
154
-
155
- await user.click(slices[0]);
156
- await user.click(slices[1]);
157
- await user.click(slices[2]);
158
-
159
- expect(onClickSpy).toHaveBeenCalledTimes(3);
160
- });
161
-
162
- it('supports keydown on the pie slices', async () => {
163
- const { getAllByRole } = render(
164
- <PieChart aria-label="Chart" data={data} onSliceClick={onClickSpy} />
165
- );
166
-
167
- const slices = getAllByRole('button');
168
- expect(slices.length).toBe(3);
169
-
170
- userEvent.keyboard('[Tab]');
171
- userEvent.keyboard('[Enter]');
172
- userEvent.keyboard('[Tab]');
173
- userEvent.keyboard('[Space]');
174
- userEvent.keyboard('[Tab]');
175
- userEvent.keyboard('[Enter]');
176
-
177
- expect(onClickSpy).toHaveBeenCalledTimes(3);
178
- });
179
-
180
- it('shows a tooltip when hovering on the pie slices ', async () => {
181
- const user = userEvent.setup();
182
- const { getAllByRole } = render(
183
- <PieChart
184
- aria-label="Chart"
185
- data={data}
186
- // The onSliceClick gives the slice the role "button" which is then used to access the slices.
187
- onSliceClick={onClickSpy}
188
- />
189
- );
190
-
191
- const slices = getAllByRole('button');
192
- expect(slices.length).toBe(3);
193
-
194
- await user.hover(slices[0]);
195
- await waitFor(() => {
196
- expect(screen.getByRole('tooltip', { exact: true })).toBeInTheDocument();
197
- });
198
- const tooltip = screen.getByRole('tooltip');
199
- expect(tooltip.textContent).toContain('Cats');
200
- });
201
- });
@@ -1,101 +0,0 @@
1
- import React, { forwardRef, useId } from 'react';
2
- import classNames from 'classnames';
3
-
4
- import { Comp } from '@redsift/design-system';
5
-
6
- import { ChartSize, ColorTheme, TooltipVariant } from '../../types';
7
- import { PieChartLabelVariant, PieChartProps, PieChartVariant } from './types';
8
- import { LoadingPieChart } from './LoadingPieChart';
9
- import { EmptyPieChart } from './EmptyPieChart';
10
- import { RenderedPieChart } from './RenderedPieChart';
11
-
12
- const COMPONENT_NAME = 'PieChart';
13
- const CLASSNAME = 'redsift-piechart';
14
- const DEFAULT_PROPS: Partial<PieChartProps> = {
15
- isSliceSelected: () => true,
16
- labelVariant: PieChartLabelVariant.none,
17
- others: true,
18
- size: ChartSize.medium,
19
- theme: ColorTheme.default,
20
- variant: PieChartVariant.plain,
21
- tooltipVariant: TooltipVariant.value,
22
- localeText: {
23
- emptyChartText: 'No Data',
24
- },
25
- };
26
-
27
- export const PieChart: Comp<PieChartProps, HTMLDivElement> = forwardRef(
28
- (props, ref) => {
29
- const {
30
- caping,
31
- chartRef,
32
- className,
33
- data: propsData,
34
- emptyComponent,
35
- id: propsId,
36
- isSliceSelected,
37
- labelDecorator,
38
- labelVariant,
39
- localeText,
40
- middleText,
41
- onSliceClick,
42
- others,
43
- size,
44
- sliceRole,
45
- subtext,
46
- text,
47
- theme,
48
- tooltipVariant,
49
- variant,
50
- ...forwardedProps
51
- } = props;
52
- const id = propsId ?? useId();
53
-
54
- if (propsData === undefined || propsData === null) {
55
- return <LoadingPieChart id={id} {...forwardedProps} ref={ref} />;
56
- }
57
-
58
- if (propsData.length === 0) {
59
- return (
60
- <EmptyPieChart
61
- data={propsData}
62
- emptyComponent={emptyComponent}
63
- id={id}
64
- localeText={localeText}
65
- size={size}
66
- variant={variant}
67
- {...forwardedProps}
68
- ref={ref}
69
- />
70
- );
71
- }
72
-
73
- return (
74
- <RenderedPieChart
75
- caping={caping}
76
- chartRef={chartRef}
77
- className={classNames(PieChart.className, className)}
78
- data={propsData}
79
- id={id}
80
- isSliceSelected={isSliceSelected}
81
- labelDecorator={labelDecorator}
82
- labelVariant={labelVariant}
83
- middleText={middleText}
84
- onSliceClick={onSliceClick}
85
- others={others}
86
- size={size}
87
- sliceRole={sliceRole}
88
- subtext={subtext}
89
- text={text}
90
- theme={theme}
91
- tooltipVariant={tooltipVariant}
92
- variant={variant}
93
- {...forwardedProps}
94
- ref={ref}
95
- />
96
- );
97
- }
98
- );
99
- PieChart.className = CLASSNAME;
100
- PieChart.defaultProps = DEFAULT_PROPS;
101
- PieChart.displayName = COMPONENT_NAME;