@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.
Files changed (223) hide show
  1. package/_virtual/_rollupPluginBabelHelpers.js +93 -0
  2. package/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/components/Arc/Arc.d.ts +6 -0
  4. package/components/Arc/Arc.js +74 -0
  5. package/components/Arc/Arc.js.map +1 -0
  6. package/components/Arc/styles.d.ts +17 -0
  7. package/components/Arc/styles.js +49 -0
  8. package/components/Arc/styles.js.map +1 -0
  9. package/components/Arc/types.d.ts +20 -0
  10. package/components/Arcs/Arcs.d.ts +6 -0
  11. package/components/Arcs/Arcs.js +90 -0
  12. package/components/Arcs/Arcs.js.map +1 -0
  13. package/components/Arcs/styles.d.ts +9 -0
  14. package/components/Arcs/styles.js +9 -0
  15. package/components/Arcs/styles.js.map +1 -0
  16. package/components/Arcs/types.d.ts +17 -0
  17. package/components/Axis/Axis.d.ts +7 -0
  18. package/components/Axis/Axis.js +211 -0
  19. package/components/Axis/Axis.js.map +1 -0
  20. package/components/Axis/computeTicks.js +117 -0
  21. package/components/Axis/computeTicks.js.map +1 -0
  22. package/components/Axis/styles.d.ts +14 -0
  23. package/components/Axis/styles.js +51 -0
  24. package/components/Axis/styles.js.map +1 -0
  25. package/components/Axis/types.d.ts +89 -0
  26. package/components/Axis/types.js +24 -0
  27. package/components/Axis/types.js.map +1 -0
  28. package/components/Bar/Bar.d.ts +6 -0
  29. package/components/Bar/Bar.js +95 -0
  30. package/components/Bar/Bar.js.map +1 -0
  31. package/components/Bar/styles.d.ts +16 -0
  32. package/components/Bar/styles.js +66 -0
  33. package/components/Bar/styles.js.map +1 -0
  34. package/components/Bar/types.d.ts +46 -0
  35. package/components/Bar/types.js +18 -0
  36. package/components/Bar/types.js.map +1 -0
  37. package/components/BarChart/BarChart.d.ts +29 -0
  38. package/components/BarChart/BarChart.js +141 -0
  39. package/components/BarChart/BarChart.js.map +1 -0
  40. package/components/BarChart/BarChartBars.js +168 -0
  41. package/components/BarChart/BarChartBars.js.map +1 -0
  42. package/components/BarChart/BarChartSection.js +139 -0
  43. package/components/BarChart/BarChartSection.js.map +1 -0
  44. package/components/BarChart/EmptyBarChart.js +57 -0
  45. package/components/BarChart/EmptyBarChart.js.map +1 -0
  46. package/components/BarChart/LoadingBarChart.js +18 -0
  47. package/components/BarChart/LoadingBarChart.js.map +1 -0
  48. package/components/BarChart/RenderedLinearBarChart.js +549 -0
  49. package/components/BarChart/RenderedLinearBarChart.js.map +1 -0
  50. package/components/BarChart/RenderedOrdinalBarChart.js +236 -0
  51. package/components/BarChart/RenderedOrdinalBarChart.js.map +1 -0
  52. package/components/BarChart/context.js +13 -0
  53. package/components/BarChart/context.js.map +1 -0
  54. package/components/BarChart/intl/en-US.json.js +17 -0
  55. package/components/BarChart/intl/en-US.json.js.map +1 -0
  56. package/components/BarChart/intl/fr-FR.json.js +17 -0
  57. package/components/BarChart/intl/fr-FR.json.js.map +1 -0
  58. package/components/BarChart/intl/index.js +10 -0
  59. package/components/BarChart/intl/index.js.map +1 -0
  60. package/components/BarChart/styles.d.ts +19 -0
  61. package/components/BarChart/styles.js +71 -0
  62. package/components/BarChart/styles.js.map +1 -0
  63. package/components/BarChart/types.d.ts +177 -0
  64. package/components/BarChart/types.js +17 -0
  65. package/components/BarChart/types.js.map +1 -0
  66. package/components/BarChart/utils.js +69 -0
  67. package/components/BarChart/utils.js.map +1 -0
  68. package/components/ChartContainer/ChartContainer.d.ts +9 -0
  69. package/components/ChartContainer/ChartContainer.js +167 -0
  70. package/components/ChartContainer/ChartContainer.js.map +1 -0
  71. package/components/ChartContainer/context.js +6 -0
  72. package/components/ChartContainer/context.js.map +1 -0
  73. package/components/ChartContainer/intl/en-US.json.js +14 -0
  74. package/components/ChartContainer/intl/en-US.json.js.map +1 -0
  75. package/components/ChartContainer/intl/fr-FR.json.js +14 -0
  76. package/components/ChartContainer/intl/fr-FR.json.js.map +1 -0
  77. package/components/ChartContainer/intl/index.js +10 -0
  78. package/components/ChartContainer/intl/index.js.map +1 -0
  79. package/components/ChartContainer/styles.d.ts +17 -0
  80. package/components/ChartContainer/styles.js +76 -0
  81. package/components/ChartContainer/styles.js.map +1 -0
  82. package/components/ChartContainer/types.d.ts +48 -0
  83. package/components/DataPoint/DataPoint.d.ts +6 -0
  84. package/components/DataPoint/DataPoint.js +104 -0
  85. package/components/DataPoint/DataPoint.js.map +1 -0
  86. package/components/DataPoint/styles.d.ts +12 -0
  87. package/components/DataPoint/styles.js +10 -0
  88. package/components/DataPoint/styles.js.map +1 -0
  89. package/components/DataPoint/types.d.ts +60 -0
  90. package/components/Dot/Dot.d.ts +6 -0
  91. package/components/Dot/Dot.js +55 -0
  92. package/components/Dot/Dot.js.map +1 -0
  93. package/components/Dot/styles.d.ts +16 -0
  94. package/components/Dot/styles.js +49 -0
  95. package/components/Dot/styles.js.map +1 -0
  96. package/components/Dot/types.d.ts +30 -0
  97. package/components/Dot/types.js +14 -0
  98. package/components/Dot/types.js.map +1 -0
  99. package/components/Legend/Legend.d.ts +6 -0
  100. package/components/Legend/Legend.js +73 -0
  101. package/components/Legend/Legend.js.map +1 -0
  102. package/components/Legend/styles.d.ts +11 -0
  103. package/components/Legend/styles.js +15 -0
  104. package/components/Legend/styles.js.map +1 -0
  105. package/components/Legend/types.d.ts +44 -0
  106. package/components/LegendItem/LegendItem.js +96 -0
  107. package/components/LegendItem/LegendItem.js.map +1 -0
  108. package/components/LegendItem/styles.js +63 -0
  109. package/components/LegendItem/styles.js.map +1 -0
  110. package/components/LegendItem/types.d.ts +20 -0
  111. package/components/Line/Line.d.ts +6 -0
  112. package/components/Line/Line.js +55 -0
  113. package/components/Line/Line.js.map +1 -0
  114. package/components/Line/styles.d.ts +9 -0
  115. package/components/Line/styles.js +9 -0
  116. package/components/Line/styles.js.map +1 -0
  117. package/components/Line/types.d.ts +21 -0
  118. package/components/LineChart/EmptyLineChart.js +58 -0
  119. package/components/LineChart/EmptyLineChart.js.map +1 -0
  120. package/components/LineChart/LineChart.d.ts +6 -0
  121. package/components/LineChart/LineChart.js +96 -0
  122. package/components/LineChart/LineChart.js.map +1 -0
  123. package/components/LineChart/LoadingLineChart.js +18 -0
  124. package/components/LineChart/LoadingLineChart.js.map +1 -0
  125. package/components/LineChart/RenderedLineChart.js +372 -0
  126. package/components/LineChart/RenderedLineChart.js.map +1 -0
  127. package/components/LineChart/intl/en-US.json.js +17 -0
  128. package/components/LineChart/intl/en-US.json.js.map +1 -0
  129. package/components/LineChart/intl/fr-FR.json.js +17 -0
  130. package/components/LineChart/intl/fr-FR.json.js.map +1 -0
  131. package/components/LineChart/intl/index.js +10 -0
  132. package/components/LineChart/intl/index.js.map +1 -0
  133. package/components/LineChart/styles.d.ts +17 -0
  134. package/components/LineChart/styles.js +53 -0
  135. package/components/LineChart/styles.js.map +1 -0
  136. package/components/LineChart/types.d.ts +90 -0
  137. package/components/LineChart/types.js +17 -0
  138. package/components/LineChart/types.js.map +1 -0
  139. package/components/LineChart/utils.js +67 -0
  140. package/components/LineChart/utils.js.map +1 -0
  141. package/components/PieChart/EmptyPieChart.js +85 -0
  142. package/components/PieChart/EmptyPieChart.js.map +1 -0
  143. package/components/PieChart/LoadingPieChart.js +18 -0
  144. package/components/PieChart/LoadingPieChart.js.map +1 -0
  145. package/components/PieChart/PieChart.d.ts +6 -0
  146. package/components/PieChart/PieChart.js +98 -0
  147. package/components/PieChart/PieChart.js.map +1 -0
  148. package/components/PieChart/RenderedPieChart.js +198 -0
  149. package/components/PieChart/RenderedPieChart.js.map +1 -0
  150. package/components/PieChart/intl/en-US.json.js +9 -0
  151. package/components/PieChart/intl/en-US.json.js.map +1 -0
  152. package/components/PieChart/intl/fr-FR.json.js +9 -0
  153. package/components/PieChart/intl/fr-FR.json.js.map +1 -0
  154. package/components/PieChart/intl/index.js +10 -0
  155. package/components/PieChart/intl/index.js.map +1 -0
  156. package/components/PieChart/styles.d.ts +24 -0
  157. package/components/PieChart/styles.js +168 -0
  158. package/components/PieChart/styles.js.map +1 -0
  159. package/components/PieChart/types.d.ts +115 -0
  160. package/components/PieChart/types.js +27 -0
  161. package/components/PieChart/types.js.map +1 -0
  162. package/components/PieChart/utils.js +37 -0
  163. package/components/PieChart/utils.js.map +1 -0
  164. package/components/ScatterPlot/EmptyScatterPlot.js +58 -0
  165. package/components/ScatterPlot/EmptyScatterPlot.js.map +1 -0
  166. package/components/ScatterPlot/LoadingScatterPlot.js +18 -0
  167. package/components/ScatterPlot/LoadingScatterPlot.js.map +1 -0
  168. package/components/ScatterPlot/RenderedScatterPlot.js +352 -0
  169. package/components/ScatterPlot/RenderedScatterPlot.js.map +1 -0
  170. package/components/ScatterPlot/ScatterPlot.d.ts +6 -0
  171. package/components/ScatterPlot/ScatterPlot.js +105 -0
  172. package/components/ScatterPlot/ScatterPlot.js.map +1 -0
  173. package/components/ScatterPlot/intl/en-US.json.js +12 -0
  174. package/components/ScatterPlot/intl/en-US.json.js.map +1 -0
  175. package/components/ScatterPlot/intl/fr-FR.json.js +17 -0
  176. package/components/ScatterPlot/intl/fr-FR.json.js.map +1 -0
  177. package/components/ScatterPlot/intl/index.js +10 -0
  178. package/components/ScatterPlot/intl/index.js.map +1 -0
  179. package/components/ScatterPlot/styles.d.ts +17 -0
  180. package/components/ScatterPlot/styles.js +53 -0
  181. package/components/ScatterPlot/styles.js.map +1 -0
  182. package/components/ScatterPlot/types.d.ts +109 -0
  183. package/components/ScatterPlot/types.js +24 -0
  184. package/components/ScatterPlot/types.js.map +1 -0
  185. package/components/ScatterPlot/utils.js +70 -0
  186. package/components/ScatterPlot/utils.js.map +1 -0
  187. package/config.js +15 -0
  188. package/config.js.map +1 -0
  189. package/design-system/src/react-aria/react-aria/i18n/useMessageFormatter.d.ts +5 -0
  190. package/hooks/useBrush.d.ts +17 -0
  191. package/hooks/useBrush.js +48 -0
  192. package/hooks/useBrush.js.map +1 -0
  193. package/hooks/useColor.d.ts +18 -0
  194. package/hooks/useColor.js +20 -0
  195. package/hooks/useColor.js.map +1 -0
  196. package/hooks/useFormatCategoricalData.d.ts +26 -0
  197. package/hooks/useFormatCategoricalData.js +57 -0
  198. package/hooks/useFormatCategoricalData.js.map +1 -0
  199. package/hooks/useZoom.d.ts +26 -0
  200. package/hooks/useZoom.js +39 -0
  201. package/hooks/useZoom.js.map +1 -0
  202. package/index.d.ts +51 -1277
  203. package/index.js +42 -5118
  204. package/index.js.map +1 -1
  205. package/package.json +4 -4
  206. package/scheme.d.ts +32 -0
  207. package/scheme.js +47 -0
  208. package/scheme.js.map +1 -0
  209. package/types/axis.d.ts +48 -0
  210. package/types/data.d.ts +72 -0
  211. package/types/legend.d.ts +30 -0
  212. package/types/legend.js +21 -0
  213. package/types/legend.js.map +1 -0
  214. package/types/scale.d.ts +48 -0
  215. package/types/size.d.ts +20 -0
  216. package/types/size.js +8 -0
  217. package/types/size.js.map +1 -0
  218. package/types/theme.d.ts +23 -0
  219. package/types/theme.js +13 -0
  220. package/types/theme.js.map +1 -0
  221. package/utils/index.d.ts +11 -0
  222. package/utils/index.js +44 -0
  223. package/utils/index.js.map +1 -0
