@redsift/charts 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/{dist/index.d.ts → index.d.ts} +8 -0
  2. package/{dist/index.js → index.js} +97 -25
  3. package/index.js.map +1 -0
  4. package/package.json +3 -2
  5. package/coverage/clover.xml +0 -1070
  6. package/coverage/coverage-final.json +0 -60
  7. package/coverage/lcov-report/ChartEmptyState/ChartEmptyState.tsx.html +0 -679
  8. package/coverage/lcov-report/ChartEmptyState/index.html +0 -146
  9. package/coverage/lcov-report/ChartEmptyState/index.ts.html +0 -91
  10. package/coverage/lcov-report/ChartEmptyState/styles.ts.html +0 -184
  11. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChart.tsx.html +0 -775
  12. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartAxisBottom.tsx.html +0 -259
  13. package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartBar.tsx.html +0 -421
  14. package/coverage/lcov-report/HorizontalBarChart/index.html +0 -191
  15. package/coverage/lcov-report/HorizontalBarChart/index.ts.html +0 -94
  16. package/coverage/lcov-report/HorizontalBarChart/styles.ts.html +0 -451
  17. package/coverage/lcov-report/HorizontalBarChart/types.ts.html +0 -433
  18. package/coverage/lcov-report/PieChart/PieChart.tsx.html +0 -1105
  19. package/coverage/lcov-report/PieChart/PieChartArc.tsx.html +0 -412
  20. package/coverage/lcov-report/PieChart/index.html +0 -176
  21. package/coverage/lcov-report/PieChart/index.ts.html +0 -94
  22. package/coverage/lcov-report/PieChart/styles.ts.html +0 -616
  23. package/coverage/lcov-report/PieChart/types.ts.html +0 -472
  24. package/coverage/lcov-report/PieChart.tsx.html +0 -1045
  25. package/coverage/lcov-report/PieChartArc.tsx.html +0 -271
  26. package/coverage/lcov-report/StaticPieChart.tsx.html +0 -286
  27. package/coverage/lcov-report/base.css +0 -224
  28. package/coverage/lcov-report/block-navigation.js +0 -87
  29. package/coverage/lcov-report/components/Arc/Arc.tsx.html +0 -304
  30. package/coverage/lcov-report/components/Arc/index.html +0 -146
  31. package/coverage/lcov-report/components/Arc/index.ts.html +0 -94
  32. package/coverage/lcov-report/components/Arc/styles.ts.html +0 -208
  33. package/coverage/lcov-report/components/Arcs/Arcs.tsx.html +0 -427
  34. package/coverage/lcov-report/components/Arcs/index.html +0 -146
  35. package/coverage/lcov-report/components/Arcs/index.ts.html +0 -94
  36. package/coverage/lcov-report/components/Arcs/styles.ts.html +0 -106
  37. package/coverage/lcov-report/components/Axis/Axis.tsx.html +0 -754
  38. package/coverage/lcov-report/components/Axis/computeTicks.ts.html +0 -481
  39. package/coverage/lcov-report/components/Axis/index.html +0 -176
  40. package/coverage/lcov-report/components/Axis/index.ts.html +0 -94
  41. package/coverage/lcov-report/components/Axis/styles.ts.html +0 -148
  42. package/coverage/lcov-report/components/Axis/types.ts.html +0 -253
  43. package/coverage/lcov-report/components/Bar/Bar.tsx.html +0 -421
  44. package/coverage/lcov-report/components/Bar/index.html +0 -161
  45. package/coverage/lcov-report/components/Bar/index.ts.html +0 -94
  46. package/coverage/lcov-report/components/Bar/styles.ts.html +0 -247
  47. package/coverage/lcov-report/components/Bar/types.ts.html +0 -178
  48. package/coverage/lcov-report/components/BarChart/BarChart.tsx.html +0 -355
  49. package/coverage/lcov-report/components/BarChart/EmptyBarChart.tsx.html +0 -259
  50. package/coverage/lcov-report/components/BarChart/LoadingBarChart.tsx.html +0 -145
  51. package/coverage/lcov-report/components/BarChart/RenderedBarChart.tsx.html +0 -496
  52. package/coverage/lcov-report/components/BarChart/index.html +0 -206
  53. package/coverage/lcov-report/components/BarChart/index.ts.html +0 -94
  54. package/coverage/lcov-report/components/BarChart/styles.ts.html +0 -190
  55. package/coverage/lcov-report/components/BarChart/utils.ts.html +0 -145
  56. package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +0 -433
  57. package/coverage/lcov-report/components/ChartContainer/index.html +0 -146
  58. package/coverage/lcov-report/components/ChartContainer/index.ts.html +0 -94
  59. package/coverage/lcov-report/components/ChartContainer/intl/index.html +0 -116
  60. package/coverage/lcov-report/components/ChartContainer/intl/index.ts.html +0 -106
  61. package/coverage/lcov-report/components/ChartContainer/styles.ts.html +0 -211
  62. package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +0 -442
  63. package/coverage/lcov-report/components/DataPoint/index.html +0 -146
  64. package/coverage/lcov-report/components/DataPoint/index.ts.html +0 -94
  65. package/coverage/lcov-report/components/DataPoint/styles.ts.html +0 -109
  66. package/coverage/lcov-report/components/Dot/Dot.tsx.html +0 -232
  67. package/coverage/lcov-report/components/Dot/index.html +0 -146
  68. package/coverage/lcov-report/components/Dot/index.ts.html +0 -94
  69. package/coverage/lcov-report/components/Dot/styles.ts.html +0 -184
  70. package/coverage/lcov-report/components/Legend/Legend.tsx.html +0 -268
  71. package/coverage/lcov-report/components/Legend/index.html +0 -146
  72. package/coverage/lcov-report/components/Legend/index.ts.html +0 -94
  73. package/coverage/lcov-report/components/Legend/styles.ts.html +0 -130
  74. package/coverage/lcov-report/components/LegendItem/LegendItem.tsx.html +0 -403
  75. package/coverage/lcov-report/components/LegendItem/index.html +0 -146
  76. package/coverage/lcov-report/components/LegendItem/index.ts.html +0 -94
  77. package/coverage/lcov-report/components/LegendItem/styles.ts.html +0 -205
  78. package/coverage/lcov-report/components/PieChart/EmptyPieChart.tsx.html +0 -343
  79. package/coverage/lcov-report/components/PieChart/LoadingPieChart.tsx.html +0 -145
  80. package/coverage/lcov-report/components/PieChart/PieChart.tsx.html +0 -388
  81. package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +0 -571
  82. package/coverage/lcov-report/components/PieChart/index.html +0 -221
  83. package/coverage/lcov-report/components/PieChart/index.ts.html +0 -94
  84. package/coverage/lcov-report/components/PieChart/styles.ts.html +0 -376
  85. package/coverage/lcov-report/components/PieChart/types.ts.html +0 -352
  86. package/coverage/lcov-report/components/PieChart/utils.ts.html +0 -199
  87. package/coverage/lcov-report/components/ScatterPlot/EmptyScatterPlot.tsx.html +0 -295
  88. package/coverage/lcov-report/components/ScatterPlot/LoadingScatterPlot.tsx.html +0 -145
  89. package/coverage/lcov-report/components/ScatterPlot/RenderedScatterPlot.tsx.html +0 -910
  90. package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +0 -379
  91. package/coverage/lcov-report/components/ScatterPlot/index.html +0 -221
  92. package/coverage/lcov-report/components/ScatterPlot/index.ts.html +0 -94
  93. package/coverage/lcov-report/components/ScatterPlot/styles.ts.html +0 -196
  94. package/coverage/lcov-report/components/ScatterPlot/types.ts.html +0 -376
  95. package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +0 -388
  96. package/coverage/lcov-report/favicon.png +0 -0
  97. package/coverage/lcov-report/hooks/index.html +0 -176
  98. package/coverage/lcov-report/hooks/index.ts.html +0 -97
  99. package/coverage/lcov-report/hooks/useBrush.tsx.html +0 -430
  100. package/coverage/lcov-report/hooks/useColor.tsx.html +0 -163
  101. package/coverage/lcov-report/hooks/useFormatCategoricalData.tsx.html +0 -289
  102. package/coverage/lcov-report/hooks/useZoom.tsx.html +0 -235
  103. package/coverage/lcov-report/index.html +0 -311
  104. package/coverage/lcov-report/index.ts.html +0 -94
  105. package/coverage/lcov-report/prettify.css +0 -1
  106. package/coverage/lcov-report/prettify.js +0 -2
  107. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  108. package/coverage/lcov-report/sorter.js +0 -196
  109. package/coverage/lcov-report/styles.ts.html +0 -631
  110. package/coverage/lcov-report/types.ts.html +0 -457
  111. package/coverage/lcov.info +0 -2272
  112. package/dist/index.js.map +0 -1
  113. package/dist/package.json +0 -98
  114. package/index.ts +0 -1
  115. package/jest.config.js +0 -3
  116. package/rollup.config.js +0 -13
  117. package/src/components/Arc/Arc.test.tsx +0 -92
  118. package/src/components/Arc/Arc.tsx +0 -73
  119. package/src/components/Arc/index.ts +0 -3
  120. package/src/components/Arc/styles.ts +0 -41
  121. package/src/components/Arc/types.ts +0 -18
  122. package/src/components/Arcs/Arcs.stories.tsx +0 -177
  123. package/src/components/Arcs/Arcs.tsx +0 -114
  124. package/src/components/Arcs/index.ts +0 -3
  125. package/src/components/Arcs/styles.ts +0 -7
  126. package/src/components/Arcs/types.ts +0 -26
  127. package/src/components/Axis/Axis.stories.tsx +0 -297
  128. package/src/components/Axis/Axis.tsx +0 -223
  129. package/src/components/Axis/computeTicks.ts +0 -132
  130. package/src/components/Axis/index.ts +0 -3
  131. package/src/components/Axis/styles.ts +0 -21
  132. package/src/components/Axis/types.ts +0 -56
  133. package/src/components/Bar/Bar.stories.tsx +0 -152
  134. package/src/components/Bar/Bar.test.tsx +0 -158
  135. package/src/components/Bar/Bar.tsx +0 -112
  136. package/src/components/Bar/index.ts +0 -3
  137. package/src/components/Bar/styles.ts +0 -54
  138. package/src/components/Bar/types.ts +0 -31
  139. package/src/components/BarChart/BarChart.stories.tsx +0 -80
  140. package/src/components/BarChart/BarChart.test.tsx +0 -189
  141. package/src/components/BarChart/BarChart.tsx +0 -90
  142. package/src/components/BarChart/EmptyBarChart.tsx +0 -58
  143. package/src/components/BarChart/LoadingBarChart.tsx +0 -20
  144. package/src/components/BarChart/RenderedBarChart.tsx +0 -137
  145. package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +0 -6932
  146. package/src/components/BarChart/index.ts +0 -3
  147. package/src/components/BarChart/styles.ts +0 -35
  148. package/src/components/BarChart/types.ts +0 -58
  149. package/src/components/BarChart/utils.ts +0 -20
  150. package/src/components/ChartContainer/ChartContainer.stories.tsx +0 -81
  151. package/src/components/ChartContainer/ChartContainer.test.tsx +0 -75
  152. package/src/components/ChartContainer/ChartContainer.tsx +0 -116
  153. package/src/components/ChartContainer/index.ts +0 -3
  154. package/src/components/ChartContainer/intl/en-US.json +0 -3
  155. package/src/components/ChartContainer/intl/fr-FR.json +0 -3
  156. package/src/components/ChartContainer/intl/index.ts +0 -7
  157. package/src/components/ChartContainer/styles.ts +0 -42
  158. package/src/components/ChartContainer/types.ts +0 -24
  159. package/src/components/DataPoint/DataPoint.tsx +0 -119
  160. package/src/components/DataPoint/index.ts +0 -3
  161. package/src/components/DataPoint/styles.ts +0 -8
  162. package/src/components/DataPoint/types.ts +0 -33
  163. package/src/components/Dot/Dot.stories.tsx +0 -157
  164. package/src/components/Dot/Dot.test.tsx +0 -136
  165. package/src/components/Dot/Dot.tsx +0 -49
  166. package/src/components/Dot/index.ts +0 -3
  167. package/src/components/Dot/styles.ts +0 -33
  168. package/src/components/Dot/types.ts +0 -16
  169. package/src/components/Legend/Legend.stories.tsx +0 -108
  170. package/src/components/Legend/Legend.tsx +0 -61
  171. package/src/components/Legend/index.ts +0 -3
  172. package/src/components/Legend/styles.ts +0 -15
  173. package/src/components/Legend/types.ts +0 -27
  174. package/src/components/LegendItem/LegendItem.test.tsx +0 -69
  175. package/src/components/LegendItem/LegendItem.tsx +0 -106
  176. package/src/components/LegendItem/index.ts +0 -3
  177. package/src/components/LegendItem/styles.ts +0 -40
  178. package/src/components/LegendItem/types.ts +0 -30
  179. package/src/components/PieChart/EmptyPieChart.tsx +0 -86
  180. package/src/components/PieChart/LoadingPieChart.tsx +0 -20
  181. package/src/components/PieChart/PieChart.stories.tsx +0 -91
  182. package/src/components/PieChart/PieChart.test.tsx +0 -201
  183. package/src/components/PieChart/PieChart.tsx +0 -101
  184. package/src/components/PieChart/RenderedPieChart.tsx +0 -162
  185. package/src/components/PieChart/__snapshots__/PieChart.stories.storyshot +0 -7843
  186. package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +0 -20540
  187. package/src/components/PieChart/index.ts +0 -3
  188. package/src/components/PieChart/styles.ts +0 -97
  189. package/src/components/PieChart/types.ts +0 -89
  190. package/src/components/PieChart/utils.ts +0 -38
  191. package/src/components/ScatterPlot/EmptyScatterPlot.tsx +0 -70
  192. package/src/components/ScatterPlot/LoadingScatterPlot.tsx +0 -20
  193. package/src/components/ScatterPlot/RenderedScatterPlot.tsx +0 -275
  194. package/src/components/ScatterPlot/ScatterPlot.stories.tsx +0 -95
  195. package/src/components/ScatterPlot/ScatterPlot.test.tsx +0 -44
  196. package/src/components/ScatterPlot/ScatterPlot.tsx +0 -98
  197. package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +0 -88352
  198. package/src/components/ScatterPlot/index.ts +0 -3
  199. package/src/components/ScatterPlot/styles.ts +0 -37
  200. package/src/components/ScatterPlot/types.ts +0 -97
  201. package/src/components/ScatterPlot/utils.ts +0 -101
  202. package/src/config.ts +0 -10
  203. package/src/hooks/index.ts +0 -4
  204. package/src/hooks/useBrush.tsx +0 -115
  205. package/src/hooks/useColor.tsx +0 -26
  206. package/src/hooks/useFormatCategoricalData.tsx +0 -68
  207. package/src/hooks/useZoom.tsx +0 -50
  208. package/src/index.ts +0 -15
  209. package/src/scheme.ts +0 -221
  210. package/src/types/data.ts +0 -52
  211. package/src/types/index.ts +0 -5
  212. package/src/types/legend.ts +0 -19
  213. package/src/types/scale.ts +0 -79
  214. package/src/types/size.ts +0 -17
  215. package/src/types/theme.ts +0 -27
  216. package/tsconfig.json +0 -3
  217. /package/{dist/CONTRIBUTING.md → CONTRIBUTING.md} +0 -0
