@pareto-engineering/design-system 5.2.1 → 5.3.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/dist/cjs/a/Charts/AreaChart/AreaChart.js +60 -5
- package/dist/cjs/a/Charts/AreaChart/styles.scss +22 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +19 -5
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +133 -68
- package/dist/cjs/a/Charts/PieChart/PieChart.js +20 -7
- package/dist/cjs/a/ThroughPutIndicator/ThroughPutIndicator.js +78 -0
- package/dist/cjs/a/ThroughPutIndicator/index.js +13 -0
- package/dist/cjs/a/ThroughPutIndicator/styles.scss +35 -0
- package/dist/cjs/a/ToggleSwitch/ToggleSwitch.js +2 -1
- package/dist/cjs/a/ToggleSwitch/styles.scss +9 -2
- package/dist/cjs/a/Tooltip/Tooltip.js +19 -2
- package/dist/cjs/a/Tooltip/styles.scss +32 -4
- package/dist/cjs/a/index.js +8 -1
- package/dist/cjs/f/FormInput/FormInput.js +7 -1
- package/dist/cjs/f/fields/ToggleInput/ToggleInput.js +126 -0
- package/dist/cjs/f/fields/ToggleInput/index.js +13 -0
- package/dist/cjs/f/fields/ToggleInput/styles.scss +22 -0
- package/dist/cjs/f/fields/index.js +8 -1
- package/dist/cjs/utils/formatting.js +27 -18
- package/dist/cjs/utils/index.js +6 -0
- package/dist/es/a/Charts/AreaChart/AreaChart.js +61 -6
- package/dist/es/a/Charts/AreaChart/styles.scss +22 -0
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +19 -5
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +122 -66
- package/dist/es/a/Charts/PieChart/PieChart.js +20 -7
- package/dist/es/a/ThroughPutIndicator/ThroughPutIndicator.js +66 -0
- package/dist/es/a/ThroughPutIndicator/index.js +2 -0
- package/dist/es/a/ThroughPutIndicator/styles.scss +35 -0
- package/dist/es/a/ToggleSwitch/ToggleSwitch.js +2 -1
- package/dist/es/a/ToggleSwitch/styles.scss +9 -2
- package/dist/es/a/Tooltip/Tooltip.js +31 -12
- package/dist/es/a/Tooltip/styles.scss +32 -4
- package/dist/es/a/index.js +2 -1
- package/dist/es/f/FormInput/FormInput.js +8 -2
- package/dist/es/f/fields/ToggleInput/ToggleInput.js +116 -0
- package/dist/es/f/fields/ToggleInput/index.js +2 -0
- package/dist/es/f/fields/ToggleInput/styles.scss +22 -0
- package/dist/es/f/fields/index.js +2 -1
- package/dist/es/utils/formatting.js +25 -17
- package/dist/es/utils/index.js +1 -1
- package/package.json +5 -5
- package/src/ui/a/Charts/AreaChart/AreaChart.jsx +73 -9
- package/src/ui/a/Charts/AreaChart/styles.scss +22 -0
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +20 -5
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +126 -79
- package/src/ui/a/Charts/PieChart/PieChart.jsx +38 -17
- package/src/ui/a/ThroughPutIndicator/ThroughPutIndicator.jsx +90 -0
- package/src/ui/a/ThroughPutIndicator/index.js +2 -0
- package/src/ui/a/ThroughPutIndicator/styles.scss +35 -0
- package/src/ui/a/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/ui/a/ToggleSwitch/styles.scss +9 -2
- package/src/ui/a/Tooltip/Tooltip.jsx +55 -26
- package/src/ui/a/Tooltip/styles.scss +32 -4
- package/src/ui/a/index.js +1 -0
- package/src/ui/f/FormInput/FormInput.jsx +11 -0
- package/src/ui/f/fields/ToggleInput/ToggleInput.jsx +140 -0
- package/src/ui/f/fields/ToggleInput/index.js +2 -0
- package/src/ui/f/fields/ToggleInput/styles.scss +22 -0
- package/src/ui/f/fields/index.js +1 -0
- package/src/ui/utils/formatting.js +38 -29
- package/src/ui/utils/index.js +1 -1
- package/tests/__snapshots__/Storyshots.test.js.snap +7 -1
|
@@ -10,6 +10,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
10
10
|
var _recharts = require("recharts");
|
|
11
11
|
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
12
12
|
var _utils = require("../../../utils");
|
|
13
|
+
var _ThroughPutIndicator = require("../../ThroughPutIndicator");
|
|
13
14
|
var _Common = require("../Common");
|
|
14
15
|
require("./styles.scss");
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -17,6 +18,33 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
19
|
const baseClassName = _exports.default.base;
|
|
19
20
|
const componentClassName = 'area-chart';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether to show only date or date with time based on the data range
|
|
24
|
+
*
|
|
25
|
+
* @param {Array} data - The chart data array
|
|
26
|
+
* @param {string} xKey - The key for the x-axis values (dates)
|
|
27
|
+
* @returns {boolean} - True if only date should be shown, false if date and time should be shown
|
|
28
|
+
*/
|
|
29
|
+
const shouldShowOnlyDate = (data, xKey) => {
|
|
30
|
+
if (!data || data.length < 2 || !xKey) return true;
|
|
31
|
+
|
|
32
|
+
// Extract dates from the data
|
|
33
|
+
const dates = data.map(item => (0, _utils.parseDate)(item[xKey])).filter(date => date !== null);
|
|
34
|
+
if (dates.length < 2) return true;
|
|
35
|
+
|
|
36
|
+
// Sort dates chronologically
|
|
37
|
+
dates.sort((a, b) => a.getTime() - b.getTime());
|
|
38
|
+
|
|
39
|
+
// Calculate the difference in days between the first and last date
|
|
40
|
+
const firstDate = dates[0];
|
|
41
|
+
const lastDate = dates[dates.length - 1];
|
|
42
|
+
const diffInMs = lastDate.getTime() - firstDate.getTime();
|
|
43
|
+
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
|
|
44
|
+
|
|
45
|
+
// If the data spans less than 4 days, show only date
|
|
46
|
+
return diffInDays > 4;
|
|
47
|
+
};
|
|
20
48
|
const AreaChart = _ref => {
|
|
21
49
|
let {
|
|
22
50
|
id,
|
|
@@ -33,7 +61,9 @@ const AreaChart = _ref => {
|
|
|
33
61
|
width,
|
|
34
62
|
isTimeFormat,
|
|
35
63
|
dateFormat,
|
|
36
|
-
capitalizedLegend
|
|
64
|
+
capitalizedLegend,
|
|
65
|
+
isWorkerSubmissionChart,
|
|
66
|
+
totalSubmissions
|
|
37
67
|
} = _ref;
|
|
38
68
|
const allYLabels = yKeys.map(key => ({
|
|
39
69
|
label: key,
|
|
@@ -45,8 +75,9 @@ const AreaChart = _ref => {
|
|
|
45
75
|
const min = Math.min(...yValues.flat());
|
|
46
76
|
const max = Math.max(...yValues.flat());
|
|
47
77
|
const margin = (max - min) * 0.1;
|
|
48
|
-
return [min - margin, max + margin];
|
|
78
|
+
return [Math.max(min - margin, 0), max + margin];
|
|
49
79
|
};
|
|
80
|
+
const showOnlyDate = shouldShowOnlyDate(data, xKey);
|
|
50
81
|
return /*#__PURE__*/React.createElement("div", {
|
|
51
82
|
id: id,
|
|
52
83
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
@@ -56,6 +87,13 @@ const AreaChart = _ref => {
|
|
|
56
87
|
allYLabels: allYLabels,
|
|
57
88
|
selectedYLabels: selectedYLabels,
|
|
58
89
|
setSelectedYLabels: setSelectedYLabels
|
|
90
|
+
})), isWorkerSubmissionChart && /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
className: "worker-submissions-total-percentage-container"
|
|
92
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
93
|
+
className: "total-submissions-text"
|
|
94
|
+
}, totalSubmissions), /*#__PURE__*/React.createElement(_ThroughPutIndicator.ThroughPutIndicator, {
|
|
95
|
+
data: data,
|
|
96
|
+
keyName: "reserved"
|
|
59
97
|
})), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
60
98
|
key: id,
|
|
61
99
|
colorsArray: colors,
|
|
@@ -78,7 +116,12 @@ const AreaChart = _ref => {
|
|
|
78
116
|
axisLine: false,
|
|
79
117
|
tickLine: false,
|
|
80
118
|
tickCount: 3,
|
|
81
|
-
tickFormatter: value =>
|
|
119
|
+
tickFormatter: value => {
|
|
120
|
+
if (showOnlyDate) {
|
|
121
|
+
return (0, _utils.formatDate)(value, dateFormat);
|
|
122
|
+
}
|
|
123
|
+
return (0, _utils.formatDate)(value, _utils.DATE_FORMATS.HUMAN_READABLE_WITH_TIME);
|
|
124
|
+
}
|
|
82
125
|
}), /*#__PURE__*/React.createElement(_recharts.YAxis, {
|
|
83
126
|
domain: yAxisBounds,
|
|
84
127
|
scale: "linear",
|
|
@@ -102,6 +145,9 @@ const AreaChart = _ref => {
|
|
|
102
145
|
if (isTimeFormat) {
|
|
103
146
|
return (0, _utils.formatTime)(value);
|
|
104
147
|
}
|
|
148
|
+
if (isWorkerSubmissionChart) {
|
|
149
|
+
return Math.round(value);
|
|
150
|
+
}
|
|
105
151
|
return value.toFixed(2);
|
|
106
152
|
}
|
|
107
153
|
}), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
@@ -188,7 +234,15 @@ AreaChart.propTypes = {
|
|
|
188
234
|
/**
|
|
189
235
|
* The type of format for the datetime value
|
|
190
236
|
*/
|
|
191
|
-
dateFormat: _propTypes.default.oneOf(Object.values(_utils.DATE_FORMATS))
|
|
237
|
+
dateFormat: _propTypes.default.oneOf(Object.values(_utils.DATE_FORMATS)),
|
|
238
|
+
/**
|
|
239
|
+
* Flag on whether the chart is a worker submission chart or not
|
|
240
|
+
*/
|
|
241
|
+
isWorkerSubmissionChart: _propTypes.default.bool,
|
|
242
|
+
/**
|
|
243
|
+
* Total submissions
|
|
244
|
+
*/
|
|
245
|
+
totalSubmissions: _propTypes.default.number
|
|
192
246
|
};
|
|
193
247
|
AreaChart.defaultProps = {
|
|
194
248
|
filled: false,
|
|
@@ -196,6 +250,7 @@ AreaChart.defaultProps = {
|
|
|
196
250
|
height: 300,
|
|
197
251
|
capitalizedLegend: false,
|
|
198
252
|
isTimeFormat: false,
|
|
199
|
-
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE
|
|
253
|
+
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE,
|
|
254
|
+
isWorkerSubmissionChart: false
|
|
200
255
|
};
|
|
201
256
|
var _default = exports.default = AreaChart;
|
|
@@ -26,6 +26,17 @@ $default-text-font-size: calc(var(--s-1) * 1rem);
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
.worker-submissions-total-percentage-container {
|
|
30
|
+
align-items: center;
|
|
31
|
+
display: flex;
|
|
32
|
+
gap: 1rem;
|
|
33
|
+
justify-content: flex-start;
|
|
34
|
+
|
|
35
|
+
.total-submissions-text {
|
|
36
|
+
font-size: calc($default-text-font-size * 2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/* stylelint-disable selector-max-compound-selectors -- nested elements */
|
|
30
41
|
.recharts-wrapper {
|
|
31
42
|
.recharts-surface {
|
|
@@ -46,3 +57,14 @@ $default-text-font-size: calc(var(--s-1) * 1rem);
|
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
59
|
}
|
|
60
|
+
|
|
61
|
+
.worker-submissions-total-percentage-container {
|
|
62
|
+
align-items: center;
|
|
63
|
+
display: flex;
|
|
64
|
+
gap: 1rem;
|
|
65
|
+
justify-content: flex-start;
|
|
66
|
+
|
|
67
|
+
.total-submissions-text {
|
|
68
|
+
font-size: calc($default-text-font-size * 2);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -14,6 +14,13 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
15
|
const baseClassName = _exports.default.base;
|
|
16
16
|
const componentClassName = 'custom-legend';
|
|
17
|
+
const toCurrency = value => {
|
|
18
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
19
|
+
style: 'currency',
|
|
20
|
+
currency: 'USD'
|
|
21
|
+
});
|
|
22
|
+
return formatter.format(value);
|
|
23
|
+
};
|
|
17
24
|
const CustomLegend = _ref => {
|
|
18
25
|
let {
|
|
19
26
|
id,
|
|
@@ -23,7 +30,9 @@ const CustomLegend = _ref => {
|
|
|
23
30
|
orientation,
|
|
24
31
|
getLegendItemTitle,
|
|
25
32
|
getLegendItemSubtitle,
|
|
26
|
-
capitalizedLegend
|
|
33
|
+
capitalizedLegend,
|
|
34
|
+
subtitleToCurrency,
|
|
35
|
+
isPayOutChart
|
|
27
36
|
} = _ref;
|
|
28
37
|
return /*#__PURE__*/React.createElement("div", {
|
|
29
38
|
id: id,
|
|
@@ -44,9 +53,9 @@ const CustomLegend = _ref => {
|
|
|
44
53
|
className: "sub-title-percentage-container"
|
|
45
54
|
}, /*#__PURE__*/React.createElement("span", {
|
|
46
55
|
className: "sub-title"
|
|
47
|
-
}, getLegendItemSubtitle(key)), key
|
|
56
|
+
}, subtitleToCurrency ? toCurrency(getLegendItemSubtitle(key)) : getLegendItemSubtitle(key)), Object.prototype.hasOwnProperty.call(key, 'percentage') && !isPayOutChart && /*#__PURE__*/React.createElement("span", {
|
|
48
57
|
className: "percentage-title"
|
|
49
|
-
}, `${key
|
|
58
|
+
}, `${key?.percentage}%`)))));
|
|
50
59
|
};
|
|
51
60
|
CustomLegend.propTypes = {
|
|
52
61
|
/**
|
|
@@ -80,13 +89,18 @@ CustomLegend.propTypes = {
|
|
|
80
89
|
/**
|
|
81
90
|
* Flag on whether to capitalize legend keys
|
|
82
91
|
*/
|
|
83
|
-
capitalizedLegend: _propTypes.default.bool
|
|
92
|
+
capitalizedLegend: _propTypes.default.bool,
|
|
93
|
+
/**
|
|
94
|
+
* Flag on whether to convert the subtitle to currency
|
|
95
|
+
*/
|
|
96
|
+
subtitleToCurrency: _propTypes.default.bool
|
|
84
97
|
};
|
|
85
98
|
CustomLegend.defaultProps = {
|
|
86
99
|
orientation: 'horizontal',
|
|
87
100
|
getLegendItemTitle: key => key,
|
|
88
101
|
/* eslint-disable no-unused-vars */
|
|
89
102
|
getLegendItemSubtitle: () => {},
|
|
90
|
-
capitalizedLegend: false
|
|
103
|
+
capitalizedLegend: false,
|
|
104
|
+
subtitleToCurrency: false
|
|
91
105
|
};
|
|
92
106
|
var _default = exports.default = CustomLegend;
|
|
@@ -14,7 +14,82 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
15
|
const baseClassName = _exports.default.base;
|
|
16
16
|
const componentClassName = 'custom-tooltip-content';
|
|
17
|
-
const
|
|
17
|
+
const formatValue = (value, isTimeFormat) => {
|
|
18
|
+
if (isTimeFormat) {
|
|
19
|
+
return (0, _utils.formatTime)(value);
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'number') {
|
|
22
|
+
return Number.isInteger(value) ? value : value.toFixed(2);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const PayoutPieChartLabel = _ref => {
|
|
27
|
+
let {
|
|
28
|
+
entry,
|
|
29
|
+
formatLabelValue
|
|
30
|
+
} = _ref;
|
|
31
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
className: "pie-chart-label"
|
|
33
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
className: "status"
|
|
35
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
className: "dot",
|
|
37
|
+
style: {
|
|
38
|
+
backgroundColor: entry?.payload?.color
|
|
39
|
+
}
|
|
40
|
+
}), /*#__PURE__*/React.createElement("p", {
|
|
41
|
+
className: "label",
|
|
42
|
+
key: `${entry.name}`,
|
|
43
|
+
style: {
|
|
44
|
+
color: entry.color,
|
|
45
|
+
textTransform: 'capitalize'
|
|
46
|
+
}
|
|
47
|
+
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)} `)), /*#__PURE__*/React.createElement("p", {
|
|
48
|
+
className: "value"
|
|
49
|
+
}, `${formatLabelValue(entry.value)}`));
|
|
50
|
+
};
|
|
51
|
+
const StandardPieChartLabel = _ref2 => {
|
|
52
|
+
let {
|
|
53
|
+
entry,
|
|
54
|
+
formatLabelValue
|
|
55
|
+
} = _ref2;
|
|
56
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", null, "Submissions"), /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
className: "pie-chart-label"
|
|
58
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
className: "status"
|
|
60
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
61
|
+
className: "dot",
|
|
62
|
+
style: {
|
|
63
|
+
backgroundColor: entry?.payload?.color
|
|
64
|
+
}
|
|
65
|
+
}), /*#__PURE__*/React.createElement("p", {
|
|
66
|
+
className: "label",
|
|
67
|
+
key: `${entry.name}`,
|
|
68
|
+
style: {
|
|
69
|
+
color: entry.color,
|
|
70
|
+
textTransform: 'capitalize'
|
|
71
|
+
}
|
|
72
|
+
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)} `)), /*#__PURE__*/React.createElement("p", {
|
|
73
|
+
className: "value"
|
|
74
|
+
}, `${formatLabelValue(entry.value)}`), /*#__PURE__*/React.createElement("p", {
|
|
75
|
+
className: "percentage-title"
|
|
76
|
+
}, `${entry?.payload?.percentage}%`)));
|
|
77
|
+
};
|
|
78
|
+
const StandardChartLabel = _ref3 => {
|
|
79
|
+
let {
|
|
80
|
+
entry,
|
|
81
|
+
formatLabelValue
|
|
82
|
+
} = _ref3;
|
|
83
|
+
return /*#__PURE__*/React.createElement("p", {
|
|
84
|
+
className: "label",
|
|
85
|
+
key: `${entry.name}`,
|
|
86
|
+
style: {
|
|
87
|
+
color: entry.color,
|
|
88
|
+
textTransform: 'capitalize'
|
|
89
|
+
}
|
|
90
|
+
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)}: ${formatLabelValue(entry.value)}`);
|
|
91
|
+
};
|
|
92
|
+
const CustomTooltipContent = _ref4 => {
|
|
18
93
|
let {
|
|
19
94
|
id,
|
|
20
95
|
className: userClassName,
|
|
@@ -24,106 +99,96 @@ const CustomTooltipContent = _ref => {
|
|
|
24
99
|
active,
|
|
25
100
|
payload,
|
|
26
101
|
label,
|
|
27
|
-
isPieChart
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
102
|
+
isPieChart,
|
|
103
|
+
isPayOutChart
|
|
104
|
+
} = _ref4;
|
|
105
|
+
const formatLabelValue = React.useCallback(value => formatValue(value, isTimeFormat), [isTimeFormat]);
|
|
106
|
+
const renderContent = React.useCallback(entry => {
|
|
107
|
+
if (isPieChart && isPayOutChart) {
|
|
108
|
+
return /*#__PURE__*/React.createElement(PayoutPieChartLabel, {
|
|
109
|
+
entry: entry,
|
|
110
|
+
formatLabelValue: formatLabelValue
|
|
111
|
+
});
|
|
36
112
|
}
|
|
37
|
-
return value;
|
|
38
|
-
};
|
|
39
|
-
const renderContent = entry => {
|
|
40
113
|
if (isPieChart) {
|
|
41
|
-
return /*#__PURE__*/React.createElement(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
46
|
-
className: "dot",
|
|
47
|
-
style: {
|
|
48
|
-
backgroundColor: entry?.payload?.color
|
|
49
|
-
}
|
|
50
|
-
}), /*#__PURE__*/React.createElement("p", {
|
|
51
|
-
className: "label",
|
|
52
|
-
key: `${entry.name}`,
|
|
53
|
-
style: {
|
|
54
|
-
color: entry.color,
|
|
55
|
-
textTransform: 'capitalize'
|
|
56
|
-
}
|
|
57
|
-
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)} `)), /*#__PURE__*/React.createElement("p", {
|
|
58
|
-
className: "value"
|
|
59
|
-
}, `${formatLabelValue(entry.value)}`), /*#__PURE__*/React.createElement("p", {
|
|
60
|
-
className: "percentage-title"
|
|
61
|
-
}, `${entry?.payload?.percentage}%`)));
|
|
114
|
+
return /*#__PURE__*/React.createElement(StandardPieChartLabel, {
|
|
115
|
+
entry: entry,
|
|
116
|
+
formatLabelValue: formatLabelValue
|
|
117
|
+
});
|
|
62
118
|
}
|
|
63
|
-
return /*#__PURE__*/React.createElement(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)}: ${formatLabelValue(entry.value)}`);
|
|
71
|
-
};
|
|
72
|
-
if (active && payload && payload?.length) {
|
|
73
|
-
const newPayload = payload.filter(item => item?.name !== 'bounds');
|
|
74
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
75
|
-
id: id,
|
|
76
|
-
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
77
|
-
}, /*#__PURE__*/React.createElement("p", {
|
|
78
|
-
className: "label"
|
|
79
|
-
}, isDateValue ? (0, _utils.formatDate)(label, dateFormat) : label), newPayload.map(entry => renderContent(entry)));
|
|
119
|
+
return /*#__PURE__*/React.createElement(StandardChartLabel, {
|
|
120
|
+
entry: entry,
|
|
121
|
+
formatLabelValue: formatLabelValue
|
|
122
|
+
});
|
|
123
|
+
}, [isPieChart, isPayOutChart, formatLabelValue]);
|
|
124
|
+
if (!active || !payload || !payload.length) {
|
|
125
|
+
return null;
|
|
80
126
|
}
|
|
81
|
-
|
|
127
|
+
const filteredPayload = payload.filter(item => item?.name !== 'bounds');
|
|
128
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
id: id,
|
|
130
|
+
className: [baseClassName, componentClassName, userClassName].filter(Boolean).join(' ')
|
|
131
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
132
|
+
className: "label"
|
|
133
|
+
}, isDateValue ? (0, _utils.formatDate)(label, dateFormat) : label), filteredPayload.map(entry => /*#__PURE__*/React.createElement(React.Fragment, {
|
|
134
|
+
key: entry.name || entry.dataKey
|
|
135
|
+
}, renderContent(entry))));
|
|
82
136
|
};
|
|
83
137
|
CustomTooltipContent.propTypes = {
|
|
84
138
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
139
|
+
* The id of the tooltip component
|
|
140
|
+
*/
|
|
87
141
|
id: _propTypes.default.string,
|
|
88
142
|
/**
|
|
89
|
-
* Additional class names for the
|
|
143
|
+
* Additional class names for the tooltip component
|
|
90
144
|
*/
|
|
91
145
|
className: _propTypes.default.string,
|
|
92
146
|
/**
|
|
93
|
-
* Flag
|
|
147
|
+
* Flag indicating whether values should be formatted as time
|
|
94
148
|
*/
|
|
95
149
|
isTimeFormat: _propTypes.default.bool,
|
|
96
150
|
/**
|
|
97
|
-
* The
|
|
151
|
+
* The format to use for date values
|
|
98
152
|
*/
|
|
99
153
|
dateFormat: _propTypes.default.oneOf(Object.values(_utils.DATE_FORMATS)),
|
|
100
154
|
/**
|
|
101
|
-
* Flag
|
|
155
|
+
* Flag indicating whether the label is a date value
|
|
102
156
|
*/
|
|
103
157
|
isDateValue: _propTypes.default.bool,
|
|
104
158
|
/**
|
|
105
|
-
* If
|
|
106
|
-
* If set false, the tooltip is hidden, usually calculated internally.
|
|
159
|
+
* If true, the tooltip is displayed
|
|
107
160
|
*/
|
|
108
161
|
active: _propTypes.default.bool.isRequired,
|
|
109
162
|
/**
|
|
110
|
-
* The source data
|
|
111
|
-
* always calculated internally and cannot be user set.
|
|
163
|
+
* The source data to be displayed in the tooltip
|
|
112
164
|
*/
|
|
113
|
-
payload: _propTypes.default.arrayOf(_propTypes.default.
|
|
165
|
+
payload: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
166
|
+
name: _propTypes.default.string,
|
|
167
|
+
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
168
|
+
payload: _propTypes.default.shape({}),
|
|
169
|
+
dataKey: _propTypes.default.string,
|
|
170
|
+
color: _propTypes.default.string
|
|
171
|
+
})).isRequired,
|
|
114
172
|
/**
|
|
115
|
-
*The label value which is active
|
|
173
|
+
* The label value which is active
|
|
116
174
|
*/
|
|
117
175
|
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
|
|
118
176
|
/**
|
|
119
|
-
* Flag
|
|
177
|
+
* Flag indicating whether the chart is a pie chart
|
|
178
|
+
*/
|
|
179
|
+
isPieChart: _propTypes.default.bool,
|
|
180
|
+
/**
|
|
181
|
+
* Flag indicating whether the chart is a payout chart
|
|
120
182
|
*/
|
|
121
|
-
|
|
183
|
+
isPayOutChart: _propTypes.default.bool
|
|
122
184
|
};
|
|
123
185
|
CustomTooltipContent.defaultProps = {
|
|
186
|
+
id: undefined,
|
|
187
|
+
className: undefined,
|
|
124
188
|
isTimeFormat: false,
|
|
125
189
|
isDateValue: true,
|
|
126
190
|
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE,
|
|
127
|
-
isPieChart: false
|
|
191
|
+
isPieChart: false,
|
|
192
|
+
isPayOutChart: false
|
|
128
193
|
};
|
|
129
|
-
var _default = exports.default = CustomTooltipContent;
|
|
194
|
+
var _default = exports.default = /*#__PURE__*/React.memo(CustomTooltipContent);
|
|
@@ -27,14 +27,18 @@ const PieChart = _ref => {
|
|
|
27
27
|
height,
|
|
28
28
|
width,
|
|
29
29
|
innerRadius,
|
|
30
|
-
outerRadius
|
|
30
|
+
outerRadius,
|
|
31
|
+
formatTotal,
|
|
32
|
+
subtitleToCurrency,
|
|
33
|
+
isPayOutChart
|
|
31
34
|
} = _ref;
|
|
32
35
|
const total = data.reduce((sum, item) => sum + item[valueKey], 0);
|
|
36
|
+
const displayTotal = formatTotal ? formatTotal(total) : `${total}`;
|
|
33
37
|
const formattedData = data.map(item => ({
|
|
34
38
|
...item,
|
|
35
39
|
label: item[labelKey],
|
|
36
40
|
color: colors[data.indexOf(item)],
|
|
37
|
-
percentage: (item[valueKey] / total * 100).toFixed(0)
|
|
41
|
+
percentage: total === 0 ? 0.0 : (item[valueKey] / total * 100).toFixed(0)
|
|
38
42
|
}));
|
|
39
43
|
return /*#__PURE__*/React.createElement("div", {
|
|
40
44
|
id: id,
|
|
@@ -63,7 +67,8 @@ const PieChart = _ref => {
|
|
|
63
67
|
}))), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
64
68
|
content: /*#__PURE__*/React.createElement(_Common.CustomTooltipContent, {
|
|
65
69
|
isDateValue: false,
|
|
66
|
-
isPieChart: true
|
|
70
|
+
isPieChart: true,
|
|
71
|
+
isPayOutChart: isPayOutChart
|
|
67
72
|
})
|
|
68
73
|
}), /*#__PURE__*/React.createElement("text", {
|
|
69
74
|
x: "50%",
|
|
@@ -81,14 +86,16 @@ const PieChart = _ref => {
|
|
|
81
86
|
dy: "1.2em",
|
|
82
87
|
fill: "var(--heading)",
|
|
83
88
|
fontSize: "22"
|
|
84
|
-
},
|
|
89
|
+
}, displayTotal)))), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
85
90
|
key: id,
|
|
86
91
|
colorsArray: colors,
|
|
87
92
|
yKeysArray: formattedData,
|
|
88
93
|
capitalizedLegend: true,
|
|
89
94
|
orientation: "vertical",
|
|
90
95
|
getLegendItemTitle: entry => entry[labelKey],
|
|
91
|
-
getLegendItemSubtitle: entry => entry[valueKey]
|
|
96
|
+
getLegendItemSubtitle: entry => entry[valueKey],
|
|
97
|
+
subtitleToCurrency: subtitleToCurrency,
|
|
98
|
+
isPayOutChart: isPayOutChart
|
|
92
99
|
})));
|
|
93
100
|
};
|
|
94
101
|
PieChart.propTypes = {
|
|
@@ -104,7 +111,10 @@ PieChart.propTypes = {
|
|
|
104
111
|
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
105
112
|
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
106
113
|
innerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
107
|
-
outerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
114
|
+
outerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
115
|
+
formatTotal: _propTypes.default.func,
|
|
116
|
+
subtitleToCurrency: _propTypes.default.bool,
|
|
117
|
+
isPayOutChart: _propTypes.default.bool
|
|
108
118
|
};
|
|
109
119
|
PieChart.defaultProps = {
|
|
110
120
|
id: undefined,
|
|
@@ -112,6 +122,9 @@ PieChart.defaultProps = {
|
|
|
112
122
|
width: '100%',
|
|
113
123
|
height: 300,
|
|
114
124
|
innerRadius: '50%',
|
|
115
|
-
outerRadius: '100%'
|
|
125
|
+
outerRadius: '100%',
|
|
126
|
+
formatTotal: null,
|
|
127
|
+
subtitleToCurrency: false,
|
|
128
|
+
isPayOutChart: false
|
|
116
129
|
};
|
|
117
130
|
var _default = exports.default = PieChart;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
10
|
+
require("./styles.scss");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
// Local Definitions
|
|
15
|
+
const baseClassName = _exports.default.base;
|
|
16
|
+
const componentClassName = 'throughput-indicator';
|
|
17
|
+
const ThroughPutIndicator = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
data,
|
|
20
|
+
keyName = 'reserved'
|
|
21
|
+
} = _ref;
|
|
22
|
+
const renderNoChange = () => /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
className: [baseClassName, componentClassName].filter(e => e).join(' ')
|
|
24
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
25
|
+
className: "no-change-text"
|
|
26
|
+
}, "No change"));
|
|
27
|
+
const renderChange = function (direction, percentage) {
|
|
28
|
+
let icon = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : direction === 'positive' ? 'S' : 'R';
|
|
29
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
className: [baseClassName, componentClassName].filter(e => e).join(' ')
|
|
31
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
32
|
+
className: `ai-icon ${direction}-throughput-indicator`
|
|
33
|
+
}, icon), /*#__PURE__*/React.createElement("p", null, percentage, "%"));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Handle invalid or insufficient data
|
|
37
|
+
if (!data || data.length < 2) {
|
|
38
|
+
return renderNoChange();
|
|
39
|
+
}
|
|
40
|
+
const first = data[0][keyName];
|
|
41
|
+
const last = data[data.length - 1][keyName];
|
|
42
|
+
|
|
43
|
+
// Handle no change scenarios
|
|
44
|
+
if (first === 0 && last === 0) {
|
|
45
|
+
return renderNoChange();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handle special case: starting from zero
|
|
49
|
+
if (first === 0 && last !== 0) {
|
|
50
|
+
return renderChange('positive', '100');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Calculate percentage change
|
|
54
|
+
const percentChange = (last - first) / Math.abs(first) * 100;
|
|
55
|
+
const rounded = Math.abs(percentChange).toFixed(1);
|
|
56
|
+
|
|
57
|
+
// No change
|
|
58
|
+
if (percentChange === 0) {
|
|
59
|
+
return renderNoChange();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Positive or negative change
|
|
63
|
+
const direction = percentChange > 0 ? 'positive' : 'negative';
|
|
64
|
+
const icon = direction === 'positive' ? 'S' : 'R';
|
|
65
|
+
return renderChange(direction, rounded, icon);
|
|
66
|
+
};
|
|
67
|
+
ThroughPutIndicator.propTypes = {
|
|
68
|
+
/**
|
|
69
|
+
* The data to be displayed in the throughput indicator
|
|
70
|
+
*/
|
|
71
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
72
|
+
data: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
73
|
+
/**
|
|
74
|
+
* The key name to be displayed in the throughput indicator
|
|
75
|
+
*/
|
|
76
|
+
keyName: _propTypes.default.string
|
|
77
|
+
};
|
|
78
|
+
var _default = exports.default = ThroughPutIndicator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ThroughPutIndicator", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ThroughPutIndicator.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ThroughPutIndicator = _interopRequireDefault(require("./ThroughPutIndicator"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
6
|
+
|
|
7
|
+
.#{bem.$base} {
|
|
8
|
+
.throughput-indicator {
|
|
9
|
+
align-items: center;
|
|
10
|
+
border: 1px solid var(--hard-grey);
|
|
11
|
+
border-radius: 2rem;
|
|
12
|
+
display: flex;
|
|
13
|
+
gap: .5rem;
|
|
14
|
+
height: 3rem;
|
|
15
|
+
padding: .5rem;
|
|
16
|
+
|
|
17
|
+
.positive-throughput-indicator {
|
|
18
|
+
color: var(--success);
|
|
19
|
+
font-size: 1rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.negative-throughput-indicator {
|
|
23
|
+
color: var(--error);
|
|
24
|
+
font-size: .75rem;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.no-change-text {
|
|
28
|
+
color: var(--paragraph);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
p {
|
|
32
|
+
font-size: 1rem;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|