@pareto-engineering/design-system 5.2.0 → 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 +61 -5
- package/dist/cjs/a/Charts/AreaChart/styles.scss +22 -0
- package/dist/cjs/a/Charts/BarChart/BarChart.js +1 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +23 -5
- package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +10 -2
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +139 -42
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/styles.scss +4 -0
- package/dist/cjs/a/Charts/PieChart/PieChart.js +39 -8
- package/dist/cjs/a/Charts/PieChart/styles.scss +88 -0
- package/dist/cjs/a/HamburgerButton/styles.scss +151 -9
- 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/XMLEditor/XMLEditor.js +4 -1
- 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 +62 -6
- package/dist/es/a/Charts/AreaChart/styles.scss +22 -0
- package/dist/es/a/Charts/BarChart/BarChart.js +1 -0
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +23 -5
- package/dist/es/a/Charts/Common/CustomLegend/styles.scss +10 -2
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +128 -40
- package/dist/es/a/Charts/Common/CustomTooltipContent/styles.scss +4 -0
- package/dist/es/a/Charts/PieChart/PieChart.js +39 -8
- package/dist/es/a/Charts/PieChart/styles.scss +88 -0
- package/dist/es/a/HamburgerButton/styles.scss +151 -9
- 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/XMLEditor/XMLEditor.js +6 -3
- 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 +7 -6
- package/src/ui/a/Charts/AreaChart/AreaChart.jsx +74 -9
- package/src/ui/a/Charts/AreaChart/styles.scss +22 -0
- package/src/ui/a/Charts/BarChart/BarChart.jsx +1 -0
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +26 -3
- package/src/ui/a/Charts/Common/CustomLegend/styles.scss +10 -2
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +132 -48
- package/src/ui/a/Charts/Common/CustomTooltipContent/styles.scss +4 -0
- package/src/ui/a/Charts/PieChart/PieChart.jsx +54 -16
- package/src/ui/a/Charts/PieChart/styles.scss +88 -0
- package/src/ui/a/HamburgerButton/styles.scss +151 -9
- 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/XMLEditor/XMLEditor.jsx +15 -2
- 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 +433 -160
|
@@ -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,7 +87,15 @@ 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, {
|
|
98
|
+
key: id,
|
|
60
99
|
colorsArray: colors,
|
|
61
100
|
yKeysArray: yKeys,
|
|
62
101
|
capitalizedLegend: capitalizedLegend
|
|
@@ -77,7 +116,12 @@ const AreaChart = _ref => {
|
|
|
77
116
|
axisLine: false,
|
|
78
117
|
tickLine: false,
|
|
79
118
|
tickCount: 3,
|
|
80
|
-
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
|
+
}
|
|
81
125
|
}), /*#__PURE__*/React.createElement(_recharts.YAxis, {
|
|
82
126
|
domain: yAxisBounds,
|
|
83
127
|
scale: "linear",
|
|
@@ -101,6 +145,9 @@ const AreaChart = _ref => {
|
|
|
101
145
|
if (isTimeFormat) {
|
|
102
146
|
return (0, _utils.formatTime)(value);
|
|
103
147
|
}
|
|
148
|
+
if (isWorkerSubmissionChart) {
|
|
149
|
+
return Math.round(value);
|
|
150
|
+
}
|
|
104
151
|
return value.toFixed(2);
|
|
105
152
|
}
|
|
106
153
|
}), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
@@ -187,7 +234,15 @@ AreaChart.propTypes = {
|
|
|
187
234
|
/**
|
|
188
235
|
* The type of format for the datetime value
|
|
189
236
|
*/
|
|
190
|
-
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
|
|
191
246
|
};
|
|
192
247
|
AreaChart.defaultProps = {
|
|
193
248
|
filled: false,
|
|
@@ -195,6 +250,7 @@ AreaChart.defaultProps = {
|
|
|
195
250
|
height: 300,
|
|
196
251
|
capitalizedLegend: false,
|
|
197
252
|
isTimeFormat: false,
|
|
198
|
-
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE
|
|
253
|
+
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE,
|
|
254
|
+
isWorkerSubmissionChart: false
|
|
199
255
|
};
|
|
200
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
|
+
}
|
|
@@ -49,6 +49,7 @@ const BarChart = _ref => {
|
|
|
49
49
|
selectedYLabels: selectedYLabels,
|
|
50
50
|
setSelectedYLabels: setSelectedYLabels
|
|
51
51
|
})), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
52
|
+
key: id,
|
|
52
53
|
colorsArray: selectedYLabels.map(item => item.color),
|
|
53
54
|
yKeysArray: selectedYLabels.map(item => item.label),
|
|
54
55
|
capitalizedLegend: capitalizedLegend
|
|
@@ -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,
|
|
@@ -40,9 +49,13 @@ const CustomLegend = _ref => {
|
|
|
40
49
|
}
|
|
41
50
|
}), /*#__PURE__*/React.createElement("span", {
|
|
42
51
|
className: "text"
|
|
43
|
-
}, capitalizedLegend ? (0, _utils.snakeCaseToTitleCase)(getLegendItemTitle(key)) : getLegendItemTitle(key))), /*#__PURE__*/React.createElement("
|
|
52
|
+
}, capitalizedLegend ? (0, _utils.snakeCaseToTitleCase)(getLegendItemTitle(key)) : getLegendItemTitle(key))), /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
className: "sub-title-percentage-container"
|
|
54
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
44
55
|
className: "sub-title"
|
|
45
|
-
}, getLegendItemSubtitle(key)))))
|
|
56
|
+
}, subtitleToCurrency ? toCurrency(getLegendItemSubtitle(key)) : getLegendItemSubtitle(key)), Object.prototype.hasOwnProperty.call(key, 'percentage') && !isPayOutChart && /*#__PURE__*/React.createElement("span", {
|
|
57
|
+
className: "percentage-title"
|
|
58
|
+
}, `${key?.percentage}%`)))));
|
|
46
59
|
};
|
|
47
60
|
CustomLegend.propTypes = {
|
|
48
61
|
/**
|
|
@@ -76,13 +89,18 @@ CustomLegend.propTypes = {
|
|
|
76
89
|
/**
|
|
77
90
|
* Flag on whether to capitalize legend keys
|
|
78
91
|
*/
|
|
79
|
-
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
|
|
80
97
|
};
|
|
81
98
|
CustomLegend.defaultProps = {
|
|
82
99
|
orientation: 'horizontal',
|
|
83
100
|
getLegendItemTitle: key => key,
|
|
84
101
|
/* eslint-disable no-unused-vars */
|
|
85
102
|
getLegendItemSubtitle: () => {},
|
|
86
|
-
capitalizedLegend: false
|
|
103
|
+
capitalizedLegend: false,
|
|
104
|
+
subtitleToCurrency: false
|
|
87
105
|
};
|
|
88
106
|
var _default = exports.default = CustomLegend;
|
|
@@ -24,7 +24,6 @@ $default-box-shadow: 0 4px 16px 0 var(--soft-shadow);
|
|
|
24
24
|
min-width: fit-content;
|
|
25
25
|
|
|
26
26
|
.item {
|
|
27
|
-
box-shadow: $default-box-shadow;
|
|
28
27
|
padding-top: $default-padding;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -55,12 +54,21 @@ $default-box-shadow: 0 4px 16px 0 var(--soft-shadow);
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
|
|
57
|
+
|
|
58
|
+
|
|
58
59
|
.sub-title {
|
|
59
60
|
color: var(--heading);
|
|
60
61
|
display: flex;
|
|
61
62
|
font-size: calc($default-text-font-size * 1.2);
|
|
62
63
|
font-weight: 500;
|
|
63
|
-
justify-content: flex-
|
|
64
|
+
justify-content: flex-start;
|
|
65
|
+
margin-left: 1rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.percentage-title {
|
|
69
|
+
color: var(--paragraph);
|
|
70
|
+
font-size: calc($default-text-font-size * .75);
|
|
71
|
+
justify-content: flex-start;
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -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,
|
|
@@ -23,75 +98,97 @@ const CustomTooltipContent = _ref => {
|
|
|
23
98
|
isDateValue,
|
|
24
99
|
active,
|
|
25
100
|
payload,
|
|
26
|
-
label
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
101
|
+
label,
|
|
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
|
+
});
|
|
31
112
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
113
|
+
if (isPieChart) {
|
|
114
|
+
return /*#__PURE__*/React.createElement(StandardPieChartLabel, {
|
|
115
|
+
entry: entry,
|
|
116
|
+
formatLabelValue: formatLabelValue
|
|
117
|
+
});
|
|
35
118
|
}
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, /*#__PURE__*/React.createElement("p", {
|
|
44
|
-
className: "label"
|
|
45
|
-
}, isDateValue ? (0, _utils.formatDate)(label, dateFormat) : label), newPayload.map(entry => /*#__PURE__*/React.createElement("p", {
|
|
46
|
-
className: "label",
|
|
47
|
-
key: `${entry.name}`,
|
|
48
|
-
style: {
|
|
49
|
-
color: entry.color,
|
|
50
|
-
textTransform: 'capitalize'
|
|
51
|
-
}
|
|
52
|
-
}, `${(0, _utils.snakeCaseToTitleCase)(entry.name)}: ${formatLabelValue(entry.value)}`)));
|
|
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;
|
|
53
126
|
}
|
|
54
|
-
|
|
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))));
|
|
55
136
|
};
|
|
56
137
|
CustomTooltipContent.propTypes = {
|
|
57
138
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
139
|
+
* The id of the tooltip component
|
|
140
|
+
*/
|
|
60
141
|
id: _propTypes.default.string,
|
|
61
142
|
/**
|
|
62
|
-
* Additional class names for the
|
|
143
|
+
* Additional class names for the tooltip component
|
|
63
144
|
*/
|
|
64
145
|
className: _propTypes.default.string,
|
|
65
146
|
/**
|
|
66
|
-
* Flag
|
|
147
|
+
* Flag indicating whether values should be formatted as time
|
|
67
148
|
*/
|
|
68
149
|
isTimeFormat: _propTypes.default.bool,
|
|
69
150
|
/**
|
|
70
|
-
* The
|
|
151
|
+
* The format to use for date values
|
|
71
152
|
*/
|
|
72
153
|
dateFormat: _propTypes.default.oneOf(Object.values(_utils.DATE_FORMATS)),
|
|
73
154
|
/**
|
|
74
|
-
* Flag
|
|
155
|
+
* Flag indicating whether the label is a date value
|
|
75
156
|
*/
|
|
76
157
|
isDateValue: _propTypes.default.bool,
|
|
77
158
|
/**
|
|
78
|
-
* If
|
|
79
|
-
* If set false, the tooltip is hidden, usually calculated internally.
|
|
159
|
+
* If true, the tooltip is displayed
|
|
80
160
|
*/
|
|
81
161
|
active: _propTypes.default.bool.isRequired,
|
|
82
162
|
/**
|
|
83
|
-
* The source data
|
|
84
|
-
|
|
163
|
+
* The source data to be displayed in the tooltip
|
|
164
|
+
*/
|
|
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,
|
|
172
|
+
/**
|
|
173
|
+
* The label value which is active
|
|
174
|
+
*/
|
|
175
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
|
|
176
|
+
/**
|
|
177
|
+
* Flag indicating whether the chart is a pie chart
|
|
85
178
|
*/
|
|
86
|
-
|
|
179
|
+
isPieChart: _propTypes.default.bool,
|
|
87
180
|
/**
|
|
88
|
-
*
|
|
181
|
+
* Flag indicating whether the chart is a payout chart
|
|
89
182
|
*/
|
|
90
|
-
|
|
183
|
+
isPayOutChart: _propTypes.default.bool
|
|
91
184
|
};
|
|
92
185
|
CustomTooltipContent.defaultProps = {
|
|
186
|
+
id: undefined,
|
|
187
|
+
className: undefined,
|
|
93
188
|
isTimeFormat: false,
|
|
94
189
|
isDateValue: true,
|
|
95
|
-
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE
|
|
190
|
+
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE,
|
|
191
|
+
isPieChart: false,
|
|
192
|
+
isPayOutChart: false
|
|
96
193
|
};
|
|
97
|
-
var _default = exports.default = CustomTooltipContent;
|
|
194
|
+
var _default = exports.default = /*#__PURE__*/React.memo(CustomTooltipContent);
|
|
@@ -5,6 +5,9 @@ $default-padding: 1rem;
|
|
|
5
5
|
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
6
6
|
$default-border-radius: .25rem;
|
|
7
7
|
$default-border-line-width: .0625rem;
|
|
8
|
+
$default-legend-dot-width: .5rem;
|
|
9
|
+
$default-legend-dot-height: .5rem;
|
|
10
|
+
$default-legend-dot-margin-right: .3125rem;
|
|
8
11
|
|
|
9
12
|
.#{bem.$base} {
|
|
10
13
|
&.custom-tooltip-content {
|
|
@@ -20,3 +23,4 @@ $default-border-line-width: .0625rem;
|
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
}
|
|
26
|
+
|
|
@@ -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,
|
|
@@ -62,15 +66,36 @@ const PieChart = _ref => {
|
|
|
62
66
|
strokeWidth: 0
|
|
63
67
|
}))), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
64
68
|
content: /*#__PURE__*/React.createElement(_Common.CustomTooltipContent, {
|
|
65
|
-
isDateValue: false
|
|
69
|
+
isDateValue: false,
|
|
70
|
+
isPieChart: true,
|
|
71
|
+
isPayOutChart: isPayOutChart
|
|
66
72
|
})
|
|
67
|
-
})
|
|
73
|
+
}), /*#__PURE__*/React.createElement("text", {
|
|
74
|
+
x: "50%",
|
|
75
|
+
y: "50%",
|
|
76
|
+
textAnchor: "middle",
|
|
77
|
+
dominantBaseline: "middle",
|
|
78
|
+
style: {}
|
|
79
|
+
}, /*#__PURE__*/React.createElement("tspan", {
|
|
80
|
+
x: "50%",
|
|
81
|
+
dy: "-1.2em",
|
|
82
|
+
fontSize: "14",
|
|
83
|
+
fill: "grey"
|
|
84
|
+
}, "Total"), /*#__PURE__*/React.createElement("tspan", {
|
|
85
|
+
x: "50%",
|
|
86
|
+
dy: "1.2em",
|
|
87
|
+
fill: "var(--heading)",
|
|
88
|
+
fontSize: "22"
|
|
89
|
+
}, displayTotal)))), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
90
|
+
key: id,
|
|
68
91
|
colorsArray: colors,
|
|
69
92
|
yKeysArray: formattedData,
|
|
70
93
|
capitalizedLegend: true,
|
|
71
94
|
orientation: "vertical",
|
|
72
95
|
getLegendItemTitle: entry => entry[labelKey],
|
|
73
|
-
getLegendItemSubtitle: entry => entry[valueKey]
|
|
96
|
+
getLegendItemSubtitle: entry => entry[valueKey],
|
|
97
|
+
subtitleToCurrency: subtitleToCurrency,
|
|
98
|
+
isPayOutChart: isPayOutChart
|
|
74
99
|
})));
|
|
75
100
|
};
|
|
76
101
|
PieChart.propTypes = {
|
|
@@ -86,14 +111,20 @@ PieChart.propTypes = {
|
|
|
86
111
|
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
87
112
|
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
88
113
|
innerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
89
|
-
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
|
|
90
118
|
};
|
|
91
119
|
PieChart.defaultProps = {
|
|
92
120
|
id: undefined,
|
|
93
121
|
className: undefined,
|
|
94
122
|
width: '100%',
|
|
95
123
|
height: 300,
|
|
96
|
-
innerRadius: '
|
|
97
|
-
outerRadius: '100%'
|
|
124
|
+
innerRadius: '50%',
|
|
125
|
+
outerRadius: '100%',
|
|
126
|
+
formatTotal: null,
|
|
127
|
+
subtitleToCurrency: false,
|
|
128
|
+
isPayOutChart: false
|
|
98
129
|
};
|
|
99
130
|
var _default = exports.default = PieChart;
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
$default-margin: 1rem;
|
|
4
4
|
$default-padding: 1rem;
|
|
5
5
|
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
+
$soft-box-shadow: 0 .25rem 1rem var(--soft-shadow);
|
|
6
7
|
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
8
|
+
$default-legend-dot-width: .75rem;
|
|
9
|
+
$default-legend-dot-height: .75rem;
|
|
10
|
+
$default-legend-dot-margin-right: .3125rem;
|
|
7
11
|
|
|
8
12
|
.#{bem.$base} {
|
|
9
13
|
&.pie-chart {
|
|
@@ -13,6 +17,90 @@ $default-text-font-size: calc(var(--s-1) * 1rem);
|
|
|
13
17
|
margin: $default-margin 0;
|
|
14
18
|
padding: $default-padding;
|
|
15
19
|
|
|
20
|
+
.custom-legend {
|
|
21
|
+
.item {
|
|
22
|
+
padding-top: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.title .dot {
|
|
26
|
+
height: $default-legend-dot-height;
|
|
27
|
+
width: $default-legend-dot-width;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.title .text {
|
|
31
|
+
font-size: calc($default-text-font-size * 1.5);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.sub-title-percentage-container {
|
|
35
|
+
align-items: center;
|
|
36
|
+
display: flex;
|
|
37
|
+
gap: .8rem;
|
|
38
|
+
margin-left: .5rem;
|
|
39
|
+
width: fit-content;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.sub-title-percentage-container .sub-title {
|
|
43
|
+
font-size: calc($default-text-font-size * 1.25);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.sub-title-percentage-container .percentage-title {
|
|
47
|
+
font-size: calc($default-text-font-size * 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.custom-tooltip-content {
|
|
52
|
+
box-shadow: $soft-box-shadow;
|
|
53
|
+
|
|
54
|
+
p {
|
|
55
|
+
color: var(--hard-paragraph);
|
|
56
|
+
font-size: calc($default-text-font-size * .8);
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
margin: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.pie-chart-label {
|
|
62
|
+
align-items: center;
|
|
63
|
+
display: flex;
|
|
64
|
+
gap: 1.25rem;
|
|
65
|
+
justify-content: flex-start;
|
|
66
|
+
|
|
67
|
+
.status {
|
|
68
|
+
align-items: center;
|
|
69
|
+
display: flex;
|
|
70
|
+
gap: .1rem;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.label {
|
|
74
|
+
color: var(--hard-paragraph);
|
|
75
|
+
font-size: calc($default-text-font-size * 1);
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
text-transform: capitalize;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.dot {
|
|
81
|
+
border-radius: 50%;
|
|
82
|
+
display: inline-block;
|
|
83
|
+
height: $default-legend-dot-height;
|
|
84
|
+
margin-right: $default-legend-dot-margin-right;
|
|
85
|
+
width: $default-legend-dot-width;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.value {
|
|
89
|
+
color: var(--hard-paragraph);
|
|
90
|
+
font-size: calc($default-text-font-size * 1);
|
|
91
|
+
font-weight: 600;
|
|
92
|
+
text-transform: capitalize;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.percentage-title {
|
|
96
|
+
color: var(--soft-paragraph);
|
|
97
|
+
font-size: calc($default-text-font-size * 1);
|
|
98
|
+
font-weight: 300;
|
|
99
|
+
text-transform: capitalize;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
16
104
|
.chart-header {
|
|
17
105
|
align-items: center;
|
|
18
106
|
display: flex;
|