@redsift/charts 8.0.0 → 8.0.1
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.
- package/coverage/clover.xml +1070 -0
- package/coverage/coverage-final.json +60 -0
- package/coverage/lcov-report/ChartEmptyState/ChartEmptyState.tsx.html +679 -0
- package/coverage/lcov-report/ChartEmptyState/index.html +146 -0
- package/coverage/lcov-report/ChartEmptyState/index.ts.html +91 -0
- package/coverage/lcov-report/ChartEmptyState/styles.ts.html +184 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChart.tsx.html +775 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartAxisBottom.tsx.html +259 -0
- package/coverage/lcov-report/HorizontalBarChart/HorizontalBarChartBar.tsx.html +421 -0
- package/coverage/lcov-report/HorizontalBarChart/index.html +191 -0
- package/coverage/lcov-report/HorizontalBarChart/index.ts.html +94 -0
- package/coverage/lcov-report/HorizontalBarChart/styles.ts.html +451 -0
- package/coverage/lcov-report/HorizontalBarChart/types.ts.html +433 -0
- package/coverage/lcov-report/PieChart/PieChart.tsx.html +1105 -0
- package/coverage/lcov-report/PieChart/PieChartArc.tsx.html +412 -0
- package/coverage/lcov-report/PieChart/index.html +176 -0
- package/coverage/lcov-report/PieChart/index.ts.html +94 -0
- package/coverage/lcov-report/PieChart/styles.ts.html +616 -0
- package/coverage/lcov-report/PieChart/types.ts.html +472 -0
- package/coverage/lcov-report/PieChart.tsx.html +1045 -0
- package/coverage/lcov-report/PieChartArc.tsx.html +271 -0
- package/coverage/lcov-report/StaticPieChart.tsx.html +286 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/components/Arc/Arc.tsx.html +304 -0
- package/coverage/lcov-report/components/Arc/index.html +146 -0
- package/coverage/lcov-report/components/Arc/index.ts.html +94 -0
- package/coverage/lcov-report/components/Arc/styles.ts.html +208 -0
- package/coverage/lcov-report/components/Arcs/Arcs.tsx.html +427 -0
- package/coverage/lcov-report/components/Arcs/index.html +146 -0
- package/coverage/lcov-report/components/Arcs/index.ts.html +94 -0
- package/coverage/lcov-report/components/Arcs/styles.ts.html +106 -0
- package/coverage/lcov-report/components/Axis/Axis.tsx.html +754 -0
- package/coverage/lcov-report/components/Axis/computeTicks.ts.html +481 -0
- package/coverage/lcov-report/components/Axis/index.html +176 -0
- package/coverage/lcov-report/components/Axis/index.ts.html +94 -0
- package/coverage/lcov-report/components/Axis/styles.ts.html +148 -0
- package/coverage/lcov-report/components/Axis/types.ts.html +253 -0
- package/coverage/lcov-report/components/Bar/Bar.tsx.html +421 -0
- package/coverage/lcov-report/components/Bar/index.html +161 -0
- package/coverage/lcov-report/components/Bar/index.ts.html +94 -0
- package/coverage/lcov-report/components/Bar/styles.ts.html +247 -0
- package/coverage/lcov-report/components/Bar/types.ts.html +178 -0
- package/coverage/lcov-report/components/BarChart/BarChart.tsx.html +355 -0
- package/coverage/lcov-report/components/BarChart/EmptyBarChart.tsx.html +259 -0
- package/coverage/lcov-report/components/BarChart/LoadingBarChart.tsx.html +145 -0
- package/coverage/lcov-report/components/BarChart/RenderedBarChart.tsx.html +496 -0
- package/coverage/lcov-report/components/BarChart/index.html +206 -0
- package/coverage/lcov-report/components/BarChart/index.ts.html +94 -0
- package/coverage/lcov-report/components/BarChart/styles.ts.html +190 -0
- package/coverage/lcov-report/components/BarChart/utils.ts.html +145 -0
- package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +433 -0
- package/coverage/lcov-report/components/ChartContainer/index.html +146 -0
- package/coverage/lcov-report/components/ChartContainer/index.ts.html +94 -0
- package/coverage/lcov-report/components/ChartContainer/intl/index.html +116 -0
- package/coverage/lcov-report/components/ChartContainer/intl/index.ts.html +106 -0
- package/coverage/lcov-report/components/ChartContainer/styles.ts.html +211 -0
- package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +442 -0
- package/coverage/lcov-report/components/DataPoint/index.html +146 -0
- package/coverage/lcov-report/components/DataPoint/index.ts.html +94 -0
- package/coverage/lcov-report/components/DataPoint/styles.ts.html +109 -0
- package/coverage/lcov-report/components/Dot/Dot.tsx.html +232 -0
- package/coverage/lcov-report/components/Dot/index.html +146 -0
- package/coverage/lcov-report/components/Dot/index.ts.html +94 -0
- package/coverage/lcov-report/components/Dot/styles.ts.html +184 -0
- package/coverage/lcov-report/components/Legend/Legend.tsx.html +268 -0
- package/coverage/lcov-report/components/Legend/index.html +146 -0
- package/coverage/lcov-report/components/Legend/index.ts.html +94 -0
- package/coverage/lcov-report/components/Legend/styles.ts.html +130 -0
- package/coverage/lcov-report/components/LegendItem/LegendItem.tsx.html +403 -0
- package/coverage/lcov-report/components/LegendItem/index.html +146 -0
- package/coverage/lcov-report/components/LegendItem/index.ts.html +94 -0
- package/coverage/lcov-report/components/LegendItem/styles.ts.html +205 -0
- package/coverage/lcov-report/components/PieChart/EmptyPieChart.tsx.html +343 -0
- package/coverage/lcov-report/components/PieChart/LoadingPieChart.tsx.html +145 -0
- package/coverage/lcov-report/components/PieChart/PieChart.tsx.html +388 -0
- package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +571 -0
- package/coverage/lcov-report/components/PieChart/index.html +221 -0
- package/coverage/lcov-report/components/PieChart/index.ts.html +94 -0
- package/coverage/lcov-report/components/PieChart/styles.ts.html +376 -0
- package/coverage/lcov-report/components/PieChart/types.ts.html +352 -0
- package/coverage/lcov-report/components/PieChart/utils.ts.html +199 -0
- package/coverage/lcov-report/components/ScatterPlot/EmptyScatterPlot.tsx.html +295 -0
- package/coverage/lcov-report/components/ScatterPlot/LoadingScatterPlot.tsx.html +145 -0
- package/coverage/lcov-report/components/ScatterPlot/RenderedScatterPlot.tsx.html +910 -0
- package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +379 -0
- package/coverage/lcov-report/components/ScatterPlot/index.html +221 -0
- package/coverage/lcov-report/components/ScatterPlot/index.ts.html +94 -0
- package/coverage/lcov-report/components/ScatterPlot/styles.ts.html +196 -0
- package/coverage/lcov-report/components/ScatterPlot/types.ts.html +376 -0
- package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +388 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hooks/index.html +176 -0
- package/coverage/lcov-report/hooks/index.ts.html +97 -0
- package/coverage/lcov-report/hooks/useBrush.tsx.html +430 -0
- package/coverage/lcov-report/hooks/useColor.tsx.html +163 -0
- package/coverage/lcov-report/hooks/useFormatCategoricalData.tsx.html +289 -0
- package/coverage/lcov-report/hooks/useZoom.tsx.html +235 -0
- package/coverage/lcov-report/index.html +311 -0
- package/coverage/lcov-report/index.ts.html +94 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/styles.ts.html +631 -0
- package/coverage/lcov-report/types.ts.html +457 -0
- package/coverage/lcov.info +2272 -0
- package/dist/index.js +6326 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +98 -0
- package/index.ts +1 -0
- package/jest.config.js +3 -0
- package/package.json +2 -3
- package/rollup.config.js +13 -0
- package/src/components/Arc/Arc.test.tsx +92 -0
- package/src/components/Arc/Arc.tsx +73 -0
- package/src/components/Arc/index.ts +3 -0
- package/src/components/Arc/styles.ts +41 -0
- package/src/components/Arc/types.ts +18 -0
- package/src/components/Arcs/Arcs.stories.tsx +177 -0
- package/src/components/Arcs/Arcs.tsx +114 -0
- package/src/components/Arcs/index.ts +3 -0
- package/src/components/Arcs/styles.ts +7 -0
- package/src/components/Arcs/types.ts +26 -0
- package/src/components/Axis/Axis.stories.tsx +297 -0
- package/src/components/Axis/Axis.tsx +223 -0
- package/src/components/Axis/computeTicks.ts +132 -0
- package/src/components/Axis/index.ts +3 -0
- package/src/components/Axis/styles.ts +21 -0
- package/src/components/Axis/types.ts +56 -0
- package/src/components/Bar/Bar.stories.tsx +152 -0
- package/src/components/Bar/Bar.test.tsx +158 -0
- package/src/components/Bar/Bar.tsx +112 -0
- package/src/components/Bar/index.ts +3 -0
- package/src/components/Bar/styles.ts +54 -0
- package/src/components/Bar/types.ts +31 -0
- package/src/components/BarChart/BarChart.stories.tsx +80 -0
- package/src/components/BarChart/BarChart.test.tsx +189 -0
- package/src/components/BarChart/BarChart.tsx +90 -0
- package/src/components/BarChart/EmptyBarChart.tsx +58 -0
- package/src/components/BarChart/LoadingBarChart.tsx +20 -0
- package/src/components/BarChart/RenderedBarChart.tsx +137 -0
- package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +6932 -0
- package/src/components/BarChart/index.ts +3 -0
- package/src/components/BarChart/styles.ts +35 -0
- package/src/components/BarChart/types.ts +58 -0
- package/src/components/BarChart/utils.ts +20 -0
- package/src/components/ChartContainer/ChartContainer.stories.tsx +81 -0
- package/src/components/ChartContainer/ChartContainer.test.tsx +75 -0
- package/src/components/ChartContainer/ChartContainer.tsx +116 -0
- package/src/components/ChartContainer/index.ts +3 -0
- package/src/components/ChartContainer/intl/en-US.json +3 -0
- package/src/components/ChartContainer/intl/fr-FR.json +3 -0
- package/src/components/ChartContainer/intl/index.ts +7 -0
- package/src/components/ChartContainer/styles.ts +42 -0
- package/src/components/ChartContainer/types.ts +24 -0
- package/src/components/DataPoint/DataPoint.tsx +119 -0
- package/src/components/DataPoint/index.ts +3 -0
- package/src/components/DataPoint/styles.ts +8 -0
- package/src/components/DataPoint/types.ts +33 -0
- package/src/components/Dot/Dot.stories.tsx +157 -0
- package/src/components/Dot/Dot.test.tsx +136 -0
- package/src/components/Dot/Dot.tsx +49 -0
- package/src/components/Dot/index.ts +3 -0
- package/src/components/Dot/styles.ts +33 -0
- package/src/components/Dot/types.ts +16 -0
- package/src/components/Legend/Legend.stories.tsx +108 -0
- package/src/components/Legend/Legend.tsx +61 -0
- package/src/components/Legend/index.ts +3 -0
- package/src/components/Legend/styles.ts +15 -0
- package/src/components/Legend/types.ts +27 -0
- package/src/components/LegendItem/LegendItem.test.tsx +69 -0
- package/src/components/LegendItem/LegendItem.tsx +106 -0
- package/src/components/LegendItem/index.ts +3 -0
- package/src/components/LegendItem/styles.ts +40 -0
- package/src/components/LegendItem/types.ts +30 -0
- package/src/components/PieChart/EmptyPieChart.tsx +86 -0
- package/src/components/PieChart/LoadingPieChart.tsx +20 -0
- package/src/components/PieChart/PieChart.stories.tsx +91 -0
- package/src/components/PieChart/PieChart.test.tsx +201 -0
- package/src/components/PieChart/PieChart.tsx +101 -0
- package/src/components/PieChart/RenderedPieChart.tsx +162 -0
- package/src/components/PieChart/__snapshots__/PieChart.stories.storyshot +7843 -0
- package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +20540 -0
- package/src/components/PieChart/index.ts +3 -0
- package/src/components/PieChart/styles.ts +97 -0
- package/src/components/PieChart/types.ts +89 -0
- package/src/components/PieChart/utils.ts +38 -0
- package/src/components/ScatterPlot/EmptyScatterPlot.tsx +70 -0
- package/src/components/ScatterPlot/LoadingScatterPlot.tsx +20 -0
- package/src/components/ScatterPlot/RenderedScatterPlot.tsx +275 -0
- package/src/components/ScatterPlot/ScatterPlot.stories.tsx +95 -0
- package/src/components/ScatterPlot/ScatterPlot.test.tsx +44 -0
- package/src/components/ScatterPlot/ScatterPlot.tsx +98 -0
- package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +88352 -0
- package/src/components/ScatterPlot/index.ts +3 -0
- package/src/components/ScatterPlot/styles.ts +37 -0
- package/src/components/ScatterPlot/types.ts +97 -0
- package/src/components/ScatterPlot/utils.ts +101 -0
- package/src/config.ts +10 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useBrush.tsx +115 -0
- package/src/hooks/useColor.tsx +26 -0
- package/src/hooks/useFormatCategoricalData.tsx +68 -0
- package/src/hooks/useZoom.tsx +50 -0
- package/src/index.ts +15 -0
- package/src/scheme.ts +221 -0
- package/src/types/data.ts +52 -0
- package/src/types/index.ts +5 -0
- package/src/types/legend.ts +19 -0
- package/src/types/scale.ts +79 -0
- package/src/types/size.ts +17 -0
- package/src/types/theme.ts +27 -0
- package/tsconfig.json +3 -0
- package/index.js +0 -2606
- package/index.js.map +0 -1
- /package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test": "yarn test:unit && yarn test:storybook"
|
|
31
31
|
},
|
|
32
32
|
"types": "types.d.ts",
|
|
33
|
-
"version": "8.0.
|
|
33
|
+
"version": "8.0.1",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@emotion/react": "^11.10.4",
|
|
36
36
|
"@emotion/styled": "^11.10.4",
|
|
@@ -94,6 +94,5 @@
|
|
|
94
94
|
"react": "18",
|
|
95
95
|
"react-dom": "18",
|
|
96
96
|
"styled-components": "^5.3.5"
|
|
97
|
-
}
|
|
98
|
-
"gitHead": "d5b44ad25f944f5869829750628000b346718034"
|
|
97
|
+
}
|
|
99
98
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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];
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
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;
|