@redsift/charts 8.1.0 → 9.0.0-alpha.0
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/index.d.ts +2 -0
- package/index.js +37 -31
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -583,6 +583,8 @@ interface PieChartProps extends ChartContainerProps {
|
|
|
583
583
|
labelDecorator?: (datum: ArcDatum) => string;
|
|
584
584
|
/** Define whether the labels should be displayed inside or outside the charts and if they should contain raw or percentage values. */
|
|
585
585
|
labelVariant?: PieChartLabelVariant;
|
|
586
|
+
/** Props to forward to the Legend block. Can be used to make the legend selectable. */
|
|
587
|
+
legendProps?: Omit<LegendProps, 'data' | 'ref' | 'variant' | 'width'>;
|
|
586
588
|
/** Labels and texts. */
|
|
587
589
|
localeText?: LocaleText$1;
|
|
588
590
|
/** Method to be called on a click on a slice. */
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, arc, pie, min, extent, descending, scaleSqrt, max } from 'd3';
|
|
2
|
-
import {
|
|
2
|
+
import { RedsiftColorPresentationBlueDefault, RedsiftColorPresentationGreyDark, RedsiftColorPresentationGreenDefault, RedsiftColorPresentationPinkDefault, RedsiftColorPresentationAquaDefault, RedsiftColorPresentationBrownDefault, RedsiftColorPresentationRedDefault, RedsiftColorPresentationYellowDefault, RedsiftColorPresentationPurpleDefault, RedsiftColorPresentationOrangeDefault, RedsiftColorPresentationGreyDefault, RedsiftColorPresentationGreenDark, RedsiftColorPresentationPinkDark, RedsiftColorPresentationAquaDark, RedsiftColorPresentationBrownDark, RedsiftColorPresentationRedDark, RedsiftColorPresentationYellowDark, RedsiftColorPresentationPurpleDark, RedsiftColorPresentationOrangeDark, RedsiftColorPresentationBlueDark, RedsiftColorPresentationGreenDarker, RedsiftColorPresentationPinkDarker, RedsiftColorPresentationAquaDarker, RedsiftColorPresentationBrownDarker, RedsiftColorPresentationRedDarker, RedsiftColorPresentationYellowDarker, RedsiftColorPresentationPurpleDarker, RedsiftColorPresentationOrangeDarker, RedsiftColorPresentationBlueDarker, RedsiftColorPresentationGreyDarker, RedsiftColorPresentationGreenDarkerer, RedsiftColorPresentationPinkDarkerer, RedsiftColorPresentationAquaDarkerer, RedsiftColorPresentationBrownDarkerer, RedsiftColorPresentationRedDarkerer, RedsiftColorPresentationYellowDarkerer, RedsiftColorPresentationPurpleDarkerer, RedsiftColorPresentationOrangeDarkerer, RedsiftColorPresentationBlueDarkerer, RedsiftColorPresentationGreyDarkerer, RedsiftColorPresentationGreenLight, RedsiftColorPresentationPinkLight, RedsiftColorPresentationAquaLight, RedsiftColorPresentationBrownLight, RedsiftColorPresentationRedLight, RedsiftColorPresentationYellowLight, RedsiftColorPresentationPurpleLight, RedsiftColorPresentationOrangeLight, RedsiftColorPresentationBlueLight, RedsiftColorPresentationGreyLight, RedsiftColorPresentationGreenLighter, RedsiftColorPresentationPinkLighter, RedsiftColorPresentationAquaLighter, RedsiftColorPresentationBrownLighter, RedsiftColorPresentationRedLighter, RedsiftColorPresentationYellowLighter, RedsiftColorPresentationPurpleLighter, RedsiftColorPresentationOrangeLighter, RedsiftColorPresentationBlueLighter, RedsiftColorPresentationGreyLighter, RedsiftColorPresentationGreenLighterer, RedsiftColorPresentationPinkLighterer, RedsiftColorPresentationAquaLighterer, RedsiftColorPresentationBrownLighterer, RedsiftColorPresentationRedLighterer, RedsiftColorPresentationYellowLighterer, RedsiftColorPresentationPurpleLighterer, RedsiftColorPresentationOrangeLighterer, RedsiftColorPresentationBlueLighterer, RedsiftColorPresentationGreyLighterer, Text, Number as Number$1, baseStyling, focusRing, Flexbox, warnIfNoAccessibleLabelFound, Heading, Button } from '@redsift/design-system';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import React__default, { useRef, useEffect, useMemo, useState, useLayoutEffect, forwardRef, useCallback, useContext, useId } from 'react';
|
|
5
5
|
import classNames from 'classnames';
|
|
@@ -51,24 +51,24 @@ const useBrush = _ref => {
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const monochrome =
|
|
55
|
-
const empty =
|
|
54
|
+
const monochrome = RedsiftColorPresentationBlueDefault;
|
|
55
|
+
const empty = RedsiftColorPresentationGreyDark;
|
|
56
56
|
const scheme = {
|
|
57
|
-
default: [
|
|
58
|
-
dark: [
|
|
59
|
-
darker: [
|
|
60
|
-
darkerer: [
|
|
61
|
-
light: [
|
|
62
|
-
lighter: [
|
|
63
|
-
lighterer: [
|
|
57
|
+
default: [RedsiftColorPresentationGreenDefault, RedsiftColorPresentationPinkDefault, RedsiftColorPresentationAquaDefault, RedsiftColorPresentationBrownDefault, RedsiftColorPresentationRedDefault, RedsiftColorPresentationYellowDefault, RedsiftColorPresentationPurpleDefault, RedsiftColorPresentationOrangeDefault, RedsiftColorPresentationBlueDefault, RedsiftColorPresentationGreyDefault],
|
|
58
|
+
dark: [RedsiftColorPresentationGreenDark, RedsiftColorPresentationPinkDark, RedsiftColorPresentationAquaDark, RedsiftColorPresentationBrownDark, RedsiftColorPresentationRedDark, RedsiftColorPresentationYellowDark, RedsiftColorPresentationPurpleDark, RedsiftColorPresentationOrangeDark, RedsiftColorPresentationBlueDark, RedsiftColorPresentationGreyDark],
|
|
59
|
+
darker: [RedsiftColorPresentationGreenDarker, RedsiftColorPresentationPinkDarker, RedsiftColorPresentationAquaDarker, RedsiftColorPresentationBrownDarker, RedsiftColorPresentationRedDarker, RedsiftColorPresentationYellowDarker, RedsiftColorPresentationPurpleDarker, RedsiftColorPresentationOrangeDarker, RedsiftColorPresentationBlueDarker, RedsiftColorPresentationGreyDarker],
|
|
60
|
+
darkerer: [RedsiftColorPresentationGreenDarkerer, RedsiftColorPresentationPinkDarkerer, RedsiftColorPresentationAquaDarkerer, RedsiftColorPresentationBrownDarkerer, RedsiftColorPresentationRedDarkerer, RedsiftColorPresentationYellowDarkerer, RedsiftColorPresentationPurpleDarkerer, RedsiftColorPresentationOrangeDarkerer, RedsiftColorPresentationBlueDarkerer, RedsiftColorPresentationGreyDarkerer],
|
|
61
|
+
light: [RedsiftColorPresentationGreenLight, RedsiftColorPresentationPinkLight, RedsiftColorPresentationAquaLight, RedsiftColorPresentationBrownLight, RedsiftColorPresentationRedLight, RedsiftColorPresentationYellowLight, RedsiftColorPresentationPurpleLight, RedsiftColorPresentationOrangeLight, RedsiftColorPresentationBlueLight, RedsiftColorPresentationGreyLight],
|
|
62
|
+
lighter: [RedsiftColorPresentationGreenLighter, RedsiftColorPresentationPinkLighter, RedsiftColorPresentationAquaLighter, RedsiftColorPresentationBrownLighter, RedsiftColorPresentationRedLighter, RedsiftColorPresentationYellowLighter, RedsiftColorPresentationPurpleLighter, RedsiftColorPresentationOrangeLighter, RedsiftColorPresentationBlueLighter, RedsiftColorPresentationGreyLighter],
|
|
63
|
+
lighterer: [RedsiftColorPresentationGreenLighterer, RedsiftColorPresentationPinkLighterer, RedsiftColorPresentationAquaLighterer, RedsiftColorPresentationBrownLighterer, RedsiftColorPresentationRedLighterer, RedsiftColorPresentationYellowLighterer, RedsiftColorPresentationPurpleLighterer, RedsiftColorPresentationOrangeLighterer, RedsiftColorPresentationBlueLighterer, RedsiftColorPresentationGreyLighterer],
|
|
64
64
|
monochrome: [monochrome],
|
|
65
65
|
empty: [empty]
|
|
66
66
|
};
|
|
67
67
|
const successDangerScheme = {
|
|
68
|
-
success:
|
|
69
|
-
warning:
|
|
70
|
-
danger:
|
|
71
|
-
neutral:
|
|
68
|
+
success: RedsiftColorPresentationGreenDefault,
|
|
69
|
+
warning: RedsiftColorPresentationOrangeDefault,
|
|
70
|
+
danger: RedsiftColorPresentationRedDefault,
|
|
71
|
+
neutral: RedsiftColorPresentationGreyDefault
|
|
72
72
|
};
|
|
73
73
|
const getColorScale = (theme, domain, isEmpty) => {
|
|
74
74
|
let d3colors = scaleOrdinal(scheme.default);
|
|
@@ -609,7 +609,7 @@ const StyledAxis = styled(it.g)`
|
|
|
609
609
|
}
|
|
610
610
|
|
|
611
611
|
text {
|
|
612
|
-
font-family: var(--redsift-typography-font-family-
|
|
612
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
613
613
|
font-size: 10px;
|
|
614
614
|
user-select: none;
|
|
615
615
|
}
|
|
@@ -1055,7 +1055,7 @@ const StyledChartContainer = styled.div`
|
|
|
1055
1055
|
display: flex;
|
|
1056
1056
|
align-items: center;
|
|
1057
1057
|
gap: 16px;
|
|
1058
|
-
font-family: var(--redsift-typography-font-family-
|
|
1058
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1059
1059
|
font-size: 11px;
|
|
1060
1060
|
justify-content: center;
|
|
1061
1061
|
margin: 8px 0;
|
|
@@ -1157,7 +1157,7 @@ const StyledBarChartEmptyText = styled.div`
|
|
|
1157
1157
|
}
|
|
1158
1158
|
|
|
1159
1159
|
> span {
|
|
1160
|
-
font-family: var(--redsift-typography-font-family-
|
|
1160
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1161
1161
|
color: var(--redsift-color-neutral-black);
|
|
1162
1162
|
font-size: ${_ref2 => {
|
|
1163
1163
|
let {
|
|
@@ -1301,7 +1301,7 @@ const RenderedBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1301
1301
|
};
|
|
1302
1302
|
const chartHeight = height - margins.top - margins.bottom;
|
|
1303
1303
|
const chartWidth = width - margins.left - margins.right;
|
|
1304
|
-
const numberOfRows = data.length;
|
|
1304
|
+
const numberOfRows = data.filter(datum => datum.value).length;
|
|
1305
1305
|
const gap = 5;
|
|
1306
1306
|
const scale = useMemo(() => scaleLinear().domain([0, Math.max(...data.map(_ref => {
|
|
1307
1307
|
let {
|
|
@@ -1748,7 +1748,7 @@ const StyledPieChartCenterText = styled.div`
|
|
|
1748
1748
|
}
|
|
1749
1749
|
|
|
1750
1750
|
> b {
|
|
1751
|
-
font-family: var(--redsift-typography-font-family-
|
|
1751
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1752
1752
|
color: var(--redsift-color-neutral-black);
|
|
1753
1753
|
font-weight: var(--redsift-typography-font-weight-medium);
|
|
1754
1754
|
font-size: ${_ref2 => {
|
|
@@ -1767,7 +1767,7 @@ const StyledPieChartCenterText = styled.div`
|
|
|
1767
1767
|
&:nth-child(2) {
|
|
1768
1768
|
font-weight: normal;
|
|
1769
1769
|
margin-top: 8px;
|
|
1770
|
-
font-family: var(--redsift-typography-font-family-
|
|
1770
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1771
1771
|
font-size: ${_ref4 => {
|
|
1772
1772
|
let {
|
|
1773
1773
|
$smallTextSize
|
|
@@ -1814,7 +1814,7 @@ const StyledPieChartCenterText = styled.div`
|
|
|
1814
1814
|
}
|
|
1815
1815
|
> b + span {
|
|
1816
1816
|
font-size: var(--redsift-typography-body-font-size);
|
|
1817
|
-
font-family: var(--redsift-typography-font-family-
|
|
1817
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1818
1818
|
line-height: var(--redsift-typography-badge-line-height);
|
|
1819
1819
|
color: rgba(0, 0, 0, 0.6);
|
|
1820
1820
|
text-align: center;
|
|
@@ -1842,7 +1842,7 @@ const StyledPieChartEmptyText = styled.div`
|
|
|
1842
1842
|
}
|
|
1843
1843
|
|
|
1844
1844
|
> span {
|
|
1845
|
-
font-family: var(--redsift-typography-font-family-
|
|
1845
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
1846
1846
|
color: ${_ref11 => {
|
|
1847
1847
|
let {
|
|
1848
1848
|
$isDonut
|
|
@@ -1969,7 +1969,7 @@ const EmptyPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1969
1969
|
}))));
|
|
1970
1970
|
});
|
|
1971
1971
|
|
|
1972
|
-
const _excluded$5 = ["caping", "className", "data", "id", "isSliceSelected", "labelDecorator", "labelVariant", "middleText", "onSliceClick", "others", "size", "sliceProps", "sliceRole", "subtext", "text", "theme", "tooltipVariant", "variant"];
|
|
1972
|
+
const _excluded$5 = ["caping", "className", "data", "id", "isSliceSelected", "labelDecorator", "labelVariant", "legendProps", "middleText", "onSliceClick", "others", "size", "sliceProps", "sliceRole", "subtext", "text", "theme", "tooltipVariant", "variant"];
|
|
1973
1973
|
const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1974
1974
|
const {
|
|
1975
1975
|
caping,
|
|
@@ -1979,6 +1979,7 @@ const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1979
1979
|
isSliceSelected,
|
|
1980
1980
|
labelDecorator,
|
|
1981
1981
|
labelVariant,
|
|
1982
|
+
legendProps,
|
|
1982
1983
|
middleText: propsMiddleText,
|
|
1983
1984
|
onSliceClick,
|
|
1984
1985
|
others,
|
|
@@ -2019,6 +2020,10 @@ const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2019
2020
|
const pieData = createPie(data);
|
|
2020
2021
|
const previousPieData = cache.current ? createPie(cache.current) : undefined;
|
|
2021
2022
|
const total = sum(data, d => d.value);
|
|
2023
|
+
const legendWidth = useRef();
|
|
2024
|
+
if (data && !legendWidth.current) {
|
|
2025
|
+
legendWidth.current = `${Math.max(...data.map(d => d.key.length + String(d.value).length)) * 8 + 32}px`;
|
|
2026
|
+
}
|
|
2022
2027
|
const text = typeof propsText === 'function' ? propsText(pieData.map(datum => {
|
|
2023
2028
|
const percent = datum.data.value / total;
|
|
2024
2029
|
return _objectSpread2(_objectSpread2({}, datum), {}, {
|
|
@@ -2094,12 +2099,13 @@ const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2094
2099
|
sliceProps: sliceProps,
|
|
2095
2100
|
tooltipVariant: tooltipVariant,
|
|
2096
2101
|
transform: `translate(${width / 2} ${height / 2})`
|
|
2097
|
-
}))), labelVariant !== PieChartLabelVariant.none && labelVariant !== PieChartLabelVariant.internal ? /*#__PURE__*/React__default.createElement(Legend, {
|
|
2102
|
+
}))), labelVariant !== PieChartLabelVariant.none && labelVariant !== PieChartLabelVariant.internal ? /*#__PURE__*/React__default.createElement(Legend, _extends({
|
|
2098
2103
|
data: data.map(d => _objectSpread2(_objectSpread2({}, d), {}, {
|
|
2099
2104
|
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
|
|
2100
2105
|
})),
|
|
2101
|
-
variant: labelVariant === PieChartLabelVariant.externalLabelValue ? LabelVariant.value : labelVariant === PieChartLabelVariant.externalLabelPercent ? LabelVariant.percent : LabelVariant.label
|
|
2102
|
-
|
|
2106
|
+
variant: labelVariant === PieChartLabelVariant.externalLabelValue ? LabelVariant.value : labelVariant === PieChartLabelVariant.externalLabelPercent ? LabelVariant.percent : LabelVariant.label,
|
|
2107
|
+
width: legendWidth.current
|
|
2108
|
+
}, legendProps)) : null);
|
|
2103
2109
|
});
|
|
2104
2110
|
|
|
2105
2111
|
const _excluded$4 = ["caping", "chartRef", "className", "data", "emptyComponent", "id", "isSliceSelected", "labelDecorator", "labelVariant", "localeText", "middleText", "onSliceClick", "others", "size", "sliceRole", "subtext", "text", "theme", "tooltipVariant", "variant"];
|
|
@@ -2235,7 +2241,7 @@ const StyledScatterPlotEmptyText = styled.div`
|
|
|
2235
2241
|
}
|
|
2236
2242
|
|
|
2237
2243
|
> span {
|
|
2238
|
-
font-family: var(--redsift-typography-font-family-
|
|
2244
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
2239
2245
|
color: var(--redsift-color-neutral-black);
|
|
2240
2246
|
font-size: ${_ref2 => {
|
|
2241
2247
|
let {
|
|
@@ -2514,14 +2520,14 @@ const RenderedScatterPlot = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
2514
2520
|
onOpen: setIsKeyPanelOpen
|
|
2515
2521
|
}, /*#__PURE__*/React__default.createElement(Popover.Trigger, null, /*#__PURE__*/React__default.createElement(Button, {
|
|
2516
2522
|
variant: "secondary",
|
|
2523
|
+
leftIcon: mdiMouse,
|
|
2517
2524
|
rightIcon: isKeyPanelOpen ? mdiChevronDown : mdiChevronRight,
|
|
2518
2525
|
color: "question",
|
|
2519
2526
|
style: {
|
|
2520
|
-
border: '1px solid var(--redsift-color-neutral-midgrey)'
|
|
2527
|
+
border: '1px solid var(--redsift-color-neutral-midgrey)',
|
|
2528
|
+
gap: '4px'
|
|
2521
2529
|
}
|
|
2522
|
-
}, /*#__PURE__*/React__default.createElement(
|
|
2523
|
-
icon: mdiMouse
|
|
2524
|
-
}))), /*#__PURE__*/React__default.createElement(Popover.Content, {
|
|
2530
|
+
})), /*#__PURE__*/React__default.createElement(Popover.Content, {
|
|
2525
2531
|
flexDirection: "column",
|
|
2526
2532
|
alignItems: "flex-start"
|
|
2527
2533
|
}, /*#__PURE__*/React__default.createElement(Text, {
|