@redsift/charts 9.2.3-patch → 9.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +1096 -0
- package/coverage/coverage-final.json +60 -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 +409 -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 +352 -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 +430 -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/BottomAxis/BottomAxis.tsx.html +247 -0
- package/coverage/lcov-report/components/BottomAxis/index.html +146 -0
- package/coverage/lcov-report/components/BottomAxis/index.ts.html +94 -0
- package/coverage/lcov-report/components/BottomAxis/styles.ts.html +139 -0
- package/coverage/lcov-report/components/ChartContainer/ChartContainer.tsx.html +361 -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 +208 -0
- package/coverage/lcov-report/components/DataPoint/DataPoint.tsx.html +391 -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/HorizontalBar/HorizontalBar.tsx.html +541 -0
- package/coverage/lcov-report/components/HorizontalBar/index.html +161 -0
- package/coverage/lcov-report/components/HorizontalBar/index.ts.html +94 -0
- package/coverage/lcov-report/components/HorizontalBar/styles.ts.html +187 -0
- package/coverage/lcov-report/components/HorizontalBar/types.ts.html +301 -0
- package/coverage/lcov-report/components/HorizontalBarChart/HorizontalBarChart.tsx.html +691 -0
- package/coverage/lcov-report/components/HorizontalBarChart/index.html +146 -0
- package/coverage/lcov-report/components/HorizontalBarChart/index.ts.html +94 -0
- package/coverage/lcov-report/components/HorizontalBarChart/styles.ts.html +196 -0
- package/coverage/lcov-report/components/HorizontalBarChart/types.ts.html +301 -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 +325 -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 +385 -0
- package/coverage/lcov-report/components/PieChart/RenderedPieChart.tsx.html +607 -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 +370 -0
- package/coverage/lcov-report/components/PieChart/types.ts.html +367 -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 +1048 -0
- package/coverage/lcov-report/components/ScatterPlot/ScatterPlot.tsx.html +367 -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 +190 -0
- package/coverage/lcov-report/components/ScatterPlot/types.ts.html +394 -0
- package/coverage/lcov-report/components/ScatterPlot/utils.ts.html +388 -0
- package/coverage/lcov-report/core/Arc/Arc.tsx.html +304 -0
- package/coverage/lcov-report/core/Arc/index.html +146 -0
- package/coverage/lcov-report/core/Arc/index.ts.html +94 -0
- package/coverage/lcov-report/core/Arc/styles.ts.html +202 -0
- package/coverage/lcov-report/core/Arcs/Arcs.tsx.html +421 -0
- package/coverage/lcov-report/core/Arcs/index.html +146 -0
- package/coverage/lcov-report/core/Arcs/index.ts.html +94 -0
- package/coverage/lcov-report/core/Arcs/styles.ts.html +106 -0
- package/coverage/lcov-report/core/Axis/Axis.tsx.html +754 -0
- package/coverage/lcov-report/core/Axis/computeTicks.ts.html +481 -0
- package/coverage/lcov-report/core/Axis/index.html +176 -0
- package/coverage/lcov-report/core/Axis/index.ts.html +94 -0
- package/coverage/lcov-report/core/Axis/styles.ts.html +145 -0
- package/coverage/lcov-report/core/Axis/types.ts.html +253 -0
- package/coverage/lcov-report/core/Bar/Bar.tsx.html +421 -0
- package/coverage/lcov-report/core/Bar/index.html +161 -0
- package/coverage/lcov-report/core/Bar/index.ts.html +94 -0
- package/coverage/lcov-report/core/Bar/styles.ts.html +190 -0
- package/coverage/lcov-report/core/Bar/types.ts.html +178 -0
- package/coverage/lcov-report/core/BottomAxis/BottomAxis.tsx.html +277 -0
- package/coverage/lcov-report/core/BottomAxis/index.html +146 -0
- package/coverage/lcov-report/core/BottomAxis/index.ts.html +94 -0
- package/coverage/lcov-report/core/BottomAxis/styles.ts.html +139 -0
- package/coverage/lcov-report/core/ChartConfig/ChartConfig.ts.html +97 -0
- package/coverage/lcov-report/core/ChartConfig/index.html +131 -0
- package/coverage/lcov-report/core/ChartConfig/index.ts.html +88 -0
- package/coverage/lcov-report/core/ChartContainer/ChartContainer.tsx.html +421 -0
- package/coverage/lcov-report/core/ChartContainer/index.html +146 -0
- package/coverage/lcov-report/core/ChartContainer/index.ts.html +94 -0
- package/coverage/lcov-report/core/ChartContainer/intl/index.html +116 -0
- package/coverage/lcov-report/core/ChartContainer/intl/index.ts.html +106 -0
- package/coverage/lcov-report/core/ChartContainer/styles.ts.html +205 -0
- package/coverage/lcov-report/core/DataPoint/DataPoint.tsx.html +442 -0
- package/coverage/lcov-report/core/DataPoint/index.html +146 -0
- package/coverage/lcov-report/core/DataPoint/index.ts.html +94 -0
- package/coverage/lcov-report/core/DataPoint/styles.ts.html +109 -0
- package/coverage/lcov-report/core/Dot/Dot.tsx.html +232 -0
- package/coverage/lcov-report/core/Dot/index.html +146 -0
- package/coverage/lcov-report/core/Dot/index.ts.html +94 -0
- package/coverage/lcov-report/core/Dot/styles.ts.html +184 -0
- package/coverage/lcov-report/core/Legend/Legend.tsx.html +277 -0
- package/coverage/lcov-report/core/Legend/index.html +146 -0
- package/coverage/lcov-report/core/Legend/index.ts.html +94 -0
- package/coverage/lcov-report/core/Legend/styles.ts.html +172 -0
- package/coverage/lcov-report/core/Point/Point.tsx.html +484 -0
- package/coverage/lcov-report/core/Point/index.html +146 -0
- package/coverage/lcov-report/core/Point/index.ts.html +94 -0
- package/coverage/lcov-report/core/Point/styles.ts.html +169 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/HorizontalBarChart.tsx.html +706 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/index.html +161 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/index.ts.html +94 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/styles.ts.html +316 -0
- package/coverage/lcov-report/gallery/HorizontalBarChart/types.ts.html +310 -0
- package/coverage/lcov-report/gallery/PieChart/PieChart.tsx.html +1252 -0
- package/coverage/lcov-report/gallery/PieChart/index.html +161 -0
- package/coverage/lcov-report/gallery/PieChart/index.ts.html +94 -0
- package/coverage/lcov-report/gallery/PieChart/styles.ts.html +517 -0
- package/coverage/lcov-report/gallery/PieChart/types.ts.html +388 -0
- package/coverage/lcov-report/gallery/ScatterPlot/index.html +146 -0
- package/coverage/lcov-report/gallery/ScatterPlot/index.ts.html +94 -0
- package/coverage/lcov-report/gallery/ScatterPlot/styles.ts.html +343 -0
- package/coverage/lcov-report/gallery/ScatterPlot/types.ts.html +433 -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/useIsEmpty.tsx.html +118 -0
- package/coverage/lcov-report/hooks/useZoom.tsx.html +235 -0
- package/coverage/lcov-report/index.html +311 -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.info +2345 -0
- package/coverage/storybook/coverage-storybook.json +79382 -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 +80 -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 +108 -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 +156 -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 +74 -0
- package/src/components/BarChart/BarChart.test.tsx +178 -0
- package/src/components/BarChart/BarChart.tsx +89 -0
- package/src/components/BarChart/EmptyBarChart.tsx +58 -0
- package/src/components/BarChart/LoadingBarChart.tsx +20 -0
- package/src/components/BarChart/RenderedBarChart.tsx +115 -0
- package/src/components/BarChart/__snapshots__/BarChart.test.tsx.snap +7028 -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 +71 -0
- package/src/components/ChartContainer/ChartContainer.tsx +92 -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 +41 -0
- package/src/components/ChartContainer/types.ts +26 -0
- package/src/components/DataPoint/DataPoint.tsx +102 -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 +80 -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 +85 -0
- package/src/components/PieChart/PieChart.test.tsx +183 -0
- package/src/components/PieChart/PieChart.tsx +100 -0
- package/src/components/PieChart/RenderedPieChart.tsx +174 -0
- package/src/components/PieChart/__snapshots__/PieChart.test.tsx.snap +21020 -0
- package/src/components/PieChart/index.ts +3 -0
- package/src/components/PieChart/styles.ts +95 -0
- package/src/components/PieChart/types.ts +94 -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 +321 -0
- package/src/components/ScatterPlot/ScatterPlot.stories.tsx +101 -0
- package/src/components/ScatterPlot/ScatterPlot.test.tsx +61 -0
- package/src/components/ScatterPlot/ScatterPlot.tsx +94 -0
- package/src/components/ScatterPlot/__snapshots__/ScatterPlot.test.tsx.snap +91712 -0
- package/src/components/ScatterPlot/index.ts +3 -0
- package/src/components/ScatterPlot/styles.ts +35 -0
- package/src/components/ScatterPlot/types.ts +103 -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 +213 -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/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{index.js.map → dist/index.js.map} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { StyledScatterPlotProps } from './types';
|
|
3
|
+
import { ChartContainer } from '../ChartContainer';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component style.
|
|
7
|
+
*/
|
|
8
|
+
export const StyledScatterPlot = styled(ChartContainer)<StyledScatterPlotProps>``;
|
|
9
|
+
|
|
10
|
+
export const StyledScatterPlotEmptyText = styled.div<{
|
|
11
|
+
$maxWidth: number;
|
|
12
|
+
$textSize: number;
|
|
13
|
+
}>`
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 0;
|
|
16
|
+
left: 0;
|
|
17
|
+
height: 100%;
|
|
18
|
+
width: 100%;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
pointer-events: none;
|
|
24
|
+
|
|
25
|
+
> * {
|
|
26
|
+
max-width: ${({ $maxWidth }) => $maxWidth}px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
> span {
|
|
30
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
31
|
+
color: var(--redsift-color-neutral-black);
|
|
32
|
+
font-size: ${({ $textSize }) => $textSize}px;
|
|
33
|
+
line-height: ${({ $textSize }) => $textSize}px;
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChartDimensions,
|
|
3
|
+
ChartSize,
|
|
4
|
+
ChartTheme,
|
|
5
|
+
TooltipVariant,
|
|
6
|
+
DotDatum,
|
|
7
|
+
CoordinatesCategoryData,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { ValueOf } from '@redsift/design-system';
|
|
10
|
+
import { ChartContainerProps } from '../ChartContainer';
|
|
11
|
+
import { MutableRefObject, ReactNode } from 'react';
|
|
12
|
+
import { DotProps } from '../Dot';
|
|
13
|
+
import { ScaleLinear as d3ScaleLinear } from 'd3';
|
|
14
|
+
import { AxisVariant } from '../Axis';
|
|
15
|
+
import { LegendProps } from '../Legend';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Component variant.
|
|
19
|
+
*/
|
|
20
|
+
export const ScatterPlotVariant = {
|
|
21
|
+
default: 'default',
|
|
22
|
+
gridded: 'gridded',
|
|
23
|
+
} as const;
|
|
24
|
+
export type ScatterPlotVariant = ValueOf<typeof ScatterPlotVariant>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Component's labels variant.
|
|
28
|
+
*/
|
|
29
|
+
export const ScatterPlotLabelVariant = {
|
|
30
|
+
none: 'none',
|
|
31
|
+
externalLabel: 'externalLabel',
|
|
32
|
+
externalLabelValue: 'externalLabelValue',
|
|
33
|
+
externalLabelPercent: 'externalLabelPercent',
|
|
34
|
+
} as const;
|
|
35
|
+
export type ScatterPlotLabelVariant = ValueOf<typeof ScatterPlotLabelVariant>;
|
|
36
|
+
|
|
37
|
+
interface LocaleText {
|
|
38
|
+
emptyChartText: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ScatterPlotDimensions = ChartDimensions & {
|
|
42
|
+
fontSize: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Component props.
|
|
47
|
+
*/
|
|
48
|
+
export interface ScatterPlotProps extends ChartContainerProps {
|
|
49
|
+
/** Dataset to use to generate the chart. */
|
|
50
|
+
data?: CoordinatesCategoryData;
|
|
51
|
+
/** Slice role. Used to indicate that dots are to be considered buttons or links. If an onClick is provided, the dots will have the role `button` unless specifically set to `link` with this prop. */
|
|
52
|
+
dotRole?: DotProps['role'];
|
|
53
|
+
/** Component to use if the chart is empty (replacing the default one). */
|
|
54
|
+
emptyComponent?: ReactNode;
|
|
55
|
+
/** Whether the Control Keys panel is displayed or not. */
|
|
56
|
+
hideControlKeyPanel?: boolean;
|
|
57
|
+
/** Whether the scatter plot dots are selectable using brush or not. */
|
|
58
|
+
isBrushable?: boolean;
|
|
59
|
+
/** Method to determine whether a dot is selected or not. */
|
|
60
|
+
isDotSelected?: (datum: DotDatum) => boolean | undefined;
|
|
61
|
+
/** Method to override the data labels. */
|
|
62
|
+
labelDecorator?: (datum: DotDatum) => string;
|
|
63
|
+
/** Define whether the labels should be displayed inside or outside the charts and if they should contain raw or percentage values. */
|
|
64
|
+
labelVariant?: ScatterPlotLabelVariant;
|
|
65
|
+
/** Props to forward to the Legend block. Can be used to make the legend selectable. */
|
|
66
|
+
legendProps?: Omit<LegendProps, 'data' | 'ref' | 'variant' | 'width'>;
|
|
67
|
+
/** Labels and texts. */
|
|
68
|
+
localeText?: LocaleText;
|
|
69
|
+
/** Method called on brush. */
|
|
70
|
+
onBrush?: (
|
|
71
|
+
selection: [[number, number], [number, number]] | null,
|
|
72
|
+
scaleX: d3ScaleLinear<number, number>,
|
|
73
|
+
scaleY: d3ScaleLinear<number, number>
|
|
74
|
+
) => void;
|
|
75
|
+
/** Method called on brush end. */
|
|
76
|
+
onBrushEnd?: (
|
|
77
|
+
selection: [[number, number], [number, number]] | null,
|
|
78
|
+
scaleX?: d3ScaleLinear<number, number>,
|
|
79
|
+
scaleY?: d3ScaleLinear<number, number>
|
|
80
|
+
) => void;
|
|
81
|
+
/** Method to be called on a click on a dot. */
|
|
82
|
+
onDotClick?: (datum: DotDatum) => void;
|
|
83
|
+
/** ScatterPlot size. */
|
|
84
|
+
size?: ChartSize | ScatterPlotDimensions;
|
|
85
|
+
/** Reference to the SVG tag. */
|
|
86
|
+
svgRef?: MutableRefObject<SVGSVGElement>;
|
|
87
|
+
/** Color palette to use. You can choose among the list of available color palette or also choose to use the success/warning/danger theme for which you have to specify which key corresponds to which status. */
|
|
88
|
+
theme?: ChartTheme;
|
|
89
|
+
/** Tooltip variant. */
|
|
90
|
+
tooltipVariant?: TooltipVariant;
|
|
91
|
+
/** Variant. */
|
|
92
|
+
variant?: ScatterPlotVariant;
|
|
93
|
+
/** X axis variant. */
|
|
94
|
+
xAxisVariant?: AxisVariant;
|
|
95
|
+
/** X axis placement. */
|
|
96
|
+
xAxisPlacement?: 'bottom' | 'top' | 'both';
|
|
97
|
+
/** Y axis variant. */
|
|
98
|
+
yAxisVariant?: AxisVariant;
|
|
99
|
+
/** Y axis placement. */
|
|
100
|
+
yAxisPlacement?: 'right' | 'left' | 'both';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type StyledScatterPlotProps = ScatterPlotProps & {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ScaleLinear as d3ScaleLinear } from 'd3';
|
|
2
|
+
|
|
3
|
+
import { CoordinatesCategoryData, CoordinatesCategoryDatum } from '../../types';
|
|
4
|
+
|
|
5
|
+
import { ChartSize } from '../../types';
|
|
6
|
+
import { ScatterPlotDimensions } from './types';
|
|
7
|
+
|
|
8
|
+
export const sizeToDimension = (
|
|
9
|
+
size: ChartSize | ScatterPlotDimensions
|
|
10
|
+
): ScatterPlotDimensions => {
|
|
11
|
+
if (typeof size !== 'string') {
|
|
12
|
+
return size;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
switch (size) {
|
|
16
|
+
case ChartSize.small:
|
|
17
|
+
return { width: 600, height: 300, fontSize: 30 };
|
|
18
|
+
case ChartSize.medium:
|
|
19
|
+
default:
|
|
20
|
+
return { width: 750, height: 375, fontSize: 34 };
|
|
21
|
+
case ChartSize.large:
|
|
22
|
+
return { width: 900, height: 450, fontSize: 38 };
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const BASE_NUMBER_OF_TICKS = 20;
|
|
27
|
+
|
|
28
|
+
export const getClosestLineIndex = (
|
|
29
|
+
value: number,
|
|
30
|
+
scale: d3ScaleLinear<number, number, never>
|
|
31
|
+
) => {
|
|
32
|
+
const ticks = scale.ticks(BASE_NUMBER_OF_TICKS);
|
|
33
|
+
const delta = ticks[1] - ticks[0];
|
|
34
|
+
const index = Math.round(value / delta);
|
|
35
|
+
const roundValue = index * delta;
|
|
36
|
+
return [index, roundValue];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const group = (
|
|
40
|
+
data: CoordinatesCategoryData,
|
|
41
|
+
x: d3ScaleLinear<number, number, never>,
|
|
42
|
+
y: d3ScaleLinear<number, number, never>
|
|
43
|
+
) => {
|
|
44
|
+
const groupDict: Record<
|
|
45
|
+
string,
|
|
46
|
+
{
|
|
47
|
+
category: string;
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
data: CoordinatesCategoryDatum;
|
|
51
|
+
points: CoordinatesCategoryData;
|
|
52
|
+
}
|
|
53
|
+
> = {};
|
|
54
|
+
|
|
55
|
+
data.forEach((d) => {
|
|
56
|
+
const [i, rx] = getClosestLineIndex(d.key[0], x);
|
|
57
|
+
const [j, ry] = getClosestLineIndex(d.key[1], y);
|
|
58
|
+
|
|
59
|
+
const key = `${i}_${j}_${d.key[2]}`;
|
|
60
|
+
if (!(key in groupDict)) {
|
|
61
|
+
groupDict[key] = {
|
|
62
|
+
category: d.key[2] as string,
|
|
63
|
+
x: rx,
|
|
64
|
+
y: ry,
|
|
65
|
+
data: {
|
|
66
|
+
key: d.key,
|
|
67
|
+
value: 0,
|
|
68
|
+
},
|
|
69
|
+
points: [],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
groupDict[key].points.push(d);
|
|
74
|
+
groupDict[key].data.value += 1;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return Object.values(groupDict);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const countBy = (arr: CoordinatesCategoryData) => {
|
|
81
|
+
const counts = arr.reduce(
|
|
82
|
+
(prev, curr) => (
|
|
83
|
+
(prev[curr.key[2] as string] =
|
|
84
|
+
++(prev[curr.key[2] as string] as number) || 1),
|
|
85
|
+
prev
|
|
86
|
+
),
|
|
87
|
+
{} as Record<string, number>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return Object.keys(counts)
|
|
91
|
+
.map((key) => ({ key: key, value: counts[key] as number }))
|
|
92
|
+
.sort((a, b) =>
|
|
93
|
+
a.value === b.value
|
|
94
|
+
? a.key > b.key
|
|
95
|
+
? 1
|
|
96
|
+
: -1
|
|
97
|
+
: a.value < b.value
|
|
98
|
+
? 1
|
|
99
|
+
: -1
|
|
100
|
+
);
|
|
101
|
+
};
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { MutableRefObject, useEffect, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
BrushBehavior as d3BrushBehavior,
|
|
4
|
+
brush as d3brush,
|
|
5
|
+
ScaleLinear as d3ScaleLinear,
|
|
6
|
+
select as d3select,
|
|
7
|
+
} from 'd3';
|
|
8
|
+
|
|
9
|
+
export interface UseBrushProps {
|
|
10
|
+
brushRef: MutableRefObject<d3BrushBehavior<unknown> | undefined>;
|
|
11
|
+
svgRef: MutableRefObject<SVGSVGElement | SVGGElement | undefined>;
|
|
12
|
+
extent?: [[number, number], [number, number]];
|
|
13
|
+
scaleX: d3ScaleLinear<number, number>;
|
|
14
|
+
scaleY: d3ScaleLinear<number, number>;
|
|
15
|
+
isBrushable?: boolean;
|
|
16
|
+
isGridded?: boolean;
|
|
17
|
+
onBrush?: (
|
|
18
|
+
selection: [[number, number], [number, number]] | null,
|
|
19
|
+
scaleX: d3ScaleLinear<number, number>,
|
|
20
|
+
scaleY: d3ScaleLinear<number, number>
|
|
21
|
+
) => void;
|
|
22
|
+
onBrushEnd?: (
|
|
23
|
+
selection: [[number, number], [number, number]] | null,
|
|
24
|
+
scaleX: d3ScaleLinear<number, number>,
|
|
25
|
+
scaleY: d3ScaleLinear<number, number>
|
|
26
|
+
) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getRoundedIntermediaryPoint = (
|
|
30
|
+
selection: [[number, number], [number, number]],
|
|
31
|
+
scaleX: d3ScaleLinear<number, number>,
|
|
32
|
+
scaleY: d3ScaleLinear<number, number>
|
|
33
|
+
) => {
|
|
34
|
+
if (!selection) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const xTicks = scaleX.ticks(20);
|
|
39
|
+
const xDelta = xTicks[1] - xTicks[0];
|
|
40
|
+
const yTicks = scaleY.ticks(20);
|
|
41
|
+
const yDelta = yTicks[1] - yTicks[0];
|
|
42
|
+
|
|
43
|
+
return [
|
|
44
|
+
[
|
|
45
|
+
scaleX(
|
|
46
|
+
Math.round(scaleX.invert(selection[0][0]) / xDelta) * xDelta -
|
|
47
|
+
xDelta / 2
|
|
48
|
+
),
|
|
49
|
+
scaleY(
|
|
50
|
+
Math.round(scaleY.invert(selection[0][1]) / yDelta) * yDelta -
|
|
51
|
+
yDelta / 2
|
|
52
|
+
),
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
scaleX(
|
|
56
|
+
Math.round(scaleX.invert(selection[1][0]) / xDelta) * xDelta -
|
|
57
|
+
xDelta / 2
|
|
58
|
+
),
|
|
59
|
+
|
|
60
|
+
scaleY(
|
|
61
|
+
Math.round(scaleY.invert(selection[1][1]) / yDelta) * yDelta -
|
|
62
|
+
yDelta / 2
|
|
63
|
+
),
|
|
64
|
+
],
|
|
65
|
+
] as [[number, number], [number, number]];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const useBrush = ({
|
|
69
|
+
brushRef: propsBrushRef,
|
|
70
|
+
svgRef,
|
|
71
|
+
extent,
|
|
72
|
+
scaleX,
|
|
73
|
+
scaleY,
|
|
74
|
+
isBrushable,
|
|
75
|
+
isGridded,
|
|
76
|
+
onBrush,
|
|
77
|
+
onBrushEnd,
|
|
78
|
+
}: UseBrushProps) => {
|
|
79
|
+
const brushRef = propsBrushRef || useRef<d3BrushBehavior<unknown>>();
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (svgRef.current && isBrushable) {
|
|
83
|
+
brushRef.current = d3brush()
|
|
84
|
+
.extent(extent!)
|
|
85
|
+
.keyModifiers(false)
|
|
86
|
+
.filter((event) => event.shiftKey)
|
|
87
|
+
.on('brush', (event) => {
|
|
88
|
+
if (!event.sourceEvent || !brushRef.current || !svgRef.current)
|
|
89
|
+
return;
|
|
90
|
+
|
|
91
|
+
if (isGridded) {
|
|
92
|
+
const selection = getRoundedIntermediaryPoint(
|
|
93
|
+
event.selection,
|
|
94
|
+
scaleX,
|
|
95
|
+
scaleY
|
|
96
|
+
);
|
|
97
|
+
d3select(svgRef.current).call(
|
|
98
|
+
brushRef.current.move as any,
|
|
99
|
+
selection
|
|
100
|
+
);
|
|
101
|
+
onBrush?.(selection, scaleX, scaleY);
|
|
102
|
+
} else {
|
|
103
|
+
onBrush?.(event.selection, scaleX, scaleY);
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.on('end', (event) => {
|
|
107
|
+
if (!event.sourceEvent || !brushRef.current || !svgRef.current)
|
|
108
|
+
return;
|
|
109
|
+
|
|
110
|
+
onBrushEnd?.(event.selection, scaleX, scaleY);
|
|
111
|
+
});
|
|
112
|
+
d3select(svgRef.current).call(brushRef.current as any);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { ScaleOrdinal as d3ScaleOrdinal } from 'd3';
|
|
3
|
+
import { getColorScale } from '../scheme';
|
|
4
|
+
import { ChartTheme, JSONArray } from '../types';
|
|
5
|
+
|
|
6
|
+
export interface UseColorProps {
|
|
7
|
+
/** Dataset to use to generate the chart. */
|
|
8
|
+
data: JSONArray;
|
|
9
|
+
/** Theme. */
|
|
10
|
+
theme: ChartTheme;
|
|
11
|
+
/** Name of the field that will be used to categorize the data. */
|
|
12
|
+
category: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useColor = ({ data, theme, category }: UseColorProps) => {
|
|
16
|
+
const colorScale = useMemo<d3ScaleOrdinal<string, string>>(
|
|
17
|
+
() =>
|
|
18
|
+
getColorScale(
|
|
19
|
+
theme,
|
|
20
|
+
data.map((d) => d[category] as string)
|
|
21
|
+
),
|
|
22
|
+
[theme]
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return colorScale;
|
|
26
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { CategoryData, ChartTheme } from '../types';
|
|
3
|
+
import { useColor } from './useColor';
|
|
4
|
+
|
|
5
|
+
export interface UseFormatCategoricalDataProps {
|
|
6
|
+
/** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */
|
|
7
|
+
data: CategoryData;
|
|
8
|
+
/** Theme. */
|
|
9
|
+
theme: ChartTheme;
|
|
10
|
+
/** Number of categories to use, the rest being put into a new category called "Others". */
|
|
11
|
+
caping?: number;
|
|
12
|
+
/** Whether a category should be displayed for categories that has been removed by the caping option. Optionaly, this prop can be used to change the label of this category. */
|
|
13
|
+
others?: boolean | string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const useFormatCategoricalData = ({
|
|
17
|
+
data,
|
|
18
|
+
caping,
|
|
19
|
+
others,
|
|
20
|
+
theme,
|
|
21
|
+
}: UseFormatCategoricalDataProps) => {
|
|
22
|
+
const computedData = useMemo(() => {
|
|
23
|
+
let computedData;
|
|
24
|
+
|
|
25
|
+
if (data === undefined || data === null) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
computedData = [...data!].sort((a, b) =>
|
|
30
|
+
a.value === b.value
|
|
31
|
+
? a.key > b.key
|
|
32
|
+
? 1
|
|
33
|
+
: -1
|
|
34
|
+
: a.value < b.value
|
|
35
|
+
? 1
|
|
36
|
+
: -1
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (caping) {
|
|
40
|
+
if (typeof others === 'boolean' && !others) {
|
|
41
|
+
computedData = computedData.slice(0, caping);
|
|
42
|
+
} else {
|
|
43
|
+
computedData = computedData.reduce<CategoryData>((acc, curr, index) => {
|
|
44
|
+
if (index < caping) {
|
|
45
|
+
acc[index] = curr;
|
|
46
|
+
} else if (index === caping) {
|
|
47
|
+
acc[index] = {
|
|
48
|
+
key: typeof others === 'string' ? others : 'Others',
|
|
49
|
+
value: curr.value,
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
acc[caping] = {
|
|
53
|
+
...acc[caping],
|
|
54
|
+
value: acc[caping].value + curr.value,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return acc;
|
|
58
|
+
}, []);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return computedData;
|
|
63
|
+
}, [data, caping]);
|
|
64
|
+
|
|
65
|
+
const colorScale = useColor({ data: computedData!, theme, category: 'key' });
|
|
66
|
+
|
|
67
|
+
return { data: computedData as CategoryData, colorScale };
|
|
68
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MutableRefObject, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
zoom as d3zoom,
|
|
4
|
+
interpolateRound as d3interpolateRound,
|
|
5
|
+
ScaleLinear as d3ScaleLinear,
|
|
6
|
+
select as d3select,
|
|
7
|
+
} from 'd3';
|
|
8
|
+
|
|
9
|
+
export interface UseZoomProps {
|
|
10
|
+
svgRef: MutableRefObject<SVGSVGElement | undefined>;
|
|
11
|
+
scaleX: d3ScaleLinear<number, number>;
|
|
12
|
+
scaleY: d3ScaleLinear<number, number>;
|
|
13
|
+
defaultTransform?: { k: number; x: number; y: number };
|
|
14
|
+
size?: any;
|
|
15
|
+
onZoom?: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useZoom = ({
|
|
19
|
+
svgRef,
|
|
20
|
+
scaleX,
|
|
21
|
+
scaleY,
|
|
22
|
+
defaultTransform = { k: 1, x: 0, y: 0 },
|
|
23
|
+
size,
|
|
24
|
+
onZoom,
|
|
25
|
+
}: UseZoomProps) => {
|
|
26
|
+
const zx = useRef<d3ScaleLinear<number, number>>(scaleX);
|
|
27
|
+
const zy = useRef<d3ScaleLinear<number, number>>(scaleY);
|
|
28
|
+
const [transform, setTransform] = useState(defaultTransform);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (svgRef.current) {
|
|
32
|
+
const zoom = d3zoom()
|
|
33
|
+
.filter((event) => !event.shiftKey)
|
|
34
|
+
.scaleExtent([1 / 2 ** 3, 2 ** 3])
|
|
35
|
+
.on('zoom', (event) => {
|
|
36
|
+
onZoom?.();
|
|
37
|
+
zx.current = event.transform
|
|
38
|
+
.rescaleX(scaleX)
|
|
39
|
+
.interpolate(d3interpolateRound);
|
|
40
|
+
zy.current = event.transform
|
|
41
|
+
.rescaleY(scaleY)
|
|
42
|
+
.interpolate(d3interpolateRound);
|
|
43
|
+
setTransform(event.transform);
|
|
44
|
+
});
|
|
45
|
+
d3select(svgRef.current).call(zoom as any);
|
|
46
|
+
}
|
|
47
|
+
}, [svgRef.current, size]);
|
|
48
|
+
|
|
49
|
+
return { transform, scaleX: zx.current, scaleY: zy.current };
|
|
50
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './scheme';
|
|
4
|
+
|
|
5
|
+
export * from './components/Arc';
|
|
6
|
+
export * from './components/Arcs';
|
|
7
|
+
export * from './components/Axis';
|
|
8
|
+
export * from './components/Bar';
|
|
9
|
+
export * from './components/BarChart';
|
|
10
|
+
export * from './components/ChartContainer';
|
|
11
|
+
export * from './components/DataPoint';
|
|
12
|
+
export * from './components/Dot';
|
|
13
|
+
export * from './components/Legend';
|
|
14
|
+
export * from './components/PieChart';
|
|
15
|
+
export * from './components/ScatterPlot';
|