@redsift/charts 11.5.0 → 11.6.0-muiv5-alpha.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/_virtual/_rollupPluginBabelHelpers.js +93 -0
- package/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/components/Arc/Arc.d.ts +6 -0
- package/components/Arc/Arc.js +74 -0
- package/components/Arc/Arc.js.map +1 -0
- package/components/Arc/styles.d.ts +17 -0
- package/components/Arc/styles.js +49 -0
- package/components/Arc/styles.js.map +1 -0
- package/components/Arc/types.d.ts +20 -0
- package/components/Arcs/Arcs.d.ts +6 -0
- package/components/Arcs/Arcs.js +90 -0
- package/components/Arcs/Arcs.js.map +1 -0
- package/components/Arcs/styles.d.ts +9 -0
- package/components/Arcs/styles.js +9 -0
- package/components/Arcs/styles.js.map +1 -0
- package/components/Arcs/types.d.ts +17 -0
- package/components/Axis/Axis.d.ts +7 -0
- package/components/Axis/Axis.js +211 -0
- package/components/Axis/Axis.js.map +1 -0
- package/components/Axis/computeTicks.js +117 -0
- package/components/Axis/computeTicks.js.map +1 -0
- package/components/Axis/styles.d.ts +14 -0
- package/components/Axis/styles.js +51 -0
- package/components/Axis/styles.js.map +1 -0
- package/components/Axis/types.d.ts +89 -0
- package/components/Axis/types.js +24 -0
- package/components/Axis/types.js.map +1 -0
- package/components/Bar/Bar.d.ts +6 -0
- package/components/Bar/Bar.js +95 -0
- package/components/Bar/Bar.js.map +1 -0
- package/components/Bar/styles.d.ts +16 -0
- package/components/Bar/styles.js +66 -0
- package/components/Bar/styles.js.map +1 -0
- package/components/Bar/types.d.ts +46 -0
- package/components/Bar/types.js +18 -0
- package/components/Bar/types.js.map +1 -0
- package/components/BarChart/BarChart.d.ts +29 -0
- package/components/BarChart/BarChart.js +141 -0
- package/components/BarChart/BarChart.js.map +1 -0
- package/components/BarChart/BarChartBars.js +168 -0
- package/components/BarChart/BarChartBars.js.map +1 -0
- package/components/BarChart/BarChartSection.js +139 -0
- package/components/BarChart/BarChartSection.js.map +1 -0
- package/components/BarChart/EmptyBarChart.js +57 -0
- package/components/BarChart/EmptyBarChart.js.map +1 -0
- package/components/BarChart/LoadingBarChart.js +18 -0
- package/components/BarChart/LoadingBarChart.js.map +1 -0
- package/components/BarChart/RenderedLinearBarChart.js +549 -0
- package/components/BarChart/RenderedLinearBarChart.js.map +1 -0
- package/components/BarChart/RenderedOrdinalBarChart.js +236 -0
- package/components/BarChart/RenderedOrdinalBarChart.js.map +1 -0
- package/components/BarChart/context.js +13 -0
- package/components/BarChart/context.js.map +1 -0
- package/components/BarChart/intl/en-US.json.js +17 -0
- package/components/BarChart/intl/en-US.json.js.map +1 -0
- package/components/BarChart/intl/fr-FR.json.js +17 -0
- package/components/BarChart/intl/fr-FR.json.js.map +1 -0
- package/components/BarChart/intl/index.js +10 -0
- package/components/BarChart/intl/index.js.map +1 -0
- package/components/BarChart/styles.d.ts +19 -0
- package/components/BarChart/styles.js +71 -0
- package/components/BarChart/styles.js.map +1 -0
- package/components/BarChart/types.d.ts +177 -0
- package/components/BarChart/types.js +17 -0
- package/components/BarChart/types.js.map +1 -0
- package/components/BarChart/utils.js +69 -0
- package/components/BarChart/utils.js.map +1 -0
- package/components/ChartContainer/ChartContainer.d.ts +9 -0
- package/components/ChartContainer/ChartContainer.js +167 -0
- package/components/ChartContainer/ChartContainer.js.map +1 -0
- package/components/ChartContainer/context.js +6 -0
- package/components/ChartContainer/context.js.map +1 -0
- package/components/ChartContainer/intl/en-US.json.js +14 -0
- package/components/ChartContainer/intl/en-US.json.js.map +1 -0
- package/components/ChartContainer/intl/fr-FR.json.js +14 -0
- package/components/ChartContainer/intl/fr-FR.json.js.map +1 -0
- package/components/ChartContainer/intl/index.js +10 -0
- package/components/ChartContainer/intl/index.js.map +1 -0
- package/components/ChartContainer/styles.d.ts +17 -0
- package/components/ChartContainer/styles.js +76 -0
- package/components/ChartContainer/styles.js.map +1 -0
- package/components/ChartContainer/types.d.ts +48 -0
- package/components/DataPoint/DataPoint.d.ts +6 -0
- package/components/DataPoint/DataPoint.js +104 -0
- package/components/DataPoint/DataPoint.js.map +1 -0
- package/components/DataPoint/styles.d.ts +12 -0
- package/components/DataPoint/styles.js +10 -0
- package/components/DataPoint/styles.js.map +1 -0
- package/components/DataPoint/types.d.ts +60 -0
- package/components/Dot/Dot.d.ts +6 -0
- package/components/Dot/Dot.js +55 -0
- package/components/Dot/Dot.js.map +1 -0
- package/components/Dot/styles.d.ts +16 -0
- package/components/Dot/styles.js +49 -0
- package/components/Dot/styles.js.map +1 -0
- package/components/Dot/types.d.ts +30 -0
- package/components/Dot/types.js +14 -0
- package/components/Dot/types.js.map +1 -0
- package/components/Legend/Legend.d.ts +6 -0
- package/components/Legend/Legend.js +73 -0
- package/components/Legend/Legend.js.map +1 -0
- package/components/Legend/styles.d.ts +11 -0
- package/components/Legend/styles.js +15 -0
- package/components/Legend/styles.js.map +1 -0
- package/components/Legend/types.d.ts +44 -0
- package/components/LegendItem/LegendItem.js +96 -0
- package/components/LegendItem/LegendItem.js.map +1 -0
- package/components/LegendItem/styles.js +63 -0
- package/components/LegendItem/styles.js.map +1 -0
- package/components/LegendItem/types.d.ts +20 -0
- package/components/Line/Line.d.ts +6 -0
- package/components/Line/Line.js +55 -0
- package/components/Line/Line.js.map +1 -0
- package/components/Line/styles.d.ts +9 -0
- package/components/Line/styles.js +9 -0
- package/components/Line/styles.js.map +1 -0
- package/components/Line/types.d.ts +21 -0
- package/components/LineChart/EmptyLineChart.js +58 -0
- package/components/LineChart/EmptyLineChart.js.map +1 -0
- package/components/LineChart/LineChart.d.ts +6 -0
- package/components/LineChart/LineChart.js +96 -0
- package/components/LineChart/LineChart.js.map +1 -0
- package/components/LineChart/LoadingLineChart.js +18 -0
- package/components/LineChart/LoadingLineChart.js.map +1 -0
- package/components/LineChart/RenderedLineChart.js +372 -0
- package/components/LineChart/RenderedLineChart.js.map +1 -0
- package/components/LineChart/intl/en-US.json.js +17 -0
- package/components/LineChart/intl/en-US.json.js.map +1 -0
- package/components/LineChart/intl/fr-FR.json.js +17 -0
- package/components/LineChart/intl/fr-FR.json.js.map +1 -0
- package/components/LineChart/intl/index.js +10 -0
- package/components/LineChart/intl/index.js.map +1 -0
- package/components/LineChart/styles.d.ts +17 -0
- package/components/LineChart/styles.js +53 -0
- package/components/LineChart/styles.js.map +1 -0
- package/components/LineChart/types.d.ts +90 -0
- package/components/LineChart/types.js +17 -0
- package/components/LineChart/types.js.map +1 -0
- package/components/LineChart/utils.js +67 -0
- package/components/LineChart/utils.js.map +1 -0
- package/components/PieChart/EmptyPieChart.js +85 -0
- package/components/PieChart/EmptyPieChart.js.map +1 -0
- package/components/PieChart/LoadingPieChart.js +18 -0
- package/components/PieChart/LoadingPieChart.js.map +1 -0
- package/components/PieChart/PieChart.d.ts +6 -0
- package/components/PieChart/PieChart.js +98 -0
- package/components/PieChart/PieChart.js.map +1 -0
- package/components/PieChart/RenderedPieChart.js +198 -0
- package/components/PieChart/RenderedPieChart.js.map +1 -0
- package/components/PieChart/intl/en-US.json.js +9 -0
- package/components/PieChart/intl/en-US.json.js.map +1 -0
- package/components/PieChart/intl/fr-FR.json.js +9 -0
- package/components/PieChart/intl/fr-FR.json.js.map +1 -0
- package/components/PieChart/intl/index.js +10 -0
- package/components/PieChart/intl/index.js.map +1 -0
- package/components/PieChart/styles.d.ts +24 -0
- package/components/PieChart/styles.js +168 -0
- package/components/PieChart/styles.js.map +1 -0
- package/components/PieChart/types.d.ts +115 -0
- package/components/PieChart/types.js +27 -0
- package/components/PieChart/types.js.map +1 -0
- package/components/PieChart/utils.js +37 -0
- package/components/PieChart/utils.js.map +1 -0
- package/components/ScatterPlot/EmptyScatterPlot.js +58 -0
- package/components/ScatterPlot/EmptyScatterPlot.js.map +1 -0
- package/components/ScatterPlot/LoadingScatterPlot.js +18 -0
- package/components/ScatterPlot/LoadingScatterPlot.js.map +1 -0
- package/components/ScatterPlot/RenderedScatterPlot.js +352 -0
- package/components/ScatterPlot/RenderedScatterPlot.js.map +1 -0
- package/components/ScatterPlot/ScatterPlot.d.ts +6 -0
- package/components/ScatterPlot/ScatterPlot.js +105 -0
- package/components/ScatterPlot/ScatterPlot.js.map +1 -0
- package/components/ScatterPlot/intl/en-US.json.js +12 -0
- package/components/ScatterPlot/intl/en-US.json.js.map +1 -0
- package/components/ScatterPlot/intl/fr-FR.json.js +17 -0
- package/components/ScatterPlot/intl/fr-FR.json.js.map +1 -0
- package/components/ScatterPlot/intl/index.js +10 -0
- package/components/ScatterPlot/intl/index.js.map +1 -0
- package/components/ScatterPlot/styles.d.ts +17 -0
- package/components/ScatterPlot/styles.js +53 -0
- package/components/ScatterPlot/styles.js.map +1 -0
- package/components/ScatterPlot/types.d.ts +109 -0
- package/components/ScatterPlot/types.js +24 -0
- package/components/ScatterPlot/types.js.map +1 -0
- package/components/ScatterPlot/utils.js +70 -0
- package/components/ScatterPlot/utils.js.map +1 -0
- package/config.js +15 -0
- package/config.js.map +1 -0
- package/design-system/src/react-aria/react-aria/i18n/useMessageFormatter.d.ts +5 -0
- package/hooks/useBrush.d.ts +17 -0
- package/hooks/useBrush.js +48 -0
- package/hooks/useBrush.js.map +1 -0
- package/hooks/useColor.d.ts +18 -0
- package/hooks/useColor.js +20 -0
- package/hooks/useColor.js.map +1 -0
- package/hooks/useFormatCategoricalData.d.ts +26 -0
- package/hooks/useFormatCategoricalData.js +57 -0
- package/hooks/useFormatCategoricalData.js.map +1 -0
- package/hooks/useZoom.d.ts +26 -0
- package/hooks/useZoom.js +39 -0
- package/hooks/useZoom.js.map +1 -0
- package/index.d.ts +51 -1277
- package/index.js +42 -5118
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/scheme.d.ts +32 -0
- package/scheme.js +47 -0
- package/scheme.js.map +1 -0
- package/types/axis.d.ts +48 -0
- package/types/data.d.ts +72 -0
- package/types/legend.d.ts +30 -0
- package/types/legend.js +21 -0
- package/types/legend.js.map +1 -0
- package/types/scale.d.ts +48 -0
- package/types/size.d.ts +20 -0
- package/types/size.js +8 -0
- package/types/size.js.map +1 -0
- package/types/theme.d.ts +23 -0
- package/types/theme.js +13 -0
- package/types/theme.js.map +1 -0
- package/utils/index.d.ts +11 -0
- package/utils/index.js +44 -0
- package/utils/index.js.map +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { ChartContainer } from '../ChartContainer/ChartContainer.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Component style.
|
|
6
|
+
*/
|
|
7
|
+
const StyledScatterPlot = styled(ChartContainer)``;
|
|
8
|
+
const StyledScatterPlotEmptyText = styled.div`
|
|
9
|
+
position: absolute;
|
|
10
|
+
top: 0;
|
|
11
|
+
left: 0;
|
|
12
|
+
height: 100%;
|
|
13
|
+
width: 100%;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
align-items: center;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
|
|
20
|
+
> * {
|
|
21
|
+
max-width: ${_ref => {
|
|
22
|
+
let {
|
|
23
|
+
$maxWidth
|
|
24
|
+
} = _ref;
|
|
25
|
+
return $maxWidth;
|
|
26
|
+
}}px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
> span {
|
|
30
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
31
|
+
color: ${_ref2 => {
|
|
32
|
+
let {
|
|
33
|
+
$theme
|
|
34
|
+
} = _ref2;
|
|
35
|
+
return `var(--redsift-color-${$theme}-components-text-primary)`;
|
|
36
|
+
}};
|
|
37
|
+
font-size: ${_ref3 => {
|
|
38
|
+
let {
|
|
39
|
+
$textSize
|
|
40
|
+
} = _ref3;
|
|
41
|
+
return $textSize;
|
|
42
|
+
}}px;
|
|
43
|
+
line-height: ${_ref4 => {
|
|
44
|
+
let {
|
|
45
|
+
$textSize
|
|
46
|
+
} = _ref4;
|
|
47
|
+
return $textSize;
|
|
48
|
+
}}px;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export { StyledScatterPlot, StyledScatterPlotEmptyText };
|
|
53
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../src/components/ScatterPlot/styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { StyledScatterPlotProps } from './types';\nimport { ChartContainer } from '../ChartContainer';\nimport { Theme } from '@redsift/design-system';\n\n/**\n * Component style.\n */\nexport const StyledScatterPlot = styled(ChartContainer)<StyledScatterPlotProps>``;\n\nexport const StyledScatterPlotEmptyText = styled.div<{\n $maxWidth: number;\n $textSize: number;\n $theme: Theme;\n}>`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n pointer-events: none;\n\n > * {\n max-width: ${({ $maxWidth }) => $maxWidth}px;\n }\n\n > span {\n font-family: var(--redsift-typography-font-family-poppins);\n color: ${({ $theme }) => `var(--redsift-color-${$theme}-components-text-primary)`};\n font-size: ${({ $textSize }) => $textSize}px;\n line-height: ${({ $textSize }) => $textSize}px;\n }\n`;\n"],"names":["StyledScatterPlot","styled","ChartContainer","StyledScatterPlotEmptyText","div","_ref","$maxWidth","_ref2","$theme","_ref3","$textSize","_ref4"],"mappings":";;;AAKA;AACA;AACA;MACaA,iBAAiB,GAAGC,MAAM,CAACC,cAAc,CAA0B,CAAC,EAAA;AAEpEC,MAAAA,0BAA0B,GAAGF,MAAM,CAACG,GAI9C,CAAA;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAA,EAAiBC,IAAA,IAAA;EAAA,IAAC;AAAEC,IAAAA,SAAAA;AAAU,GAAC,GAAAD,IAAA,CAAA;AAAA,EAAA,OAAKC,SAAS,CAAA;AAAA,CAAC,CAAA;AAC9C;AACA;AACA;AACA;AACA,WAAA,EAAaC,KAAA,IAAA;EAAA,IAAC;AAAEC,IAAAA,MAAAA;AAAO,GAAC,GAAAD,KAAA,CAAA;EAAA,OAAM,CAAA,oBAAA,EAAsBC,MAAO,CAA0B,yBAAA,CAAA,CAAA;AAAA,CAAC,CAAA;AACtF,eAAA,EAAiBC,KAAA,IAAA;EAAA,IAAC;AAAEC,IAAAA,SAAAA;AAAU,GAAC,GAAAD,KAAA,CAAA;AAAA,EAAA,OAAKC,SAAS,CAAA;AAAA,CAAC,CAAA;AAC9C,iBAAA,EAAmBC,KAAA,IAAA;EAAA,IAAC;AAAED,IAAAA,SAAAA;AAAU,GAAC,GAAAC,KAAA,CAAA;AAAA,EAAA,OAAKD,SAAS,CAAA;AAAA,CAAC,CAAA;AAChD;AACA;;;;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ValueOf, Theme } from '@redsift/design-system';
|
|
2
|
+
import { ReactNode, ReactElement, MutableRefObject } from 'react';
|
|
3
|
+
import { ScaleLinear } from 'd3';
|
|
4
|
+
import { SortingMethod } from '../../utils/index.js';
|
|
5
|
+
import { CoordinatesCategoryData, DotDatum, Statistics } from '../../types/data.js';
|
|
6
|
+
import { ChartDimensions, MarginProps, ChartSize } from '../../types/size.js';
|
|
7
|
+
import { ChartContainerProps } from '../ChartContainer/types.js';
|
|
8
|
+
import { ChartAxesProps } from '../../types/axis.js';
|
|
9
|
+
import { AnchorProps } from '../DataPoint/types.js';
|
|
10
|
+
import { DotProps } from '../Dot/types.js';
|
|
11
|
+
import { LegendProps } from '../Legend/types.js';
|
|
12
|
+
import { ChartTheme } from '../../types/theme.js';
|
|
13
|
+
import { TooltipVariant } from '../../types/legend.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Component variant.
|
|
17
|
+
*/
|
|
18
|
+
declare const ScatterPlotVariant: {
|
|
19
|
+
readonly default: "default";
|
|
20
|
+
readonly gridded: "gridded";
|
|
21
|
+
};
|
|
22
|
+
type ScatterPlotVariant = ValueOf<typeof ScatterPlotVariant>;
|
|
23
|
+
/**
|
|
24
|
+
* Component's labels variant.
|
|
25
|
+
*/
|
|
26
|
+
declare const ScatterPlotLegendVariant: {
|
|
27
|
+
readonly none: "none";
|
|
28
|
+
readonly externalLabel: "externalLabel";
|
|
29
|
+
readonly externalLabelValue: "externalLabelValue";
|
|
30
|
+
readonly externalLabelPercent: "externalLabelPercent";
|
|
31
|
+
readonly custom: "custom";
|
|
32
|
+
};
|
|
33
|
+
type ScatterPlotLegendVariant = ValueOf<typeof ScatterPlotLegendVariant>;
|
|
34
|
+
interface LocaleText {
|
|
35
|
+
emptyChartText: string;
|
|
36
|
+
}
|
|
37
|
+
type ScatterPlotDimensions = ChartDimensions & {
|
|
38
|
+
fontSize: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Component props.
|
|
42
|
+
*/
|
|
43
|
+
interface ScatterPlotProps extends ChartContainerProps, ChartAxesProps {
|
|
44
|
+
/** Dataset to use to generate the chart. */
|
|
45
|
+
data?: CoordinatesCategoryData;
|
|
46
|
+
/** Method used to define the anchor props to use when the dot is a navigation link. */
|
|
47
|
+
getDotAnchorProps?: (datum: DotDatum) => AnchorProps;
|
|
48
|
+
/** Dot role. If an onClick is provided, the dots will have the role `button`. For a navigation link, please use `getDotAnchorProps` instead. */
|
|
49
|
+
dotRole?: DotProps['role'];
|
|
50
|
+
/** Component to use if the chart is empty (replacing the default one). */
|
|
51
|
+
emptyComponent?: ReactNode;
|
|
52
|
+
/** Whether the Control Keys panel is displayed or not. */
|
|
53
|
+
hideControlKeyPanel?: boolean;
|
|
54
|
+
/** Whether the scatter plot dots are selectable using brush or not. */
|
|
55
|
+
isBrushable?: boolean;
|
|
56
|
+
/** Method to determine whether a dot is selected or not. */
|
|
57
|
+
isDotSelected?: (datum: DotDatum) => boolean | undefined;
|
|
58
|
+
/** Method to override the data point labels. */
|
|
59
|
+
labelDecorator?: (datum: DotDatum, props?: {
|
|
60
|
+
index?: number;
|
|
61
|
+
isSelected?: boolean;
|
|
62
|
+
color?: string;
|
|
63
|
+
}) => string | ReactElement;
|
|
64
|
+
/** Method modifying what's displayed within the legend when the legendVariant is "custom". */
|
|
65
|
+
legendDecorator?: (datum: DotDatum, props?: {
|
|
66
|
+
index?: number;
|
|
67
|
+
isSelected?: boolean;
|
|
68
|
+
color?: string;
|
|
69
|
+
}) => string | ReactElement;
|
|
70
|
+
/** Define whether the labels should be displayed inside or outside the charts and if they should contain raw or percentage values. If set to "custom", use `legendDecorator` to customize it. */
|
|
71
|
+
legendVariant?: ScatterPlotLegendVariant;
|
|
72
|
+
/** Props to forward to the Legend block. Can be used to make the legend selectable. */
|
|
73
|
+
legendProps?: Omit<LegendProps, 'data' | 'ref' | 'variant' | 'width'> & {
|
|
74
|
+
extraLegendItems?: Statistics;
|
|
75
|
+
};
|
|
76
|
+
/** Labels and texts. */
|
|
77
|
+
localeText?: LocaleText;
|
|
78
|
+
/** Custom margins, used to give more space for axes labels and legend for instance. */
|
|
79
|
+
margins?: MarginProps;
|
|
80
|
+
/** Method called on brush. */
|
|
81
|
+
onBrush?: (selection: [[number, number], [number, number]] | null, scaleX: ScaleLinear<number, number>, scaleY: ScaleLinear<number, number>) => void;
|
|
82
|
+
/** Method called on brush end. */
|
|
83
|
+
onBrushEnd?: (selection: [[number, number], [number, number]] | null, scaleX?: ScaleLinear<number, number>, scaleY?: ScaleLinear<number, number>) => void;
|
|
84
|
+
/** Method to be called on a click on a dot. For a navigation link, please use `getDotAnchorProps` instead. */
|
|
85
|
+
onDotClick?: (datum: DotDatum) => void;
|
|
86
|
+
/** ScatterPlot size. */
|
|
87
|
+
size?: ChartSize | ScatterPlotDimensions;
|
|
88
|
+
/** Define how to sort categories. */
|
|
89
|
+
sortingMethod?: SortingMethod;
|
|
90
|
+
/** Reference to the SVG tag. */
|
|
91
|
+
svgRef?: MutableRefObject<SVGSVGElement>;
|
|
92
|
+
/** 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. */
|
|
93
|
+
colorTheme?: ChartTheme;
|
|
94
|
+
/** Method modifying what's displayed within the tooltip when the tooltipVariant is "custom". */
|
|
95
|
+
tooltipDecorator?: (data: DotDatum, props?: {
|
|
96
|
+
index?: number;
|
|
97
|
+
isSelected?: boolean;
|
|
98
|
+
color?: string;
|
|
99
|
+
}) => string | ReactElement;
|
|
100
|
+
/** Tooltip variant. */
|
|
101
|
+
tooltipVariant?: TooltipVariant;
|
|
102
|
+
/** Variant. */
|
|
103
|
+
variant?: ScatterPlotVariant;
|
|
104
|
+
/** Theme. */
|
|
105
|
+
theme?: Theme;
|
|
106
|
+
}
|
|
107
|
+
type StyledScatterPlotProps = ScatterPlotProps & {};
|
|
108
|
+
|
|
109
|
+
export { ScatterPlotDimensions, ScatterPlotLegendVariant, ScatterPlotProps, ScatterPlotVariant, StyledScatterPlotProps };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component variant.
|
|
3
|
+
*/
|
|
4
|
+
const ScatterPlotVariant = {
|
|
5
|
+
default: 'default',
|
|
6
|
+
gridded: 'gridded'
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Component's labels variant.
|
|
10
|
+
*/
|
|
11
|
+
const ScatterPlotLegendVariant = {
|
|
12
|
+
none: 'none',
|
|
13
|
+
externalLabel: 'externalLabel',
|
|
14
|
+
externalLabelValue: 'externalLabelValue',
|
|
15
|
+
externalLabelPercent: 'externalLabelPercent',
|
|
16
|
+
custom: 'custom'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Component props.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export { ScatterPlotLegendVariant, ScatterPlotVariant };
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/components/ScatterPlot/types.ts"],"sourcesContent":["import {\n ChartDimensions,\n ChartSize,\n ChartTheme,\n TooltipVariant,\n DotDatum,\n CoordinatesCategoryData,\n ChartAxesProps,\n MarginProps,\n Statistics,\n} from '../../types';\nimport { Theme, ValueOf } from '@redsift/design-system';\nimport { ChartContainerProps } from '../ChartContainer';\nimport { MutableRefObject, ReactElement, ReactNode } from 'react';\nimport { DotProps } from '../Dot';\nimport { ScaleLinear as d3ScaleLinear } from 'd3';\nimport { LegendProps } from '../Legend';\nimport { SortingMethod } from '../../utils';\nimport { AnchorProps } from '../DataPoint';\n\n/**\n * Component variant.\n */\nexport const ScatterPlotVariant = {\n default: 'default',\n gridded: 'gridded',\n} as const;\nexport type ScatterPlotVariant = ValueOf<typeof ScatterPlotVariant>;\n\n/**\n * Component's labels variant.\n */\nexport const ScatterPlotLegendVariant = {\n none: 'none',\n externalLabel: 'externalLabel',\n externalLabelValue: 'externalLabelValue',\n externalLabelPercent: 'externalLabelPercent',\n custom: 'custom',\n} as const;\nexport type ScatterPlotLegendVariant = ValueOf<typeof ScatterPlotLegendVariant>;\n\ninterface LocaleText {\n emptyChartText: string;\n}\n\nexport type ScatterPlotDimensions = ChartDimensions & {\n fontSize: number;\n};\n\n/**\n * Component props.\n */\nexport interface ScatterPlotProps extends ChartContainerProps, ChartAxesProps {\n /** Dataset to use to generate the chart. */\n data?: CoordinatesCategoryData;\n /** Method used to define the anchor props to use when the dot is a navigation link. */\n getDotAnchorProps?: (datum: DotDatum) => AnchorProps;\n /** Dot role. If an onClick is provided, the dots will have the role `button`. For a navigation link, please use `getDotAnchorProps` instead. */\n dotRole?: DotProps['role'];\n /** Component to use if the chart is empty (replacing the default one). */\n emptyComponent?: ReactNode;\n /** Whether the Control Keys panel is displayed or not. */\n hideControlKeyPanel?: boolean;\n /** Whether the scatter plot dots are selectable using brush or not. */\n isBrushable?: boolean;\n /** Method to determine whether a dot is selected or not. */\n isDotSelected?: (datum: DotDatum) => boolean | undefined;\n /** Method to override the data point labels. */\n labelDecorator?: (\n datum: DotDatum,\n props?: { index?: number; isSelected?: boolean; color?: string }\n ) => string | ReactElement;\n /** Method modifying what's displayed within the legend when the legendVariant is \"custom\". */\n legendDecorator?: (\n datum: DotDatum,\n props?: { index?: number; isSelected?: boolean; color?: string }\n ) => string | ReactElement;\n /** Define whether the labels should be displayed inside or outside the charts and if they should contain raw or percentage values. If set to \"custom\", use `legendDecorator` to customize it. */\n legendVariant?: ScatterPlotLegendVariant;\n /** Props to forward to the Legend block. Can be used to make the legend selectable. */\n legendProps?: Omit<LegendProps, 'data' | 'ref' | 'variant' | 'width'> & {\n extraLegendItems?: Statistics;\n };\n /** Labels and texts. */\n localeText?: LocaleText;\n /** Custom margins, used to give more space for axes labels and legend for instance. */\n margins?: MarginProps;\n /** Method called on brush. */\n onBrush?: (\n selection: [[number, number], [number, number]] | null,\n scaleX: d3ScaleLinear<number, number>,\n scaleY: d3ScaleLinear<number, number>\n ) => void;\n /** Method called on brush end. */\n onBrushEnd?: (\n selection: [[number, number], [number, number]] | null,\n scaleX?: d3ScaleLinear<number, number>,\n scaleY?: d3ScaleLinear<number, number>\n ) => void;\n /** Method to be called on a click on a dot. For a navigation link, please use `getDotAnchorProps` instead. */\n onDotClick?: (datum: DotDatum) => void;\n /** ScatterPlot size. */\n size?: ChartSize | ScatterPlotDimensions;\n /** Define how to sort categories. */\n sortingMethod?: SortingMethod;\n /** Reference to the SVG tag. */\n svgRef?: MutableRefObject<SVGSVGElement>;\n /** 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. */\n colorTheme?: ChartTheme;\n /** Method modifying what's displayed within the tooltip when the tooltipVariant is \"custom\". */\n tooltipDecorator?: (\n data: DotDatum,\n props?: { index?: number; isSelected?: boolean; color?: string }\n ) => string | ReactElement;\n /** Tooltip variant. */\n tooltipVariant?: TooltipVariant;\n /** Variant. */\n variant?: ScatterPlotVariant;\n /** Theme. */\n theme?: Theme;\n}\n\nexport type StyledScatterPlotProps = ScatterPlotProps & {};\n"],"names":["ScatterPlotVariant","default","gridded","ScatterPlotLegendVariant","none","externalLabel","externalLabelValue","externalLabelPercent","custom"],"mappings":"AAoBA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG;AAChCC,EAAAA,OAAO,EAAE,SAAS;AAClBC,EAAAA,OAAO,EAAE,SAAA;AACX,EAAU;AAGV;AACA;AACA;AACO,MAAMC,wBAAwB,GAAG;AACtCC,EAAAA,IAAI,EAAE,MAAM;AACZC,EAAAA,aAAa,EAAE,eAAe;AAC9BC,EAAAA,kBAAkB,EAAE,oBAAoB;AACxCC,EAAAA,oBAAoB,EAAE,sBAAsB;AAC5CC,EAAAA,MAAM,EAAE,QAAA;AACV,EAAU;;AAWV;AACA;AACA;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getSortingMethod } from '../../utils/index.js';
|
|
2
|
+
import { ChartSize } from '../../types/size.js';
|
|
3
|
+
|
|
4
|
+
const sizeToDimension = size => {
|
|
5
|
+
if (typeof size !== 'string') {
|
|
6
|
+
return size;
|
|
7
|
+
}
|
|
8
|
+
switch (size) {
|
|
9
|
+
case ChartSize.small:
|
|
10
|
+
return {
|
|
11
|
+
width: 600,
|
|
12
|
+
height: 300,
|
|
13
|
+
fontSize: 30
|
|
14
|
+
};
|
|
15
|
+
case ChartSize.medium:
|
|
16
|
+
default:
|
|
17
|
+
return {
|
|
18
|
+
width: 750,
|
|
19
|
+
height: 375,
|
|
20
|
+
fontSize: 34
|
|
21
|
+
};
|
|
22
|
+
case ChartSize.large:
|
|
23
|
+
return {
|
|
24
|
+
width: 900,
|
|
25
|
+
height: 450,
|
|
26
|
+
fontSize: 38
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const BASE_NUMBER_OF_TICKS = 20;
|
|
31
|
+
const getClosestLineIndex = (value, scale) => {
|
|
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
|
+
const group = (data, x, y) => {
|
|
39
|
+
const groupDict = {};
|
|
40
|
+
data.forEach(d => {
|
|
41
|
+
const [i, rx] = getClosestLineIndex(d.key[0], x);
|
|
42
|
+
const [j, ry] = getClosestLineIndex(d.key[1], y);
|
|
43
|
+
const key = `${i}_${j}_${d.key[2]}`;
|
|
44
|
+
if (!(key in groupDict)) {
|
|
45
|
+
groupDict[key] = {
|
|
46
|
+
category: d.key[2],
|
|
47
|
+
x: rx,
|
|
48
|
+
y: ry,
|
|
49
|
+
data: {
|
|
50
|
+
key: d.key,
|
|
51
|
+
value: 0
|
|
52
|
+
},
|
|
53
|
+
points: []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
groupDict[key].points.push(d);
|
|
57
|
+
groupDict[key].data.value += 1;
|
|
58
|
+
});
|
|
59
|
+
return Object.values(groupDict);
|
|
60
|
+
};
|
|
61
|
+
const countBy = (arr, sortingMethod) => {
|
|
62
|
+
const counts = arr.reduce((prev, curr) => (prev[curr.key[2]] = ++prev[curr.key[2]] || 1, prev), {});
|
|
63
|
+
return Object.keys(counts).map(key => ({
|
|
64
|
+
key: key,
|
|
65
|
+
value: counts[key]
|
|
66
|
+
})).sort(getSortingMethod(sortingMethod));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { BASE_NUMBER_OF_TICKS, countBy, getClosestLineIndex, group, sizeToDimension };
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/components/ScatterPlot/utils.ts"],"sourcesContent":["import { ScaleLinear as d3ScaleLinear } from 'd3';\n\nimport { CoordinatesCategoryData, CoordinatesCategoryDatum } from '../../types';\n\nimport { ChartSize } from '../../types';\nimport { ScatterPlotDimensions } from './types';\nimport { SortingMethod, getSortingMethod } from '../../utils';\n\nexport const sizeToDimension = (size: ChartSize | ScatterPlotDimensions): ScatterPlotDimensions => {\n if (typeof size !== 'string') {\n return size;\n }\n\n switch (size) {\n case ChartSize.small:\n return { width: 600, height: 300, fontSize: 30 };\n case ChartSize.medium:\n default:\n return { width: 750, height: 375, fontSize: 34 };\n case ChartSize.large:\n return { width: 900, height: 450, fontSize: 38 };\n }\n};\n\nexport const BASE_NUMBER_OF_TICKS = 20;\n\nexport const getClosestLineIndex = (value: number, scale: d3ScaleLinear<number, number, never>) => {\n const ticks = scale.ticks(BASE_NUMBER_OF_TICKS);\n const delta = ticks[1] - ticks[0];\n const index = Math.round(value / delta);\n const roundValue = index * delta;\n return [index, roundValue];\n};\n\nexport const group = (\n data: CoordinatesCategoryData,\n x: d3ScaleLinear<number, number, never>,\n y: d3ScaleLinear<number, number, never>\n) => {\n const groupDict: Record<\n string,\n {\n category: string;\n x: number;\n y: number;\n data: CoordinatesCategoryDatum;\n points: CoordinatesCategoryData;\n }\n > = {};\n\n data.forEach((d) => {\n const [i, rx] = getClosestLineIndex(d.key[0], x);\n const [j, ry] = getClosestLineIndex(d.key[1], y);\n\n const key = `${i}_${j}_${d.key[2]}`;\n if (!(key in groupDict)) {\n groupDict[key] = {\n category: d.key[2] as string,\n x: rx,\n y: ry,\n data: {\n key: d.key,\n value: 0,\n },\n points: [],\n };\n }\n\n groupDict[key].points.push(d);\n groupDict[key].data.value += 1;\n });\n\n return Object.values(groupDict);\n};\n\nexport const countBy = (arr: CoordinatesCategoryData, sortingMethod: SortingMethod) => {\n const counts = arr.reduce(\n (prev, curr) => ((prev[curr.key[2] as string] = ++(prev[curr.key[2] as string] as number) || 1), prev),\n {} as Record<string, number>\n );\n\n return Object.keys(counts)\n .map((key) => ({ key: key, value: counts[key] as number }))\n .sort(getSortingMethod(sortingMethod));\n};\n"],"names":["sizeToDimension","size","ChartSize","small","width","height","fontSize","medium","large","BASE_NUMBER_OF_TICKS","getClosestLineIndex","value","scale","ticks","delta","index","Math","round","roundValue","group","data","x","y","groupDict","forEach","d","i","rx","key","j","ry","category","points","push","Object","values","countBy","arr","sortingMethod","counts","reduce","prev","curr","keys","map","sort","getSortingMethod"],"mappings":";;;AAQaA,MAAAA,eAAe,GAAIC,IAAuC,IAA4B;AACjG,EAAA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;AAC5B,IAAA,OAAOA,IAAI,CAAA;AACb,GAAA;AAEA,EAAA,QAAQA,IAAI;IACV,KAAKC,SAAS,CAACC,KAAK;MAClB,OAAO;AAAEC,QAAAA,KAAK,EAAE,GAAG;AAAEC,QAAAA,MAAM,EAAE,GAAG;AAAEC,QAAAA,QAAQ,EAAE,EAAA;OAAI,CAAA;IAClD,KAAKJ,SAAS,CAACK,MAAM,CAAA;AACrB,IAAA;MACE,OAAO;AAAEH,QAAAA,KAAK,EAAE,GAAG;AAAEC,QAAAA,MAAM,EAAE,GAAG;AAAEC,QAAAA,QAAQ,EAAE,EAAA;OAAI,CAAA;IAClD,KAAKJ,SAAS,CAACM,KAAK;MAClB,OAAO;AAAEJ,QAAAA,KAAK,EAAE,GAAG;AAAEC,QAAAA,MAAM,EAAE,GAAG;AAAEC,QAAAA,QAAQ,EAAE,EAAA;OAAI,CAAA;AACpD,GAAA;AACF,EAAC;AAEM,MAAMG,oBAAoB,GAAG,GAAE;MAEzBC,mBAAmB,GAAGA,CAACC,KAAa,EAAEC,KAA2C,KAAK;AACjG,EAAA,MAAMC,KAAK,GAAGD,KAAK,CAACC,KAAK,CAACJ,oBAAoB,CAAC,CAAA;EAC/C,MAAMK,KAAK,GAAGD,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,CAAA;EACjC,MAAME,KAAK,GAAGC,IAAI,CAACC,KAAK,CAACN,KAAK,GAAGG,KAAK,CAAC,CAAA;AACvC,EAAA,MAAMI,UAAU,GAAGH,KAAK,GAAGD,KAAK,CAAA;AAChC,EAAA,OAAO,CAACC,KAAK,EAAEG,UAAU,CAAC,CAAA;AAC5B,EAAC;AAEM,MAAMC,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AACC,GAA4B,EAAEC,aAA4B,KAAK;AACrF,EAAA,MAAMC,MAAM,GAAGF,GAAG,CAACG,MAAM,CACvB,CAACC,IAAI,EAAEC,IAAI,MAAOD,IAAI,CAACC,IAAI,CAACd,GAAG,CAAC,CAAC,CAAC,CAAW,GAAG,EAAGa,IAAI,CAACC,IAAI,CAACd,GAAG,CAAC,CAAC,CAAC,CAAsB,IAAI,CAAC,EAAGa,IAAI,CAAC,EACtG,EACF,CAAC,CAAA;EAED,OAAOP,MAAM,CAACS,IAAI,CAACJ,MAAM,CAAC,CACvBK,GAAG,CAAEhB,GAAG,KAAM;AAAEA,IAAAA,GAAG,EAAEA,GAAG;IAAEjB,KAAK,EAAE4B,MAAM,CAACX,GAAG,CAAA;GAAa,CAAC,CAAC,CAC1DiB,IAAI,CAACC,gBAAgB,CAACR,aAAa,CAAC,CAAC,CAAA;AAC1C;;;;"}
|
package/config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './node_modules/@react-spring/web/dist/esm/index.js';
|
|
2
|
+
import { easings as Lt } from './node_modules/@react-spring/shared/dist/esm/index.js';
|
|
3
|
+
import './node_modules/@react-spring/core/dist/esm/index.js';
|
|
4
|
+
|
|
5
|
+
const config = (() => ({
|
|
6
|
+
config: {
|
|
7
|
+
duration: 700,
|
|
8
|
+
easing: Lt.easeInOutQuad
|
|
9
|
+
},
|
|
10
|
+
reset: true,
|
|
11
|
+
immediate: false
|
|
12
|
+
}))();
|
|
13
|
+
|
|
14
|
+
export { config };
|
|
15
|
+
//# sourceMappingURL=config.js.map
|
package/config.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../src/config.ts"],"sourcesContent":["import { easings } from '@react-spring/web';\n\nexport const config = (() => ({\n config: {\n duration: 700,\n easing: easings.easeInOutQuad,\n },\n reset: true,\n immediate: false,\n}))();\n"],"names":["config","duration","easing","easings","easeInOutQuad","reset","immediate"],"mappings":";;;;AAEaA,MAAAA,MAAM,GAAG,CAAC,OAAO;AAC5BA,EAAAA,MAAM,EAAE;AACNC,IAAAA,QAAQ,EAAE,GAAG;IACbC,MAAM,EAAEC,EAAO,CAACC,aAAAA;GACjB;AACDC,EAAAA,KAAK,EAAE,IAAI;AACXC,EAAAA,SAAS,EAAE,KAAA;AACb,CAAC,CAAC;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { BrushBehavior, ScaleLinear } from 'd3';
|
|
3
|
+
|
|
4
|
+
interface UseBrushProps {
|
|
5
|
+
brushRef: MutableRefObject<BrushBehavior<unknown> | undefined>;
|
|
6
|
+
svgRef: MutableRefObject<SVGSVGElement | SVGGElement | undefined>;
|
|
7
|
+
extent?: [[number, number], [number, number]];
|
|
8
|
+
scaleX: ScaleLinear<number, number>;
|
|
9
|
+
scaleY: ScaleLinear<number, number>;
|
|
10
|
+
isBrushable?: boolean;
|
|
11
|
+
isGridded?: boolean;
|
|
12
|
+
onBrush?: (selection: [[number, number], [number, number]] | null, scaleX: ScaleLinear<number, number>, scaleY: ScaleLinear<number, number>) => void;
|
|
13
|
+
onBrushEnd?: (selection: [[number, number], [number, number]] | null, scaleX: ScaleLinear<number, number>, scaleY: ScaleLinear<number, number>) => void;
|
|
14
|
+
}
|
|
15
|
+
declare const useBrush: ({ brushRef: propsBrushRef, svgRef, extent, scaleX, scaleY, isBrushable, isGridded, onBrush, onBrushEnd, }: UseBrushProps) => void;
|
|
16
|
+
|
|
17
|
+
export { UseBrushProps, useBrush };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { brush, select } from 'd3';
|
|
3
|
+
|
|
4
|
+
const getRoundedIntermediaryPoint = (selection, scaleX, scaleY) => {
|
|
5
|
+
if (!selection) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const xTicks = scaleX.ticks(20);
|
|
9
|
+
const xDelta = xTicks[1] - xTicks[0];
|
|
10
|
+
const yTicks = scaleY.ticks(20);
|
|
11
|
+
const yDelta = yTicks[1] - yTicks[0];
|
|
12
|
+
return [[scaleX(Math.round(scaleX.invert(selection[0][0]) / xDelta) * xDelta - xDelta / 2), scaleY(Math.round(scaleY.invert(selection[0][1]) / yDelta) * yDelta - yDelta / 2)], [scaleX(Math.round(scaleX.invert(selection[1][0]) / xDelta) * xDelta - xDelta / 2), scaleY(Math.round(scaleY.invert(selection[1][1]) / yDelta) * yDelta - yDelta / 2)]];
|
|
13
|
+
};
|
|
14
|
+
const useBrush = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
brushRef: propsBrushRef,
|
|
17
|
+
svgRef,
|
|
18
|
+
extent,
|
|
19
|
+
scaleX,
|
|
20
|
+
scaleY,
|
|
21
|
+
isBrushable,
|
|
22
|
+
isGridded,
|
|
23
|
+
onBrush,
|
|
24
|
+
onBrushEnd
|
|
25
|
+
} = _ref;
|
|
26
|
+
const brushRef = propsBrushRef || useRef();
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (svgRef.current && isBrushable) {
|
|
29
|
+
brushRef.current = brush().extent(extent).keyModifiers(false).filter(event => event.shiftKey).on('brush', event => {
|
|
30
|
+
if (!event.sourceEvent || !brushRef.current || !svgRef.current) return;
|
|
31
|
+
if (isGridded) {
|
|
32
|
+
const selection = getRoundedIntermediaryPoint(event.selection, scaleX, scaleY);
|
|
33
|
+
select(svgRef.current).call(brushRef.current.move, selection);
|
|
34
|
+
onBrush === null || onBrush === void 0 ? void 0 : onBrush(selection, scaleX, scaleY);
|
|
35
|
+
} else {
|
|
36
|
+
onBrush === null || onBrush === void 0 ? void 0 : onBrush(event.selection, scaleX, scaleY);
|
|
37
|
+
}
|
|
38
|
+
}).on('end', event => {
|
|
39
|
+
if (!event.sourceEvent || !brushRef.current || !svgRef.current) return;
|
|
40
|
+
onBrushEnd === null || onBrushEnd === void 0 ? void 0 : onBrushEnd(event.selection, scaleX, scaleY);
|
|
41
|
+
});
|
|
42
|
+
select(svgRef.current).call(brushRef.current);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { useBrush };
|
|
48
|
+
//# sourceMappingURL=useBrush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrush.js","sources":["../../src/hooks/useBrush.tsx"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\nimport {\n BrushBehavior as d3BrushBehavior,\n brush as d3brush,\n ScaleLinear as d3ScaleLinear,\n select as d3select,\n} from 'd3';\n\nexport interface UseBrushProps {\n brushRef: MutableRefObject<d3BrushBehavior<unknown> | undefined>;\n svgRef: MutableRefObject<SVGSVGElement | SVGGElement | undefined>;\n extent?: [[number, number], [number, number]];\n scaleX: d3ScaleLinear<number, number>;\n scaleY: d3ScaleLinear<number, number>;\n isBrushable?: boolean;\n isGridded?: boolean;\n onBrush?: (\n selection: [[number, number], [number, number]] | null,\n scaleX: d3ScaleLinear<number, number>,\n scaleY: d3ScaleLinear<number, number>\n ) => void;\n onBrushEnd?: (\n selection: [[number, number], [number, number]] | null,\n scaleX: d3ScaleLinear<number, number>,\n scaleY: d3ScaleLinear<number, number>\n ) => void;\n}\n\nconst getRoundedIntermediaryPoint = (\n selection: [[number, number], [number, number]],\n scaleX: d3ScaleLinear<number, number>,\n scaleY: d3ScaleLinear<number, number>\n) => {\n if (!selection) {\n return null;\n }\n\n const xTicks = scaleX.ticks(20);\n const xDelta = xTicks[1] - xTicks[0];\n const yTicks = scaleY.ticks(20);\n const yDelta = yTicks[1] - yTicks[0];\n\n return [\n [\n scaleX(\n Math.round(scaleX.invert(selection[0][0]) / xDelta) * xDelta -\n xDelta / 2\n ),\n scaleY(\n Math.round(scaleY.invert(selection[0][1]) / yDelta) * yDelta -\n yDelta / 2\n ),\n ],\n [\n scaleX(\n Math.round(scaleX.invert(selection[1][0]) / xDelta) * xDelta -\n xDelta / 2\n ),\n\n scaleY(\n Math.round(scaleY.invert(selection[1][1]) / yDelta) * yDelta -\n yDelta / 2\n ),\n ],\n ] as [[number, number], [number, number]];\n};\n\nexport const useBrush = ({\n brushRef: propsBrushRef,\n svgRef,\n extent,\n scaleX,\n scaleY,\n isBrushable,\n isGridded,\n onBrush,\n onBrushEnd,\n}: UseBrushProps) => {\n const brushRef = propsBrushRef || useRef<d3BrushBehavior<unknown>>();\n\n useEffect(() => {\n if (svgRef.current && isBrushable) {\n brushRef.current = d3brush()\n .extent(extent!)\n .keyModifiers(false)\n .filter((event) => event.shiftKey)\n .on('brush', (event) => {\n if (!event.sourceEvent || !brushRef.current || !svgRef.current)\n return;\n\n if (isGridded) {\n const selection = getRoundedIntermediaryPoint(\n event.selection,\n scaleX,\n scaleY\n );\n d3select(svgRef.current).call(\n brushRef.current.move as any,\n selection\n );\n onBrush?.(selection, scaleX, scaleY);\n } else {\n onBrush?.(event.selection, scaleX, scaleY);\n }\n })\n .on('end', (event) => {\n if (!event.sourceEvent || !brushRef.current || !svgRef.current)\n return;\n\n onBrushEnd?.(event.selection, scaleX, scaleY);\n });\n d3select(svgRef.current).call(brushRef.current as any);\n }\n });\n};\n"],"names":["getRoundedIntermediaryPoint","selection","scaleX","scaleY","xTicks","ticks","xDelta","yTicks","yDelta","Math","round","invert","useBrush","_ref","brushRef","propsBrushRef","svgRef","extent","isBrushable","isGridded","onBrush","onBrushEnd","useRef","useEffect","current","d3brush","keyModifiers","filter","event","shiftKey","on","sourceEvent","d3select","call","move"],"mappings":";;;AA4BA,MAAMA,2BAA2B,GAAGA,CAClCC,SAA+C,EAC/CC,MAAqC,EACrCC,MAAqC,KAClC;EACH,IAAI,CAACF,SAAS,EAAE;AACd,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AAEA,EAAA,MAAMG,MAAM,GAAGF,MAAM,CAACG,KAAK,CAAC,EAAE,CAAC,CAAA;EAC/B,MAAMC,MAAM,GAAGF,MAAM,CAAC,CAAC,CAAC,GAAGA,MAAM,CAAC,CAAC,CA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AAAA,UAAU,KAAVA,IAAAA,IAAAA,UAAU,KAAVA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAU,CAAGO,KAAK,CAAC3B,SAAS,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAA;AAC/C,OAAC,CAAC,CAAA;MACJ6B,MAAQ,CAAChB,MAAM,CAACQ,OAAO,CAAC,CAACS,IAAI,CAACnB,QAAQ,CAACU,OAAc,CAAC,CAAA;AACxD,KAAA;AACF,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ScaleOrdinal } from 'd3';
|
|
2
|
+
import { Theme } from '@redsift/design-system';
|
|
3
|
+
import { JSONArray, JSONObject } from '../types/data.js';
|
|
4
|
+
import { ChartTheme } from '../types/theme.js';
|
|
5
|
+
|
|
6
|
+
interface UseColorProps {
|
|
7
|
+
/** Dataset to use to generate the chart. */
|
|
8
|
+
data: JSONArray;
|
|
9
|
+
/** Color palette to use. */
|
|
10
|
+
colorTheme: ChartTheme;
|
|
11
|
+
/** Name of the field that will be used to categorize the data. */
|
|
12
|
+
category: string | ((d: JSONObject) => string);
|
|
13
|
+
/** Theme */
|
|
14
|
+
theme: Theme;
|
|
15
|
+
}
|
|
16
|
+
declare const useColor: ({ data, colorTheme, category, theme }: UseColorProps) => ScaleOrdinal<string, string, never>;
|
|
17
|
+
|
|
18
|
+
export { UseColorProps, useColor };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getColorScale } from '../scheme.js';
|
|
3
|
+
|
|
4
|
+
const useColor = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
data,
|
|
7
|
+
colorTheme,
|
|
8
|
+
category,
|
|
9
|
+
theme
|
|
10
|
+
} = _ref;
|
|
11
|
+
const colorScale = useMemo(() => getColorScale({
|
|
12
|
+
colorTheme,
|
|
13
|
+
domain: data.map(d => typeof category === 'string' ? d[category] : category(d)),
|
|
14
|
+
theme
|
|
15
|
+
}), [colorTheme]);
|
|
16
|
+
return colorScale;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { useColor };
|
|
20
|
+
//# sourceMappingURL=useColor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useColor.js","sources":["../../src/hooks/useColor.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { ScaleOrdinal as d3ScaleOrdinal } from 'd3';\nimport { getColorScale } from '../scheme';\nimport { ChartTheme, JSONArray, JSONObject } from '../types';\nimport { Theme } from '@redsift/design-system';\n\nexport interface UseColorProps {\n /** Dataset to use to generate the chart. */\n data: JSONArray;\n /** Color palette to use. */\n colorTheme: ChartTheme;\n /** Name of the field that will be used to categorize the data. */\n category: string | ((d: JSONObject) => string);\n /** Theme */\n theme: Theme;\n}\n\nexport const useColor = ({ data, colorTheme, category, theme }: UseColorProps) => {\n const colorScale = useMemo<d3ScaleOrdinal<string, string>>(\n () =>\n getColorScale({\n colorTheme,\n domain: data.map((d) => (typeof category === 'string' ? (d[category] as string) : category(d))),\n theme,\n }),\n [colorTheme]\n );\n\n return colorScale;\n};\n"],"names":["useColor","_ref","data","colorTheme","category","theme","colorScale","useMemo","getColorScale","domain","map","d"],"mappings":";;;AAiBaA,MAAAA,QAAQ,GAAGC,IAAA,IAA0D;EAAA,IAAzD;IAAEC,IAAI;IAAEC,UAAU;IAAEC,QAAQ;AAAEC,IAAAA,KAAAA;AAAqB,GAAC,GAAAJ,IAAA,CAAA;AAC3E,EAAA,MAAMK,UAAU,GAAGC,OAAO,CACxB,MACEC,aAAa,CAAC;IACZL,UAAU;IACVM,MAAM,EAAEP,IAAI,CAACQ,GAAG,CAAEC,CAAC,IAAM,OAAOP,QAAQ,KAAK,QAAQ,GAAIO,CAAC,CAACP,QAAQ,CAAC,GAAcA,QAAQ,CAACO,CAAC,CAAE,CAAC;AAC/FN,IAAAA,KAAAA;AACF,GAAC,CAAC,EACJ,CAACF,UAAU,CACb,CAAC,CAAA;AAED,EAAA,OAAOG,UAAU,CAAA;AACnB;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as d3_scale from 'd3-scale';
|
|
2
|
+
import { SortingMethod } from '../utils/index.js';
|
|
3
|
+
import { Theme } from '@redsift/design-system';
|
|
4
|
+
import { CategoryData } from '../types/data.js';
|
|
5
|
+
import { ChartTheme } from '../types/theme.js';
|
|
6
|
+
|
|
7
|
+
interface UseFormatCategoricalDataProps {
|
|
8
|
+
/** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */
|
|
9
|
+
data: CategoryData;
|
|
10
|
+
/** Color palette to use. */
|
|
11
|
+
colorTheme: ChartTheme;
|
|
12
|
+
/** Define how to sort categories. */
|
|
13
|
+
sortingMethod: SortingMethod;
|
|
14
|
+
/** Number of categories to use, the rest being put into a new category called "Others". */
|
|
15
|
+
caping?: number;
|
|
16
|
+
/** 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. */
|
|
17
|
+
others?: boolean | string;
|
|
18
|
+
/** Theme */
|
|
19
|
+
theme: Theme;
|
|
20
|
+
}
|
|
21
|
+
declare const useFormatCategoricalData: ({ data, caping, sortingMethod, others, colorTheme, theme, }: UseFormatCategoricalDataProps) => {
|
|
22
|
+
data: CategoryData;
|
|
23
|
+
colorScale: d3_scale.ScaleOrdinal<string, string, never>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { UseFormatCategoricalDataProps, useFormatCategoricalData };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useColor } from './useColor.js';
|
|
4
|
+
import { getSortingMethod } from '../utils/index.js';
|
|
5
|
+
|
|
6
|
+
const useFormatCategoricalData = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
data,
|
|
9
|
+
caping,
|
|
10
|
+
sortingMethod,
|
|
11
|
+
others,
|
|
12
|
+
colorTheme,
|
|
13
|
+
theme
|
|
14
|
+
} = _ref;
|
|
15
|
+
const computedData = useMemo(() => {
|
|
16
|
+
let computedData;
|
|
17
|
+
if (data === undefined || data === null) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
computedData = [...data].sort(getSortingMethod(sortingMethod));
|
|
21
|
+
if (caping) {
|
|
22
|
+
if (typeof others === 'boolean' && !others) {
|
|
23
|
+
computedData = computedData.slice(0, caping);
|
|
24
|
+
} else {
|
|
25
|
+
computedData = computedData.reduce((acc, curr, index) => {
|
|
26
|
+
if (index < caping) {
|
|
27
|
+
acc[index] = curr;
|
|
28
|
+
} else if (index === caping) {
|
|
29
|
+
acc[index] = {
|
|
30
|
+
key: typeof others === 'string' ? others : 'Others',
|
|
31
|
+
value: curr.value
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
acc[caping] = _objectSpread2(_objectSpread2({}, acc[caping]), {}, {
|
|
35
|
+
value: acc[caping].value + curr.value
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return acc;
|
|
39
|
+
}, []);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return computedData;
|
|
43
|
+
}, [data, caping]);
|
|
44
|
+
const colorScale = useColor({
|
|
45
|
+
data: computedData,
|
|
46
|
+
colorTheme,
|
|
47
|
+
category: 'key',
|
|
48
|
+
theme
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
data: computedData,
|
|
52
|
+
colorScale
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { useFormatCategoricalData };
|
|
57
|
+
//# sourceMappingURL=useFormatCategoricalData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormatCategoricalData.js","sources":["../../src/hooks/useFormatCategoricalData.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { CategoryData, ChartTheme } from '../types';\nimport { useColor } from './useColor';\nimport { SortingMethod, getSortingMethod } from '../utils';\nimport { Theme } from '@redsift/design-system';\n\nexport interface UseFormatCategoricalDataProps {\n /** Dataset to use to generate the chart, should be a list of objects containing a key and a value. */\n data: CategoryData;\n /** Color palette to use. */\n colorTheme: ChartTheme;\n /** Define how to sort categories. */\n sortingMethod: SortingMethod;\n /** Number of categories to use, the rest being put into a new category called \"Others\". */\n caping?: number;\n /** 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. */\n others?: boolean | string;\n /** Theme */\n theme: Theme;\n}\n\nexport const useFormatCategoricalData = ({\n data,\n caping,\n sortingMethod,\n others,\n colorTheme,\n theme,\n}: UseFormatCategoricalDataProps) => {\n const computedData = useMemo(() => {\n let computedData;\n\n if (data === undefined || data === null) {\n return undefined;\n }\n\n computedData = [...data!].sort(getSortingMethod(sortingMethod));\n\n if (caping) {\n if (typeof others === 'boolean' && !others) {\n computedData = computedData.slice(0, caping);\n } else {\n computedData = computedData.reduce<CategoryData>((acc, curr, index) => {\n if (index < caping) {\n acc[index] = curr;\n } else if (index === caping) {\n acc[index] = {\n key: typeof others === 'string' ? others : 'Others',\n value: curr.value,\n };\n } else {\n acc[caping] = {\n ...acc[caping],\n value: acc[caping].value + curr.value,\n };\n }\n return acc;\n }, []);\n }\n }\n\n return computedData;\n }, [data, caping]);\n\n const colorScale = useColor({ data: computedData!, colorTheme, category: 'key', theme });\n\n return { data: computedData as CategoryData, colorScale };\n};\n"],"names":["useFormatCategoricalData","_ref","data","caping","sortingMethod","others","colorTheme","theme","computedData","useMemo","undefined","sort","getSortingMethod","slice","reduce","acc","curr","index","key","value","_objectSpread","colorScale","useColor","category"],"mappings":";;;;;AAqBaA,MAAAA,wBAAwB,GAAGC,IAAA,IAOH;EAAA,IAPI;IACvCC,IAAI;IACJC,MAAM;IACNC,aAAa;IACbC,MAAM;IACNC,UAAU;AACVC,IAAAA,KAAAA;AAC6B,GAAC,GAAAN,IAAA,CAAA;AAC9B,EAAA,MAA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A,OAAOP,YAAY,CAAA;AACrB,GAAC,EAAE,CAACN,IAAI,EAAEC,MAAM,CAAC,CAAC,CAAA;EAElB,MAAMkB,UAAU,GAAGC,QAAQ,CAAC;AAAEpB,IAAAA,IAAI,EAAEM,YAAa;IAAEF,UAAU;AAAEiB,IAAAA,QAAQ,EAAE,KAAK;AAAEhB,IAAAA,KAAAA;AAAM,GAAC,CAAC,CAAA;EAExF,OAAO;AAAEL,IAAAA,IAAI,EAAEM,YAA4B;AAAEa,IAAAA,UAAAA;GAAY,CAAA;AAC3D;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { ScaleLinear } from 'd3';
|
|
3
|
+
|
|
4
|
+
interface UseZoomProps {
|
|
5
|
+
svgRef: MutableRefObject<SVGSVGElement | undefined>;
|
|
6
|
+
scaleX: ScaleLinear<number, number>;
|
|
7
|
+
scaleY: ScaleLinear<number, number>;
|
|
8
|
+
defaultTransform?: {
|
|
9
|
+
k: number;
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
size?: any;
|
|
14
|
+
onZoom?: () => void;
|
|
15
|
+
}
|
|
16
|
+
declare const useZoom: ({ svgRef, scaleX, scaleY, defaultTransform, size, onZoom, }: UseZoomProps) => {
|
|
17
|
+
transform: {
|
|
18
|
+
k: number;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
};
|
|
22
|
+
scaleX: ScaleLinear<number, number, never>;
|
|
23
|
+
scaleY: ScaleLinear<number, number, never>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { UseZoomProps, useZoom };
|
package/hooks/useZoom.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import { zoom, interpolateRound, select } from 'd3';
|
|
3
|
+
|
|
4
|
+
const useZoom = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
svgRef,
|
|
7
|
+
scaleX,
|
|
8
|
+
scaleY,
|
|
9
|
+
defaultTransform = {
|
|
10
|
+
k: 1,
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0
|
|
13
|
+
},
|
|
14
|
+
size,
|
|
15
|
+
onZoom
|
|
16
|
+
} = _ref;
|
|
17
|
+
const zx = useRef(scaleX);
|
|
18
|
+
const zy = useRef(scaleY);
|
|
19
|
+
const [transform, setTransform] = useState(defaultTransform);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (svgRef.current) {
|
|
22
|
+
const zoom$1 = zoom().filter(event => !event.shiftKey).scaleExtent([1 / 2 ** 3, 2 ** 3]).on('zoom', event => {
|
|
23
|
+
onZoom === null || onZoom === void 0 ? void 0 : onZoom();
|
|
24
|
+
zx.current = event.transform.rescaleX(scaleX).interpolate(interpolateRound);
|
|
25
|
+
zy.current = event.transform.rescaleY(scaleY).interpolate(interpolateRound);
|
|
26
|
+
setTransform(event.transform);
|
|
27
|
+
});
|
|
28
|
+
select(svgRef.current).call(zoom$1);
|
|
29
|
+
}
|
|
30
|
+
}, [svgRef.current, size]);
|
|
31
|
+
return {
|
|
32
|
+
transform,
|
|
33
|
+
scaleX: zx.current,
|
|
34
|
+
scaleY: zy.current
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { useZoom };
|
|
39
|
+
//# sourceMappingURL=useZoom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useZoom.js","sources":["../../src/hooks/useZoom.tsx"],"sourcesContent":["import { MutableRefObject, useEffect, useRef, useState } from 'react';\nimport {\n zoom as d3zoom,\n interpolateRound as d3interpolateRound,\n ScaleLinear as d3ScaleLinear,\n select as d3select,\n} from 'd3';\n\nexport interface UseZoomProps {\n svgRef: MutableRefObject<SVGSVGElement | undefined>;\n scaleX: d3ScaleLinear<number, number>;\n scaleY: d3ScaleLinear<number, number>;\n defaultTransform?: { k: number; x: number; y: number };\n size?: any;\n onZoom?: () => void;\n}\n\nexport const useZoom = ({\n svgRef,\n scaleX,\n scaleY,\n defaultTransform = { k: 1, x: 0, y: 0 },\n size,\n onZoom,\n}: UseZoomProps) => {\n const zx = useRef<d3ScaleLinear<number, number>>(scaleX);\n const zy = useRef<d3ScaleLinear<number, number>>(scaleY);\n const [transform, setTransform] = useState(defaultTransform);\n\n useEffect(() => {\n if (svgRef.current) {\n const zoom = d3zoom()\n .filter((event) => !event.shiftKey)\n .scaleExtent([1 / 2 ** 3, 2 ** 3])\n .on('zoom', (event) => {\n onZoom?.();\n zx.current = event.transform\n .rescaleX(scaleX)\n .interpolate(d3interpolateRound);\n zy.current = event.transform\n .rescaleY(scaleY)\n .interpolate(d3interpolateRound);\n setTransform(event.transform);\n });\n d3select(svgRef.current).call(zoom as any);\n }\n }, [svgRef.current, size]);\n\n return { transform, scaleX: zx.current, scaleY: zy.current };\n};\n"],"names":["useZoom","_ref","svgRef","scaleX","scaleY","defaultTransform","k","x","y","size","onZoom","zx","useRef","zy","transform","setTransform","useState","useEffect","current","zoom","d3zoom","filter","event","shiftKey","scaleExtent","on","rescaleX","interpolate","d3interpolateRound","rescaleY","d3select","call"],"mappings":";;;AAiBaA,MAAAA,OAAO,GAAGC,IAAA,IAOH;EAAA,IAPI;IACtBC,MAAM;IACNC,MAAM;IACNC,MAAM;AACNC,IAAAA,gBAAgB,GAAG;AAAEC,MAAAA,CAAC,EAAE,CAAC;AAAEC,MAAAA,CAAC,EAAE,CAAC;AAAEC,MAAAA,CAAC,EAAE,CAAA;KAAG;IACvCC,IAAI;AACJC,IAAAA,MAAAA;AACY,GAAC,GAAAT,IAAA,CAAA;AACb,EAAA,MAAMU,EAAE,GAAGC,MAAM,CAAgCT,MAAM,CAAC,CAAA;AACxD,EAAA,MAAMU,EAAE,GAAGD,MAAM,CAAgCR,MAAM,CAAC,CAAA;EACxD,MAAM,CAACU,SAAS,EAAEC,YAAY,CAAC,GAAGC,QAAQ,CAACX,gBAAgB,CAAC,CAAA;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