@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
package/dist/package.json DELETED
@@ -1,98 +0,0 @@
1
- {
2
- "author": {
3
- "name": "Red Sift"
4
- },
5
- "bugs": {
6
- "url": "https://github.com/redsift/design-system/issues"
7
- },
8
- "description": "Chart component library as part of Red Sift's Design System. This package is based on d3.js for computation, react for rendering and events and react-spring for animations and transitions.",
9
- "homepage": "https://github.com/redsift/design-system",
10
- "license": "MIT",
11
- "main": "index.js",
12
- "module": "index.js",
13
- "name": "@redsift/charts",
14
- "publishConfig": {
15
- "directory": "dist"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/redsift/design-system"
20
- },
21
- "sideEffects": false,
22
- "scripts": {
23
- "build": "rollup -c",
24
- "check-types": "tsc && tsc-strict",
25
- "lint": "eslint --ext .js,.jsx,.ts,.tsx src/",
26
- "prepare": "install-peers || exit 0",
27
- "prepublishOnly": "yarn build",
28
- "test:unit": "NODE_ENV=test jest --verbose",
29
- "test:storybook": "test-storybook -c ../../.storybook --url http://localhost:9000/ --coverage",
30
- "test": "yarn test:unit && yarn test:storybook"
31
- },
32
- "types": "types.d.ts",
33
- "version": "8.0.1",
34
- "dependencies": {
35
- "@emotion/react": "^11.10.4",
36
- "@emotion/styled": "^11.10.4",
37
- "classnames": "^2.3.1",
38
- "d3": "^7.8.0",
39
- "d3-shape": "^3.1.0",
40
- "react-aria": "^3.23.1"
41
- },
42
- "devDependencies": {
43
- "@babel/core": "^7.8.3",
44
- "@babel/plugin-proposal-class-properties": "^7.16.7",
45
- "@babel/plugin-proposal-export-default-from": "^7.16.7",
46
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
47
- "@babel/plugin-proposal-object-rest-spread": "^7.17.3",
48
- "@babel/plugin-proposal-optional-chaining": "^7.16.7",
49
- "@babel/plugin-proposal-private-methods": "^7.16.11",
50
- "@babel/plugin-proposal-private-property-in-object": "^7.16.7",
51
- "@babel/preset-env": "^7.17.10",
52
- "@babel/preset-react": "^7.17.12",
53
- "@babel/preset-typescript": "^7.16.7",
54
- "@react-spring/web": "^9.7.1",
55
- "@rollup/plugin-babel": "^6.0.2",
56
- "@rollup/plugin-commonjs": "^24.0.0",
57
- "@rollup/plugin-json": "^6.0.0",
58
- "@rollup/plugin-node-resolve": "^13.3.0",
59
- "@testing-library/dom": "^8.5.0",
60
- "@testing-library/jest-dom": "^5.16.4",
61
- "@testing-library/react": "^13.4.0",
62
- "@testing-library/react-hooks": "^8.0.1",
63
- "@testing-library/user-event": "14.2.1",
64
- "@types/d3": "^7.4.0",
65
- "@types/d3-shape": "^3.1.0",
66
- "@types/jest": "^27.5.1",
67
- "@types/react": "18.0.12",
68
- "@types/react-dom": "18.0.5",
69
- "@types/styled-components": "^5.1.25",
70
- "@typescript-eslint/eslint-plugin": "^5.48.0",
71
- "@typescript-eslint/parser": "^5.26.0",
72
- "identity-obj-proxy": "^3.0.0",
73
- "install-peers-cli": "^2.2.0",
74
- "jest": "^28.1.0",
75
- "jest-environment-jsdom": "^29.3.0",
76
- "msw": "^0.47.4",
77
- "react": "18.2.0",
78
- "react-dom": "18.2.0",
79
- "rollup": "^2.72.1",
80
- "rollup-plugin-analyzer": "^4.0.0",
81
- "rollup-plugin-auto-external": "^2.0.0",
82
- "rollup-plugin-cleaner": "^1.0.0",
83
- "rollup-plugin-copy": "^3.4.0",
84
- "rollup-plugin-dts": "^5.0.0",
85
- "rollup-plugin-execute": "^1.1.0",
86
- "rollup-plugin-svg": "^2.0.0",
87
- "rollup-plugin-ts-paths-resolve": "^1.7.1",
88
- "rollup-plugin-typescript-paths": "^1.3.1",
89
- "ts-jest": "^28.0.3"
90
- },
91
- "peerDependencies": {
92
- "@redsift/design-system": "^7.8.1",
93
- "@redsift/popovers": "^7.8.1",
94
- "react": "18",
95
- "react-dom": "18",
96
- "styled-components": "^5.3.5"
97
- }
98
- }
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './src';
package/jest.config.js DELETED
@@ -1,3 +0,0 @@
1
- var JEST_CONFIG = require('../../configs/jest.config');
2
-
3
- module.exports = { ...JEST_CONFIG };
package/rollup.config.js DELETED
@@ -1,13 +0,0 @@
1
- import { rollupConfig } from '../../configs/rollup.base.config';
2
-
3
- import pkg from './package.json';
4
-
5
- const baseRollupConfig = rollupConfig(__dirname, pkg);
6
-
7
- // Bundle JS code
8
- const bundleJS = { ...baseRollupConfig.bundleJS };
9
-
10
- // Bundle TS types in D.TS files
11
- const bundleType = { ...baseRollupConfig.bundleType };
12
-
13
- export default [bundleJS, bundleType];
@@ -1,92 +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 { arc as d3arc, pie as d3pie } from 'd3';
5
-
6
- import { Arc } from './Arc';
7
- import { ArcDatum, TooltipVariant, CategoryDatum } from '../../types';
8
-
9
- jest.mock('react', () => ({
10
- ...jest.requireActual('react'),
11
- useId: () => '123',
12
- }));
13
-
14
- const createArc = d3arc<ArcDatum>().innerRadius(0).outerRadius(150);
15
- const createPie = d3pie<CategoryDatum>()
16
- .value((d) => d.value)
17
- .sort(null);
18
- const data = [
19
- {
20
- key: 'Croissant',
21
- value: 333,
22
- },
23
- ];
24
- const pieData = createPie(data);
25
-
26
- describe('Arc', () => {
27
- const onClickSpy = jest.fn();
28
-
29
- afterEach(() => {
30
- onClickSpy.mockClear();
31
- });
32
-
33
- it('supports click', async () => {
34
- const { getByRole } = render(
35
- <svg width={500} height={500}>
36
- <Arc
37
- id="123"
38
- index={0}
39
- data={pieData[0]}
40
- createArc={createArc}
41
- onClick={onClickSpy}
42
- />
43
- </svg>
44
- );
45
-
46
- const bar = getByRole('button');
47
- fireEvent.click(bar);
48
- expect(onClickSpy).toHaveBeenCalledWith(pieData[0]);
49
- });
50
-
51
- it('supports keydown', async () => {
52
- const { getByRole } = render(
53
- <svg width={500} height={500}>
54
- <Arc
55
- id="123"
56
- index={0}
57
- data={pieData[0]}
58
- createArc={createArc}
59
- onClick={onClickSpy}
60
- />
61
- </svg>
62
- );
63
-
64
- const bar = getByRole('button');
65
- fireEvent.keyDown(bar, { key: 'Enter', code: 'Enter', charCode: 13 });
66
- expect(onClickSpy).toHaveBeenCalledWith(pieData[0]);
67
- });
68
-
69
- it('shows a tooltip on hover', async () => {
70
- const user = userEvent.setup();
71
- const { getByRole } = render(
72
- <svg width={500} height={500}>
73
- <Arc
74
- index={0}
75
- // The onClick gives the bar the role "button" which is then used to access the bars.
76
- onClick={onClickSpy}
77
- data={pieData[0]}
78
- createArc={createArc}
79
- tooltipVariant={TooltipVariant.label}
80
- />
81
- </svg>
82
- );
83
-
84
- const bar = getByRole('button');
85
- await user.hover(bar);
86
- await waitFor(() => {
87
- expect(screen.getByRole('tooltip', { exact: true })).toBeInTheDocument();
88
- });
89
- const tooltip = screen.getByRole('tooltip');
90
- expect(tooltip.textContent).toContain('Croissant');
91
- });
92
- });
@@ -1,73 +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 { ArcProps } from './types';
9
- import { StyledArc } from './styles';
10
- import { monochrome } from '../../scheme';
11
- import { config } from '../../config';
12
-
13
- const COMPONENT_NAME = 'Arc';
14
- const CLASSNAME = 'redsift-arc';
15
- const DEFAULT_PROPS: Partial<ArcProps> = {
16
- color: monochrome,
17
- index: 0,
18
- previousData: {
19
- data: {
20
- key: '',
21
- value: 0,
22
- },
23
- startAngle: 0,
24
- endAngle: 0,
25
- padAngle: 0,
26
- value: 0,
27
- index: 0,
28
- },
29
- };
30
-
31
- export const Arc: Comp<ArcProps, SVGGElement> = forwardRef((props, ref) => {
32
- const { color, data, isSelected: propsIsSelected, onClick, role } = props;
33
-
34
- const { className, createArc, hasStroke, previousData, ...forwardedProps } =
35
- props;
36
-
37
- const interpolator = d3interpolate(previousData, data);
38
-
39
- const isSelectable = role === 'option';
40
- const isDeselected = isSelectable && propsIsSelected === false;
41
-
42
- const animatedProps = useSpring({
43
- ...config,
44
- to: async (next: (props?: object) => Promise<void>) => {
45
- await next({ t: 1 });
46
- },
47
- from: { t: 0 },
48
- });
49
-
50
- return (
51
- <StyledArc
52
- {...forwardedProps}
53
- ref={ref}
54
- className={classNames(Arc.className, className)}
55
- $clickable={Boolean(onClick)}
56
- $hasStroke={Boolean(hasStroke)}
57
- >
58
- <animated.path
59
- d={
60
- config.immediate
61
- ? (createArc(data) as unknown as string)
62
- : (animatedProps.t.to((t) =>
63
- createArc(interpolator(t))
64
- ) as unknown as string)
65
- }
66
- fill={isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color}
67
- />
68
- </StyledArc>
69
- );
70
- });
71
- Arc.className = CLASSNAME;
72
- Arc.defaultProps = DEFAULT_PROPS;
73
- Arc.displayName = COMPONENT_NAME;
@@ -1,3 +0,0 @@
1
- export * from './Arc';
2
- export * from './types';
3
- export * from './styles';
@@ -1,41 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
- import { StyledArcProps } from './types';
3
- import { DataPoint } from '../DataPoint';
4
-
5
- /**
6
- * Component style.
7
- */
8
- export const StyledArc = styled(DataPoint)<StyledArcProps>`
9
- ${({ $hasStroke }) =>
10
- $hasStroke
11
- ? css`
12
- path {
13
- stroke-width: 2px;
14
- stroke: #fff;
15
- }
16
- `
17
- : ''}
18
-
19
- ${({ $clickable }) =>
20
- $clickable
21
- ? css`
22
- cursor: pointer;
23
-
24
- &:hover,
25
- &:focus,
26
- &.focused {
27
- opacity: 0.8;
28
- outline: none;
29
- }
30
-
31
- &:focus-visible,
32
- &.focused {
33
- path {
34
- stroke: var(--redsift-color-default-primary);
35
- stroke-width: 4px;
36
- paint-order: stroke;
37
- }
38
- }
39
- `
40
- : ''}}
41
- `;
@@ -1,18 +0,0 @@
1
- import { Arc as d3Arc } from 'd3';
2
- import { ArcDatum } from '../../types';
3
- import { DataPointProps, StyledDataPointProps } from '../DataPoint';
4
-
5
- /**
6
- * Component props.
7
- */
8
- export interface ArcProps extends DataPointProps<ArcDatum> {
9
- /** Arc generator used to determine the width of the arc. */
10
- createArc: d3Arc<any, ArcDatum>;
11
- /** Whether the arc has a stroke or not. Used to create a gap between two siblings. */
12
- hasStroke?: boolean;
13
- }
14
-
15
- export type StyledArcProps = StyledDataPointProps &
16
- Omit<ArcProps, 'createArc'> & {
17
- $hasStroke: ArcProps['hasStroke'];
18
- };
@@ -1,177 +0,0 @@
1
- import React from 'react';
2
- // @ts-ignore
3
- import type { StoryObj } from '@storybook/react';
4
- import { arc as d3arc, pie as d3pie } from 'd3';
5
-
6
- import { Arcs, ArcsProps } from '.';
7
- import { ArcDatum, TooltipVariant, CategoryDatum } from '../../types';
8
-
9
- const meta = {
10
- title: 'Charts/Core/Arcs',
11
- component: Arcs,
12
- };
13
-
14
- export default meta;
15
- type Story = StoryObj<ArcsProps>;
16
-
17
- const createArc = d3arc<ArcDatum>().innerRadius(0).outerRadius(150);
18
-
19
- export const Simple: Story = {
20
- render: () => {
21
- const createPie = d3pie<CategoryDatum>()
22
- .value((d) => d.value)
23
- .sort(null);
24
- const data = [
25
- {
26
- key: 'Croissant',
27
- value: 333,
28
- },
29
- ];
30
- const pieData = createPie(data);
31
-
32
- return (
33
- <svg width={500} height={500}>
34
- <Arcs
35
- hasLabels
36
- transform="translate(250,250)"
37
- arcs={[
38
- {
39
- id: '123',
40
- createArc,
41
- data: pieData[0],
42
- },
43
- ]}
44
- />
45
- </svg>
46
- );
47
- },
48
- };
49
-
50
- export const Clickable: Story = {
51
- render: () => {
52
- const createPie = d3pie<CategoryDatum>()
53
- .value((d) => d.value)
54
- .sort(null);
55
- const data = [
56
- {
57
- key: 'Button',
58
- value: 150,
59
- },
60
- {
61
- key: 'Link',
62
- value: 333,
63
- },
64
- ];
65
- const pieData = createPie(data);
66
-
67
- return (
68
- <svg width={500} height={500}>
69
- <Arcs
70
- hasLabels
71
- transform="translate(250,250)"
72
- id="123"
73
- hasStroke
74
- arcs={[
75
- {
76
- createArc,
77
- onClick: (datum) => console.log(datum),
78
- data: pieData[0],
79
- },
80
- {
81
- createArc,
82
- onClick: (datum) => {
83
- window.open(
84
- `https://en.wikipedia.org/wiki/${datum.data.key}`,
85
- '_blank'
86
- );
87
- },
88
- data: pieData[1],
89
- },
90
- ]}
91
- />
92
- </svg>
93
- );
94
- },
95
- };
96
-
97
- export const Selectable: Story = {
98
- render: () => {
99
- const createPie = d3pie<CategoryDatum>()
100
- .value((d) => d.value)
101
- .sort(null);
102
- const data = [
103
- {
104
- key: 'Deselected',
105
- value: 150,
106
- },
107
- {
108
- key: 'Selected',
109
- value: 333,
110
- },
111
- ];
112
- const pieData = createPie(data);
113
-
114
- return (
115
- <svg width={500} height={500}>
116
- <Arcs
117
- hasLabels
118
- transform="translate(250,250)"
119
- role="option"
120
- arcs={[
121
- {
122
- createArc,
123
- isSelected: false,
124
- onClick: (datum) =>
125
- console.log('Clicked on the non-selected arc', datum),
126
- data: pieData[0],
127
- },
128
- {
129
- createArc,
130
- isSelected: true,
131
- onClick: (datum) =>
132
- console.log('Clicked on the selected arc', datum),
133
- data: pieData[1],
134
- },
135
- ]}
136
- />
137
- </svg>
138
- );
139
- },
140
- };
141
-
142
- export const WithTooltip: Story = {
143
- render: () => {
144
- const createPie = d3pie<CategoryDatum>()
145
- .value((d) => d.value)
146
- .sort(null);
147
- const data = Object.keys(TooltipVariant).map((tooltipVariant) => ({
148
- key: tooltipVariant,
149
- value: 333,
150
- }));
151
- const pieData = createPie(data);
152
-
153
- return (
154
- <svg width={500} height={500}>
155
- <Arcs
156
- hasLabels
157
- transform="translate(250,250)"
158
- arcs={Object.keys(TooltipVariant).map((tooltipVariant, index) => ({
159
- createArc,
160
- hasStroke: true,
161
- index,
162
- isSelected: true,
163
- key: tooltipVariant,
164
- labelDecorator: (datum: ArcDatum) =>
165
- `${datum.data.key.charAt(0).toUpperCase()}${datum.data.key.slice(
166
- 1
167
- )}`,
168
- percent: 0.25,
169
- data: pieData[index],
170
- tooltipVariant,
171
- role: 'option',
172
- }))}
173
- />
174
- </svg>
175
- );
176
- },
177
- };
@@ -1,114 +0,0 @@
1
- import React, { RefObject, forwardRef, useId } 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 { ArcsProps } from './types';
9
- import { StyledArcs } from './styles';
10
- import { Arc } from '../Arc';
11
- import { config } from '../../config';
12
-
13
- const COMPONENT_NAME = 'Arcs';
14
- const CLASSNAME = 'redsift-arcs';
15
- const DEFAULT_PROPS: Partial<ArcsProps> = {};
16
-
17
- export const Arcs: Comp<ArcsProps, SVGGElement> = forwardRef((props, ref) => {
18
- const {
19
- arcs,
20
- className,
21
- color,
22
- hasLabels,
23
- hasStroke,
24
- id: propsId,
25
- labelDecorator,
26
- onClick,
27
- role,
28
- sliceProps,
29
- tooltipVariant,
30
- ...forwardedProps
31
- } = props;
32
- const id = propsId ?? useId();
33
-
34
- const animatedProps = useSpring({
35
- ...config,
36
- to: async (next: (props?: object) => Promise<void>) => {
37
- await next({ t: 1 });
38
- },
39
- from: { t: 0 },
40
- });
41
-
42
- return (
43
- <StyledArcs
44
- {...forwardedProps}
45
- className={classNames(Arcs.className, className)}
46
- ref={ref as RefObject<SVGGElement>}
47
- >
48
- <g className="arc-group">
49
- {arcs.map((arc, index) => {
50
- const arcIndex = arc.index ?? index;
51
- const arcId = arc.id ?? `id${id}__arc-${arcIndex}`;
52
-
53
- return (
54
- <Arc
55
- {...sliceProps}
56
- color={color}
57
- hasStroke={hasStroke}
58
- labelDecorator={labelDecorator}
59
- onClick={onClick}
60
- role={role}
61
- tooltipVariant={tooltipVariant}
62
- {...arc}
63
- key={arcId}
64
- id={arcId}
65
- index={arcIndex}
66
- />
67
- );
68
- })}
69
- </g>
70
- {hasLabels ? (
71
- <g className="arc-label-group">
72
- {arcs
73
- .filter((arc) => {
74
- const value = arc.data.data.value;
75
- const percent = arc.data.data.percent;
76
- return percent ? value > 0 && percent >= 0.1 : value > 0;
77
- })
78
- .map((arc, index) => {
79
- const arcIndex = arc.index ?? index;
80
- const arcId = arc.id ?? `id${id}__arc-${arcIndex}`;
81
- const arcLabelDecorator = arc.labelDecorator ?? labelDecorator;
82
- const interpolator = d3interpolate(arc.from, arc.data);
83
-
84
- return (
85
- <animated.text
86
- alignmentBaseline="middle"
87
- className={`arc-label _${index}`}
88
- key={`${arcId}-label`}
89
- textAnchor="middle"
90
- transform={
91
- config.immediate
92
- ? `translate(${arc.createArc.centroid(arc.data)})`
93
- : animatedProps.t.to(
94
- (t) =>
95
- `translate(${arc.createArc.centroid(
96
- interpolator(t)
97
- )})`
98
- )
99
- }
100
- >
101
- {arcLabelDecorator
102
- ? arcLabelDecorator(arc.data)
103
- : arc.data.data.key}
104
- </animated.text>
105
- );
106
- })}
107
- </g>
108
- ) : null}
109
- </StyledArcs>
110
- );
111
- });
112
- Arcs.className = CLASSNAME;
113
- Arcs.defaultProps = DEFAULT_PROPS;
114
- Arcs.displayName = COMPONENT_NAME;
@@ -1,3 +0,0 @@
1
- export * from './Arcs';
2
- export * from './types';
3
- export * from './styles';
@@ -1,7 +0,0 @@
1
- import styled from 'styled-components';
2
- import { StyledArcsProps } from './types';
3
-
4
- /**
5
- * Component style.
6
- */
7
- export const StyledArcs = styled.g<StyledArcsProps>``;
@@ -1,26 +0,0 @@
1
- import { ComponentProps } from 'react';
2
- import { ArcProps } from '../Arc/types';
3
-
4
- /**
5
- * Component props.
6
- */
7
- export interface ArcsProps
8
- extends Omit<ComponentProps<'g'>, 'onClick' | 'role'>,
9
- Pick<
10
- ArcProps,
11
- | 'id'
12
- | 'labelDecorator'
13
- | 'onClick'
14
- | 'role'
15
- | 'hasStroke'
16
- | 'tooltipVariant'
17
- > {
18
- /** Arc props. */
19
- arcs: Omit<ArcProps, 'ref'>[];
20
- /** Whether arcs have internal labels or not. */
21
- hasLabels?: boolean;
22
- /** Native HTML props to forward to each slice. */
23
- sliceProps?: Omit<ComponentProps<'g'>, 'onClick' | 'ref' | 'width'>;
24
- }
25
-
26
- export type StyledArcsProps = Omit<ArcsProps, 'arcs'> & {};