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