@redsift/charts 8.0.1 → 8.0.3

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 -28
  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 './PieChart';
2
- export * from './types';
3
- export * from './styles';
@@ -1,97 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
- import { StyledPieChartProps } from './types';
3
- import { ChartContainer } from '../ChartContainer';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledPieChart = styled(ChartContainer)<StyledPieChartProps>`
9
- .redsift-piechart__chart-wrapper {
10
- position: relative;
11
- }
12
- `;
13
-
14
- export const StyledPieChartCenterText = styled.div<{
15
- $maxWidth: number;
16
- $textSize: number;
17
- $smallTextSize: number;
18
- }>`
19
- position: absolute;
20
- top: 0;
21
- left: 0;
22
- height: 100%;
23
- width: 100%;
24
- display: flex;
25
- flex-direction: column;
26
- justify-content: center;
27
- align-items: center;
28
- pointer-events: none;
29
-
30
- > * {
31
- max-width: ${({ $maxWidth }) => $maxWidth}px;
32
- }
33
-
34
- > b {
35
- font-family: var(--redsift-typography-font-family-source-code-pro);
36
- color: var(--redsift-color-neutral-black);
37
- font-weight: var(--redsift-typography-font-weight-medium);
38
- font-size: ${({ $textSize }) => $textSize}px;
39
- line-height: ${({ $textSize }) => $textSize}px;
40
-
41
- &:nth-child(2) {
42
- font-weight: normal;
43
- margin-top: 8px;
44
- font-family: var(--redsift-typography-font-family-raleway);
45
- font-size: ${({ $smallTextSize }) => $smallTextSize}px;
46
- line-height: ${({ $smallTextSize }) => $smallTextSize}px;
47
- }
48
- }
49
- > span {
50
- color: var(--redsift-color-neutral-black);
51
- font-size: ${({ $textSize }) => $textSize}px;
52
- line-height: ${({ $textSize }) => $textSize}px;
53
- &:nth-child(3) {
54
- margin-top: 4px;
55
- font-size: ${({ $smallTextSize }) => $smallTextSize}px;
56
- line-height: ${({ $smallTextSize }) => $smallTextSize}px;
57
- }
58
- }
59
- > b + span {
60
- font-size: var(--redsift-typography-body-font-size);
61
- font-family: var(--redsift-typography-font-family-raleway);
62
- line-height: var(--redsift-typography-badge-line-height);
63
- color: rgba(0, 0, 0, 0.6);
64
- text-align: center;
65
- }
66
- `;
67
-
68
- export const StyledPieChartEmptyText = styled.div<{
69
- $maxWidth: number;
70
- $textSize: number;
71
- $isDonut: boolean;
72
- }>`
73
- position: absolute;
74
- top: 0;
75
- left: 0;
76
- height: 100%;
77
- width: 100%;
78
- display: flex;
79
- flex-direction: column;
80
- justify-content: center;
81
- align-items: center;
82
- pointer-events: none;
83
-
84
- > * {
85
- max-width: ${({ $maxWidth }) => $maxWidth}px;
86
- }
87
-
88
- > span {
89
- font-family: var(--redsift-typography-font-family-raleway);
90
- color: ${({ $isDonut }) =>
91
- $isDonut
92
- ? css`var(--redsift-color-neutral-midgrey)`
93
- : css`var(--redsift-color-neutral-black)`};
94
- font-size: ${({ $textSize }) => $textSize}px;
95
- line-height: ${({ $textSize }) => $textSize}px;
96
- }
97
- `;
@@ -1,89 +0,0 @@
1
- import {
2
- ChartDimensions,
3
- ChartSize,
4
- ChartTheme,
5
- ArcDatum,
6
- TooltipVariant,
7
- CategoryData,
8
- } from '../../types';
9
- import { ValueOf } from '@redsift/design-system';
10
- import { ArcProps } from '../Arc';
11
- import { ChartContainerProps } from '../ChartContainer';
12
- import { ComponentProps, ReactNode } from 'react';
13
-
14
- /**
15
- * Component variant.
16
- */
17
- export const PieChartVariant = {
18
- plain: 'plain',
19
- spaced: 'spaced',
20
- donut: 'donut',
21
- spacedDonut: 'spacedDonut',
22
- } as const;
23
- export type PieChartVariant = ValueOf<typeof PieChartVariant>;
24
-
25
- /**
26
- * Component's labels variant.
27
- */
28
- export const PieChartLabelVariant = {
29
- none: 'none',
30
- internal: 'internal',
31
- externalLabel: 'externalLabel',
32
- externalLabelValue: 'externalLabelValue',
33
- externalLabelPercent: 'externalLabelPercent',
34
- } as const;
35
- export type PieChartLabelVariant = ValueOf<typeof PieChartLabelVariant>;
36
-
37
- interface LocaleText {
38
- emptyChartText: string;
39
- }
40
-
41
- export type PieChartDimensions = ChartDimensions & {
42
- smallFontSize: number;
43
- fontSize: number;
44
- innerRadius: number;
45
- };
46
-
47
- /**
48
- * Component props.
49
- */
50
- export interface PieChartProps extends ChartContainerProps {
51
- /** Number of categories to use, the rest being put into a new category called "Others". */
52
- caping?: number;
53
- /** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */
54
- data?: CategoryData;
55
- /** Component to use if the chart is empty (replacing the default one). */
56
- emptyComponent?: ReactNode;
57
- /** Method to determine whether a slice is selected or not. */
58
- isSliceSelected?: (datum: ArcDatum) => boolean | undefined;
59
- /** Method to override the data labels. */
60
- labelDecorator?: (datum: ArcDatum) => string;
61
- /** Define whether the labels should be displayed inside or outside the charts and if they should contain raw or percentage values. */
62
- labelVariant?: PieChartLabelVariant;
63
- /** Labels and texts. */
64
- localeText?: LocaleText;
65
- /** Method to be called on a click on a slice. */
66
- onSliceClick?: (datum: ArcDatum) => void;
67
- /** 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. */
68
- others?: boolean | string;
69
- /** PieChart size. */
70
- size?: ChartSize | PieChartDimensions;
71
- /** Native HTML props to forward to each slice. */
72
- sliceProps?: Omit<ComponentProps<'g'>, 'onClick' | 'ref' | 'width'>;
73
- /** Slice role. Used to indicate that slices are to be considered buttons or links. If an onClick is provided, the slices will have the role `button` unless specifically set to `link` with this prop. */
74
- sliceRole?: ArcProps['role'];
75
- /** Secondary text to be displayed in the middle of the chart, between the main text and subtext. Recommended to be used with donut variants only. */
76
- middleText?: string;
77
- /** Secondary text to be displayed in the middle of the chart, above the main text. Recommended to be used with `donut` variants only. */
78
- subtext?: string;
79
- /** Main text to be displayed in the middle of the chart. Recommended to be used with `donut` variants only. */
80
- text?: string;
81
- /** 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. */
82
- theme?: ChartTheme;
83
- /** PieChart variant. */
84
- variant?: PieChartVariant;
85
- /** Tooltip variant. */
86
- tooltipVariant?: TooltipVariant;
87
- }
88
-
89
- export type StyledPieChartProps = PieChartProps & {};
@@ -1,38 +0,0 @@
1
- import { ChartSize } from '../../types';
2
- import { PieChartDimensions } from './types';
3
-
4
- export const sizeToDimension = (
5
- size: ChartSize | PieChartDimensions
6
- ): PieChartDimensions => {
7
- if (typeof size !== 'string') {
8
- return size;
9
- }
10
-
11
- switch (size) {
12
- case ChartSize.small:
13
- return {
14
- width: 200,
15
- height: 200,
16
- smallFontSize: 13,
17
- fontSize: 30,
18
- innerRadius: 55,
19
- };
20
- case ChartSize.large:
21
- return {
22
- width: 300,
23
- height: 300,
24
- smallFontSize: 18,
25
- fontSize: 38,
26
- innerRadius: 80,
27
- };
28
- case ChartSize.medium:
29
- default:
30
- return {
31
- width: 240,
32
- height: 240,
33
- smallFontSize: 14,
34
- fontSize: 34,
35
- innerRadius: 65,
36
- };
37
- }
38
- };
@@ -1,70 +0,0 @@
1
- import React, { forwardRef, RefObject, useEffect, useRef } from 'react';
2
- import { scaleLinear as d3scaleLinear } from 'd3';
3
-
4
- import { AnyScale, JSONArray } from '../../types';
5
- import { ScatterPlotProps } from './types';
6
- import { StyledScatterPlot, StyledScatterPlotEmptyText } from './styles';
7
- import { Axis } from '../Axis';
8
- import { sizeToDimension } from './utils';
9
-
10
- export const EmptyScatterPlot = forwardRef<HTMLDivElement, ScatterPlotProps>(
11
- (props, ref) => {
12
- const {
13
- className,
14
- data: propsData,
15
- emptyComponent,
16
- localeText,
17
- size,
18
- ...forwardedProps
19
- } = props;
20
-
21
- const cache = useRef<JSONArray>();
22
-
23
- const data = propsData;
24
-
25
- useEffect(() => {
26
- cache.current = data;
27
- });
28
-
29
- const chartDimensions = sizeToDimension(size!);
30
- const width = chartDimensions.width;
31
- const height = chartDimensions.height;
32
- const margins = { top: 16, left: 48, right: 16, bottom: 48 };
33
- const chartWidth = width - margins.left - margins.right;
34
-
35
- return (
36
- <StyledScatterPlot
37
- {...forwardedProps}
38
- className={className}
39
- ref={ref as RefObject<HTMLDivElement>}
40
- >
41
- {emptyComponent ?? (
42
- <>
43
- <StyledScatterPlotEmptyText
44
- $maxWidth={width}
45
- $textSize={chartDimensions.fontSize / 2}
46
- >
47
- <span>{localeText?.emptyChartText}</span>
48
- </StyledScatterPlotEmptyText>
49
- <svg width={width} height={height}>
50
- <g transform={`translate(${margins.left},${margins.top})`}>
51
- <Axis
52
- position="bottom"
53
- length={width - 32}
54
- scale={
55
- d3scaleLinear()
56
- .domain([])
57
- .range([0, chartWidth]) as AnyScale
58
- }
59
- x={0}
60
- y={height}
61
- tickValues={4}
62
- />
63
- </g>
64
- </svg>
65
- </>
66
- )}
67
- </StyledScatterPlot>
68
- );
69
- }
70
- );
@@ -1,20 +0,0 @@
1
- import React, { forwardRef, RefObject } from 'react';
2
-
3
- import { ScatterPlotProps } from './types';
4
- import { StyledScatterPlot } from './styles';
5
-
6
- export const LoadingScatterPlot = forwardRef<HTMLDivElement, ScatterPlotProps>(
7
- (props, ref) => {
8
- const { className, ...forwardedProps } = props;
9
-
10
- return (
11
- <StyledScatterPlot
12
- {...forwardedProps}
13
- className={className}
14
- ref={ref as RefObject<HTMLDivElement>}
15
- >
16
- Loading...
17
- </StyledScatterPlot>
18
- );
19
- }
20
- );
@@ -1,275 +0,0 @@
1
- import React, { forwardRef, RefObject, useEffect, useRef } from 'react';
2
- import {
3
- BrushBehavior as d3BrushBehavior,
4
- descending as d3descending,
5
- extent as d3extent,
6
- max as d3max,
7
- min as d3min,
8
- scaleLinear as d3scaleLinear,
9
- scaleSqrt as d3scaleSqrt,
10
- select as d3select,
11
- } from 'd3';
12
-
13
- import { AnyScale, JSONArray, LabelVariant } from '../../types';
14
- import {
15
- ScatterPlotLabelVariant,
16
- ScatterPlotProps,
17
- ScatterPlotVariant,
18
- } from './types';
19
- import { StyledScatterPlot } from './styles';
20
- import { useZoom, useColor, useBrush } from '../../hooks';
21
- import { Axis } from '../Axis';
22
- import { Legend } from '../Legend';
23
- import { Dot } from '../Dot';
24
- import { BASE_NUMBER_OF_TICKS, countBy, group, sizeToDimension } from './utils';
25
-
26
- interface RenderedScatterPlotProps
27
- extends Required<Pick<ScatterPlotProps, 'data'>>,
28
- Omit<ScatterPlotProps, 'data'> {}
29
-
30
- export const RenderedScatterPlot = forwardRef<
31
- HTMLDivElement,
32
- RenderedScatterPlotProps
33
- >((props, ref) => {
34
- const {
35
- isBrushable,
36
- className,
37
- data: propsData,
38
- dotRole,
39
- id,
40
- isDotSelected,
41
- labelDecorator,
42
- labelVariant,
43
- legendProps,
44
- onBrush,
45
- onBrushEnd,
46
- onDotClick,
47
- size,
48
- theme,
49
- tooltipVariant,
50
- variant,
51
- xAxisVariant,
52
- yAxisVariant,
53
- ...forwardedProps
54
- } = props;
55
-
56
- const cache = useRef<JSONArray>();
57
-
58
- const data = propsData.filter(
59
- (datum) =>
60
- datum.value &&
61
- typeof datum.key[0] === 'number' &&
62
- !Number.isNaN(datum.key[0]) &&
63
- typeof datum.key[1] === 'number' &&
64
- !Number.isNaN(datum.key[1])
65
- );
66
-
67
- useEffect(() => {
68
- cache.current = data;
69
- });
70
-
71
- const chartDimensions = sizeToDimension(size!);
72
- const width = chartDimensions.width;
73
- const height = chartDimensions.height;
74
- const margins = { top: 16, left: 48, right: 16, bottom: 48 };
75
- const chartHeight = height - margins.top - margins.bottom;
76
- const chartWidth = width - margins.left - margins.right;
77
- const minSize = d3min([chartWidth, chartHeight]) as number;
78
-
79
- const extendedScaleX = (() => {
80
- const domain = d3extent(data, (d) => d.key[0]) as [number, number];
81
- const gap = domain[1] - domain[0];
82
- domain[0] -= gap * 0.1;
83
- domain[1] += gap * 0.1;
84
- return d3scaleLinear().domain(domain).range([0, chartWidth]).nice();
85
- })();
86
- const extendedScaleY = (() => {
87
- const domain = d3extent(data, (d) => d.key[1]) as [number, number];
88
- const gap = domain[1] - domain[0];
89
- domain[0] -= gap * 0.1;
90
- domain[1] += gap * 0.1;
91
- return d3scaleLinear().domain(domain).range([chartHeight, 0]).nice();
92
- })();
93
-
94
- const hasCategory =
95
- data[0] &&
96
- data[0].key.length >= 3 &&
97
- data[0].key[2] !== null &&
98
- data[0].key[2] !== undefined;
99
- const countsByCategory = hasCategory ? countBy(data) : undefined;
100
- const colorScale = useColor({
101
- data: countsByCategory || data,
102
- theme: theme!,
103
- category: 'key',
104
- });
105
-
106
- const svgRef = useRef<SVGSVGElement>();
107
- const brushRef = useRef<d3BrushBehavior<unknown>>();
108
- const svgBrushRef = useRef<SVGGElement>();
109
- const { scaleX, scaleY, transform } = useZoom({
110
- svgRef,
111
- scaleX: extendedScaleX,
112
- scaleY: extendedScaleY,
113
- size,
114
- onZoom: () => {
115
- if (brushRef.current && svgBrushRef.current) {
116
- brushRef.current.clear(d3select(svgBrushRef.current));
117
-
118
- onBrushEnd?.(null);
119
- }
120
- },
121
- });
122
- useBrush({
123
- brushRef,
124
- svgRef: svgBrushRef,
125
- extent: [
126
- [0, 0],
127
- [chartWidth, chartHeight],
128
- ],
129
- scaleX,
130
- scaleY,
131
- isBrushable,
132
- isGridded: variant === ScatterPlotVariant.gridded,
133
- onBrush,
134
- onBrushEnd,
135
- });
136
-
137
- const circles =
138
- variant === ScatterPlotVariant.gridded
139
- ? group(data, scaleX, scaleY).sort((a, b) =>
140
- d3descending(a.points.length, b.points.length)
141
- )
142
- : data.map((d) => ({
143
- category: d.key[2],
144
- x: d.key[0],
145
- y: d.key[1],
146
- data: {
147
- key: d.key,
148
- value: 1,
149
- },
150
- points: [d],
151
- }));
152
- const globalSize =
153
- variant === ScatterPlotVariant.gridded
154
- ? d3scaleSqrt()
155
- .domain([1, Math.max(d3max(circles, (d) => d.points.length)!, 1)])
156
- .range([3, minSize / BASE_NUMBER_OF_TICKS / 2])
157
- : undefined;
158
- const legendWidth = useRef<string>();
159
- if (countsByCategory && !legendWidth.current) {
160
- legendWidth.current = `${
161
- Math.max(
162
- ...countsByCategory.map((d) => d.key.length + String(d.value).length)
163
- ) *
164
- 8 +
165
- 32
166
- }px`;
167
- }
168
-
169
- return (
170
- <StyledScatterPlot
171
- {...forwardedProps}
172
- id={id}
173
- className={className}
174
- ref={ref as RefObject<HTMLDivElement>}
175
- >
176
- <svg
177
- ref={svgRef as RefObject<SVGSVGElement>}
178
- width={width}
179
- height={height}
180
- >
181
- <g
182
- ref={svgBrushRef as RefObject<SVGGElement>}
183
- transform={`translate(${margins.left},${margins.top})`}
184
- />
185
- <g transform={`translate(${margins.left},${margins.top})`}>
186
- <g>
187
- {circles.map((circle, index) => {
188
- const scaleXDomain = scaleX.domain();
189
- const scaleYDomain = scaleY.domain();
190
-
191
- if (
192
- circle.x! < scaleXDomain[0] ||
193
- circle.x! > scaleXDomain[1] ||
194
- circle.y! < scaleYDomain[0] ||
195
- circle.y! > scaleYDomain[1]
196
- ) {
197
- return null;
198
- }
199
-
200
- const to = {
201
- ...circle,
202
- data: {
203
- ...circle.data,
204
- percent: circle.category
205
- ? circle.data.value /
206
- countsByCategory?.find(
207
- ({ key }) => key === circle.category
208
- )?.value!
209
- : undefined,
210
- },
211
- r:
212
- variant === ScatterPlotVariant.gridded
213
- ? globalSize!(circle.points.length) /
214
- (transform.k < 1 ? transform.k : 1)
215
- : 4,
216
- };
217
-
218
- return (
219
- <Dot
220
- color={colorScale?.(circle.category!)}
221
- data={to}
222
- isSelected={Boolean(isDotSelected?.(to))}
223
- key={`circle _${index}`}
224
- labelDecorator={labelDecorator}
225
- onClick={onDotClick}
226
- role={dotRole}
227
- scaleX={scaleX}
228
- scaleY={scaleY}
229
- tooltipVariant={tooltipVariant}
230
- />
231
- );
232
- })}
233
- </g>
234
- </g>
235
- <g transform={`translate(${margins.left},${margins.top})`}>
236
- <Axis
237
- position="left"
238
- length={chartHeight}
239
- scale={scaleY as AnyScale}
240
- x={0}
241
- y={0}
242
- tickValues={8}
243
- variant={xAxisVariant}
244
- />
245
- <Axis
246
- position="bottom"
247
- length={chartWidth}
248
- scale={scaleX as AnyScale}
249
- x={0}
250
- y={chartHeight}
251
- tickValues={8}
252
- variant={yAxisVariant}
253
- />
254
- </g>
255
- </svg>
256
- {hasCategory && labelVariant !== ScatterPlotLabelVariant.none ? (
257
- <Legend
258
- data={countsByCategory!.map((d) => ({
259
- ...d,
260
- color: colorScale?.(d.key)!,
261
- }))}
262
- variant={
263
- labelVariant === ScatterPlotLabelVariant.externalLabelValue
264
- ? LabelVariant.value
265
- : labelVariant === ScatterPlotLabelVariant.externalLabelPercent
266
- ? LabelVariant.percent
267
- : LabelVariant.label
268
- }
269
- width={legendWidth.current}
270
- {...legendProps}
271
- />
272
- ) : null}
273
- </StyledScatterPlot>
274
- );
275
- });
@@ -1,95 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
-
3
- import mock from '../../../../../.storybook/static/mocks/bakery-trimmed.json';
4
-
5
- import { DataVizColorPalette } from '@redsift/design-system';
6
- import { ScatterPlot } from '.';
7
- import { ScatterPlotLabelVariant, ScatterPlotVariant } from './types';
8
- import {
9
- ChartSize,
10
- ColorTheme,
11
- CoordinatesCategoryData,
12
- CoordinatesCategoryDim,
13
- TooltipVariant,
14
- } from '../../types';
15
- import { AxisVariant } from '../Axis';
16
-
17
- export const themes = {
18
- ...ColorTheme,
19
- 'success-warning-danger': {
20
- success: 'Bread',
21
- warning: 'Tea',
22
- danger: 'Coffee',
23
- },
24
- 'success-warning-danger-neutral': {
25
- success: 'Bread',
26
- warning: 'Tea',
27
- danger: 'Coffee',
28
- neutral: 'Pastry',
29
- },
30
- custom: {
31
- Coffee: DataVizColorPalette.purple,
32
- Bread: DataVizColorPalette.pink,
33
- Tea: DataVizColorPalette.aqua,
34
- },
35
- };
36
-
37
- const meta: Meta<typeof ScatterPlot> = {
38
- title: 'Charts/ScatterPlot',
39
- component: ScatterPlot as any,
40
- argTypes: {
41
- variant: {
42
- options: Object.values(ScatterPlotVariant),
43
- control: { type: 'select' },
44
- },
45
- labelVariant: {
46
- options: Object.values(ScatterPlotLabelVariant),
47
- control: { type: 'select' },
48
- },
49
- tooltipVariant: {
50
- options: Object.values(TooltipVariant),
51
- control: { type: 'select' },
52
- },
53
- size: {
54
- options: Object.values(ChartSize),
55
- control: { type: 'select' },
56
- },
57
- theme: {
58
- options: Object.keys(themes),
59
- mapping: themes,
60
- control: {
61
- type: 'select',
62
- },
63
- },
64
- xAxisVariant: {
65
- options: Object.values(AxisVariant),
66
- control: { type: 'select' },
67
- },
68
- yAxisVariant: {
69
- options: Object.values(AxisVariant),
70
- control: { type: 'select' },
71
- },
72
- },
73
- };
74
- export default meta;
75
- type Story = StoryObj<typeof ScatterPlot>;
76
-
77
- const data: CoordinatesCategoryData = mock.map((d) => ({
78
- key: [+d.x!, +d.y!, d.Items] as CoordinatesCategoryDim,
79
- value: 1,
80
- }));
81
-
82
- export const Controls: Story = {
83
- args: {
84
- title: 'Scatter Plot',
85
- variant: 'gridded',
86
- labelVariant: 'externalLabelValue',
87
- tooltipVariant: 'value',
88
- size: 'medium',
89
- theme: 'default',
90
- isBrushable: true,
91
- xAxisVariant: 'default',
92
- yAxisVariant: 'default',
93
- data: data,
94
- },
95
- };