@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,95 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { forwardRef } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { a as it } from '../../node_modules/@react-spring/web/dist/esm/index.js';
|
|
5
|
+
import { interpolate } from 'd3';
|
|
6
|
+
import { useTheme } from '@redsift/design-system';
|
|
7
|
+
import { BarOrientation, BarDirection } from './types.js';
|
|
8
|
+
import { StyledBar } from './styles.js';
|
|
9
|
+
import { monochrome } from '../../scheme.js';
|
|
10
|
+
import { config } from '../../config.js';
|
|
11
|
+
import { useSpring as J } from '../../node_modules/@react-spring/core/dist/esm/index.js';
|
|
12
|
+
|
|
13
|
+
const _excluded = ["className", "disableAnimations", "gap", "height", "maxHeight", "orientation", "direction", "previousData", "scale", "scalePosition", "width", "minWidth"];
|
|
14
|
+
const COMPONENT_NAME = 'Bar';
|
|
15
|
+
const CLASSNAME = 'redsift-bar';
|
|
16
|
+
const Bar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
color = monochrome,
|
|
19
|
+
data,
|
|
20
|
+
index = 0,
|
|
21
|
+
isSelected: propsIsSelected,
|
|
22
|
+
labelDecorator,
|
|
23
|
+
onClick,
|
|
24
|
+
role
|
|
25
|
+
} = props;
|
|
26
|
+
const {
|
|
27
|
+
className,
|
|
28
|
+
disableAnimations,
|
|
29
|
+
gap = 5,
|
|
30
|
+
height = 40,
|
|
31
|
+
maxHeight = 100,
|
|
32
|
+
orientation = BarOrientation.horizontal,
|
|
33
|
+
direction = BarDirection.up,
|
|
34
|
+
previousData = {
|
|
35
|
+
data: {
|
|
36
|
+
key: '',
|
|
37
|
+
value: 0
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
scale,
|
|
41
|
+
scalePosition,
|
|
42
|
+
width = 40,
|
|
43
|
+
minWidth
|
|
44
|
+
} = props,
|
|
45
|
+
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
46
|
+
const theme = useTheme();
|
|
47
|
+
const getValue = data => (data === null || data === void 0 ? void 0 : data.cumulativeValue) !== undefined ? data.cumulativeValue : data === null || data === void 0 ? void 0 : data.value;
|
|
48
|
+
const interpolator = interpolate(getValue(previousData.data) || 0, getValue(data.data) || 0);
|
|
49
|
+
const text = labelDecorator ? labelDecorator(data, {
|
|
50
|
+
index,
|
|
51
|
+
isSelected: propsIsSelected,
|
|
52
|
+
color
|
|
53
|
+
}) : data.data.key;
|
|
54
|
+
const isSelectable = role === 'option';
|
|
55
|
+
const isDeselected = isSelectable && propsIsSelected === false;
|
|
56
|
+
const isHorizontal = orientation === BarOrientation.horizontal;
|
|
57
|
+
const goesUp = direction === BarDirection.up;
|
|
58
|
+
const isOrdinal = typeof scalePosition.domain()[0] === 'string';
|
|
59
|
+
const animatedProps = J(_objectSpread2(_objectSpread2({}, config), {}, {
|
|
60
|
+
to: async next => {
|
|
61
|
+
await next({
|
|
62
|
+
t: 1
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
from: {
|
|
66
|
+
t: 0
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
const computedWidth = minWidth ? Math.max(minWidth, width) : width;
|
|
70
|
+
return /*#__PURE__*/React__default.createElement(StyledBar, _extends({}, forwardedProps, {
|
|
71
|
+
ref: ref,
|
|
72
|
+
className: classNames(Bar.className, className),
|
|
73
|
+
transform: isHorizontal ? `translate(0, ${scalePosition(data.data.key) + gap / 2})` : `translate(${goesUp ? scalePosition(data.data.key) + (isOrdinal ? computedWidth + gap / 2 : computedWidth / 2) : scalePosition(data.data.key) + (isOrdinal ? -computedWidth + gap / 2 : -computedWidth / 2)}, ${maxHeight})${goesUp ? ', rotate(180)' : ''}`,
|
|
74
|
+
$clickable: Boolean(onClick),
|
|
75
|
+
$theme: theme
|
|
76
|
+
}), isHorizontal ? /*#__PURE__*/React__default.createElement(it.rect, {
|
|
77
|
+
height: height,
|
|
78
|
+
fill: isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color,
|
|
79
|
+
width: config.immediate || disableAnimations ? scale(data.data.value) : animatedProps.t.to(t => scale(interpolator(t)))
|
|
80
|
+
}) : /*#__PURE__*/React__default.createElement(it.rect, {
|
|
81
|
+
height: config.immediate || disableAnimations ? goesUp ? maxHeight - scale(getValue(data.data)) : scale(getValue(data.data)) - maxHeight : animatedProps.t.to(t => Math.max(0, goesUp ? maxHeight - scale(interpolator(t)) : scale(interpolator(t)) - maxHeight)),
|
|
82
|
+
fill: isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color,
|
|
83
|
+
width: computedWidth
|
|
84
|
+
}), isHorizontal ? /*#__PURE__*/React__default.createElement("text", {
|
|
85
|
+
x: "10",
|
|
86
|
+
y: height / 2,
|
|
87
|
+
dy: "0.35em",
|
|
88
|
+
"aria-hidden": true
|
|
89
|
+
}, text) : null);
|
|
90
|
+
});
|
|
91
|
+
Bar.className = CLASSNAME;
|
|
92
|
+
Bar.displayName = COMPONENT_NAME;
|
|
93
|
+
|
|
94
|
+
export { Bar };
|
|
95
|
+
//# sourceMappingURL=Bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bar.js","sources":["../../../src/components/Bar/Bar.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classNames from 'classnames';\nimport { animated, useSpring } from '@react-spring/web';\nimport { interpolate as d3interpolate } from 'd3';\n\nimport { Comp, useTheme } from '@redsift/design-system';\n\nimport { BarDirection, BarOrientation, BarProps } from './types';\nimport { StyledBar } from './styles';\nimport { monochrome } from '../../scheme';\nimport { config } from '../../config';\nimport { BarDatum } from '@redsift/charts/types';\n\nconst COMPONENT_NAME = 'Bar';\nconst CLASSNAME = 'redsift-bar';\n\nexport const Bar: Comp<BarProps, SVGGElement> = forwardRef((props, ref) => {\n const { color = monochrome, data, index = 0, isSelected: propsIsSelected, labelDecorator, onClick, role } = props;\n\n const {\n className,\n disableAnimations,\n gap = 5,\n height = 40,\n maxHeight = 100,\n orientation = BarOrientation.horizontal,\n direction = BarDirection.up,\n previousData = {\n data: {\n key: '',\n value: 0,\n },\n },\n scale,\n scalePosition,\n width = 40,\n minWidth,\n ...forwardedProps\n } = props;\n\n const theme = useTheme();\n\n const getValue = (data: BarDatum['data']) =>\n data?.cumulativeValue !== undefined ? data.cumulativeValue : data?.value;\n const interpolator = d3interpolate(getValue(previousData!.data) || 0, getValue(data.data) || 0);\n\n const text = labelDecorator\n ? labelDecorator(data, { index, isSelected: propsIsSelected, color })\n : (data.data.key as string);\n const isSelectable = role === 'option';\n const isDeselected = isSelectable && propsIsSelected === false;\n const isHorizontal = orientation === BarOrientation.horizontal;\n const goesUp = direction === BarDirection.up;\n const isOrdinal = typeof scalePosition.domain()[0] === 'string';\n\n const animatedProps = useSpring({\n ...config,\n to: async (next: (props?: object) => Promise<void>) => {\n await next({ t: 1 });\n },\n from: { t: 0 },\n });\n\n const computedWidth: number = minWidth ? Math.max(minWidth, width) : width;\n\n return (\n <StyledBar\n {...forwardedProps}\n ref={ref}\n className={classNames(Bar.className, className)}\n transform={\n isHorizontal\n ? `translate(0, ${scalePosition(data.data.key as any)! + gap! / 2})`\n : `translate(${\n goesUp\n ? scalePosition(data.data.key as any)! + (isOrdinal ? computedWidth + gap! / 2 : computedWidth / 2)\n : scalePosition(data.data.key as any)! + (isOrdinal ? -computedWidth + gap! / 2 : -computedWidth / 2)\n }, ${maxHeight})${goesUp ? ', rotate(180)' : ''}`\n }\n $clickable={Boolean(onClick)}\n $theme={theme}\n >\n {isHorizontal ? (\n <animated.rect\n height={height}\n fill={isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color}\n width={\n config.immediate || disableAnimations\n ? scale(data.data.value)\n : animatedProps.t.to((t) => scale(interpolator(t)))\n }\n />\n ) : (\n <animated.rect\n height={\n config.immediate || disableAnimations\n ? goesUp\n ? maxHeight! - scale(getValue(data.data))\n : scale(getValue(data.data)) - maxHeight!\n : animatedProps.t.to((t) =>\n Math.max(0, goesUp ? maxHeight! - scale(interpolator(t)) : scale(interpolator(t)) - maxHeight!)\n )\n }\n fill={isDeselected ? 'var(--redsift-color-neutral-light-grey)' : color}\n width={computedWidth}\n />\n )}\n {isHorizontal ? (\n <text x=\"10\" y={height! / 2} dy=\"0.35em\" aria-hidden={true}>\n {text}\n </text>\n ) : null}\n </StyledBar>\n );\n});\nBar.className = CLASSNAME;\nBar.displayName = COMPONENT_NAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","Bar","forwardRef","props","ref","color","monochrome","data","index","isSelected","propsIsSelected","labelDecorator","onClick","role","className","disableAnimations","gap","height","maxHeight","orientation","BarOrientation","horizontal","direction","BarDirection","up","previousData","key","value","scale","scalePosition","width","minWidth","forwardedProps","_objectWithoutProperties","_excluded","theme","useTheme","getValue","cumulativeValue","undefined","interpolator","d3interpolate","text","isSelectable","isDeselected","isHorizontal","goesUp","isOrdinal","domain","animatedProps","useSpring","_objectSpread","config","to","next","t","from","computedWidth","Math","max","React","createElement","StyledBar","_extends","classNames","transform","$clickable","Boolean","$theme","animated","rect","fill","immediate","x","y","dy","displayName"],"mappings":";;;;;;;;;;;;;AAaA,MAAMA,cAAc,GAAG,KAAK,CAAA;AAC5B,MAAMC,SAAS,GAAG,aAAa,CAAA;AAExB,MAAMC,GAAgC,gBAAGC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAK;EACzE,MAAM;AAAEC,IAAAA,KAAK,GAAGC,UAAU;IAAEC,IAAI;AAAEC,IAAAA,KAAK,GAAG,CAAC;AAAEC,IAAAA,UAAU,EAAEC,eAAe;IAAEC,cAAc;IAAEC,OAAO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,SAAU,GACzC+B,aAAa,CAACM,CAAC,CAACF,EAAE,CAAEE,CAAC,IACnBG,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEb,MAAM,GAAG5B,SAAS,GAAIU,KAAK,CAACY,YAAY,CAACe,CAAC,CAAC,CAAC,GAAG3B,KAAK,CAACY,YAAY,CAACe,CAAC,CAAC,CAAC,GAAGrC,SAAU,CAChG,CACL;AACDqD,IAAAA,IAAI,EAAE3B,YAAY,GAAG,yCAAyC,GAAGvC,KAAM;AACvEyB,IAAAA,KAAK,EAAE2B,aAAAA;AAAc,GACtB,CACF,EACAZ,YAAY,gBACXe,cAAA,CAAAC,aAAA,CAAA,MAAA,EAAA;AAAMY,IAAAA,CAAC,EAAC,IAAI;IAACC,CAAC,EAAEzD,MAAM,GAAI,CAAE;AAAC0D,IAAAA,EAAE,EAAC,QAAQ;IAAC,aAAa,EAAA,IAAA;AAAK,GAAA,EACxDjC,IACG,CAAC,GACL,IACK,CAAC,CAAA;AAEhB,CAAC,EAAC;AACFzC,GAAG,CAACa,SAAS,GAAGd,SAAS,CAAA;AACzBC,GAAG,CAAC2E,WAAW,GAAG7E,cAAc;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as styled_components from 'styled-components';
|
|
2
|
+
import { BarProps } from './types.js';
|
|
3
|
+
import * as _redsift_design_system from '@redsift/design-system';
|
|
4
|
+
import { Theme } from '@redsift/design-system';
|
|
5
|
+
import { DataPointProps } from '../DataPoint/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Component style.
|
|
9
|
+
*/
|
|
10
|
+
declare const StyledBar: styled_components.StyledComponent<_redsift_design_system.Comp<DataPointProps<any>, SVGGElement>, any, Omit<DataPointProps<any>, "data" | "dataset"> & {
|
|
11
|
+
$clickable: boolean;
|
|
12
|
+
} & Omit<BarProps, "scale" | "scalePosition"> & {
|
|
13
|
+
$theme: Theme;
|
|
14
|
+
}, never>;
|
|
15
|
+
|
|
16
|
+
export { StyledBar };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { Theme } from '@redsift/design-system';
|
|
3
|
+
import { DataPoint } from '../DataPoint/DataPoint.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component style.
|
|
7
|
+
*/
|
|
8
|
+
const StyledBar = styled(DataPoint)`
|
|
9
|
+
text {
|
|
10
|
+
${_ref => {
|
|
11
|
+
let {
|
|
12
|
+
$theme
|
|
13
|
+
} = _ref;
|
|
14
|
+
return css`
|
|
15
|
+
fill: var(--redsift-color-neutral-${$theme === Theme.dark ? 'white' : 'x-dark-grey'});
|
|
16
|
+
`;
|
|
17
|
+
}}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
${_ref2 => {
|
|
21
|
+
let {
|
|
22
|
+
$clickable
|
|
23
|
+
} = _ref2;
|
|
24
|
+
return $clickable ? css`
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
|
|
27
|
+
&:hover,
|
|
28
|
+
&:focus,
|
|
29
|
+
&.focused {
|
|
30
|
+
outline: none;
|
|
31
|
+
rect {
|
|
32
|
+
fill-opacity: 0.7;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// &:focus-visible {
|
|
37
|
+
// rect {
|
|
38
|
+
// stroke: var(--redsift-color-primary-n);
|
|
39
|
+
// stroke-width: 4px;
|
|
40
|
+
// paint-order: stroke;
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
45
|
+
&:focus-visible,
|
|
46
|
+
&.focused {
|
|
47
|
+
outline: 2px solid var(--redsift-color-primary-n);
|
|
48
|
+
transition: outline-offset 75ms ease-out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&:not(&:active)&:focus-visible,
|
|
52
|
+
&:not(&:active)&.focused {
|
|
53
|
+
transition-duration: 0.25s;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:not(&:active)&:focus-visible,
|
|
58
|
+
&:not(&:active)&.focused {
|
|
59
|
+
outline-offset: 0.2rem;
|
|
60
|
+
}
|
|
61
|
+
` : '';
|
|
62
|
+
}}}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
export { StyledBar };
|
|
66
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../../../src/components/Bar/styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport { StyledBarProps } from './types';\nimport { DataPoint } from '../DataPoint';\nimport { Theme } from '@redsift/design-system';\n\n/**\n * Component style.\n */\nexport const StyledBar = styled(DataPoint)<StyledBarProps>`\n text {\n ${({ $theme }) => css`\n fill: var(--redsift-color-neutral-${$theme === Theme.dark ? 'white' : 'x-dark-grey'});\n `}\n }\n\n ${({ $clickable }) =>\n $clickable\n ? css`\n cursor: pointer;\n\n &:hover,\n &:focus,\n &.focused {\n outline: none;\n rect {\n fill-opacity: 0.7;\n }\n }\n\n // &:focus-visible {\n // rect {\n // stroke: var(--redsift-color-primary-n);\n // stroke-width: 4px;\n // paint-order: stroke;\n // }\n // }\n\n @media (prefers-reduced-motion: no-preference) {\n &:focus-visible,\n &.focused {\n outline: 2px solid var(--redsift-color-primary-n);\n transition: outline-offset 75ms ease-out;\n }\n\n &:not(&:active)&:focus-visible,\n &:not(&:active)&.focused {\n transition-duration: 0.25s;\n }\n }\n\n &:not(&:active)&:focus-visible,\n &:not(&:active)&.focused {\n outline-offset: 0.2rem;\n }\n `\n : ''}}\n`;\n"],"names":["StyledBar","styled","DataPoint","_ref","$theme","css","Theme","dark","_ref2","$clickable"],"mappings":";;;;AAKA;AACA;AACA;MACaA,SAAS,GAAGC,MAAM,CAACC,SAAS,CAAkB,CAAA;AAC3D;AACA,IAAA,EAAMC,IAAA,IAAA;EAAA,IAAC;AAAEC,IAAAA,MAAAA;AAAO,GAAC,GAAAD,IAAA,CAAA;AAAA,EAAA,OAAKE,GAAI,CAAA;AAC1B,wCAA0CD,EAAAA,MAAM,KAAKE,KAAK,CAACC,IAAI,GAAG,OAAO,GAAG,aAAc,CAAA;AAC1F,IAAK,CAAA,CAAA;AAAA,CAAC,CAAA;AACN;AACA;AACA,EAAA,EAAIC,KAAA,IAAA;EAAA,IAAC;AAAEC,IAAAA,UAAAA;AAAW,GAAC,GAAAD,KAAA,CAAA;EAAA,OACfC,UAAU,GACNJ,GAAI,CAAA;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAA,CAAS,GACD,EAAE,CAAA;AAAA,CAAC,CAAA;AACX;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ScaleLinear, ScaleTime, ScalePoint } from 'd3';
|
|
2
|
+
import { ValueOf, Theme } from '@redsift/design-system';
|
|
3
|
+
import { BarDatum } from '../../types/data.js';
|
|
4
|
+
import { DataPointProps, StyledDataPointProps } from '../DataPoint/types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Component variant.
|
|
8
|
+
*/
|
|
9
|
+
declare const BarOrientation: {
|
|
10
|
+
horizontal: string;
|
|
11
|
+
vertical: string;
|
|
12
|
+
};
|
|
13
|
+
type BarOrientation = ValueOf<typeof BarOrientation>;
|
|
14
|
+
declare const BarDirection: {
|
|
15
|
+
up: string;
|
|
16
|
+
down: string;
|
|
17
|
+
};
|
|
18
|
+
type BarDirection = ValueOf<typeof BarDirection>;
|
|
19
|
+
/**
|
|
20
|
+
* Component props.
|
|
21
|
+
*/
|
|
22
|
+
interface BarProps extends DataPointProps<BarDatum> {
|
|
23
|
+
/** Gap between two siblings. */
|
|
24
|
+
gap?: number;
|
|
25
|
+
/** Height of the bar in horizontal orientation. */
|
|
26
|
+
height?: number;
|
|
27
|
+
/** Maximum height of the bar. */
|
|
28
|
+
maxHeight?: number;
|
|
29
|
+
/** Orientation of the bar. */
|
|
30
|
+
orientation?: BarOrientation;
|
|
31
|
+
/** Direction of the bar, works only with vertical orientation. */
|
|
32
|
+
direction?: BarOrientation;
|
|
33
|
+
/** A linear continuous scale defined over a numeric domain used to determine the width or height of the bar (depending on the orientation). */
|
|
34
|
+
scale: ScaleLinear<number, number, never>;
|
|
35
|
+
/** A scale defined over a numeric/time/ordinal domain used to determine the position of the bar. */
|
|
36
|
+
scalePosition: ScaleLinear<number, number, never> | ScaleTime<number, number, never> | ScalePoint<string>;
|
|
37
|
+
/** Width of the bar in vertical orientation. */
|
|
38
|
+
width?: number;
|
|
39
|
+
/** Min width of the bar in vertical orientation. */
|
|
40
|
+
minWidth?: number;
|
|
41
|
+
}
|
|
42
|
+
type StyledBarProps = StyledDataPointProps & Omit<BarProps, 'scale' | 'scalePosition'> & {
|
|
43
|
+
$theme: Theme;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { BarDirection, BarOrientation, BarProps, StyledBarProps };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component variant.
|
|
3
|
+
*/
|
|
4
|
+
const BarOrientation = {
|
|
5
|
+
horizontal: 'horizontal',
|
|
6
|
+
vertical: 'vertical'
|
|
7
|
+
};
|
|
8
|
+
const BarDirection = {
|
|
9
|
+
up: 'up',
|
|
10
|
+
down: 'down'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Component props.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { BarDirection, BarOrientation };
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/components/Bar/types.ts"],"sourcesContent":["import { ScaleLinear as d3ScaleLinear, ScaleTime as d3ScaleTime, ScalePoint as d3ScalePoint } from 'd3';\nimport { Theme, ValueOf } from '@redsift/design-system';\nimport { BarDatum } from '../../types';\nimport { DataPointProps, StyledDataPointProps } from '../DataPoint';\n\n/**\n * Component variant.\n */\nexport const BarOrientation = {\n horizontal: 'horizontal',\n vertical: 'vertical',\n};\nexport type BarOrientation = ValueOf<typeof BarOrientation>;\n\nexport const BarDirection = {\n up: 'up',\n down: 'down',\n};\nexport type BarDirection = ValueOf<typeof BarDirection>;\n\n/**\n * Component props.\n */\nexport interface BarProps extends DataPointProps<BarDatum> {\n /** Gap between two siblings. */\n gap?: number;\n /** Height of the bar in horizontal orientation. */\n height?: number;\n /** Maximum height of the bar. */\n maxHeight?: number;\n /** Orientation of the bar. */\n orientation?: BarOrientation;\n /** Direction of the bar, works only with vertical orientation. */\n direction?: BarOrientation;\n /** A linear continuous scale defined over a numeric domain used to determine the width or height of the bar (depending on the orientation). */\n scale: d3ScaleLinear<number, number, never>;\n /** A scale defined over a numeric/time/ordinal domain used to determine the position of the bar. */\n scalePosition: d3ScaleLinear<number, number, never> | d3ScaleTime<number, number, never> | d3ScalePoint<string>;\n /** Width of the bar in vertical orientation. */\n width?: number;\n /** Min width of the bar in vertical orientation. */\n minWidth?: number;\n}\n\nexport type StyledBarProps = StyledDataPointProps &\n Omit<BarProps, 'scale' | 'scalePosition'> & {\n $theme: Theme;\n };\n"],"names":["BarOrientation","horizontal","vertical","BarDirection","up","down"],"mappings":"AAKA;AACA;AACA;AACO,MAAMA,cAAc,GAAG;AAC5BC,EAAAA,UAAU,EAAE,YAAY;AACxBC,EAAAA,QAAQ,EAAE,UAAA;AACZ,EAAC;AAGM,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,EAAE,EAAE,IAAI;AACRC,EAAAA,IAAI,EAAE,MAAA;AACR,EAAC;;AAGD;AACA;AACA;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BarChartProps, BarChartSectionProps, BarChartBarsProps, ComputedBarProps } from './types.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Comp } from '@redsift/design-system';
|
|
4
|
+
import { AxisProps } from '../Axis/types.js';
|
|
5
|
+
import { BarDatum } from '../../types/data.js';
|
|
6
|
+
import { LegendProps } from '../Legend/types.js';
|
|
7
|
+
import { LegendItemProps } from '../LegendItem/types.js';
|
|
8
|
+
import { ChartContainerProps } from '../ChartContainer/types.js';
|
|
9
|
+
|
|
10
|
+
declare const BaseBarChart: Comp<BarChartProps, HTMLDivElement>;
|
|
11
|
+
declare const BarChart: Comp<BarChartProps, HTMLDivElement> & {
|
|
12
|
+
Section: Comp<BarChartSectionProps, SVGGElement>;
|
|
13
|
+
Bars: Comp<BarChartBarsProps, SVGGElement>;
|
|
14
|
+
Axis: Comp<AxisProps, SVGGElement>;
|
|
15
|
+
GroupedTooltip: React.FC<{
|
|
16
|
+
dateFormatter: (date: Date) => string;
|
|
17
|
+
categories: string[];
|
|
18
|
+
categoryDecorator?: ((category: string) => string) | undefined;
|
|
19
|
+
categoryColor: (category: string) => string;
|
|
20
|
+
datum: BarDatum;
|
|
21
|
+
groupedData: ComputedBarProps[] | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
Legend: Comp<LegendProps, HTMLUListElement>;
|
|
24
|
+
LegendItem: Comp<LegendItemProps, HTMLLIElement>;
|
|
25
|
+
Title: Comp<Pick<ChartContainerProps, "onReset"> & React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
26
|
+
Description: Comp<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, HTMLDivElement>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { BarChart, BaseBarChart };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { forwardRef } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { useId } from '@redsift/design-system';
|
|
5
|
+
import { BarChartLegendVariant } from './types.js';
|
|
6
|
+
import { EmptyBarChart } from './EmptyBarChart.js';
|
|
7
|
+
import { LoadingBarChart } from './LoadingBarChart.js';
|
|
8
|
+
import { RenderedOrdinalBarChart } from './RenderedOrdinalBarChart.js';
|
|
9
|
+
import { RenderedLinearBarChart } from './RenderedLinearBarChart.js';
|
|
10
|
+
import { isValidDate } from '../../utils/index.js';
|
|
11
|
+
import { BarChartSection } from './BarChartSection.js';
|
|
12
|
+
import { BarChartBars, BarChartGroupedTooltip } from './BarChartBars.js';
|
|
13
|
+
import { ColorTheme } from '../../types/theme.js';
|
|
14
|
+
import { ChartContainerTitle, ChartContainerDescription } from '../ChartContainer/ChartContainer.js';
|
|
15
|
+
import { BarOrientation } from '../Bar/types.js';
|
|
16
|
+
import { ChartSize } from '../../types/size.js';
|
|
17
|
+
import { TooltipVariant } from '../../types/legend.js';
|
|
18
|
+
import { Axis } from '../Axis/Axis.js';
|
|
19
|
+
import { Legend } from '../Legend/Legend.js';
|
|
20
|
+
import { LegendItem } from '../LegendItem/LegendItem.js';
|
|
21
|
+
|
|
22
|
+
const _excluded = ["barRole", "caping", "chartRef", "className", "colorTheme", "data", "dataType", "emptyComponent", "id", "isBarSelected", "labelDecorator", "legendDecorator", "legendVariant", "localeText", "onBarClick", "orientation", "others", "size", "sortingMethod", "theme", "tooltipDecorator", "tooltipVariant", "xAxisPlacement", "yAxisPlacement"];
|
|
23
|
+
const COMPONENT_NAME = 'BarChart';
|
|
24
|
+
const CLASSNAME = 'redsift-barchart';
|
|
25
|
+
const BaseBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
26
|
+
const {
|
|
27
|
+
barRole,
|
|
28
|
+
caping,
|
|
29
|
+
chartRef,
|
|
30
|
+
className,
|
|
31
|
+
colorTheme = ColorTheme.default,
|
|
32
|
+
data: propsData,
|
|
33
|
+
dataType: propsDataType,
|
|
34
|
+
emptyComponent,
|
|
35
|
+
id: propsId,
|
|
36
|
+
isBarSelected = () => true,
|
|
37
|
+
labelDecorator,
|
|
38
|
+
legendDecorator,
|
|
39
|
+
legendVariant: propsLegendVariant,
|
|
40
|
+
localeText = {
|
|
41
|
+
emptyChartText: 'No Data'
|
|
42
|
+
},
|
|
43
|
+
onBarClick,
|
|
44
|
+
orientation = BarOrientation.horizontal,
|
|
45
|
+
others = true,
|
|
46
|
+
size = ChartSize.medium,
|
|
47
|
+
sortingMethod = 'desc-value',
|
|
48
|
+
theme,
|
|
49
|
+
tooltipDecorator,
|
|
50
|
+
tooltipVariant = TooltipVariant.value,
|
|
51
|
+
xAxisPlacement = 'bottom',
|
|
52
|
+
yAxisPlacement = 'left'
|
|
53
|
+
} = props,
|
|
54
|
+
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
55
|
+
const [_id] = useId();
|
|
56
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
57
|
+
const legendVariant = propsLegendVariant !== null && propsLegendVariant !== void 0 ? propsLegendVariant : BarChartLegendVariant.externalLabel;
|
|
58
|
+
if (propsData === undefined || propsData === null) {
|
|
59
|
+
return /*#__PURE__*/React__default.createElement(LoadingBarChart, _extends({
|
|
60
|
+
id: id
|
|
61
|
+
}, forwardedProps, {
|
|
62
|
+
ref: ref
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
if (propsData.length === 0) {
|
|
66
|
+
return /*#__PURE__*/React__default.createElement(EmptyBarChart, _extends({
|
|
67
|
+
data: propsData,
|
|
68
|
+
emptyComponent: emptyComponent,
|
|
69
|
+
id: id,
|
|
70
|
+
localeText: localeText,
|
|
71
|
+
size: size
|
|
72
|
+
}, forwardedProps, {
|
|
73
|
+
ref: ref
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
const dataType = propsDataType ? propsDataType : Array.isArray(propsData[0].key) ? 'TwoCategoryData' : propsData[0].key instanceof Date ? 'LinearData' : typeof propsData[0].key === 'number' ? 'LinearData' : typeof propsData[0].key === 'string' && isValidDate(propsData[0].key) ? 'LinearData' : typeof propsData[0].key === 'string' ? 'CategoryData' : 'CategoryData';
|
|
77
|
+
if (dataType === 'CategoryData') {
|
|
78
|
+
return /*#__PURE__*/React__default.createElement(RenderedOrdinalBarChart, _extends({
|
|
79
|
+
barRole: barRole,
|
|
80
|
+
caping: caping,
|
|
81
|
+
chartRef: chartRef,
|
|
82
|
+
className: classNames(BaseBarChart.className, className),
|
|
83
|
+
data: propsData,
|
|
84
|
+
id: id,
|
|
85
|
+
isBarSelected: isBarSelected,
|
|
86
|
+
labelDecorator: labelDecorator,
|
|
87
|
+
onBarClick: onBarClick,
|
|
88
|
+
orientation: orientation,
|
|
89
|
+
others: others,
|
|
90
|
+
size: size,
|
|
91
|
+
sortingMethod: sortingMethod,
|
|
92
|
+
theme: theme,
|
|
93
|
+
tooltipDecorator: tooltipDecorator,
|
|
94
|
+
colorTheme: colorTheme,
|
|
95
|
+
tooltipVariant: tooltipVariant,
|
|
96
|
+
xAxisPlacement: xAxisPlacement,
|
|
97
|
+
yAxisPlacement: yAxisPlacement
|
|
98
|
+
}, forwardedProps, {
|
|
99
|
+
ref: ref
|
|
100
|
+
}));
|
|
101
|
+
} else if (dataType === 'LinearData' || dataType === 'TwoCategoryData') {
|
|
102
|
+
return /*#__PURE__*/React__default.createElement(RenderedLinearBarChart, _extends({
|
|
103
|
+
barRole: barRole,
|
|
104
|
+
chartRef: chartRef,
|
|
105
|
+
className: classNames(BaseBarChart.className, className),
|
|
106
|
+
data: propsData,
|
|
107
|
+
id: id,
|
|
108
|
+
isBarSelected: isBarSelected,
|
|
109
|
+
labelDecorator: labelDecorator,
|
|
110
|
+
legendDecorator: legendDecorator,
|
|
111
|
+
legendVariant: legendVariant,
|
|
112
|
+
onBarClick: onBarClick,
|
|
113
|
+
size: size,
|
|
114
|
+
sortingMethod: sortingMethod,
|
|
115
|
+
theme: theme,
|
|
116
|
+
tooltipDecorator: tooltipDecorator,
|
|
117
|
+
colorTheme: colorTheme,
|
|
118
|
+
tooltipVariant: tooltipVariant,
|
|
119
|
+
xAxisPlacement: xAxisPlacement,
|
|
120
|
+
yAxisPlacement: yAxisPlacement
|
|
121
|
+
}, forwardedProps, {
|
|
122
|
+
ref: ref
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
});
|
|
127
|
+
BaseBarChart.className = CLASSNAME;
|
|
128
|
+
BaseBarChart.displayName = COMPONENT_NAME;
|
|
129
|
+
const BarChart = Object.assign(BaseBarChart, {
|
|
130
|
+
Section: BarChartSection,
|
|
131
|
+
Bars: BarChartBars,
|
|
132
|
+
Axis: Axis,
|
|
133
|
+
GroupedTooltip: BarChartGroupedTooltip,
|
|
134
|
+
Legend: Legend,
|
|
135
|
+
LegendItem: LegendItem,
|
|
136
|
+
Title: ChartContainerTitle,
|
|
137
|
+
Description: ChartContainerDescription
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export { BarChart, BaseBarChart };
|
|
141
|
+
//# sourceMappingURL=BarChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BarChart.js","sources":["../../../src/components/BarChart/BarChart.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classNames from 'classnames';\n\nimport { Comp, useId } from '@redsift/design-system';\n\nimport { ChartSize, ColorTheme, LinearData, TooltipVariant } from '../../types';\nimport { BarChartLegendVariant, BarChartProps } from './types';\nimport { EmptyBarChart } from './EmptyBarChart';\nimport { LoadingBarChart } from './LoadingBarChart';\nimport { RenderedOrdinalBarChart } from './RenderedOrdinalBarChart';\nimport { RenderedLinearBarChart } from './RenderedLinearBarChart';\nimport { BarOrientation } from '../Bar';\nimport { isValidDate } from '../../utils';\nimport { BarChartSection } from './BarChartSection';\nimport { BarChartBars, BarChartGroupedTooltip } from './BarChartBars';\nimport { Axis } from '../Axis';\nimport { Legend } from '../Legend';\nimport { LegendItem } from '../LegendItem';\nimport { ChartContainerDescription, ChartContainerTitle } from '../ChartContainer';\n\nconst COMPONENT_NAME = 'BarChart';\nconst CLASSNAME = 'redsift-barchart';\n\nexport const BaseBarChart: Comp<BarChartProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n barRole,\n caping,\n chartRef,\n className,\n colorTheme = ColorTheme.default,\n data: propsData,\n dataType: propsDataType,\n emptyComponent,\n id: propsId,\n isBarSelected = () => true,\n labelDecorator,\n legendDecorator,\n legendVariant: propsLegendVariant,\n localeText = { emptyChartText: 'No Data' },\n onBarClick,\n orientation = BarOrientation.horizontal,\n others = true,\n size = ChartSize.medium,\n sortingMethod = 'desc-value',\n theme,\n tooltipDecorator,\n tooltipVariant = TooltipVariant.value,\n xAxisPlacement = 'bottom',\n yAxisPlacement = 'left',\n ...forwardedProps\n } = props;\n const [_id] = useId();\n const id = propsId ?? _id;\n\n const legendVariant = propsLegendVariant ?? BarChartLegendVariant.externalLabel;\n\n if (propsData === undefined || propsData === null) {\n return <LoadingBarChart id={id} {...forwardedProps} ref={ref} />;\n }\n\n if (propsData.length === 0) {\n return (\n <EmptyBarChart\n data={propsData}\n emptyComponent={emptyComponent}\n id={id}\n localeText={localeText}\n size={size}\n {...forwardedProps}\n ref={ref}\n />\n );\n }\n\n const dataType = propsDataType\n ? propsDataType\n : Array.isArray(propsData[0].key)\n ? 'TwoCategoryData'\n : propsData[0].key instanceof Date\n ? 'LinearData'\n : typeof propsData[0].key === 'number'\n ? 'LinearData'\n : typeof propsData[0].key === 'string' && isValidDate(propsData[0].key)\n ? 'LinearData'\n : typeof propsData[0].key === 'string'\n ? 'CategoryData'\n : 'CategoryData';\n\n if (dataType === 'CategoryData') {\n return (\n <RenderedOrdinalBarChart\n barRole={barRole}\n caping={caping}\n chartRef={chartRef}\n className={classNames(BaseBarChart.className, className)}\n data={propsData}\n id={id}\n isBarSelected={isBarSelected}\n labelDecorator={labelDecorator}\n onBarClick={onBarClick}\n orientation={orientation}\n others={others}\n size={size}\n sortingMethod={sortingMethod}\n theme={theme}\n tooltipDecorator={tooltipDecorator}\n colorTheme={colorTheme}\n tooltipVariant={tooltipVariant}\n xAxisPlacement={xAxisPlacement}\n yAxisPlacement={yAxisPlacement}\n {...forwardedProps}\n ref={ref}\n />\n );\n } else if (dataType === 'LinearData' || dataType === 'TwoCategoryData') {\n return (\n <RenderedLinearBarChart\n barRole={barRole}\n chartRef={chartRef}\n className={classNames(BaseBarChart.className, className)}\n data={propsData as LinearData}\n id={id}\n isBarSelected={isBarSelected}\n labelDecorator={labelDecorator}\n legendDecorator={legendDecorator}\n legendVariant={legendVariant}\n onBarClick={onBarClick}\n size={size}\n sortingMethod={sortingMethod}\n theme={theme}\n tooltipDecorator={tooltipDecorator}\n colorTheme={colorTheme}\n tooltipVariant={tooltipVariant}\n xAxisPlacement={xAxisPlacement}\n yAxisPlacement={yAxisPlacement}\n {...forwardedProps}\n ref={ref}\n />\n );\n }\n\n return null;\n});\nBaseBarChart.className = CLASSNAME;\nBaseBarChart.displayName = COMPONENT_NAME;\n\nexport const BarChart = Object.assign(BaseBarChart, {\n Section: BarChartSection,\n Bars: BarChartBars,\n Axis: Axis,\n GroupedTooltip: BarChartGroupedTooltip,\n Legend: Legend,\n LegendItem: LegendItem,\n Title: ChartContainerTitle,\n Description: ChartContainerDescription,\n});\n"],"names":["COMPONENT_NAME","CLASSNAME","BaseBarChart","forwardRef","props","ref","barRole","caping","chartRef","className","colorTheme","ColorTheme","default","data","propsData","dataType","propsDataType","emptyComponent","id","propsId","isBarSelected","labelDecorator","legendDecorator","legendVariant","propsLegendVariant","localeText","emptyChartText","onBarClick","orientation","BarOrientation","horizontal","others","size","ChartSize","medium","sortingMethod","theme","tooltipDecorator","tooltipVariant","TooltipVariant","value","xAxisPlacement","yAxisPlacement","forwardedProps","_objectWithoutProperties","_excluded","_id","useId","BarChartLegendVariant","externalLabel","undefined","React","createElement","LoadingBarChart","_extends","length","EmptyBarChart","Array","isArray","key","Date","isValidDate","RenderedOrdinalBarChart","classNames","RenderedLinearBarChart","displayName","BarChart","Object","assign","Section","BarChartSection","Bars","BarChartBars","Axis","GroupedTooltip","BarChartGroupedTooltip","Legend","LegendItem","Title","ChartContainerTitle","Description","ChartContainerDescription"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAMA,cAAc,GAAG,UAAU,CAAA;AACjC,MAAMC,SAAS,GAAG,kBAAkB,CAAA;AAE7B,MAAMC,YAAiD,gBAAGC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAK;EAC1F,MAAM;MACJC,OAAO;MACPC,MAAM;MACNC,QAAQ;MACRC,SAAS;MACTC,UAAU,GAAGC,UAAU,CAACC,OAAO;AAC/BC,MAAAA,IAAI,EAAEC,SAAS;AACfC,MAAAA,QAAQ,EAAEC,aAAa;MACvBC,cAAc;AACdC,MAAAA,EAAE,EAAEC,OAAO;MACXC,aAAa,GAAGA,MAAM,IAAI;MAC1BC,cAAc;MACdC,eAAe;AACfC,MAAAA,aAAa,EAAEC,kBAAkB;AACjCC,MAAAA,UAAU,GAAG;AAAEC,QAAAA,cAAc,EAAE,SAAA;OAAW;MAC1CC,UAAU;MACVC,WAAW,GAAGC,cAAc,CAACC,UAAU;AACvCC,MAAAA,MAAM,GAAG,IAAI;MACbC,IAAI,GAAGC,SAAS,CAACC,MAAM;AACvBC,MAAAA,aAAa,GAAG,YAAY;MAC5BC,KAAK;MACLC,gBAAgB;MAChBC,cAAc,GAAGC,cAAc,CAACC,KAAK;AACrCC,MAAAA,cAAc,GAAG,QAAQ;AACzBC,MAAAA,cAAc,GAAG,MAAA;AAEnB,KAAC,GAAGtC,KAAK;AADJuC,IAAAA,cAAc,GAAAC,wBAAA,CACfxC,KAAK,EAAAyC,SAAA,CAAA,CAAA;AACT,EAAA,MAAM,CAACC,GAAG,CAAC,GAAGC,KAAK,EAAE,CAAA;EACrB,MAAM7B,EAAE,GAAGC,OAAO,KAAA,IAAA,IAAPA,OAAO,KAAPA,KAAAA,CAAAA,GAAAA,OAAO,GAAI2B,GAAG,CAAA;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,168 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { forwardRef } from 'react';
|
|
3
|
+
import { Flexbox, Text } from '@redsift/design-system';
|
|
4
|
+
import { StyledBarChartBars } from './styles.js';
|
|
5
|
+
import { useBarChartContext } from './context.js';
|
|
6
|
+
import { Bar } from '../Bar/Bar.js';
|
|
7
|
+
import { BarOrientation } from '../Bar/types.js';
|
|
8
|
+
|
|
9
|
+
const _excluded = ["category"];
|
|
10
|
+
const COMPONENT_NAME = 'BarChartBars';
|
|
11
|
+
const CLASSNAME = 'redsift-bars';
|
|
12
|
+
const BarChartBars = /*#__PURE__*/forwardRef((props, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
category = 'default'
|
|
15
|
+
} = props,
|
|
16
|
+
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
17
|
+
const {
|
|
18
|
+
barProps,
|
|
19
|
+
barRole,
|
|
20
|
+
bars,
|
|
21
|
+
barWidth,
|
|
22
|
+
cache,
|
|
23
|
+
categories,
|
|
24
|
+
colorScale,
|
|
25
|
+
direction,
|
|
26
|
+
disableAnimations,
|
|
27
|
+
format,
|
|
28
|
+
gap,
|
|
29
|
+
getBarAnchorProps,
|
|
30
|
+
hasCategory,
|
|
31
|
+
id,
|
|
32
|
+
isBarSelected,
|
|
33
|
+
labelDecorator,
|
|
34
|
+
onBarClick,
|
|
35
|
+
scaleX,
|
|
36
|
+
scaleY,
|
|
37
|
+
tooltipVariant,
|
|
38
|
+
tooltipDecorator,
|
|
39
|
+
xScaleType
|
|
40
|
+
} = useBarChartContext();
|
|
41
|
+
const filteredBarChartBars = bars.filter(bar => bar.category === category && bar.value > 0);
|
|
42
|
+
const categoryIndex = categories.indexOf(category);
|
|
43
|
+
const categoryLength = categories.length;
|
|
44
|
+
return /*#__PURE__*/React__default.createElement(StyledBarChartBars, _extends({
|
|
45
|
+
key: `${id}-series-${category}`,
|
|
46
|
+
"aria-hidden": "false",
|
|
47
|
+
role: "region"
|
|
48
|
+
}, hasCategory ? {
|
|
49
|
+
'aria-label': format('series-legend', {
|
|
50
|
+
category,
|
|
51
|
+
categoryIndex: categoryIndex + 1,
|
|
52
|
+
categoryLength,
|
|
53
|
+
barLength: filteredBarChartBars.length
|
|
54
|
+
})
|
|
55
|
+
} : {}, forwardedProps, {
|
|
56
|
+
ref: ref
|
|
57
|
+
}), filteredBarChartBars.map((bar, index) => {
|
|
58
|
+
const to = {
|
|
59
|
+
data: bar,
|
|
60
|
+
category
|
|
61
|
+
};
|
|
62
|
+
const from = cache.current ? {
|
|
63
|
+
data: cache.current[index]
|
|
64
|
+
} : undefined;
|
|
65
|
+
const groupedBars = bars.filter(b => {
|
|
66
|
+
return xScaleType === 'Date' || xScaleType === 'dateString' ? b.key.getTime() === bar.key.getTime() : b.key === bar.key;
|
|
67
|
+
});
|
|
68
|
+
return /*#__PURE__*/React__default.createElement(Bar, _extends({
|
|
69
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(to.data.category),
|
|
70
|
+
data: to,
|
|
71
|
+
dataset: bars,
|
|
72
|
+
groupedData: groupedBars,
|
|
73
|
+
disableAnimations: disableAnimations,
|
|
74
|
+
gap: gap,
|
|
75
|
+
id: `id${id}__bar-${categoryIndex}.${index}`,
|
|
76
|
+
index: index,
|
|
77
|
+
isSelected: Boolean(isBarSelected(to)),
|
|
78
|
+
key: `bar _${categoryIndex}.${index}`,
|
|
79
|
+
labelDecorator: labelDecorator,
|
|
80
|
+
maxHeight: scaleY(bar.cumulativeValue - bar.value),
|
|
81
|
+
anchorProps: getBarAnchorProps ? getBarAnchorProps(to) : undefined,
|
|
82
|
+
onClick: onBarClick,
|
|
83
|
+
orientation: BarOrientation.vertical,
|
|
84
|
+
direction: direction,
|
|
85
|
+
previousData: from,
|
|
86
|
+
scale: scaleY,
|
|
87
|
+
scalePosition: scaleX,
|
|
88
|
+
tooltipVariant: tooltipVariant,
|
|
89
|
+
tooltipDecorator: tooltipDecorator
|
|
90
|
+
}, barProps, {
|
|
91
|
+
width: barProps !== null && barProps !== void 0 && barProps.width && typeof barProps.width === 'number' ? barProps.width : barWidth,
|
|
92
|
+
height: undefined,
|
|
93
|
+
role: barRole
|
|
94
|
+
}));
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
BarChartBars.className = CLASSNAME;
|
|
98
|
+
BarChartBars.displayName = COMPONENT_NAME;
|
|
99
|
+
const BarChartGroupedTooltip = _ref => {
|
|
100
|
+
let {
|
|
101
|
+
dateFormatter,
|
|
102
|
+
categories,
|
|
103
|
+
categoryDecorator,
|
|
104
|
+
categoryColor,
|
|
105
|
+
datum,
|
|
106
|
+
groupedData
|
|
107
|
+
} = _ref;
|
|
108
|
+
return /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
109
|
+
flexDirection: "column",
|
|
110
|
+
margin: "16px",
|
|
111
|
+
gap: "0"
|
|
112
|
+
}, /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
113
|
+
flexDirection: "row",
|
|
114
|
+
gap: "8px"
|
|
115
|
+
}, /*#__PURE__*/React__default.createElement(Text, {
|
|
116
|
+
fontWeight: "400",
|
|
117
|
+
fontSize: "14px"
|
|
118
|
+
}, "Date:"), /*#__PURE__*/React__default.createElement(Text, {
|
|
119
|
+
fontWeight: "700",
|
|
120
|
+
fontSize: "14px"
|
|
121
|
+
}, dateFormatter(datum.data.key))), /*#__PURE__*/React__default.createElement("div", {
|
|
122
|
+
style: {
|
|
123
|
+
width: '100%',
|
|
124
|
+
height: '1px',
|
|
125
|
+
backgroundColor: '#858585',
|
|
126
|
+
margin: '8px 0'
|
|
127
|
+
}
|
|
128
|
+
}), /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
129
|
+
flexDirection: "row",
|
|
130
|
+
gap: "8px"
|
|
131
|
+
}, /*#__PURE__*/React__default.createElement(Text, {
|
|
132
|
+
fontWeight: "400",
|
|
133
|
+
fontSize: "14px"
|
|
134
|
+
}, "Total:"), /*#__PURE__*/React__default.createElement(Text, {
|
|
135
|
+
fontWeight: "600",
|
|
136
|
+
fontSize: "14px"
|
|
137
|
+
}, groupedData === null || groupedData === void 0 ? void 0 : groupedData.reduce((acc, d) => acc + d.value, 0))), /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
138
|
+
flexDirection: "column",
|
|
139
|
+
marginTop: "4px",
|
|
140
|
+
gap: "8px"
|
|
141
|
+
}, categories.map(category => {
|
|
142
|
+
var _groupedData$find;
|
|
143
|
+
const value = groupedData === null || groupedData === void 0 ? void 0 : (_groupedData$find = groupedData.find(d => d.category === category)) === null || _groupedData$find === void 0 ? void 0 : _groupedData$find.value;
|
|
144
|
+
const color = categoryColor(category);
|
|
145
|
+
return value ? /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
146
|
+
key: category,
|
|
147
|
+
alignItems: "center",
|
|
148
|
+
gap: "8px"
|
|
149
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
150
|
+
style: {
|
|
151
|
+
width: '16px',
|
|
152
|
+
height: '16px',
|
|
153
|
+
backgroundColor: color
|
|
154
|
+
}
|
|
155
|
+
}), /*#__PURE__*/React__default.createElement(Text, {
|
|
156
|
+
fontWeight: "400",
|
|
157
|
+
fontSize: "14px",
|
|
158
|
+
lineHeight: "18px"
|
|
159
|
+
}, categoryDecorator ? categoryDecorator(category) : category), /*#__PURE__*/React__default.createElement(Text, {
|
|
160
|
+
fontWeight: "600",
|
|
161
|
+
fontSize: "14px",
|
|
162
|
+
lineHeight: "18px"
|
|
163
|
+
}, value)) : null;
|
|
164
|
+
})));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export { BarChartBars, BarChartGroupedTooltip };
|
|
168
|
+
//# sourceMappingURL=BarChartBars.js.map
|