@redsift/charts 11.5.0 → 11.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/Arc.js +2 -0
- package/_internal/Arc.js.map +1 -0
- package/_internal/Arc2.js +117 -0
- package/_internal/Arc2.js.map +1 -0
- package/_internal/Arcs.js +2 -0
- package/_internal/Arcs.js.map +1 -0
- package/_internal/Arcs2.js +94 -0
- package/_internal/Arcs2.js.map +1 -0
- package/_internal/Axis.js +2 -0
- package/_internal/Axis.js.map +1 -0
- package/_internal/Axis2.js +388 -0
- package/_internal/Axis2.js.map +1 -0
- package/_internal/Bar.js +2 -0
- package/_internal/Bar.js.map +1 -0
- package/_internal/Bar2.js +170 -0
- package/_internal/Bar2.js.map +1 -0
- package/_internal/BarChart.js +2 -0
- package/_internal/BarChart.js.map +1 -0
- package/_internal/BarChart2.js +1419 -0
- package/_internal/BarChart2.js.map +1 -0
- package/_internal/ChartContainer.js +2 -0
- package/_internal/ChartContainer.js.map +1 -0
- package/_internal/ChartContainer2.js +266 -0
- package/_internal/ChartContainer2.js.map +1 -0
- package/_internal/DataPoint.js +2 -0
- package/_internal/DataPoint.js.map +1 -0
- package/_internal/DataPoint2.js +110 -0
- package/_internal/DataPoint2.js.map +1 -0
- package/_internal/Dot.js +2 -0
- package/_internal/Dot.js.map +1 -0
- package/_internal/Dot2.js +110 -0
- package/_internal/Dot2.js.map +1 -0
- package/_internal/Legend.js +2 -0
- package/_internal/Legend.js.map +1 -0
- package/_internal/Legend3.js +84 -0
- package/_internal/Legend3.js.map +1 -0
- package/_internal/LegendItem.js +2 -0
- package/_internal/LegendItem.js.map +1 -0
- package/_internal/LegendItem2.js +153 -0
- package/_internal/LegendItem2.js.map +1 -0
- package/_internal/Line.js +2 -0
- package/_internal/Line.js.map +1 -0
- package/_internal/Line2.js +59 -0
- package/_internal/Line2.js.map +1 -0
- package/_internal/LineChart.js +2 -0
- package/_internal/LineChart.js.map +1 -0
- package/_internal/LineChart2.js +669 -0
- package/_internal/LineChart2.js.map +1 -0
- package/_internal/PieChart.js +2 -0
- package/_internal/PieChart.js.map +1 -0
- package/_internal/PieChart2.js +605 -0
- package/_internal/PieChart2.js.map +1 -0
- package/_internal/ScatterPlot.js +2 -0
- package/_internal/ScatterPlot.js.map +1 -0
- package/_internal/ScatterPlot2.js +744 -0
- package/_internal/ScatterPlot2.js.map +1 -0
- package/_internal/_rollupPluginBabelHelpers.js +93 -0
- package/_internal/_rollupPluginBabelHelpers.js.map +1 -0
- package/_internal/config.js +13 -0
- package/_internal/config.js.map +1 -0
- package/_internal/legend2.js +21 -0
- package/_internal/legend2.js.map +1 -0
- package/_internal/scheme.js +47 -0
- package/_internal/scheme.js.map +1 -0
- package/_internal/theme.js +79 -0
- package/_internal/theme.js.map +1 -0
- package/_internal/useFormatCategoricalData.js +56 -0
- package/_internal/useFormatCategoricalData.js.map +1 -0
- package/index.js +17 -5118
- package/index.js.map +1 -1
- package/index2.js +16 -0
- package/index2.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import { _ as _objectWithoutProperties, a as _extends, b as _objectSpread2 } from './_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { forwardRef, useRef, useEffect } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { useTheme, useMessageFormatter, Flexbox, useId } from '@redsift/design-system';
|
|
5
|
+
import { L as LegendVariant, T as TooltipVariant } from './legend2.js';
|
|
6
|
+
import { C as ChartSize, g as getSortingMethod, i as isValidDate, u as useColor, m as mergeLegends, a as ColorTheme } from './theme.js';
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { C as ChartContainer } from './ChartContainer2.js';
|
|
9
|
+
import { scaleLinear, extent, scaleTime, scalePoint, line } from 'd3';
|
|
10
|
+
import { A as Axis, a as AxisVariant } from './Axis2.js';
|
|
11
|
+
import { L as Line } from './Line2.js';
|
|
12
|
+
import { D as Dot, a as DotVariant } from './Dot2.js';
|
|
13
|
+
import { L as Legend } from './Legend3.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Component's labels variant.
|
|
17
|
+
*/
|
|
18
|
+
const LineChartLegendVariant = {
|
|
19
|
+
none: 'none',
|
|
20
|
+
externalLabel: 'externalLabel',
|
|
21
|
+
externalLabelValue: 'externalLabelValue',
|
|
22
|
+
externalLabelPercent: 'externalLabelPercent',
|
|
23
|
+
custom: 'custom'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Component props.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Component style.
|
|
32
|
+
*/
|
|
33
|
+
const StyledLineChart = styled(ChartContainer)``;
|
|
34
|
+
const StyledLineChartEmptyText = styled.div`
|
|
35
|
+
position: absolute;
|
|
36
|
+
top: 0;
|
|
37
|
+
left: 0;
|
|
38
|
+
height: 100%;
|
|
39
|
+
width: 100%;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
align-items: center;
|
|
44
|
+
pointer-events: none;
|
|
45
|
+
|
|
46
|
+
> * {
|
|
47
|
+
max-width: ${_ref => {
|
|
48
|
+
let {
|
|
49
|
+
$maxWidth
|
|
50
|
+
} = _ref;
|
|
51
|
+
return $maxWidth;
|
|
52
|
+
}}px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
> span {
|
|
56
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
57
|
+
color: ${_ref2 => {
|
|
58
|
+
let {
|
|
59
|
+
$theme
|
|
60
|
+
} = _ref2;
|
|
61
|
+
return `var(--redsift-color-${$theme}-components-text-primary)`;
|
|
62
|
+
}};
|
|
63
|
+
font-size: ${_ref3 => {
|
|
64
|
+
let {
|
|
65
|
+
$textSize
|
|
66
|
+
} = _ref3;
|
|
67
|
+
return $textSize;
|
|
68
|
+
}}px;
|
|
69
|
+
line-height: ${_ref4 => {
|
|
70
|
+
let {
|
|
71
|
+
$textSize
|
|
72
|
+
} = _ref4;
|
|
73
|
+
return $textSize;
|
|
74
|
+
}}px;
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const _excluded$3 = ["className"];
|
|
79
|
+
const LoadingLineChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
80
|
+
const {
|
|
81
|
+
className
|
|
82
|
+
} = props,
|
|
83
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$3);
|
|
84
|
+
return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({}, forwardedProps, {
|
|
85
|
+
className: className,
|
|
86
|
+
ref: ref
|
|
87
|
+
}), "Loading...");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const sizeToDimension = size => {
|
|
91
|
+
if (typeof size !== 'string') {
|
|
92
|
+
return size;
|
|
93
|
+
}
|
|
94
|
+
switch (size) {
|
|
95
|
+
case ChartSize.small:
|
|
96
|
+
return {
|
|
97
|
+
width: 600,
|
|
98
|
+
height: 300,
|
|
99
|
+
fontSize: 30
|
|
100
|
+
};
|
|
101
|
+
case ChartSize.medium:
|
|
102
|
+
default:
|
|
103
|
+
return {
|
|
104
|
+
width: 750,
|
|
105
|
+
height: 375,
|
|
106
|
+
fontSize: 34
|
|
107
|
+
};
|
|
108
|
+
case ChartSize.large:
|
|
109
|
+
return {
|
|
110
|
+
width: 900,
|
|
111
|
+
height: 450,
|
|
112
|
+
fontSize: 38
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const statsBy = (arr, sortingMethod) => {
|
|
117
|
+
const counts = arr.reduce((prev, curr) => {
|
|
118
|
+
if (!curr.value) {
|
|
119
|
+
return prev;
|
|
120
|
+
}
|
|
121
|
+
if (!prev[curr.key[1]]) {
|
|
122
|
+
prev[curr.key[1]] = {
|
|
123
|
+
value: curr.value,
|
|
124
|
+
min: curr.value,
|
|
125
|
+
max: curr.value,
|
|
126
|
+
values: [curr.value]
|
|
127
|
+
};
|
|
128
|
+
} else {
|
|
129
|
+
prev[curr.key[1]] = {
|
|
130
|
+
value: prev[curr.key[1]].value + curr.value,
|
|
131
|
+
min: Math.min(prev[curr.key[1]].min, curr.value),
|
|
132
|
+
max: Math.max(prev[curr.key[1]].max, curr.value),
|
|
133
|
+
values: [...prev[curr.key[1]].values, curr.value]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return prev;
|
|
137
|
+
}, {});
|
|
138
|
+
return Object.keys(counts).map(key => ({
|
|
139
|
+
key: key,
|
|
140
|
+
value: counts[key].value,
|
|
141
|
+
min: counts[key].min,
|
|
142
|
+
max: counts[key].max,
|
|
143
|
+
values: counts[key].values,
|
|
144
|
+
first: counts[key].values[0],
|
|
145
|
+
last: counts[key].values[counts[key].values.length - 1],
|
|
146
|
+
trending: {
|
|
147
|
+
overall: (counts[key].values[counts[key].values.length - 1] - counts[key].values[0]) * 100 / counts[key].values[0]
|
|
148
|
+
}
|
|
149
|
+
})).sort(getSortingMethod(sortingMethod));
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const _excluded$2 = ["className", "data", "emptyComponent", "localeText", "size"];
|
|
153
|
+
const EmptyLineChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
154
|
+
const {
|
|
155
|
+
className,
|
|
156
|
+
data: propsData,
|
|
157
|
+
emptyComponent,
|
|
158
|
+
localeText,
|
|
159
|
+
size
|
|
160
|
+
} = props,
|
|
161
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$2);
|
|
162
|
+
const theme = useTheme();
|
|
163
|
+
const cache = useRef();
|
|
164
|
+
const data = propsData;
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
cache.current = data;
|
|
167
|
+
});
|
|
168
|
+
const chartDimensions = sizeToDimension(size);
|
|
169
|
+
const width = chartDimensions.width;
|
|
170
|
+
const height = chartDimensions.height;
|
|
171
|
+
const margins = {
|
|
172
|
+
top: 16,
|
|
173
|
+
left: 48,
|
|
174
|
+
right: 16,
|
|
175
|
+
bottom: 48
|
|
176
|
+
};
|
|
177
|
+
const chartWidth = width - margins.left - margins.right;
|
|
178
|
+
return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({}, forwardedProps, {
|
|
179
|
+
className: className,
|
|
180
|
+
ref: ref
|
|
181
|
+
}), emptyComponent !== null && emptyComponent !== void 0 ? emptyComponent : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(StyledLineChartEmptyText, {
|
|
182
|
+
$maxWidth: width,
|
|
183
|
+
$textSize: chartDimensions.fontSize / 2,
|
|
184
|
+
$theme: theme
|
|
185
|
+
}, /*#__PURE__*/React__default.createElement("span", null, localeText === null || localeText === void 0 ? void 0 : localeText.emptyChartText)), /*#__PURE__*/React__default.createElement("svg", {
|
|
186
|
+
width: width,
|
|
187
|
+
height: height
|
|
188
|
+
}, /*#__PURE__*/React__default.createElement("g", {
|
|
189
|
+
transform: `translate(${margins.left},${margins.top})`
|
|
190
|
+
}, /*#__PURE__*/React__default.createElement(Axis, {
|
|
191
|
+
position: "bottom",
|
|
192
|
+
length: width - 32,
|
|
193
|
+
scale: scaleLinear().domain([]).range([0, chartWidth]),
|
|
194
|
+
x: 0,
|
|
195
|
+
y: height,
|
|
196
|
+
tickValues: 4
|
|
197
|
+
})))));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
var enUS = {
|
|
201
|
+
"interactive-chart": "Interactive Line Chart",
|
|
202
|
+
"static-chart": "Static Line Chart",
|
|
203
|
+
"definition-linear": "Linear Line Chart with {circleLength} circles.",
|
|
204
|
+
"definition-linear-with-categories": "Linear Line Chart with {categoryLength} categories and {circleLength} circles.",
|
|
205
|
+
"definition-ordinal": "Ordinal Line Chart with {circleLength} circles.",
|
|
206
|
+
"x-axis-numbers-definition": "The chart has {numAxis, plural, =0 {0 X axis} =1 {1 X axis} other {# X axes}} displaying numbers from {start, number} to {end, number}.",
|
|
207
|
+
"y-axis-numbers-definition": "The chart has {numAxis, plural, =0 {0 Y axis} =1 {1 Y axis} other {# Y axes}} displaying numbers from {start, number} to {end, number}.",
|
|
208
|
+
"x-axis-dates-definition": "The chart has {numAxis, plural, =0 {0 X axis} =1 {1 X axis} other {# X axes}} displaying dates from {start, date, ::yyyyMMdd} to {end, date, ::yyyyMMdd}.",
|
|
209
|
+
"y-axis-dates-definition": "The chart has {numAxis, plural, =0 {0 Y axis} =1 {1 Y axis} other {# Y axes}} displaying dates from {start, date, ::yyyyMMdd} to {end, date, ::yyyyMMdd}.",
|
|
210
|
+
"x-axis-categories-definition": "The chart has {numAxis, plural, =0 {0 X axis} =1 {1 X axis} other {# X axes}} displaying categories.",
|
|
211
|
+
"y-axis-categories-definition": "The chart has {numAxis, plural, =0 {0 Y axis} =1 {1 Y axis} other {# Y axes}} displaying categories.",
|
|
212
|
+
"series-legend": "{category}, line {categoryIndex} of {categoryLength} with {circleLength} circles"
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
var frFR = {
|
|
216
|
+
"interactive-chart": "Graphique en courbe interactif",
|
|
217
|
+
"static-chart": "Graphique en courbe statique",
|
|
218
|
+
"definition-linear": "Graphique en courbe contenant {circleLength} points répartis sur un axe linéraire.",
|
|
219
|
+
"definition-linear-with-categories": "Graphique en courbe contenant {categoryLength} courbes et {circleLength} points répartis sur un axe linéraire.",
|
|
220
|
+
"definition-ordinal": "Graphique en courbe contenant {circleLength} points.",
|
|
221
|
+
"x-axis-numbers-definition": "Le graphique a {numAxis, plural, =0 {0 axe X} =1 {1 axe X} other {# axes X}} affichant des nombres allant de {start, number} à {end, number}.",
|
|
222
|
+
"y-axis-numbers-definition": "Le graphique a {numAxis, plural, =0 {0 axe Y} =1 {1 axe Y} other {# axes Y}} affichant des nombres allant de {start, number} à {end, number}.",
|
|
223
|
+
"x-axis-dates-definition": "Le graphique a {numAxis, plural, =0 {0 axe X} =1 {1 axe X} other {# axes X}} affichant des dates allant de {start, date, ::yyyyMMdd} à {end, date, ::yyyyMMdd}.",
|
|
224
|
+
"y-axis-dates-definition": "Le graphique a {numAxis, plural, =0 {0 axe Y} =1 {1 axe Y} other {# axes Y}} affichant des dates allant de {start, date, ::yyyyMMdd} à {end, date, ::yyyyMMdd}.",
|
|
225
|
+
"x-axis-categories-definition": "Le graphique a {numAxis, plural, =0 {0 axe X} =1 {1 axe X} other {# axes X}} affichant des categories.",
|
|
226
|
+
"y-axis-categories-definition": "Le graphique a {numAxis, plural, =0 {0 axe Y} =1 {1 axe Y} other {# axes Y}} affichant des categories.",
|
|
227
|
+
"series-legend": "{category}, courbe {categoryIndex} sur {categoryLength} contenant {circleLength} points"
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
var intlMessages = {
|
|
231
|
+
'en-US': enUS,
|
|
232
|
+
'fr-FR': frFR
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const _excluded$1 = ["className", "data", "dotRole", "disableAnimations", "getDotAnchorProps", "id", "isDotSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onDotClick", "size", "sortingMethod", "colorTheme", "tooltipDecorator", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "dateParser"],
|
|
236
|
+
_excluded2 = ["extraLegendItems"];
|
|
237
|
+
const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
238
|
+
const {
|
|
239
|
+
className,
|
|
240
|
+
data: propsData,
|
|
241
|
+
dotRole,
|
|
242
|
+
disableAnimations,
|
|
243
|
+
getDotAnchorProps,
|
|
244
|
+
id,
|
|
245
|
+
isDotSelected,
|
|
246
|
+
labelDecorator,
|
|
247
|
+
legendDecorator,
|
|
248
|
+
legendVariant,
|
|
249
|
+
legendProps,
|
|
250
|
+
margins: propsMargins,
|
|
251
|
+
onDotClick,
|
|
252
|
+
size,
|
|
253
|
+
sortingMethod,
|
|
254
|
+
colorTheme,
|
|
255
|
+
tooltipDecorator,
|
|
256
|
+
tooltipVariant,
|
|
257
|
+
xAxisVariant,
|
|
258
|
+
xAxisPlacement,
|
|
259
|
+
xAxisTickFormat: propsXAxisTickFormat,
|
|
260
|
+
xAxisTickPadding,
|
|
261
|
+
xAxisTickRotation,
|
|
262
|
+
xAxisTickSize,
|
|
263
|
+
xAxisTickValues,
|
|
264
|
+
xAxisMinValue,
|
|
265
|
+
xAxisMaxValue,
|
|
266
|
+
xAxisTickRemodelling,
|
|
267
|
+
yAxisVariant,
|
|
268
|
+
yAxisPlacement,
|
|
269
|
+
yAxisTickFormat,
|
|
270
|
+
yAxisTickPadding,
|
|
271
|
+
yAxisTickRotation,
|
|
272
|
+
yAxisTickSize,
|
|
273
|
+
yAxisTickValues,
|
|
274
|
+
yAxisMinValue,
|
|
275
|
+
yAxisMaxValue,
|
|
276
|
+
yAxisTickRemodelling,
|
|
277
|
+
dateParser
|
|
278
|
+
} = props,
|
|
279
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
280
|
+
const cache = useRef();
|
|
281
|
+
const theme = useTheme();
|
|
282
|
+
const format = useMessageFormatter(intlMessages);
|
|
283
|
+
const xScaleType = propsData[0].key[0] instanceof Date ? 'Date' : typeof propsData[0].key[0] === 'number' ? 'number' : typeof propsData[0].key[0] === 'string' && isValidDate(propsData[0].key[0]) ? 'dateString' : typeof propsData[0].key[0] === 'string' ? 'string' : undefined;
|
|
284
|
+
const data = xScaleType === 'number' ? propsData.filter(datum => typeof datum.key[0] === 'number' && !Number.isNaN(datum.key[0])) : xScaleType === 'dateString' ? propsData.filter(datum => isValidDate(datum.key[0])) : xScaleType === 'string' ? propsData.filter(datum => typeof datum.key[0] === 'string') : xScaleType === 'Date' ? propsData.filter(datum => datum.key[0] instanceof Date) : propsData;
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
cache.current = data;
|
|
287
|
+
});
|
|
288
|
+
const svgRef = useRef();
|
|
289
|
+
const chartDimensions = sizeToDimension(size);
|
|
290
|
+
const width = chartDimensions.width;
|
|
291
|
+
const height = chartDimensions.height;
|
|
292
|
+
const margins = _objectSpread2({
|
|
293
|
+
top: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8,
|
|
294
|
+
left: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
|
|
295
|
+
right: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
|
|
296
|
+
bottom: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8
|
|
297
|
+
}, propsMargins);
|
|
298
|
+
const chartHeight = height - margins.top - margins.bottom;
|
|
299
|
+
const chartWidth = width - margins.left - margins.right;
|
|
300
|
+
const scaleX = (() => {
|
|
301
|
+
if (xScaleType === 'number') {
|
|
302
|
+
var _ref, _ref2;
|
|
303
|
+
const domain = extent(data, d => d.key[0]);
|
|
304
|
+
domain[0] = (_ref = xAxisMinValue) !== null && _ref !== void 0 ? _ref : domain[0];
|
|
305
|
+
domain[1] = (_ref2 = xAxisMaxValue) !== null && _ref2 !== void 0 ? _ref2 : domain[1];
|
|
306
|
+
return scaleLinear().domain(domain).range([0, chartWidth]).nice();
|
|
307
|
+
} else if (xScaleType === 'dateString') {
|
|
308
|
+
var _ref3, _ref4;
|
|
309
|
+
const domain = extent(data, d => Date.parse(d.key[0]));
|
|
310
|
+
domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
|
|
311
|
+
domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
|
|
312
|
+
return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
|
|
313
|
+
} else if (xScaleType === 'Date') {
|
|
314
|
+
var _ref5, _ref6;
|
|
315
|
+
const domain = extent(data, d => d.key[0].valueOf());
|
|
316
|
+
domain[0] = (_ref5 = xAxisMinValue) !== null && _ref5 !== void 0 ? _ref5 : domain[0];
|
|
317
|
+
domain[1] = (_ref6 = xAxisMaxValue) !== null && _ref6 !== void 0 ? _ref6 : domain[1];
|
|
318
|
+
return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
|
|
319
|
+
} else {
|
|
320
|
+
var _ref7, _ref8;
|
|
321
|
+
const domain = xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0]);
|
|
322
|
+
domain[0] = (_ref7 = xAxisMinValue) !== null && _ref7 !== void 0 ? _ref7 : domain[0];
|
|
323
|
+
domain[1] = (_ref8 = xAxisMaxValue) !== null && _ref8 !== void 0 ? _ref8 : domain[1];
|
|
324
|
+
return scalePoint().domain(domain).range([0, chartWidth]);
|
|
325
|
+
}
|
|
326
|
+
})();
|
|
327
|
+
const scaleY = (() => {
|
|
328
|
+
var _ref9, _ref10;
|
|
329
|
+
const domain = extent(data, d => d.value);
|
|
330
|
+
domain[0] = (_ref9 = yAxisMinValue) !== null && _ref9 !== void 0 ? _ref9 : domain[0];
|
|
331
|
+
domain[1] = (_ref10 = yAxisMaxValue) !== null && _ref10 !== void 0 ? _ref10 : domain[1];
|
|
332
|
+
return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
|
|
333
|
+
})();
|
|
334
|
+
const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
|
|
335
|
+
const hasCategory = data[0] && data[0].key.length >= 2 && data[0].key[1] !== null && data[0].key[1] !== undefined;
|
|
336
|
+
const statsByCategory = statsBy(data, sortingMethod);
|
|
337
|
+
const colorScale = useColor({
|
|
338
|
+
data: statsByCategory,
|
|
339
|
+
colorTheme: colorTheme,
|
|
340
|
+
category: d => d.key,
|
|
341
|
+
theme
|
|
342
|
+
});
|
|
343
|
+
const circles = data.sort((a, b) => {
|
|
344
|
+
if (xScaleType === 'number') {
|
|
345
|
+
if (a.key[0] < b.key[0]) return -1;
|
|
346
|
+
if (a.key[0] > b.key[0]) return 1;
|
|
347
|
+
return 0;
|
|
348
|
+
} else if (xScaleType === 'dateString') {
|
|
349
|
+
if (Date.parse(a.key[0]) < Date.parse(b.key[0])) return -1;
|
|
350
|
+
if (Date.parse(a.key[0]) > Date.parse(b.key[0])) return 1;
|
|
351
|
+
return 0;
|
|
352
|
+
} else if (xScaleType === 'Date') {
|
|
353
|
+
if (a.key[0].valueOf() < b.key[0].valueOf()) return -1;
|
|
354
|
+
if (a.key[0].valueOf() > b.key[0].valueOf()) return 1;
|
|
355
|
+
return 0;
|
|
356
|
+
} else if (xScaleType === 'string' && xAxisTickValues && Array.isArray(xAxisTickValues)) {
|
|
357
|
+
if (xAxisTickValues.indexOf(a.key[0]) < xAxisTickValues.indexOf(b.key[0])) return -1;
|
|
358
|
+
if (xAxisTickValues.indexOf(a.key[0]) > xAxisTickValues.indexOf(b.key[0])) return 1;
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
return 0;
|
|
362
|
+
}).filter(d => d.value !== null).map(d => {
|
|
363
|
+
var _d$key$;
|
|
364
|
+
return {
|
|
365
|
+
category: (_d$key$ = d.key[1]) !== null && _d$key$ !== void 0 ? _d$key$ : 'default',
|
|
366
|
+
x: xScaleType === 'dateString' ? dateParser ? dateParser(d.key[0]) : new Date(Date.parse(d.key[0])) : d.key[0],
|
|
367
|
+
y: d.value,
|
|
368
|
+
data: {
|
|
369
|
+
key: d.key,
|
|
370
|
+
value: d.value
|
|
371
|
+
},
|
|
372
|
+
points: [d]
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
const lines = hasCategory ? Object.values(circles.reduce((prev, curr) => {
|
|
376
|
+
if (!prev[curr.category]) {
|
|
377
|
+
prev[curr.category] = [];
|
|
378
|
+
}
|
|
379
|
+
prev[curr.category].push(curr);
|
|
380
|
+
return prev;
|
|
381
|
+
}, {})) : [circles];
|
|
382
|
+
const createLine = line().x(d => scaleX(d.x)).y(d => scaleY(d.y));
|
|
383
|
+
const categories = [];
|
|
384
|
+
const pivotedTable = circles.reduce((acc, item) => {
|
|
385
|
+
const {
|
|
386
|
+
x,
|
|
387
|
+
category,
|
|
388
|
+
y
|
|
389
|
+
} = item;
|
|
390
|
+
if (!categories.includes(category)) {
|
|
391
|
+
categories.push(category);
|
|
392
|
+
}
|
|
393
|
+
const formattedKey = xAxisTickFormat ? xAxisTickFormat(x) : x.toString();
|
|
394
|
+
let entry = acc.find(e => e.key === formattedKey);
|
|
395
|
+
if (!entry) {
|
|
396
|
+
entry = {
|
|
397
|
+
key: formattedKey
|
|
398
|
+
};
|
|
399
|
+
acc.push(entry);
|
|
400
|
+
}
|
|
401
|
+
entry[category] = y;
|
|
402
|
+
return acc;
|
|
403
|
+
}, []);
|
|
404
|
+
const _ref11 = legendProps || {},
|
|
405
|
+
{
|
|
406
|
+
extraLegendItems
|
|
407
|
+
} = _ref11,
|
|
408
|
+
forwardedLegendProps = _objectWithoutProperties(_ref11, _excluded2);
|
|
409
|
+
return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({
|
|
410
|
+
mode: typeof onDotClick === 'function' || typeof getDotAnchorProps === 'function' ? 'interactive' : 'static',
|
|
411
|
+
definition: hasCategory ? format('definition-linear-with-categories', {
|
|
412
|
+
categoryLength: categories.length,
|
|
413
|
+
circleLength: circles.length
|
|
414
|
+
}) : format('definition-linear', {
|
|
415
|
+
circleLength: circles.length
|
|
416
|
+
}),
|
|
417
|
+
xAxisDefinition: xScaleType !== 'string' ? format(`x-axis-${xScaleType === 'number' ? 'numbers' : 'dates'}-definition`, {
|
|
418
|
+
numAxis: xAxisPlacement === 'both' ? 2 : 1,
|
|
419
|
+
start: scaleX.domain()[0],
|
|
420
|
+
end: scaleX.domain()[1]
|
|
421
|
+
}) : format('x-axis-categories-definition', {
|
|
422
|
+
numAxis: xAxisPlacement === 'both' ? 2 : 1
|
|
423
|
+
}),
|
|
424
|
+
yAxisDefinition: format('y-axis-numbers-definition', {
|
|
425
|
+
numAxis: yAxisPlacement === 'both' ? 2 : 1,
|
|
426
|
+
start: scaleY.domain()[0],
|
|
427
|
+
end: scaleY.domain()[1]
|
|
428
|
+
}),
|
|
429
|
+
dataTableRepresentation: hasCategory ? {
|
|
430
|
+
header: /*#__PURE__*/React__default.createElement("thead", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("th", {
|
|
431
|
+
scope: "col"
|
|
432
|
+
}, xScaleType === 'Date' || xScaleType === 'dateString' ? 'Date' : 'Key'), categories.map(category => /*#__PURE__*/React__default.createElement("th", {
|
|
433
|
+
key: category,
|
|
434
|
+
scope: "col"
|
|
435
|
+
}, category)))),
|
|
436
|
+
body: /*#__PURE__*/React__default.createElement("tbody", null, pivotedTable.map(row => /*#__PURE__*/React__default.createElement("tr", {
|
|
437
|
+
key: row.key
|
|
438
|
+
}, /*#__PURE__*/React__default.createElement("th", {
|
|
439
|
+
scope: "row"
|
|
440
|
+
}, row.key), categories.map(category => /*#__PURE__*/React__default.createElement("th", {
|
|
441
|
+
key: `${row.key}-${category}-${row[category]}`,
|
|
442
|
+
scope: "col"
|
|
443
|
+
}, row[category])))))
|
|
444
|
+
} : {
|
|
445
|
+
header: /*#__PURE__*/React__default.createElement("thead", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("th", {
|
|
446
|
+
scope: "col"
|
|
447
|
+
}, xScaleType === 'Date' || xScaleType === 'dateString' ? 'Date' : 'Key'), /*#__PURE__*/React__default.createElement("th", {
|
|
448
|
+
scope: "col"
|
|
449
|
+
}, "Value"))),
|
|
450
|
+
body: /*#__PURE__*/React__default.createElement("tbody", null, circles.map(datum => {
|
|
451
|
+
const key = xAxisTickFormat ? xAxisTickFormat(datum.x) : datum.x.toString();
|
|
452
|
+
return /*#__PURE__*/React__default.createElement("tr", {
|
|
453
|
+
key: key
|
|
454
|
+
}, /*#__PURE__*/React__default.createElement("th", {
|
|
455
|
+
scope: "row"
|
|
456
|
+
}, key), /*#__PURE__*/React__default.createElement("td", null, datum.y));
|
|
457
|
+
}))
|
|
458
|
+
}
|
|
459
|
+
}, forwardedProps, {
|
|
460
|
+
id: id,
|
|
461
|
+
className: className,
|
|
462
|
+
ref: ref
|
|
463
|
+
}), /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
464
|
+
flexDirection: "column",
|
|
465
|
+
alignItems: "center",
|
|
466
|
+
gap: "8"
|
|
467
|
+
}, /*#__PURE__*/React__default.createElement("svg", {
|
|
468
|
+
ref: svgRef,
|
|
469
|
+
width: width,
|
|
470
|
+
height: height,
|
|
471
|
+
"aria-label": typeof onDotClick === 'function' || typeof getDotAnchorProps === 'function' ? format('interactive-chart') : format('static-chart'),
|
|
472
|
+
"aria-hidden": "false"
|
|
473
|
+
}, /*#__PURE__*/React__default.createElement("g", {
|
|
474
|
+
transform: `translate(${margins.left},${margins.top})`,
|
|
475
|
+
"aria-hidden": "true"
|
|
476
|
+
}, lines.map((line, index) => {
|
|
477
|
+
return /*#__PURE__*/React__default.createElement(Line, {
|
|
478
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(line[0].category),
|
|
479
|
+
data: line.filter(point => point.y !== null),
|
|
480
|
+
disableAnimations: disableAnimations,
|
|
481
|
+
createLine: createLine,
|
|
482
|
+
key: `line _${index}`
|
|
483
|
+
});
|
|
484
|
+
})), categories.map((category, categoryIndex) => {
|
|
485
|
+
const filteredCircles = circles.filter(circle => circle.category === category);
|
|
486
|
+
return /*#__PURE__*/React__default.createElement("g", _extends({
|
|
487
|
+
key: `${id}-series-${category}`,
|
|
488
|
+
transform: `translate(${margins.left},${margins.top})`,
|
|
489
|
+
"aria-hidden": "false",
|
|
490
|
+
role: "region"
|
|
491
|
+
}, hasCategory ? {
|
|
492
|
+
'aria-label': `${category}, category ${categoryIndex + 1} of ${categories.length} with ${filteredCircles.length} circles`
|
|
493
|
+
} : {}), filteredCircles.map((circle, index) => {
|
|
494
|
+
const scaleXDomain = scaleX.domain();
|
|
495
|
+
const scaleYDomain = scaleY.domain();
|
|
496
|
+
if (xScaleType === 'number' && (circle.x < scaleXDomain[0] || circle.x > scaleXDomain[1] || circle.y < scaleYDomain[0] || circle.y > scaleYDomain[1])) {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
const to = _objectSpread2(_objectSpread2({}, circle), {}, {
|
|
500
|
+
r: 4
|
|
501
|
+
});
|
|
502
|
+
return /*#__PURE__*/React__default.createElement(Dot, {
|
|
503
|
+
id: `id${id}__circle-${categoryIndex}.${index}`,
|
|
504
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(circle.category),
|
|
505
|
+
data: to,
|
|
506
|
+
dataset: circles,
|
|
507
|
+
isSelected: Boolean(isDotSelected === null || isDotSelected === void 0 ? void 0 : isDotSelected(to)),
|
|
508
|
+
anchorProps: getDotAnchorProps ? getDotAnchorProps(to) : undefined,
|
|
509
|
+
key: `circle _${categoryIndex}.${index}`,
|
|
510
|
+
labelDecorator: labelDecorator,
|
|
511
|
+
onClick: onDotClick,
|
|
512
|
+
role: dotRole,
|
|
513
|
+
scaleX: scaleX,
|
|
514
|
+
scaleY: scaleY,
|
|
515
|
+
tooltipDecorator: tooltipDecorator,
|
|
516
|
+
tooltipVariant: tooltipVariant,
|
|
517
|
+
variant: DotVariant.hollow
|
|
518
|
+
});
|
|
519
|
+
}));
|
|
520
|
+
}), /*#__PURE__*/React__default.createElement("g", {
|
|
521
|
+
transform: `translate(${margins.left},${margins.top})`
|
|
522
|
+
}, ['bottom', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
|
|
523
|
+
disableAnimations: disableAnimations,
|
|
524
|
+
position: "bottom",
|
|
525
|
+
length: chartWidth,
|
|
526
|
+
scale: scaleX,
|
|
527
|
+
x: 0,
|
|
528
|
+
y: chartHeight,
|
|
529
|
+
tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
|
|
530
|
+
tickPadding: xAxisTickPadding,
|
|
531
|
+
tickRotation: xAxisTickRotation,
|
|
532
|
+
tickSize: xAxisTickSize,
|
|
533
|
+
tickFormat: xAxisTickFormat,
|
|
534
|
+
tickRemodelling: xAxisTickRemodelling,
|
|
535
|
+
variant: xAxisVariant
|
|
536
|
+
}) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
|
|
537
|
+
disableAnimations: disableAnimations,
|
|
538
|
+
position: "top",
|
|
539
|
+
length: chartWidth,
|
|
540
|
+
scale: scaleX,
|
|
541
|
+
x: 0,
|
|
542
|
+
y: 0,
|
|
543
|
+
tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
|
|
544
|
+
tickPadding: xAxisTickPadding,
|
|
545
|
+
tickRotation: xAxisTickRotation,
|
|
546
|
+
tickSize: xAxisTickSize,
|
|
547
|
+
tickFormat: xAxisTickFormat,
|
|
548
|
+
tickRemodelling: xAxisTickRemodelling,
|
|
549
|
+
variant: xAxisVariant
|
|
550
|
+
}) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
|
|
551
|
+
disableAnimations: disableAnimations,
|
|
552
|
+
position: "left",
|
|
553
|
+
length: chartHeight,
|
|
554
|
+
scale: scaleY,
|
|
555
|
+
x: 0,
|
|
556
|
+
y: chartHeight,
|
|
557
|
+
tickValues: yAxisTickValues !== null && yAxisTickValues !== void 0 ? yAxisTickValues : 8,
|
|
558
|
+
tickPadding: yAxisTickPadding,
|
|
559
|
+
tickRotation: yAxisTickRotation,
|
|
560
|
+
tickSize: yAxisTickSize,
|
|
561
|
+
tickFormat: yAxisTickFormat,
|
|
562
|
+
tickRemodelling: yAxisTickRemodelling,
|
|
563
|
+
variant: yAxisVariant
|
|
564
|
+
}) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
|
|
565
|
+
disableAnimations: disableAnimations,
|
|
566
|
+
position: "right",
|
|
567
|
+
length: chartHeight,
|
|
568
|
+
scale: scaleY,
|
|
569
|
+
x: chartWidth,
|
|
570
|
+
y: chartHeight,
|
|
571
|
+
tickValues: yAxisTickValues !== null && yAxisTickValues !== void 0 ? yAxisTickValues : 8,
|
|
572
|
+
tickPadding: yAxisTickPadding,
|
|
573
|
+
tickRotation: yAxisTickRotation,
|
|
574
|
+
tickSize: yAxisTickSize,
|
|
575
|
+
tickFormat: yAxisTickFormat,
|
|
576
|
+
tickRemodelling: yAxisTickRemodelling,
|
|
577
|
+
variant: yAxisVariant
|
|
578
|
+
}) : null))), hasCategory && legendVariant !== LineChartLegendVariant.none ? /*#__PURE__*/React__default.createElement(Legend, _extends({
|
|
579
|
+
data: (extraLegendItems ? mergeLegends(extraLegendItems, statsByCategory).sort(getSortingMethod(sortingMethod)) : statsByCategory).map(d => _objectSpread2(_objectSpread2({}, d), {}, {
|
|
580
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
|
|
581
|
+
})),
|
|
582
|
+
variant: legendVariant === LineChartLegendVariant.externalLabelValue ? LegendVariant.value : legendVariant === LineChartLegendVariant.externalLabelPercent ? LegendVariant.percent : legendVariant === LineChartLegendVariant.externalLabel ? LegendVariant.label : LegendVariant.custom,
|
|
583
|
+
legendDecorator: legendDecorator ? (datum, props) => legendDecorator(datum, props) : undefined
|
|
584
|
+
}, forwardedLegendProps)) : null);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const _excluded = ["className", "colorTheme", "data", "dotRole", "emptyComponent", "id", "isDotSelected", "labelDecorator", "legendDecorator", "legendVariant", "localeText", "onDotClick", "size", "sortingMethod", "tooltipDecorator", "tooltipVariant", "xAxisPlacement", "xAxisVariant", "yAxisPlacement", "yAxisVariant"];
|
|
588
|
+
const COMPONENT_NAME = 'LineChart';
|
|
589
|
+
const CLASSNAME = 'redsift-line-chart';
|
|
590
|
+
const LineChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
591
|
+
const {
|
|
592
|
+
className,
|
|
593
|
+
colorTheme = ColorTheme.dark,
|
|
594
|
+
data: propsData,
|
|
595
|
+
dotRole,
|
|
596
|
+
emptyComponent,
|
|
597
|
+
id: propsId,
|
|
598
|
+
isDotSelected,
|
|
599
|
+
labelDecorator,
|
|
600
|
+
legendDecorator,
|
|
601
|
+
legendVariant: propsLegendVariant,
|
|
602
|
+
localeText = {
|
|
603
|
+
emptyChartText: 'No Data'
|
|
604
|
+
},
|
|
605
|
+
onDotClick,
|
|
606
|
+
size = ChartSize.medium,
|
|
607
|
+
sortingMethod = 'desc-value',
|
|
608
|
+
tooltipDecorator,
|
|
609
|
+
tooltipVariant = TooltipVariant.none,
|
|
610
|
+
xAxisPlacement = 'bottom',
|
|
611
|
+
xAxisVariant = AxisVariant.default,
|
|
612
|
+
yAxisPlacement = 'left',
|
|
613
|
+
yAxisVariant = AxisVariant.default
|
|
614
|
+
} = props,
|
|
615
|
+
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
616
|
+
const [_id] = useId();
|
|
617
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
618
|
+
const legendVariant = propsLegendVariant !== null && propsLegendVariant !== void 0 ? propsLegendVariant : LineChartLegendVariant.externalLabel;
|
|
619
|
+
if (propsData === undefined || propsData === null) {
|
|
620
|
+
return /*#__PURE__*/React__default.createElement(LoadingLineChart, _extends({
|
|
621
|
+
id: id
|
|
622
|
+
}, forwardedProps, {
|
|
623
|
+
ref: ref
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
626
|
+
if (propsData.length === 0) {
|
|
627
|
+
return /*#__PURE__*/React__default.createElement(EmptyLineChart, _extends({
|
|
628
|
+
data: propsData,
|
|
629
|
+
emptyComponent: emptyComponent,
|
|
630
|
+
localeText: localeText,
|
|
631
|
+
size: size,
|
|
632
|
+
sortingMethod: sortingMethod,
|
|
633
|
+
xAxisPlacement: xAxisPlacement,
|
|
634
|
+
xAxisVariant: xAxisVariant,
|
|
635
|
+
yAxisPlacement: yAxisPlacement,
|
|
636
|
+
yAxisVariant: yAxisVariant
|
|
637
|
+
}, forwardedProps, {
|
|
638
|
+
ref: ref
|
|
639
|
+
}));
|
|
640
|
+
}
|
|
641
|
+
return /*#__PURE__*/React__default.createElement(RenderedLineChart, _extends({
|
|
642
|
+
className: classNames(LineChart.className, className),
|
|
643
|
+
colorTheme: colorTheme,
|
|
644
|
+
data: propsData,
|
|
645
|
+
dotRole: dotRole,
|
|
646
|
+
id: id,
|
|
647
|
+
isDotSelected: isDotSelected,
|
|
648
|
+
labelDecorator: labelDecorator,
|
|
649
|
+
legendDecorator: legendDecorator,
|
|
650
|
+
legendVariant: legendVariant,
|
|
651
|
+
localeText: localeText,
|
|
652
|
+
onDotClick: onDotClick,
|
|
653
|
+
size: size,
|
|
654
|
+
sortingMethod: sortingMethod,
|
|
655
|
+
tooltipDecorator: tooltipDecorator,
|
|
656
|
+
tooltipVariant: tooltipVariant,
|
|
657
|
+
xAxisPlacement: xAxisPlacement,
|
|
658
|
+
xAxisVariant: xAxisVariant,
|
|
659
|
+
yAxisPlacement: yAxisPlacement,
|
|
660
|
+
yAxisVariant: yAxisVariant
|
|
661
|
+
}, forwardedProps, {
|
|
662
|
+
ref: ref
|
|
663
|
+
}));
|
|
664
|
+
});
|
|
665
|
+
LineChart.className = CLASSNAME;
|
|
666
|
+
LineChart.displayName = COMPONENT_NAME;
|
|
667
|
+
|
|
668
|
+
export { LineChart as L, StyledLineChart as S, LineChartLegendVariant as a, StyledLineChartEmptyText as b };
|
|
669
|
+
//# sourceMappingURL=LineChart2.js.map
|