@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,56 +0,0 @@
1
- import { ComponentProps } from 'react';
2
- import { ValueOf } from '@redsift/design-system';
3
- import { AnyScale, TicksSpec } from '../../types';
4
-
5
- /**
6
- * Component variant.
7
- */
8
- export const AxisVariant = {
9
- none: 'none',
10
- line: 'line',
11
- lineTick: 'lineTick',
12
- tick: 'tick',
13
- tickValue: 'tickValue',
14
- default: 'default',
15
- } as const;
16
- export type AxisVariant = ValueOf<typeof AxisVariant>;
17
-
18
- export const AxisPosition = {
19
- top: 'top',
20
- right: 'right',
21
- bottom: 'bottom',
22
- left: 'left',
23
- };
24
- export type AxisPosition = ValueOf<typeof AxisPosition>;
25
-
26
- /**
27
- * Component props.
28
- */
29
- export interface AxisProps extends Omit<ComponentProps<'g'>, 'scale'> {
30
- areLabelsRotated?: boolean;
31
- format?: string;
32
- legend?: string;
33
- legendOffset?: number;
34
- legendPosition?: 'start' | 'middle' | 'end';
35
- /** Length of the axis. */
36
- length?: number;
37
- /** Position of axis. top|bottom means this is an x axis, right|left means this is an y axis. */
38
- position?: AxisPosition;
39
- /** Scale (d3.js) used to generate the axis. */
40
- scale: AnyScale;
41
- tickPadding?: number;
42
- tickRotation?: number;
43
- tickSize?: number;
44
- tickValues?: TicksSpec;
45
- /** Variant. */
46
- variant?: AxisVariant;
47
- /** X position. */
48
- x?: number;
49
- /** Y position. */
50
- y?: number;
51
- }
52
-
53
- export type StyledAxisProps = Omit<
54
- AxisProps,
55
- 'areXLabelsRotated' | 'size' | 'scale'
56
- > & {};
@@ -1,152 +0,0 @@
1
- import React from 'react';
2
- // @ts-ignore
3
- import type { StoryObj } from '@storybook/react';
4
- import { scaleLinear as d3scaleLinear } from 'd3';
5
-
6
- import { Bar, BarOrientation, BarProps } from '.';
7
- import { BarDatum, TooltipVariant } from '../../types';
8
-
9
- const meta = {
10
- title: 'Charts/Core/Bar',
11
- component: Bar,
12
- };
13
-
14
- export default meta;
15
- type Story = StoryObj<BarProps>;
16
-
17
- const scale = d3scaleLinear().domain([0, 1000]).range([0, 500]);
18
-
19
- export const Simple: Story = {
20
- render: () => (
21
- <>
22
- {Object.keys(BarOrientation).map((orientation) => (
23
- <svg width={500} height={500} key={orientation}>
24
- <Bar
25
- orientation={orientation}
26
- data={{
27
- data: {
28
- key: 'Croissant',
29
- value: 333,
30
- },
31
- }}
32
- scale={scale}
33
- />
34
- </svg>
35
- ))}
36
- </>
37
- ),
38
- };
39
-
40
- export const Clickable: Story = {
41
- render: () => (
42
- <>
43
- {Object.keys(BarOrientation).map((orientation) => (
44
- <svg width={500} height={500} key={orientation}>
45
- <Bar
46
- index={0}
47
- isSelected={false}
48
- onClick={(datum) => console.log(datum)}
49
- orientation={orientation}
50
- data={{
51
- data: {
52
- key: 'Button',
53
- value: 150,
54
- },
55
- }}
56
- scale={scale}
57
- />
58
- <Bar
59
- index={1}
60
- isSelected
61
- onClick={(datum) => {
62
- window.open(
63
- `https://en.wikipedia.org/wiki/${datum.data.key}`,
64
- '_blank'
65
- );
66
- }}
67
- orientation={orientation}
68
- data={{
69
- data: {
70
- key: 'Link',
71
- value: 333,
72
- },
73
- }}
74
- role="link"
75
- scale={scale}
76
- />
77
- </svg>
78
- ))}
79
- </>
80
- ),
81
- };
82
-
83
- export const Selectable: Story = {
84
- render: () => (
85
- <>
86
- {Object.keys(BarOrientation).map((orientation) => (
87
- <svg width={500} height={500} key={orientation}>
88
- <Bar
89
- index={0}
90
- isSelected={false}
91
- orientation={orientation}
92
- data={{
93
- data: {
94
- key: 'Deselected',
95
- value: 150,
96
- },
97
- }}
98
- role="option"
99
- scale={scale}
100
- />
101
- <Bar
102
- index={1}
103
- isSelected
104
- orientation={orientation}
105
- data={{
106
- data: {
107
- key: 'Selected',
108
- value: 333,
109
- },
110
- }}
111
- role="option"
112
- scale={scale}
113
- />
114
- </svg>
115
- ))}
116
- </>
117
- ),
118
- };
119
-
120
- export const WithTooltip: Story = {
121
- render: () => (
122
- <>
123
- {Object.keys(BarOrientation).map((orientation) => (
124
- <svg width={500} height={500} key={orientation}>
125
- {Object.keys(TooltipVariant).map((tooltipVariant, index) => (
126
- <Bar
127
- index={index}
128
- isSelected
129
- key={tooltipVariant}
130
- labelDecorator={(datum: BarDatum) =>
131
- `${datum.data.key
132
- .charAt(0)
133
- .toUpperCase()}${datum.data.key.slice(1)}`
134
- }
135
- orientation={orientation}
136
- data={{
137
- data: {
138
- key: tooltipVariant,
139
- value: 333,
140
- percent: 0.05,
141
- },
142
- }}
143
- tooltipVariant={tooltipVariant as TooltipVariant}
144
- role="option"
145
- scale={scale}
146
- />
147
- ))}
148
- </svg>
149
- ))}
150
- </>
151
- ),
152
- };
@@ -1,158 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { scaleLinear as d3scaleLinear } from 'd3';
5
-
6
- import { Bar } from './Bar';
7
- import { TooltipVariant } from '../../types';
8
-
9
- jest.mock('react', () => ({
10
- ...jest.requireActual('react'),
11
- useId: () => '123',
12
- }));
13
-
14
- const scale = d3scaleLinear().domain([0, 1000]).range([0, 500]);
15
-
16
- describe('Bar', () => {
17
- const onClickSpy = jest.fn();
18
-
19
- afterEach(() => {
20
- onClickSpy.mockClear();
21
- });
22
-
23
- it('supports click', async () => {
24
- const { getByRole } = render(
25
- <svg width={500} height={500}>
26
- <Bar
27
- id="123"
28
- index={0}
29
- data={{
30
- data: {
31
- key: 'Croissant',
32
- value: 333,
33
- },
34
- }}
35
- scale={scale}
36
- onClick={onClickSpy}
37
- />
38
- </svg>
39
- );
40
-
41
- const bar = getByRole('button');
42
- fireEvent.click(bar);
43
- expect(onClickSpy).toHaveBeenCalledWith({
44
- data: { key: 'Croissant', value: 333 },
45
- });
46
- });
47
-
48
- it('supports keydown', async () => {
49
- const { getByRole } = render(
50
- <svg width={500} height={500}>
51
- <Bar
52
- id="123"
53
- index={0}
54
- data={{
55
- data: {
56
- key: 'Croissant',
57
- value: 333,
58
- },
59
- }}
60
- scale={scale}
61
- onClick={onClickSpy}
62
- orientation="vertical"
63
- />
64
- </svg>
65
- );
66
-
67
- const bar = getByRole('button');
68
- fireEvent.keyDown(bar, { key: 'Enter', code: 'Enter', charCode: 13 });
69
- expect(onClickSpy).toHaveBeenCalledWith({
70
- data: { key: 'Croissant', value: 333 },
71
- });
72
- });
73
-
74
- it('shows a tooltip on hover', async () => {
75
- const user = userEvent.setup();
76
- const { getByRole } = render(
77
- <svg width={500} height={500}>
78
- <Bar
79
- id="123"
80
- index={0}
81
- // The onClick gives the bar the role "button" which is then used to access the bars.
82
- onClick={onClickSpy}
83
- data={{
84
- data: {
85
- key: 'Croissant',
86
- value: 333,
87
- },
88
- }}
89
- scale={scale}
90
- tooltipVariant={TooltipVariant.label}
91
- />
92
- </svg>
93
- );
94
-
95
- const bar = getByRole('button');
96
- await user.hover(bar);
97
- await waitFor(() => {
98
- expect(screen.getByRole('tooltip', { exact: true })).toBeInTheDocument();
99
- });
100
- const tooltip = screen.getByRole('tooltip');
101
- expect(tooltip.textContent).toContain('Croissant');
102
- });
103
-
104
- it.each`
105
- Type | props | result
106
- ${'with label'} | ${{ data: { data: { key: 'Croissant', value: 333 } }, tooltipVariant: TooltipVariant.label }} | ${'Croissant'}
107
- ${'with value'} | ${{ data: { data: { key: 'Croissant', value: 333 } }, tooltipVariant: TooltipVariant.value }} | ${'Croissant - 333'}
108
- ${'with percent'} | ${{ data: { data: { key: 'Croissant', value: 333, percent: 0.05 } }, tooltipVariant: TooltipVariant.percent }} | ${'Croissant - 5%'}
109
- ${'with empty value if there is a label'} | ${{ data: { data: { key: 'Croissant', value: 0 } }, tooltipVariant: TooltipVariant.value }} | ${'Croissant'}
110
- `('it shows a tooltip on hover $Type', async function ({ props, result }) {
111
- const user = userEvent.setup();
112
- const { getByRole } = render(
113
- <svg width={500} height={500}>
114
- <Bar
115
- id="123"
116
- index={0}
117
- // The onClick gives the bar the role "button" which is then used to access the bars.
118
- onClick={onClickSpy}
119
- scale={scale}
120
- {...props}
121
- />
122
- </svg>
123
- );
124
-
125
- const bar = getByRole('button');
126
- await user.hover(bar);
127
- await waitFor(() => {
128
- expect(screen.getByRole('tooltip', { exact: true })).toBeInTheDocument();
129
- });
130
- const tooltip = screen.getByRole('tooltip');
131
- expect(tooltip.textContent).toBe(result);
132
- });
133
-
134
- it.each`
135
- Type | props
136
- ${'with variant label when label is empty'} | ${{ data: { data: { key: '', value: 333 } }, tooltipVariant: TooltipVariant.label }}
137
- `('it does not show a tooltip on hover $Type', async function ({ props }) {
138
- const user = userEvent.setup();
139
- const { getByRole } = render(
140
- <svg width={500} height={500}>
141
- <Bar
142
- id="123"
143
- index={0}
144
- // The onClick gives the bar the role "button" which is then used to access the bars.
145
- onClick={onClickSpy}
146
- scale={scale}
147
- {...props}
148
- />
149
- </svg>
150
- );
151
-
152
- const bar = getByRole('button');
153
- await user.hover(bar);
154
- expect(() => screen.getByRole('tooltip')).toThrow(
155
- 'Unable to find an accessible element with the role "tooltip"'
156
- );
157
- });
158
- });
@@ -1,112 +0,0 @@
1
- import React, { forwardRef } from 'react';
2
- import classNames from 'classnames';
3
- import { animated, useSpring } from '@react-spring/web';
4
- import { interpolate as d3interpolate } from 'd3';
5
-
6
- import { Comp } from '@redsift/design-system';
7
-
8
- import { BarOrientation, BarProps } from './types';
9
- import { StyledBar } from './styles';
10
- import { monochrome } from '../../scheme';
11
- import { config } from '../../config';
12
-
13
- const COMPONENT_NAME = 'Bar';
14
- const CLASSNAME = 'redsift-bar';
15
- const DEFAULT_PROPS: Partial<BarProps> = {
16
- color: monochrome,
17
- index: 0,
18
- gap: 5,
19
- height: 40,
20
- orientation: BarOrientation.horizontal,
21
- previousData: {
22
- data: {
23
- key: '',
24
- value: 0,
25
- },
26
- },
27
- width: 40,
28
- };
29
-
30
- export const Bar: Comp<BarProps, SVGGElement> = forwardRef((props, ref) => {
31
- const {
32
- color,
33
- data,
34
- index,
35
- isSelected: propsIsSelected,
36
- labelDecorator,
37
- onClick,
38
- role,
39
- } = props;
40
-
41
- const {
42
- className,
43
- gap,
44
- height,
45
- orientation,
46
- previousData,
47
- scale,
48
- width,
49
- ...forwardedProps
50
- } = props;
51
-
52
- const interpolator = d3interpolate(
53
- previousData!.data?.value || 0,
54
- data.data.value
55
- );
56
-
57
- const text = labelDecorator ? labelDecorator(data) : data.data.key;
58
- const isSelectable = role === 'option';
59
- const isDeselected = isSelectable && propsIsSelected === false;
60
-
61
- const animatedProps = useSpring({
62
- ...config,
63
- to: async (next: (props?: object) => Promise<void>) => {
64
- await next({ t: 1 });
65
- },
66
- from: { t: 0 },
67
- });
68
-
69
- return (
70
- <StyledBar
71
- {...forwardedProps}
72
- ref={ref}
73
- className={classNames(Bar.className, className)}
74
- transform={
75
- orientation === BarOrientation.horizontal
76
- ? `translate(0, ${gap! * (index! + 1) + height! * index!})`
77
- : `translate(${gap! * (index! + 1) + width! * index!}, 0)`
78
- }
79
- $clickable={Boolean(onClick)}
80
- >
81
- {orientation === BarOrientation.horizontal ? (
82
- <animated.rect
83
- height={height}
84
- fill={isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color}
85
- width={
86
- config.immediate
87
- ? scale(data.data.value)
88
- : animatedProps.t.to((t) => scale(interpolator(t)))
89
- }
90
- />
91
- ) : (
92
- <animated.rect
93
- height={
94
- config.immediate
95
- ? scale(data.data.value)
96
- : animatedProps.t.to((t) => scale(interpolator(t)))
97
- }
98
- fill={isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color}
99
- width={width}
100
- />
101
- )}
102
- {orientation === BarOrientation.horizontal ? (
103
- <text x="10" y={height! / 2} dy="0.35em" aria-hidden={true}>
104
- {text}
105
- </text>
106
- ) : null}
107
- </StyledBar>
108
- );
109
- });
110
- Bar.className = CLASSNAME;
111
- Bar.defaultProps = DEFAULT_PROPS;
112
- Bar.displayName = COMPONENT_NAME;
@@ -1,3 +0,0 @@
1
- export * from './Bar';
2
- export * from './types';
3
- export * from './styles';
@@ -1,54 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
- import { StyledBarProps } from './types';
3
- import { DataPoint } from '../DataPoint';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledBar = styled(DataPoint)<StyledBarProps>`
9
- rect {
10
- fill-opacity: 0.9;
11
- }
12
-
13
- ${({ $clickable }) =>
14
- $clickable
15
- ? css`
16
- cursor: pointer;
17
-
18
- &:hover,
19
- &:focus,
20
- &.focused {
21
- outline: none;
22
- rect {
23
- fill-opacity: 0.7;
24
- }
25
- }
26
-
27
- // &:focus-visible {
28
- // rect {
29
- // stroke: var(--redsift-color-default-primary);
30
- // stroke-width: 4px;
31
- // paint-order: stroke;
32
- // }
33
- // }
34
-
35
- @media (prefers-reduced-motion: no-preference) {
36
- &:focus-visible,
37
- &.focused {
38
- outline: 2px solid var(--redsift-color-default-primary);
39
- transition: outline-offset 75ms ease-out;
40
- }
41
-
42
- &:not(&:active)&:focus-visible,
43
- &:not(&:active)&.focused {
44
- transition-duration: 0.25s;
45
- }
46
- }
47
-
48
- &:not(&:active)&:focus-visible,
49
- &:not(&:active)&.focused {
50
- outline-offset: 0.2rem;
51
- }
52
- `
53
- : ''}}
54
- `;
@@ -1,31 +0,0 @@
1
- import { ScaleLinear as d3ScaleLinear } from 'd3';
2
- import { ValueOf } from '@redsift/design-system';
3
- import { BarDatum } from '../../types';
4
- import { DataPointProps, StyledDataPointProps } from '../DataPoint';
5
-
6
- /**
7
- * Component variant.
8
- */
9
- export const BarOrientation = {
10
- horizontal: 'horizontal',
11
- vertical: 'vertical',
12
- };
13
- export type BarOrientation = ValueOf<typeof BarOrientation>;
14
-
15
- /**
16
- * Component props.
17
- */
18
- export interface BarProps extends DataPointProps<BarDatum> {
19
- /** Gap between two siblings. */
20
- gap?: number;
21
- /** Height of the bar in horizontal orientation. */
22
- height?: number;
23
- /** Orientation of the bar. */
24
- orientation?: BarOrientation;
25
- /** A linear continuous scale defined over a numeric domain used to determine the width or height of the bar (depending on the orientation). */
26
- scale: d3ScaleLinear<number, number, never>;
27
- /** Width of the bar in vertical orientation. */
28
- width?: number;
29
- }
30
-
31
- export type StyledBarProps = StyledDataPointProps & Omit<BarProps, 'scale'>;
@@ -1,80 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
-
3
- import { DataVizColorPalette } from '@redsift/design-system';
4
- import { BarChart } from '.';
5
- import {
6
- CategoryData,
7
- ChartSize,
8
- ChartTheme,
9
- ColorTheme,
10
- TooltipVariant,
11
- } from '../../types';
12
-
13
- const themes = {
14
- ...ColorTheme,
15
- 'success-warning-danger': {
16
- success: 'Bread',
17
- warning: 'Tea',
18
- danger: 'Coffee',
19
- },
20
- 'success-warning-danger-neutral': {
21
- success: 'Bread',
22
- warning: 'Tea',
23
- danger: 'Coffee',
24
- neutral: 'Pastry',
25
- },
26
- custom: {
27
- Coffee: DataVizColorPalette.purple,
28
- Bread: DataVizColorPalette.pink,
29
- Tea: DataVizColorPalette.aqua,
30
- },
31
- };
32
-
33
- const meta: Meta<typeof BarChart> = {
34
- title: 'Charts/BarChart',
35
- component: BarChart as any,
36
- argTypes: {
37
- tooltipVariant: {
38
- options: Object.values(TooltipVariant),
39
- control: { type: 'select' },
40
- },
41
- size: {
42
- options: Object.values(ChartSize),
43
- control: { type: 'select' },
44
- },
45
- theme: {
46
- options: Object.keys(themes),
47
- mapping: themes,
48
- control: {
49
- type: 'select',
50
- },
51
- },
52
- },
53
- };
54
- export default meta;
55
- type Story = StoryObj<typeof BarChart>;
56
-
57
- const data: CategoryData = [
58
- { key: 'Cookies', value: 540 },
59
- { key: 'Coffee', value: 5471 },
60
- { key: 'Bread', value: 3325 },
61
- { key: 'Tea', value: 1435 },
62
- { key: 'Pastry', value: 856 },
63
- { key: 'Sandwich', value: 771 },
64
- { key: 'Croissant', value: 771 },
65
- { key: 'Hot chocolate', value: 588 },
66
- { key: 'Toast', value: 318 },
67
- ];
68
-
69
- export const Controls: Story = {
70
- args: {
71
- title: 'Bar Chart',
72
- tooltipVariant: 'value',
73
- size: 'medium',
74
- theme: 'success-warning-danger-neutral' as ChartTheme,
75
- caping: 4,
76
- others: true,
77
- onBarClick: (datum) => console.log(datum),
78
- data: data,
79
- },
80
- };