@@ -1,3 +0,0 @@
1
- export * from './ScatterPlot';
2
- export * from './types';
3
- export * from './styles';
@@ -1,37 +0,0 @@
1
- import styled from 'styled-components';
2
- import { StyledScatterPlotProps } from './types';
3
- import { ChartContainer } from '../ChartContainer';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledScatterPlot = styled(
9
- ChartContainer
10
- )<StyledScatterPlotProps>``;
11
-
12
- export const StyledScatterPlotEmptyText = styled.div<{
13
- $maxWidth: number;
14
- $textSize: number;
15
- }>`
16
- position: absolute;
17
- top: 0;
18
- left: 0;
19
- height: 100%;
20
- width: 100%;
21
- display: flex;
22
- flex-direction: column;
23
- justify-content: center;
24
- align-items: center;
25
- pointer-events: none;
26
-
27
- > * {
28
- max-width: ${({ $maxWidth }) => $maxWidth}px;
29
- }
30
-
31
- > span {
32
- font-family: var(--redsift-typography-font-family-raleway);
33
- color: var(--redsift-color-neutral-black);
34
- font-size: ${({ $textSize }) => $textSize}px;
35
- line-height: ${({ $textSize }) => $textSize}px;
36
- }
37
- `;
@@ -1,97 +0,0 @@
1
- import {
2
- ChartDimensions,
3
- ChartSize,
4
- ChartTheme,
5
- TooltipVariant,
6
- DotDatum,
7
- CoordinatesCategoryData,
8
- } from '../../types';
9
- import { ValueOf } from '@redsift/design-system';
10
- import { ChartContainerProps } from '../ChartContainer';
11
- import { MutableRefObject, ReactNode } from 'react';
12
- import { DotProps } from '../Dot';
13
- import { ScaleLinear as d3ScaleLinear } from 'd3';
14
- import { AxisVariant } from '../Axis';
15
- import { LegendProps } from '../Legend';
16
-
17
- /**
18
- * Component variant.
19
- */
20
- export const ScatterPlotVariant = {
21
- default: 'default',
22
- gridded: 'gridded',
23
- } as const;
24
- export type ScatterPlotVariant = ValueOf<typeof ScatterPlotVariant>;
25
-
26
- /**
27
- * Component's labels variant.
28
- */
29
- export const ScatterPlotLabelVariant = {
30
- none: 'none',
31
- externalLabel: 'externalLabel',
32
- externalLabelValue: 'externalLabelValue',
33
- externalLabelPercent: 'externalLabelPercent',
34
- } as const;
35
- export type ScatterPlotLabelVariant = ValueOf<typeof ScatterPlotLabelVariant>;
36
-
37
- interface LocaleText {
38
- emptyChartText: string;
39
- }
40
-
41
- export type ScatterPlotDimensions = ChartDimensions & {
42
- fontSize: number;
43
- };
44
-
45
- /**
46
- * Component props.
47
- */
48
- export interface ScatterPlotProps extends ChartContainerProps {
49
- /** Dataset to use to generate the chart. */
50
- data?: CoordinatesCategoryData;
51
- /** Slice role. Used to indicate that dots are to be considered buttons or links. If an onClick is provided, the dots will have the role `button` unless specifically set to `link` with this prop. */
52
- dotRole?: DotProps['role'];
53
- /** Component to use if the chart is empty (replacing the default one). */
54
- emptyComponent?: ReactNode;
55
- /** Whether the scatter plot dots are selectable using brush or not. */
56
- isBrushable?: boolean;
57
- /** Method to determine whether a dot is selected or not. */
58
- isDotSelected?: (datum: DotDatum) => boolean | undefined;
59
- /** Method to override the data labels. */
60
- labelDecorator?: (datum: DotDatum) => 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?: ScatterPlotLabelVariant;
63
- /** Props to forward to the Legend block. Can be used to make the legend selectable. */
64
- legendProps?: Omit<LegendProps, 'data' | 'ref' | 'variant' | 'width'>;
65
- /** Labels and texts. */
66
- localeText?: LocaleText;
67
- /** Method called on brush. */
68
- onBrush?: (
69
- selection: [[number, number], [number, number]] | null,
70
- scaleX: d3ScaleLinear<number, number>,
71
- scaleY: d3ScaleLinear<number, number>
72
- ) => void;
73
- /** Method called on brush end. */
74
- onBrushEnd?: (
75
- selection: [[number, number], [number, number]] | null,
76
- scaleX?: d3ScaleLinear<number, number>,
77
- scaleY?: d3ScaleLinear<number, number>
78
- ) => void;
79
- /** Method to be called on a click on a dot. */
80
- onDotClick?: (datum: DotDatum) => void;
81
- /** ScatterPlot size. */
82
- size?: ChartSize | ScatterPlotDimensions;
83
- /** Reference to the SVG tag. */
84
- svgRef?: MutableRefObject<SVGSVGElement>;
85
- /** 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. */
86
- theme?: ChartTheme;
87
- /** Tooltip variant. */
88
- tooltipVariant?: TooltipVariant;
89
- /** Variant. */
90
- variant?: ScatterPlotVariant;
91
- /** X axis variant. */
92
- xAxisVariant?: AxisVariant;
93
- /** Y axis variant. */
94
- yAxisVariant?: AxisVariant;
95
- }
96
-
97
- export type StyledScatterPlotProps = ScatterPlotProps & {};
@@ -1,101 +0,0 @@
1
- import { ScaleLinear as d3ScaleLinear } from 'd3';
2
-
3
- import { CoordinatesCategoryData, CoordinatesCategoryDatum } from '../../types';
4
-
5
- import { ChartSize } from '../../types';
6
- import { ScatterPlotDimensions } from './types';
7
-
8
- export const sizeToDimension = (
9
- size: ChartSize | ScatterPlotDimensions
10
- ): ScatterPlotDimensions => {
11
- if (typeof size !== 'string') {
12
- return size;
13
- }
14
-
15
- switch (size) {
16
- case ChartSize.small:
17
- return { width: 600, height: 300, fontSize: 30 };
18
- case ChartSize.medium:
19
- default:
20
- return { width: 750, height: 375, fontSize: 34 };
21
- case ChartSize.large:
22
- return { width: 900, height: 450, fontSize: 38 };
23
- }
24
- };
25
-
26
- export const BASE_NUMBER_OF_TICKS = 20;
27
-
28
- export const getClosestLineIndex = (
29
- value: number,
30
- scale: d3ScaleLinear<number, number, never>
31
- ) => {
32
- const ticks = scale.ticks(BASE_NUMBER_OF_TICKS);
33
- const delta = ticks[1] - ticks[0];
34
- const index = Math.round(value / delta);
35
- const roundValue = index * delta;
36
- return [index, roundValue];
37
- };
38
-
39
- export const group = (
40
- data: CoordinatesCategoryData,
41
- x: d3ScaleLinear<number, number, never>,
42
- y: d3ScaleLinear<number, number, never>
43
- ) => {
44
- const groupDict: Record<
45
- string,
46
- {
47
- category: string;
48
- x: number;
49
- y: number;
50
- data: CoordinatesCategoryDatum;
51
- points: CoordinatesCategoryData;
52
- }
53
- > = {};
54
-
55
- data.forEach((d) => {
56
- const [i, rx] = getClosestLineIndex(d.key[0], x);
57
- const [j, ry] = getClosestLineIndex(d.key[1], y);
58
-
59
- const key = `${i}_${j}_${d.key[2]}`;
60
- if (!(key in groupDict)) {
61
- groupDict[key] = {
62
- category: d.key[2] as string,
63
- x: rx,
64
- y: ry,
65
- data: {
66
- key: d.key,
67
- value: 0,
68
- },
69
- points: [],
70
- };
71
- }
72
-
73
- groupDict[key].points.push(d);
74
- groupDict[key].data.value += 1;
75
- });
76
-
77
- return Object.values(groupDict);
78
- };
79
-
80
- export const countBy = (arr: CoordinatesCategoryData) => {
81
- const counts = arr.reduce(
82
- (prev, curr) => (
83
- (prev[curr.key[2] as string] =
84
- ++(prev[curr.key[2] as string] as number) || 1),
85
- prev
86
- ),
87
- {} as Record<string, number>
88
- );
89
-
90
- return Object.keys(counts)
91
- .map((key) => ({ key: key, value: counts[key] as number }))
92
- .sort((a, b) =>
93
- a.value === b.value
94
- ? a.key > b.key
95
- ? 1
96
- : -1
97
- : a.value < b.value
98
- ? 1
99
- : -1
100
- );
101
- };
package/src/config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { easings } from '@react-spring/web';
2
-
3
- export const config = (() => ({
4
- config: {
5
- duration: 700,
6
- easing: easings.easeInOutQuad,
7
- },
8
- reset: true,
9
- immediate: false,
10
- }))();
@@ -1,4 +0,0 @@
1
- export * from './useBrush';
2
- export * from './useColor';
3
- export * from './useFormatCategoricalData';
4
- export * from './useZoom';
@@ -1,115 +0,0 @@
1
- import { MutableRefObject, useEffect, useRef } from 'react';
2
- import {
3
- BrushBehavior as d3BrushBehavior,
4
- brush as d3brush,
5
- ScaleLinear as d3ScaleLinear,
6
- select as d3select,
7
- } from 'd3';
8
-
9
- export interface UseBrushProps {
10
- brushRef: MutableRefObject<d3BrushBehavior<unknown> | undefined>;
11
- svgRef: MutableRefObject<SVGSVGElement | SVGGElement | undefined>;
12
- extent?: [[number, number], [number, number]];
13
- scaleX: d3ScaleLinear<number, number>;
14
- scaleY: d3ScaleLinear<number, number>;
15
- isBrushable?: boolean;
16
- isGridded?: boolean;
17
- onBrush?: (
18
- selection: [[number, number], [number, number]] | null,
19
- scaleX: d3ScaleLinear<number, number>,
20
- scaleY: d3ScaleLinear<number, number>
21
- ) => void;
22
- onBrushEnd?: (
23
- selection: [[number, number], [number, number]] | null,
24
- scaleX: d3ScaleLinear<number, number>,
25
- scaleY: d3ScaleLinear<number, number>
26
- ) => void;
27
- }
28
-
29
- const getRoundedIntermediaryPoint = (
30
- selection: [[number, number], [number, number]],
31
- scaleX: d3ScaleLinear<number, number>,
32
- scaleY: d3ScaleLinear<number, number>
33
- ) => {
34
- if (!selection) {
35
- return null;
36
- }
37
-
38
- const xTicks = scaleX.ticks(20);
39
- const xDelta = xTicks[1] - xTicks[0];
40
- const yTicks = scaleY.ticks(20);
41
- const yDelta = yTicks[1] - yTicks[0];
42
-
43
- return [
44
- [
45
- scaleX(
46
- Math.round(scaleX.invert(selection[0][0]) / xDelta) * xDelta -
47
- xDelta / 2
48
- ),
49
- scaleY(
50
- Math.round(scaleY.invert(selection[0][1]) / yDelta) * yDelta -
51
- yDelta / 2
52
- ),
53
- ],
54
- [
55
- scaleX(
56
- Math.round(scaleX.invert(selection[1][0]) / xDelta) * xDelta -
57
- xDelta / 2
58
- ),
59
-
60
- scaleY(
61
- Math.round(scaleY.invert(selection[1][1]) / yDelta) * yDelta -
62
- yDelta / 2
63
- ),
64
- ],
65
- ] as [[number, number], [number, number]];
66
- };
67
-
68
- export const useBrush = ({
69
- brushRef: propsBrushRef,
70
- svgRef,
71
- extent,
72
- scaleX,
73
- scaleY,
74
- isBrushable,
75
- isGridded,
76
- onBrush,
77
- onBrushEnd,
78
- }: UseBrushProps) => {
79
- const brushRef = propsBrushRef || useRef<d3BrushBehavior<unknown>>();
80
-
81
- useEffect(() => {
82
- if (svgRef.current && isBrushable) {
83
- brushRef.current = d3brush()
84
- .extent(extent!)
85
- .keyModifiers(false)
86
- .filter((event) => event.shiftKey)
87
- .on('brush', (event) => {
88
- if (!event.sourceEvent || !brushRef.current || !svgRef.current)
89
- return;
90
-
91
- if (isGridded) {
92
- const selection = getRoundedIntermediaryPoint(
93
- event.selection,
94
- scaleX,
95
- scaleY
96
- );
97
- d3select(svgRef.current).call(
98
- brushRef.current.move as any,
99
- selection
100
- );
101
- onBrush?.(selection, scaleX, scaleY);
102
- } else {
103
- onBrush?.(event.selection, scaleX, scaleY);
104
- }
105
- })
106
- .on('end', (event) => {
107
- if (!event.sourceEvent || !brushRef.current || !svgRef.current)
108
- return;
109
-
110
- onBrushEnd?.(event.selection, scaleX, scaleY);
111
- });
112
- d3select(svgRef.current).call(brushRef.current as any);
113
- }
114
- });
115
- };
@@ -1,26 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { ScaleOrdinal as d3ScaleOrdinal } from 'd3';
3
- import { getColorScale } from '../scheme';
4
- import { ChartTheme, JSONArray } from '../types';
5
-
6
- export interface UseColorProps {
7
- /** Dataset to use to generate the chart. */
8
- data: JSONArray;
9
- /** Theme. */
10
- theme: ChartTheme;
11
- /** Name of the field that will be used to categorize the data. */
12
- category: string;
13
- }
14
-
15
- export const useColor = ({ data, theme, category }: UseColorProps) => {
16
- const colorScale = useMemo<d3ScaleOrdinal<string, string>>(
17
- () =>
18
- getColorScale(
19
- theme,
20
- data.map((d) => d[category] as string)
21
- ),
22
- [theme]
23
- );
24
-
25
- return colorScale;
26
- };
@@ -1,68 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { CategoryData, ChartTheme } from '../types';
3
- import { useColor } from './useColor';
4
-
5
- export interface UseFormatCategoricalDataProps {
6
- /** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */
7
- data: CategoryData;
8
- /** Theme. */
9
- theme: ChartTheme;
10
- /** Number of categories to use, the rest being put into a new category called "Others". */
11
- caping?: number;
12
- /** 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. */
13
- others?: boolean | string;
14
- }
15
-
16
- export const useFormatCategoricalData = ({
17
- data,
18
- caping,
19
- others,
20
- theme,
21
- }: UseFormatCategoricalDataProps) => {
22
- const computedData = useMemo(() => {
23
- let computedData;
24
-
25
- if (data === undefined || data === null) {
26
- return undefined;
27
- }
28
-
29
- computedData = [...data!].sort((a, b) =>
30
- a.value === b.value
31
- ? a.key > b.key
32
- ? 1
33
- : -1
34
- : a.value < b.value
35
- ? 1
36
- : -1
37
- );
38
-
39
- if (caping) {
40
- if (typeof others === 'boolean' && !others) {
41
- computedData = computedData.slice(0, caping);
42
- } else {
43
- computedData = computedData.reduce<CategoryData>((acc, curr, index) => {
44
- if (index < caping) {
45
- acc[index] = curr;
46
- } else if (index === caping) {
47
- acc[index] = {
48
- key: typeof others === 'string' ? others : 'Others',
49
- value: curr.value,
50
- };
51
- } else {
52
- acc[caping] = {
53
- ...acc[caping],
54
- value: acc[caping].value + curr.value,
55
- };
56
- }
57
- return acc;
58
- }, []);
59
- }
60
- }
61
-
62
- return computedData;
63
- }, [data, caping]);
64
-
65
- const colorScale = useColor({ data: computedData!, theme, category: 'key' });
66
-
67
- return { data: computedData as CategoryData, colorScale };
68
- };
@@ -1,50 +0,0 @@
1
- import { MutableRefObject, useEffect, useRef, useState } from 'react';
2
- import {
3
- zoom as d3zoom,
4
- interpolateRound as d3interpolateRound,
5
- ScaleLinear as d3ScaleLinear,
6
- select as d3select,
7
- } from 'd3';
8
-
9
- export interface UseZoomProps {
10
- svgRef: MutableRefObject<SVGSVGElement | undefined>;
11
- scaleX: d3ScaleLinear<number, number>;
12
- scaleY: d3ScaleLinear<number, number>;
13
- defaultTransform?: { k: number; x: number; y: number };
14
- size?: any;
15
- onZoom?: () => void;
16
- }
17
-
18
- export const useZoom = ({
19
- svgRef,
20
- scaleX,
21
- scaleY,
22
- defaultTransform = { k: 1, x: 0, y: 0 },
23
- size,
24
- onZoom,
25
- }: UseZoomProps) => {
26
- const zx = useRef<d3ScaleLinear<number, number>>(scaleX);
27
- const zy = useRef<d3ScaleLinear<number, number>>(scaleY);
28
- const [transform, setTransform] = useState(defaultTransform);
29
-
30
- useEffect(() => {
31
- if (svgRef.current) {
32
- const zoom = d3zoom()
33
- .filter((event) => !event.shiftKey)
34
- .scaleExtent([1 / 2 ** 3, 2 ** 3])
35
- .on('zoom', (event) => {
36
- onZoom?.();
37
- zx.current = event.transform
38
- .rescaleX(scaleX)
39
- .interpolate(d3interpolateRound);
40
- zy.current = event.transform
41
- .rescaleY(scaleY)
42
- .interpolate(d3interpolateRound);
43
- setTransform(event.transform);
44
- });
45
- d3select(svgRef.current).call(zoom as any);
46
- }
47
- }, [svgRef.current, size]);
48
-
49
- return { transform, scaleX: zx.current, scaleY: zy.current };
50
- };
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- export * from './hooks';
2
- export * from './types';
3
- export * from './scheme';
4
-
5
- export * from './components/Arc';
6
- export * from './components/Arcs';
7
- export * from './components/Axis';
8
- export * from './components/Bar';
9
- export * from './components/BarChart';
10
- export * from './components/ChartContainer';
11
- export * from './components/DataPoint';
12
- export * from './components/Dot';
13
- export * from './components/Legend';
14
- export * from './components/PieChart';
15
- export * from './components/ScatterPlot';