@@ -0,0 +1,549 @@
1
+ import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import React__default, { forwardRef, useRef, useMemo, useEffect } from 'react';
3
+ import { extent, scaleLinear, scaleUtc, scalePoint, utcParse, scaleLog } from 'd3';
4
+ import { useTheme, useMessageFormatter, isComponent, Flexbox } from '@redsift/design-system';
5
+ import intlMessages from './intl/index.js';
6
+ import { BarChartLegendVariant } from './types.js';
7
+ import { StyledBarChart } from './styles.js';
8
+ import { sizeToDimension, statsBy } from './utils.js';
9
+ import { isValidDate, getSortingMethod, mergeLegends } from '../../utils/index.js';
10
+ import { BarChartContext } from './context.js';
11
+ import { ChartTypeContext } from '../ChartContainer/context.js';
12
+ import { BarChartBars } from './BarChartBars.js';
13
+ import { BarDirection } from '../Bar/types.js';
14
+ import { useColor } from '../../hooks/useColor.js';
15
+ import { getAxisType, Axis } from '../Axis/Axis.js';
16
+ import { Legend } from '../Legend/Legend.js';
17
+ import { AxisVariant } from '../Axis/types.js';
18
+ import { LegendVariant } from '../../types/legend.js';
19
+
20
+ const _excluded = ["barProps", "children", "className", "data", "direction", "disableAnimations", "id", "getBarAnchorProps", "isBarSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "tooltipDecorator", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "xAxisStartDateOffset", "xAxisEndDateOffset", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "xScaleType", "yScaleLogBase", "dateParser"],
21
+ _excluded2 = ["extraLegendItems"];
22
+ const COMPONENT_TYPES = {
23
+ AXES: 'Axis',
24
+ SECTIONS: 'BarChartSection',
25
+ BARS: 'BarChartBars',
26
+ LEGENDS: 'Legend'
27
+ };
28
+ const getComponentPosition = child => {
29
+ var _child$type;
30
+ if (! /*#__PURE__*/React__default.isValidElement(child)) return null;
31
+ const displayName = (_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.displayName;
32
+ if (COMPONENT_TYPES.AXES === displayName) return 'axes';
33
+ if (COMPONENT_TYPES.SECTIONS === displayName) return 'sections';
34
+ if (COMPONENT_TYPES.BARS === displayName) return 'bars';
35
+ if (COMPONENT_TYPES.LEGENDS === displayName) return 'legend';
36
+ return null;
37
+ };
38
+ const getKey = datum => Array.isArray(datum.key) ? datum.key[0] : datum.key;
39
+ const filterData = (hasCategory, data, filterFn) => {
40
+ if (hasCategory) {
41
+ return data.filter(filterFn);
42
+ }
43
+ return data.filter(filterFn);
44
+ };
45
+ const reduceData = (hasCategory, data, reduceFn, initialValue) => {
46
+ if (hasCategory) {
47
+ return data.reduce(reduceFn, initialValue);
48
+ }
49
+ return data.reduce(reduceFn, initialValue);
50
+ };
51
+ const isSameKey = (key, previousKey, xScaleType) => xScaleType === 'Date' || xScaleType === 'dateString' ? key.getTime() === previousKey.getTime() : key === previousKey;
52
+ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
53
+ var _chartDimensions$maxW, _chartDimensions$minW;
54
+ const {
55
+ barProps,
56
+ children,
57
+ className,
58
+ data: propsData,
59
+ direction = BarDirection.up,
60
+ disableAnimations,
61
+ id,
62
+ getBarAnchorProps,
63
+ isBarSelected,
64
+ labelDecorator,
65
+ legendDecorator,
66
+ legendVariant,
67
+ legendProps,
68
+ margins: propsMargins,
69
+ onBarClick,
70
+ size,
71
+ sortingMethod: propsSortingMethod,
72
+ barRole,
73
+ colorTheme,
74
+ tooltipVariant,
75
+ tooltipDecorator,
76
+ xAxisVariant: propsXAxisVariant,
77
+ xAxisPlacement,
78
+ xAxisTickFormat: propsXAxisTickFormat,
79
+ xAxisTickPadding,
80
+ xAxisTickRotation,
81
+ xAxisTickSize,
82
+ xAxisTickValues,
83
+ xAxisMinValue,
84
+ xAxisMaxValue,
85
+ xAxisTickRemodelling,
86
+ xAxisStartDateOffset = -1,
87
+ xAxisEndDateOffset = 1,
88
+ yAxisVariant: propsYAxisVariant,
89
+ yAxisPlacement,
90
+ yAxisTickFormat,
91
+ yAxisTickPadding,
92
+ yAxisTickRotation,
93
+ yAxisTickSize,
94
+ yAxisTickValues,
95
+ yAxisMinValue,
96
+ yAxisMaxValue,
97
+ yAxisTickRemodelling,
98
+ xScaleType: propsXScaleType,
99
+ yScaleLogBase,
100
+ dateParser
101
+ } = props,
102
+ forwardedProps = _objectWithoutProperties(props, _excluded);
103
+ const cache = useRef();
104
+ const theme = useTheme();
105
+ const format = useMessageFormatter(intlMessages);
106
+ const hasCategory = propsData[0] && Array.isArray(propsData[0].key) && propsData[0].key.length >= 2 && propsData[0].key[1] !== null && propsData[0].key[1] !== undefined;
107
+ const sections = useMemo(() => {
108
+ const sectionList = [];
109
+ React__default.Children.forEach(children, child => {
110
+ if (isComponent('BarChartSection')(child)) {
111
+ const categories = React__default.Children.toArray(child.props.children).filter(c => isComponent('BarChartBars')(c)).map(c => c.props.category);
112
+ sectionList.push(categories);
113
+ }
114
+ });
115
+ return sectionList;
116
+ }, [children]);
117
+ const hasSections = sections.length > 0;
118
+ const sortingMethod = hasSections ? sections.flat() : propsSortingMethod;
119
+ const xScaleType = propsXScaleType ? propsXScaleType : getKey(propsData[0]) instanceof Date ? 'Date' : typeof getKey(propsData[0]) === 'number' ? 'number' : typeof getKey(propsData[0]) === 'string' && isValidDate(getKey(propsData[0])) ? 'dateString' : undefined;
120
+ const data = xScaleType === 'number' ? filterData(hasCategory, propsData, datum => typeof getKey(datum) === 'number' && !Number.isNaN(getKey(datum))) : xScaleType === 'dateString' ? filterData(hasCategory, propsData, datum => isValidDate(getKey(datum))) : xScaleType === 'Date' ? filterData(hasCategory, propsData, datum => getKey(datum) instanceof Date) : propsData;
121
+ useEffect(() => {
122
+ cache.current = data;
123
+ });
124
+ const svgRef = useRef();
125
+ const xAxisVariant = propsXAxisVariant ? propsXAxisVariant : AxisVariant.tickValue;
126
+ const yAxisVariant = propsYAxisVariant ? propsYAxisVariant : AxisVariant.default;
127
+ const chartDimensions = sizeToDimension(size);
128
+ const width = Math.max(Math.min(chartDimensions.width, (_chartDimensions$maxW = chartDimensions.maxWidth) !== null && _chartDimensions$maxW !== void 0 ? _chartDimensions$maxW : Infinity), (_chartDimensions$minW = chartDimensions.minWidth) !== null && _chartDimensions$minW !== void 0 ? _chartDimensions$minW : -Infinity);
129
+ const height = chartDimensions.height;
130
+ const margins = _objectSpread2({
131
+ top: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8,
132
+ left: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
133
+ right: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
134
+ bottom: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8
135
+ }, propsMargins);
136
+ const chartHeight = height - margins.top - margins.bottom;
137
+ const chartWidth = width - margins.left - margins.right;
138
+ const numberOfBars = filterData(hasCategory, data, datum => datum.value).length;
139
+ const gap = 5;
140
+ let barWidth = chartWidth / (numberOfBars * 2) - gap;
141
+ const scaleX = (() => {
142
+ if (xScaleType === 'number') {
143
+ var _ref, _ref2;
144
+ const domain = extent(data, d => getKey(d));
145
+ domain[0] = (_ref = xAxisMinValue) !== null && _ref !== void 0 ? _ref : domain[0];
146
+ domain[1] = (_ref2 = xAxisMaxValue) !== null && _ref2 !== void 0 ? _ref2 : domain[1];
147
+ const gap = domain[1] - domain[0];
148
+ domain[0] -= gap * 0.1;
149
+ domain[1] += gap * 0.1;
150
+ return scaleLinear().domain(domain).range([0, chartWidth]).nice();
151
+ } else if (xScaleType === 'dateString' || xScaleType === 'Date') {
152
+ var _ref3, _ref4;
153
+ const domain = xScaleType === 'dateString' ? extent(data, d => Date.parse(getKey(d))) : extent(data, d => getKey(d).valueOf());
154
+ domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
155
+ domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
156
+ const startDate = xAxisTickValues && typeof xAxisTickValues === 'function' && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[0]), xAxisStartDateOffset) : new Date(domain[0]);
157
+ const endDate = xAxisTickValues && typeof xAxisTickValues === 'function' && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[1]), xAxisEndDateOffset) : new Date(domain[1]);
158
+ return barProps !== null && barProps !== void 0 && barProps.width && typeof barProps.width === 'number' ? scaleUtc().domain([startDate, endDate]).range([barProps.width / 2 + 10, chartWidth - (barProps.width / 2 + 5)]) : scaleUtc().domain([startDate, endDate]).range([barWidth, chartWidth - barWidth]).nice();
159
+ } else {
160
+ var _ref5, _ref6;
161
+ const domain = xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => getKey(d));
162
+ domain[0] = (_ref5 = xAxisMinValue) !== null && _ref5 !== void 0 ? _ref5 : domain[0];
163
+ domain[1] = (_ref6 = xAxisMaxValue) !== null && _ref6 !== void 0 ? _ref6 : domain[1];
164
+ return scalePoint().domain(domain).range([0, chartWidth]);
165
+ }
166
+ })();
167
+ const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
168
+ const statsByCategory = statsBy(data, sortingMethod);
169
+ const colorScale = useColor({
170
+ data: statsByCategory,
171
+ colorTheme: colorTheme,
172
+ category: d => d.key,
173
+ theme
174
+ });
175
+ const bars = reduceData(hasCategory, filterData(hasCategory, data.sort((a, b) => {
176
+ const currentKeyA = hasCategory ? a.key[0] : a.key;
177
+ const currentKeyB = hasCategory ? b.key[0] : b.key;
178
+ if (xScaleType === 'number') {
179
+ if (currentKeyA < currentKeyB) return -1;
180
+ if (currentKeyA > currentKeyB) return 1;
181
+ } else if (xScaleType === 'dateString') {
182
+ if (Date.parse(currentKeyA) < Date.parse(currentKeyB)) return -1;
183
+ if (Date.parse(currentKeyA) > Date.parse(currentKeyB)) return 1;
184
+ } else if (xScaleType === 'Date') {
185
+ if (currentKeyA.valueOf() < currentKeyB.valueOf()) return -1;
186
+ if (currentKeyA.valueOf() > currentKeyB.valueOf()) return 1;
187
+ } else if (xScaleType === 'string' && xAxisTickValues && Array.isArray(xAxisTickValues)) {
188
+ if (xAxisTickValues.indexOf(currentKeyA) < xAxisTickValues.indexOf(currentKeyB)) return -1;
189
+ if (xAxisTickValues.indexOf(currentKeyA) > xAxisTickValues.indexOf(currentKeyB)) return 1;
190
+ }
191
+ return hasCategory ? getSortingMethod(sortingMethod !== null && sortingMethod !== void 0 ? sortingMethod : 'asc-key')({
192
+ key: a.key[1],
193
+ value: a.value
194
+ }, {
195
+ key: b.key[1],
196
+ value: b.value
197
+ }) : 0;
198
+ }), d => d.value !== null), (previousValue, currentValue, currentIndex) => {
199
+ var _key$;
200
+ const currentKeyD = hasCategory ? currentValue.key[0] : currentValue.key;
201
+ const formattedKeyD = xScaleType === 'dateString' ? dateParser ? dateParser(currentKeyD) : utcParse('%Y-%m-%d')(currentKeyD) : currentKeyD;
202
+ const category = hasCategory ? (_key$ = currentValue.key[1]) !== null && _key$ !== void 0 ? _key$ : 'default' : 'default';
203
+ const isSameSection = !hasSections ? true : (() => {
204
+ var _previousValue;
205
+ const findSectionIndex = cat => sections.findIndex(section => section.includes(cat));
206
+ const currentSection = findSectionIndex(category);
207
+ const prevSection = findSectionIndex((_previousValue = previousValue[currentIndex - 1]) === null || _previousValue === void 0 ? void 0 : _previousValue.category);
208
+ return currentSection !== -1 && currentSection === prevSection;
209
+ })();
210
+ previousValue.push({
211
+ category,
212
+ key: formattedKeyD,
213
+ value: currentValue.value,
214
+ cumulativeValue: currentValue.value
215
+ });
216
+ if (hasCategory && currentIndex > 0 && isSameKey(formattedKeyD, previousValue[currentIndex - 1].key, xScaleType) && isSameSection) {
217
+ previousValue[currentIndex].cumulativeValue = previousValue[currentIndex].cumulativeValue + previousValue[currentIndex - 1].cumulativeValue;
218
+ }
219
+ return previousValue;
220
+ }, []).filter(bar => yScaleLogBase === undefined || bar.cumulativeValue !== 0);
221
+ const getScaleY = function (direction) {
222
+ var _ref7, _ref8;
223
+ let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
224
+ let to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
225
+ let categories = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['default'];
226
+ let hasSectionTitle = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
227
+ const domain = extent(bars.filter(bar => categories.includes(bar.category)), d => d.cumulativeValue);
228
+ domain[0] = (_ref7 = yAxisMinValue) !== null && _ref7 !== void 0 ? _ref7 : domain[0];
229
+ domain[1] = (_ref8 = yAxisMaxValue) !== null && _ref8 !== void 0 ? _ref8 : domain[1] * (hasSectionTitle ? 1.2 : 1);
230
+ if (domain[1] === 0 && domain[0] === 0) {
231
+ domain[1] = 1;
232
+ }
233
+ return (yScaleLogBase ? scaleLog().clamp(true).base(yScaleLogBase) : scaleLinear()).domain(domain).range(direction === 'down' ? [0, chartHeight * to - chartHeight * from] : [chartHeight * to - chartHeight * from, 0]).nice();
234
+ };
235
+ if (xScaleType) {
236
+ const minimalGap = Math.min(...bars.map((bar, i) => i > 0 ? Math.abs(bar.key - bars[i - 1].key) : undefined).filter(k => k)) * 0.9;
237
+ barWidth = Math.min(barWidth, chartWidth / ((scaleX.domain()[1] - scaleX.domain()[0]) / minimalGap), chartWidth / (xAxisTickValues && typeof xAxisTickValues !== 'string' ? typeof xAxisTickValues === 'number' ? xAxisTickValues : Array.isArray(xAxisTickValues) ? xAxisTickValues.length : xAxisTickValues.range(scaleX.domain()[0], scaleX.domain()[1]).length : 1));
238
+ }
239
+ const categories = sortingMethod && Array.isArray(sortingMethod) ? sortingMethod : [];
240
+ const pivotedTable = bars.reduce((acc, item) => {
241
+ const {
242
+ key,
243
+ category,
244
+ value
245
+ } = item;
246
+ if (!categories.includes(category)) {
247
+ categories.push(category);
248
+ }
249
+ const formattedKey = xAxisTickFormat ? xAxisTickFormat(key) : key.toString();
250
+ let entry = acc.find(e => e.key === formattedKey);
251
+ if (!entry) {
252
+ entry = {
253
+ key: formattedKey
254
+ };
255
+ acc.push(entry);
256
+ }
257
+ entry[category] = value;
258
+ return acc;
259
+ }, []);
260
+ const scaleY = getScaleY(direction, 0, 1, categories);
261
+ const _ref9 = legendProps || {},
262
+ {
263
+ extraLegendItems
264
+ } = _ref9,
265
+ forwardedLegendProps = _objectWithoutProperties(_ref9, _excluded2);
266
+ const {
267
+ axisComponents,
268
+ sectionComponents,
269
+ barsComponents,
270
+ legendComponents,
271
+ titleComponent,
272
+ descriptionComponent,
273
+ multipleScaleY
274
+ } = useMemo(() => {
275
+ const axisComponents = [];
276
+ const sectionComponents = [];
277
+ const barsComponents = [];
278
+ const legendComponents = [];
279
+ let titleComponent;
280
+ let descriptionComponent;
281
+ const multipleScaleY = [];
282
+ React__default.Children.forEach(children, (child, index) => {
283
+ const position = getComponentPosition(child);
284
+ if (isComponent('ChartContainerTitle')(child)) {
285
+ titleComponent = child;
286
+ }
287
+ if (isComponent('ChartContainerDescription')(child)) {
288
+ descriptionComponent = child;
289
+ }
290
+ if (!position || ! /*#__PURE__*/React__default.isValidElement(child)) return;
291
+ let enhancedChild = child;
292
+ if (isComponent('BarChartSection')(child)) {
293
+ const categories = React__default.Children.toArray(child.props.children).filter(c => isComponent('BarChartBars')(c)).map(c => c.props.category);
294
+ const scaleY = getScaleY(child.props.direction || 'up', child.props.from, child.props.to, categories, child.props.title !== '');
295
+ multipleScaleY.push(scaleY);
296
+ enhancedChild = /*#__PURE__*/React__default.cloneElement(child, _objectSpread2({
297
+ scaleX: scaleX,
298
+ scaleY: scaleY,
299
+ key: child.key || `section-${child.props.from}-${child.props.to}-${categories.join('-')}`
300
+ }, child.props));
301
+ }
302
+ if (isComponent('Axis')(child)) {
303
+ var _ref10;
304
+ const isX = getAxisType(child.props.position) === 'x';
305
+ enhancedChild = /*#__PURE__*/React__default.cloneElement(child, _objectSpread2({
306
+ key: child.key || `axis-${child.props.position}-${index}`,
307
+ chartWidth,
308
+ chartHeight,
309
+ scale: isX ? scaleX : scaleY,
310
+ x: child.props.position === 'right' ? chartWidth : 0,
311
+ y: child.props.position === 'bottom' ? chartHeight : child.props.position === 'top' ? 0 : chartHeight,
312
+ disableAnimations,
313
+ length: isX ? chartWidth : chartHeight,
314
+ tickValues: (_ref10 = isX ? xAxisTickValues : yAxisTickValues) !== null && _ref10 !== void 0 ? _ref10 : 8,
315
+ tickPadding: isX ? xAxisTickPadding : yAxisTickPadding,
316
+ tickRotation: isX ? xAxisTickRotation : yAxisTickRotation,
317
+ tickSize: isX ? xAxisTickSize : yAxisTickSize,
318
+ tickFormat: isX ? xAxisTickFormat : yAxisTickFormat,
319
+ tickRemodelling: isX ? xAxisTickRemodelling : yAxisTickRemodelling,
320
+ variant: isX ? xAxisVariant : yAxisVariant
321
+ }, child.props));
322
+ }
323
+ if (isComponent('Legend')(child)) {
324
+ enhancedChild = /*#__PURE__*/React__default.cloneElement(child, _objectSpread2({
325
+ key: child.key || `legend-${index}`,
326
+ data: (extraLegendItems ? mergeLegends(extraLegendItems, statsByCategory).sort(getSortingMethod(sortingMethod)) : statsByCategory).map(d => _objectSpread2(_objectSpread2({}, d), {}, {
327
+ color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
328
+ }))
329
+ }, child.props));
330
+ }
331
+ switch (position) {
332
+ case 'axes':
333
+ axisComponents.push(enhancedChild);
334
+ break;
335
+ case 'sections':
336
+ sectionComponents.push(enhancedChild);
337
+ break;
338
+ case 'bars':
339
+ barsComponents.push(enhancedChild);
340
+ break;
341
+ case 'legend':
342
+ legendComponents.push(enhancedChild);
343
+ break;
344
+ }
345
+ });
346
+ return {
347
+ axisComponents,
348
+ sectionComponents,
349
+ barsComponents,
350
+ legendComponents,
351
+ titleComponent,
352
+ descriptionComponent,
353
+ multipleScaleY
354
+ };
355
+ }, [children]);
356
+ return /*#__PURE__*/React__default.createElement(ChartTypeContext.Provider, {
357
+ value: "bar"
358
+ }, /*#__PURE__*/React__default.createElement(BarChartContext.Provider, {
359
+ value: {
360
+ barProps,
361
+ barRole,
362
+ bars: bars,
363
+ barWidth,
364
+ cache,
365
+ categories,
366
+ chartHeight,
367
+ chartWidth,
368
+ colorScale,
369
+ direction,
370
+ disableAnimations,
371
+ format,
372
+ gap,
373
+ getBarAnchorProps,
374
+ hasCategory,
375
+ id,
376
+ isBarSelected,
377
+ labelDecorator,
378
+ margins,
379
+ onBarClick,
380
+ scaleX,
381
+ scaleY,
382
+ tooltipVariant,
383
+ tooltipDecorator,
384
+ xAxisTickFormat,
385
+ xAxisTickPadding,
386
+ xAxisTickRemodelling,
387
+ xAxisTickRotation,
388
+ xAxisTickSize,
389
+ xAxisTickValues,
390
+ xAxisVariant,
391
+ xScaleType,
392
+ yAxisTickValues,
393
+ yAxisTickPadding,
394
+ yAxisTickRotation,
395
+ yAxisTickSize,
396
+ yAxisTickFormat,
397
+ yAxisTickRemodelling,
398
+ yAxisVariant
399
+ }
400
+ }, /*#__PURE__*/React__default.createElement(StyledBarChart, _extends({
401
+ mode: typeof onBarClick === 'function' || typeof getBarAnchorProps === 'function' ? 'interactive' : 'static',
402
+ definition: hasCategory ? format('definition-linear-with-categories', {
403
+ categoryLength: categories.length,
404
+ barLength: bars.length
405
+ }) : format('definition-linear', {
406
+ barLength: bars.length
407
+ }),
408
+ xAxisDefinition: format(`x-axis-${xScaleType === 'number' ? 'numbers' : 'dates'}-definition`, {
409
+ numAxis: xAxisPlacement === 'both' ? 2 : 1,
410
+ start: xAxisTickFormat ? xAxisTickFormat(scaleX.domain()[0]) : scaleX.domain()[0],
411
+ end: xAxisTickFormat ? xAxisTickFormat(scaleX.domain()[1]) : scaleX.domain()[1]
412
+ }),
413
+ yAxisDefinition: multipleScaleY.length > 0 ? multipleScaleY.map(scale => format('y-axis-numbers-definition', {
414
+ numAxis: yAxisPlacement === 'both' ? 2 : 1,
415
+ start: scale.domain()[0],
416
+ end: scale.domain()[1]
417
+ })).join(' ') : format('y-axis-numbers-definition', {
418
+ numAxis: yAxisPlacement === 'both' ? 2 : 1,
419
+ start: scaleY.domain()[0],
420
+ end: scaleY.domain()[1]
421
+ }),
422
+ dataTableRepresentation: hasCategory ? {
423
+ header: /*#__PURE__*/React__default.createElement("thead", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("th", {
424
+ scope: "col"
425
+ }, xScaleType === 'Date' || xScaleType === 'dateString' ? 'Date' : 'Key'), categories.map(category => /*#__PURE__*/React__default.createElement("th", {
426
+ key: category,
427
+ scope: "col"
428
+ }, category)))),
429
+ body: /*#__PURE__*/React__default.createElement("tbody", null, pivotedTable.map(row => /*#__PURE__*/React__default.createElement("tr", {
430
+ key: row.key
431
+ }, /*#__PURE__*/React__default.createElement("th", {
432
+ scope: "row"
433
+ }, row.key), categories.map(category => /*#__PURE__*/React__default.createElement("th", {
434
+ key: `${row.key}-${category}-${row[category]}`,
435
+ scope: "col"
436
+ }, row[category])))))
437
+ } : {
438
+ header: /*#__PURE__*/React__default.createElement("thead", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("th", {
439
+ scope: "col"
440
+ }, xScaleType === 'Date' || xScaleType === 'dateString' ? 'Date' : 'Key'), /*#__PURE__*/React__default.createElement("th", {
441
+ scope: "col"
442
+ }, "Value"))),
443
+ body: /*#__PURE__*/React__default.createElement("tbody", null, bars.map(datum => {
444
+ const key = xAxisTickFormat ? xAxisTickFormat(datum.key) : datum.key.toString();
445
+ return /*#__PURE__*/React__default.createElement("tr", {
446
+ key: key
447
+ }, /*#__PURE__*/React__default.createElement("th", {
448
+ scope: "row"
449
+ }, key), /*#__PURE__*/React__default.createElement("td", null, datum.value));
450
+ }))
451
+ },
452
+ title: titleComponent,
453
+ description: descriptionComponent
454
+ }, forwardedProps, {
455
+ id: id,
456
+ className: className,
457
+ ref: ref
458
+ }), /*#__PURE__*/React__default.createElement(Flexbox, {
459
+ flexDirection: "column",
460
+ alignItems: "center",
461
+ gap: "8"
462
+ }, /*#__PURE__*/React__default.createElement("svg", {
463
+ ref: svgRef,
464
+ width: width,
465
+ height: height,
466
+ "aria-label": typeof onBarClick === 'function' || typeof getBarAnchorProps === 'function' ? format('interactive-chart') : format('static-chart'),
467
+ "aria-hidden": "false"
468
+ }, axisComponents.length === 0 && sectionComponents.length === 0 ? /*#__PURE__*/React__default.createElement("g", {
469
+ transform: `translate(${margins.left},${margins.top})`,
470
+ "aria-hidden": "true"
471
+ }, ['bottom', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
472
+ disableAnimations: disableAnimations,
473
+ position: "bottom",
474
+ length: chartWidth,
475
+ scale: scaleX,
476
+ x: 0,
477
+ y: chartHeight,
478
+ tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
479
+ tickPadding: xAxisTickPadding,
480
+ tickRotation: xAxisTickRotation,
481
+ tickSize: xAxisTickSize,
482
+ tickFormat: xAxisTickFormat,
483
+ tickRemodelling: xAxisTickRemodelling,
484
+ variant: xAxisVariant
485
+ }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
486
+ disableAnimations: disableAnimations,
487
+ position: "top",
488
+ length: chartWidth,
489
+ scale: scaleX,
490
+ x: 0,
491
+ y: 0,
492
+ tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
493
+ tickPadding: xAxisTickPadding,
494
+ tickRotation: xAxisTickRotation,
495
+ tickSize: xAxisTickSize,
496
+ tickFormat: xAxisTickFormat,
497
+ tickRemodelling: xAxisTickRemodelling,
498
+ variant: xAxisVariant
499
+ }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
500
+ disableAnimations: disableAnimations,
501
+ position: "left",
502
+ length: chartHeight,
503
+ scale: scaleY,
504
+ x: 0,
505
+ y: chartHeight,
506
+ tickValues: yAxisTickValues !== null && yAxisTickValues !== void 0 ? yAxisTickValues : 8,
507
+ tickPadding: yAxisTickPadding,
508
+ tickRotation: yAxisTickRotation,
509
+ tickSize: yAxisTickSize,
510
+ tickFormat: yAxisTickFormat,
511
+ tickRemodelling: yAxisTickRemodelling,
512
+ variant: yAxisVariant
513
+ }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
514
+ disableAnimations: disableAnimations,
515
+ position: "right",
516
+ length: chartHeight,
517
+ scale: scaleY,
518
+ x: chartWidth,
519
+ y: chartHeight,
520
+ tickValues: yAxisTickValues !== null && yAxisTickValues !== void 0 ? yAxisTickValues : 8,
521
+ tickPadding: yAxisTickPadding,
522
+ tickRotation: yAxisTickRotation,
523
+ tickSize: yAxisTickSize,
524
+ tickFormat: yAxisTickFormat,
525
+ tickRemodelling: yAxisTickRemodelling,
526
+ variant: yAxisVariant
527
+ }) : null) : /*#__PURE__*/React__default.createElement("g", {
528
+ transform: `translate(${margins.left},${margins.top})`,
529
+ "aria-hidden": "true"
530
+ }, axisComponents), sectionComponents, barsComponents.length === 0 && sectionComponents.length === 0 ? /*#__PURE__*/React__default.createElement("g", {
531
+ transform: `translate(${margins.left},${margins.top})`,
532
+ "aria-hidden": "true"
533
+ }, (hasSections ? sections : [categories]).map(section => section.map(category => /*#__PURE__*/React__default.createElement(BarChartBars, {
534
+ key: category,
535
+ category: category
536
+ }))), ' ') : /*#__PURE__*/React__default.createElement("g", {
537
+ transform: `translate(${margins.left},${margins.top})`,
538
+ "aria-hidden": "true"
539
+ }, barsComponents))), legendComponents.length === 0 && hasCategory && legendVariant !== BarChartLegendVariant.none ? /*#__PURE__*/React__default.createElement(Legend, _extends({
540
+ data: (extraLegendItems ? mergeLegends(extraLegendItems, statsByCategory).sort(getSortingMethod(sortingMethod)) : statsByCategory).map(d => _objectSpread2(_objectSpread2({}, d), {}, {
541
+ color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
542
+ })),
543
+ variant: legendVariant === BarChartLegendVariant.externalLabelValue ? LegendVariant.value : legendVariant === BarChartLegendVariant.externalLabelPercent ? LegendVariant.percent : legendVariant === BarChartLegendVariant.externalLabel ? LegendVariant.label : LegendVariant.custom,
544
+ legendDecorator: legendDecorator ? (datum, props) => legendDecorator(datum, props) : undefined
545
+ }, forwardedLegendProps)) : legendComponents)));
546
+ });
547
+
548
+ export { COMPONENT_TYPES, RenderedLinearBarChart, getComponentPosition };
549
+ //# sourceMappingURL=RenderedLinearBarChart.js.map