@pareto-engineering/design-system 5.0.2 → 5.0.5
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 +13 -3
- package/dist/cjs/a/Charts/BarChart/BarChart.js +4 -6
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +7 -26
- package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +14 -41
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +7 -18
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +4 -3
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +6 -7
- package/dist/cjs/a/Charts/index.js +1 -8
- package/dist/cjs/a/index.js +0 -6
- package/dist/cjs/f/fields/FileUpload/common/Preview/Preview.js +9 -2
- package/dist/cjs/utils/formatting.js +2 -10
- package/dist/cjs/utils/index.js +0 -6
- package/dist/es/a/Charts/AreaChart/AreaChart.js +13 -3
- package/dist/es/a/Charts/BarChart/BarChart.js +4 -6
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +21 -38
- package/dist/es/a/Charts/Common/CustomLegend/styles.scss +14 -41
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +8 -19
- package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +5 -3
- package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +6 -7
- package/dist/es/a/Charts/index.js +1 -2
- package/dist/es/a/index.js +1 -1
- package/dist/es/f/fields/FileUpload/common/Preview/Preview.js +9 -2
- package/dist/es/utils/formatting.js +0 -7
- package/dist/es/utils/index.js +1 -1
- package/package.json +2 -2
- package/src/stories/a/AreaChart.stories.jsx +1 -1
- package/src/stories/a/BarChart.stories.jsx +1 -1
- package/src/ui/a/Charts/AreaChart/AreaChart.jsx +14 -8
- package/src/ui/a/Charts/BarChart/BarChart.jsx +2 -4
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +29 -54
- package/src/ui/a/Charts/Common/CustomLegend/styles.scss +14 -41
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +13 -25
- package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +4 -4
- package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +6 -7
- package/src/ui/a/Charts/index.js +0 -1
- package/src/ui/a/index.js +1 -1
- package/src/ui/f/fields/FileUpload/common/Preview/Preview.jsx +26 -12
- package/src/ui/utils/formatting.js +0 -8
- package/src/ui/utils/index.js +1 -3
- package/tests/__snapshots__/Storyshots.test.js.snap +428 -1164
- package/dist/cjs/a/Charts/PieChart/PieChart.js +0 -99
- package/dist/cjs/a/Charts/PieChart/index.js +0 -13
- package/dist/cjs/a/Charts/PieChart/styles.scss +0 -48
- package/dist/es/a/Charts/PieChart/PieChart.js +0 -89
- package/dist/es/a/Charts/PieChart/index.js +0 -1
- package/dist/es/a/Charts/PieChart/styles.scss +0 -48
- package/src/stories/a/PieChart.stories.jsx +0 -53
- package/src/ui/a/Charts/PieChart/PieChart.jsx +0 -125
- package/src/ui/a/Charts/PieChart/index.js +0 -1
- package/src/ui/a/Charts/PieChart/styles.scss +0 -48
|
@@ -1,99 +0,0 @@
|
|
|
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 _recharts = require("recharts");
|
|
10
|
-
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
11
|
-
var _Common = require("../Common");
|
|
12
|
-
require("./styles.scss");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
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); }
|
|
15
|
-
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; }
|
|
16
|
-
const baseClassName = _exports.default.base;
|
|
17
|
-
const componentClassName = 'pie-chart';
|
|
18
|
-
const PieChart = _ref => {
|
|
19
|
-
let {
|
|
20
|
-
id,
|
|
21
|
-
className: userClassName,
|
|
22
|
-
data,
|
|
23
|
-
title,
|
|
24
|
-
valueKey,
|
|
25
|
-
labelKey,
|
|
26
|
-
colors,
|
|
27
|
-
height,
|
|
28
|
-
width,
|
|
29
|
-
innerRadius,
|
|
30
|
-
outerRadius
|
|
31
|
-
} = _ref;
|
|
32
|
-
const total = data.reduce((sum, item) => sum + item[valueKey], 0);
|
|
33
|
-
const formattedData = data.map(item => ({
|
|
34
|
-
...item,
|
|
35
|
-
label: item[labelKey],
|
|
36
|
-
color: colors[data.indexOf(item)],
|
|
37
|
-
percentage: (item[valueKey] / total * 100).toFixed(0)
|
|
38
|
-
}));
|
|
39
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
40
|
-
id: id,
|
|
41
|
-
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
42
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
43
|
-
className: "chart-header"
|
|
44
|
-
}, /*#__PURE__*/React.createElement("h3", null, title)), /*#__PURE__*/React.createElement("div", {
|
|
45
|
-
className: "chart-content"
|
|
46
|
-
}, /*#__PURE__*/React.createElement(_recharts.ResponsiveContainer, {
|
|
47
|
-
width: width,
|
|
48
|
-
height: height
|
|
49
|
-
}, /*#__PURE__*/React.createElement(_recharts.PieChart, null, /*#__PURE__*/React.createElement(_recharts.Pie, {
|
|
50
|
-
data: formattedData,
|
|
51
|
-
dataKey: valueKey,
|
|
52
|
-
nameKey: labelKey,
|
|
53
|
-
cx: "50%",
|
|
54
|
-
cy: "50%",
|
|
55
|
-
innerRadius: innerRadius,
|
|
56
|
-
outerRadius: outerRadius,
|
|
57
|
-
label: false,
|
|
58
|
-
paddingAngle: 0
|
|
59
|
-
}, formattedData.map((entry, index) => /*#__PURE__*/React.createElement(_recharts.Cell, {
|
|
60
|
-
key: entry[labelKey],
|
|
61
|
-
fill: colors[index],
|
|
62
|
-
strokeWidth: 0
|
|
63
|
-
}))), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
64
|
-
content: /*#__PURE__*/React.createElement(_Common.CustomTooltipContent, {
|
|
65
|
-
isDateValue: false
|
|
66
|
-
})
|
|
67
|
-
}))), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
68
|
-
colorsArray: colors,
|
|
69
|
-
yKeysArray: formattedData,
|
|
70
|
-
capitalizedLegend: true,
|
|
71
|
-
orientation: "vertical",
|
|
72
|
-
getLegendItemTitle: entry => entry[labelKey],
|
|
73
|
-
getLegendItemSubtitle: entry => entry[valueKey]
|
|
74
|
-
})));
|
|
75
|
-
};
|
|
76
|
-
PieChart.propTypes = {
|
|
77
|
-
id: _propTypes.default.string,
|
|
78
|
-
className: _propTypes.default.string,
|
|
79
|
-
data: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
80
|
-
[_propTypes.default.string]: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
81
|
-
})).isRequired,
|
|
82
|
-
title: _propTypes.default.string.isRequired,
|
|
83
|
-
valueKey: _propTypes.default.string.isRequired,
|
|
84
|
-
labelKey: _propTypes.default.string.isRequired,
|
|
85
|
-
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
86
|
-
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
87
|
-
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
88
|
-
innerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
89
|
-
outerRadius: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
90
|
-
};
|
|
91
|
-
PieChart.defaultProps = {
|
|
92
|
-
id: undefined,
|
|
93
|
-
className: undefined,
|
|
94
|
-
width: '100%',
|
|
95
|
-
height: 300,
|
|
96
|
-
innerRadius: '0%',
|
|
97
|
-
outerRadius: '100%'
|
|
98
|
-
};
|
|
99
|
-
var _default = exports.default = PieChart;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "PieChart", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _PieChart.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _PieChart = _interopRequireDefault(require("./PieChart"));
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
@use "@pareto-engineering/bem";
|
|
2
|
-
|
|
3
|
-
$default-margin: 1rem;
|
|
4
|
-
$default-padding: 1rem;
|
|
5
|
-
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
-
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
7
|
-
|
|
8
|
-
.#{bem.$base} {
|
|
9
|
-
&.pie-chart {
|
|
10
|
-
background-color: var(--background-far);
|
|
11
|
-
border-radius: var(--theme-default-border-radius);
|
|
12
|
-
box-shadow: $default-box-shadow;
|
|
13
|
-
margin: $default-margin 0;
|
|
14
|
-
padding: $default-padding;
|
|
15
|
-
|
|
16
|
-
.chart-header {
|
|
17
|
-
align-items: center;
|
|
18
|
-
display: flex;
|
|
19
|
-
justify-content: space-between;
|
|
20
|
-
margin-bottom: $default-margin;
|
|
21
|
-
|
|
22
|
-
h3 {
|
|
23
|
-
color: var(--subtitle);
|
|
24
|
-
margin: calc($default-margin / 5);
|
|
25
|
-
text-align: left;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.chart-content {
|
|
30
|
-
align-items: flex-start;
|
|
31
|
-
display: flex;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.recharts-wrapper {
|
|
35
|
-
.recharts-surface {
|
|
36
|
-
.recharts-text {
|
|
37
|
-
fill: var(--soft-paragraph);
|
|
38
|
-
font-size: calc($default-text-font-size * .75);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.recharts-text.recharts-label {
|
|
42
|
-
fill: var(--paragraph);
|
|
43
|
-
font-size: $default-text-font-size;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { PieChart as RechartsPieChart, Pie, Cell, ResponsiveContainer, Tooltip } from 'recharts';
|
|
4
|
-
import styleNames from '@pareto-engineering/bem/exports';
|
|
5
|
-
import { CustomLegend, CustomTooltipContent } from "../Common";
|
|
6
|
-
import "./styles.scss";
|
|
7
|
-
const baseClassName = styleNames.base;
|
|
8
|
-
const componentClassName = 'pie-chart';
|
|
9
|
-
const PieChart = ({
|
|
10
|
-
id,
|
|
11
|
-
className: userClassName,
|
|
12
|
-
data,
|
|
13
|
-
title,
|
|
14
|
-
valueKey,
|
|
15
|
-
labelKey,
|
|
16
|
-
colors,
|
|
17
|
-
height,
|
|
18
|
-
width,
|
|
19
|
-
innerRadius,
|
|
20
|
-
outerRadius
|
|
21
|
-
}) => {
|
|
22
|
-
const total = data.reduce((sum, item) => sum + item[valueKey], 0);
|
|
23
|
-
const formattedData = data.map(item => ({
|
|
24
|
-
...item,
|
|
25
|
-
label: item[labelKey],
|
|
26
|
-
color: colors[data.indexOf(item)],
|
|
27
|
-
percentage: (item[valueKey] / total * 100).toFixed(0)
|
|
28
|
-
}));
|
|
29
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
30
|
-
id: id,
|
|
31
|
-
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
32
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
33
|
-
className: "chart-header"
|
|
34
|
-
}, /*#__PURE__*/React.createElement("h3", null, title)), /*#__PURE__*/React.createElement("div", {
|
|
35
|
-
className: "chart-content"
|
|
36
|
-
}, /*#__PURE__*/React.createElement(ResponsiveContainer, {
|
|
37
|
-
width: width,
|
|
38
|
-
height: height
|
|
39
|
-
}, /*#__PURE__*/React.createElement(RechartsPieChart, null, /*#__PURE__*/React.createElement(Pie, {
|
|
40
|
-
data: formattedData,
|
|
41
|
-
dataKey: valueKey,
|
|
42
|
-
nameKey: labelKey,
|
|
43
|
-
cx: "50%",
|
|
44
|
-
cy: "50%",
|
|
45
|
-
innerRadius: innerRadius,
|
|
46
|
-
outerRadius: outerRadius,
|
|
47
|
-
label: false,
|
|
48
|
-
paddingAngle: 0
|
|
49
|
-
}, formattedData.map((entry, index) => /*#__PURE__*/React.createElement(Cell, {
|
|
50
|
-
key: entry[labelKey],
|
|
51
|
-
fill: colors[index],
|
|
52
|
-
strokeWidth: 0
|
|
53
|
-
}))), /*#__PURE__*/React.createElement(Tooltip, {
|
|
54
|
-
content: /*#__PURE__*/React.createElement(CustomTooltipContent, {
|
|
55
|
-
isDateValue: false
|
|
56
|
-
})
|
|
57
|
-
}))), /*#__PURE__*/React.createElement(CustomLegend, {
|
|
58
|
-
colorsArray: colors,
|
|
59
|
-
yKeysArray: formattedData,
|
|
60
|
-
capitalizedLegend: true,
|
|
61
|
-
orientation: "vertical",
|
|
62
|
-
getLegendItemTitle: entry => entry[labelKey],
|
|
63
|
-
getLegendItemSubtitle: entry => entry[valueKey]
|
|
64
|
-
})));
|
|
65
|
-
};
|
|
66
|
-
PieChart.propTypes = {
|
|
67
|
-
id: PropTypes.string,
|
|
68
|
-
className: PropTypes.string,
|
|
69
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
70
|
-
[PropTypes.string]: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
71
|
-
})).isRequired,
|
|
72
|
-
title: PropTypes.string.isRequired,
|
|
73
|
-
valueKey: PropTypes.string.isRequired,
|
|
74
|
-
labelKey: PropTypes.string.isRequired,
|
|
75
|
-
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
76
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
77
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
78
|
-
innerRadius: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
79
|
-
outerRadius: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
80
|
-
};
|
|
81
|
-
PieChart.defaultProps = {
|
|
82
|
-
id: undefined,
|
|
83
|
-
className: undefined,
|
|
84
|
-
width: '100%',
|
|
85
|
-
height: 300,
|
|
86
|
-
innerRadius: '0%',
|
|
87
|
-
outerRadius: '100%'
|
|
88
|
-
};
|
|
89
|
-
export default PieChart;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PieChart } from "./PieChart";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
@use "@pareto-engineering/bem";
|
|
2
|
-
|
|
3
|
-
$default-margin: 1rem;
|
|
4
|
-
$default-padding: 1rem;
|
|
5
|
-
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
-
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
7
|
-
|
|
8
|
-
.#{bem.$base} {
|
|
9
|
-
&.pie-chart {
|
|
10
|
-
background-color: var(--background-far);
|
|
11
|
-
border-radius: var(--theme-default-border-radius);
|
|
12
|
-
box-shadow: $default-box-shadow;
|
|
13
|
-
margin: $default-margin 0;
|
|
14
|
-
padding: $default-padding;
|
|
15
|
-
|
|
16
|
-
.chart-header {
|
|
17
|
-
align-items: center;
|
|
18
|
-
display: flex;
|
|
19
|
-
justify-content: space-between;
|
|
20
|
-
margin-bottom: $default-margin;
|
|
21
|
-
|
|
22
|
-
h3 {
|
|
23
|
-
color: var(--subtitle);
|
|
24
|
-
margin: calc($default-margin / 5);
|
|
25
|
-
text-align: left;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.chart-content {
|
|
30
|
-
align-items: flex-start;
|
|
31
|
-
display: flex;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.recharts-wrapper {
|
|
35
|
-
.recharts-surface {
|
|
36
|
-
.recharts-text {
|
|
37
|
-
fill: var(--soft-paragraph);
|
|
38
|
-
font-size: calc($default-text-font-size * .75);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.recharts-text.recharts-label {
|
|
42
|
-
fill: var(--paragraph);
|
|
43
|
-
font-size: $default-text-font-size;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { PieChart } from 'ui'
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
title :'a/Charts/PieChart',
|
|
6
|
-
component:PieChart,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const data = [
|
|
10
|
-
{ status: 'pendingReview', value: 230 },
|
|
11
|
-
{ status: 'accepted', value: 350 },
|
|
12
|
-
{ status: 'rejected', value: 80 },
|
|
13
|
-
{ status: 'toRevise', value: 10 },
|
|
14
|
-
{ status: 'revised', value: 60 },
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
const Template = (args) => (
|
|
18
|
-
<div style={{ height: '100%', width: '100%' }}>
|
|
19
|
-
<PieChart {...args} />
|
|
20
|
-
</div>
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
export const Default = Template.bind({})
|
|
24
|
-
Default.args = {
|
|
25
|
-
data,
|
|
26
|
-
valueKey:'value',
|
|
27
|
-
labelKey:'status',
|
|
28
|
-
colors :['#8CB0F8', '#7F7CF6', '#FFD66E', '#E8E9ED', '#F6BC7E'],
|
|
29
|
-
height :400,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const TemplateSideBySide = (args) => (
|
|
33
|
-
<div style={{ display: 'flex', gap: '20px' }}>
|
|
34
|
-
<div style={{ flex: 1 }}>
|
|
35
|
-
{/* eslint-disable-next-line react/destructuring-assignment */}
|
|
36
|
-
<PieChart {...args[0]} />
|
|
37
|
-
</div>
|
|
38
|
-
<div style={{ flex: 1 }}>
|
|
39
|
-
{/* eslint-disable-next-line react/destructuring-assignment */}
|
|
40
|
-
<PieChart {...args[1]} />
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export const SideBySide = TemplateSideBySide.bind({})
|
|
46
|
-
SideBySide.args = [
|
|
47
|
-
{
|
|
48
|
-
...Default.args,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
...Default.args,
|
|
52
|
-
},
|
|
53
|
-
]
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
PieChart as RechartsPieChart,
|
|
7
|
-
Pie,
|
|
8
|
-
Cell,
|
|
9
|
-
ResponsiveContainer,
|
|
10
|
-
Tooltip,
|
|
11
|
-
} from 'recharts'
|
|
12
|
-
|
|
13
|
-
import styleNames from '@pareto-engineering/bem/exports'
|
|
14
|
-
|
|
15
|
-
import { CustomLegend, CustomTooltipContent } from '../Common'
|
|
16
|
-
|
|
17
|
-
import './styles.scss'
|
|
18
|
-
|
|
19
|
-
const baseClassName = styleNames.base
|
|
20
|
-
|
|
21
|
-
const componentClassName = 'pie-chart'
|
|
22
|
-
|
|
23
|
-
const PieChart = ({
|
|
24
|
-
id,
|
|
25
|
-
className: userClassName,
|
|
26
|
-
data,
|
|
27
|
-
title,
|
|
28
|
-
valueKey,
|
|
29
|
-
labelKey,
|
|
30
|
-
colors,
|
|
31
|
-
height,
|
|
32
|
-
width,
|
|
33
|
-
innerRadius,
|
|
34
|
-
outerRadius,
|
|
35
|
-
}) => {
|
|
36
|
-
const total = data.reduce((sum, item) => sum + item[valueKey], 0)
|
|
37
|
-
|
|
38
|
-
const formattedData = data.map((item) => ({
|
|
39
|
-
...item,
|
|
40
|
-
label :item[labelKey],
|
|
41
|
-
color :colors[data.indexOf(item)],
|
|
42
|
-
percentage:((item[valueKey] / total) * 100).toFixed(0),
|
|
43
|
-
}))
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div
|
|
47
|
-
id={id}
|
|
48
|
-
className={[
|
|
49
|
-
baseClassName,
|
|
50
|
-
componentClassName,
|
|
51
|
-
userClassName,
|
|
52
|
-
]
|
|
53
|
-
.filter((e) => e)
|
|
54
|
-
.join(' ')}
|
|
55
|
-
>
|
|
56
|
-
<div className="chart-header">
|
|
57
|
-
<h3>{title}</h3>
|
|
58
|
-
</div>
|
|
59
|
-
<div className="chart-content">
|
|
60
|
-
<ResponsiveContainer width={width} height={height}>
|
|
61
|
-
<RechartsPieChart>
|
|
62
|
-
<Pie
|
|
63
|
-
data={formattedData}
|
|
64
|
-
dataKey={valueKey}
|
|
65
|
-
nameKey={labelKey}
|
|
66
|
-
cx="50%"
|
|
67
|
-
cy="50%"
|
|
68
|
-
innerRadius={innerRadius}
|
|
69
|
-
outerRadius={outerRadius}
|
|
70
|
-
label={false}
|
|
71
|
-
paddingAngle={0}
|
|
72
|
-
>
|
|
73
|
-
{formattedData.map((entry, index) => (
|
|
74
|
-
<Cell
|
|
75
|
-
key={entry[labelKey]}
|
|
76
|
-
fill={colors[index]}
|
|
77
|
-
strokeWidth={0}
|
|
78
|
-
/>
|
|
79
|
-
))}
|
|
80
|
-
</Pie>
|
|
81
|
-
<Tooltip content={<CustomTooltipContent isDateValue={false} />} />
|
|
82
|
-
</RechartsPieChart>
|
|
83
|
-
</ResponsiveContainer>
|
|
84
|
-
<CustomLegend
|
|
85
|
-
colorsArray={colors}
|
|
86
|
-
yKeysArray={formattedData}
|
|
87
|
-
capitalizedLegend
|
|
88
|
-
orientation="vertical"
|
|
89
|
-
getLegendItemTitle={(entry) => entry[labelKey]}
|
|
90
|
-
getLegendItemSubtitle={(entry) => entry[valueKey]}
|
|
91
|
-
/>
|
|
92
|
-
</div>
|
|
93
|
-
</div>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
PieChart.propTypes = {
|
|
98
|
-
id :PropTypes.string,
|
|
99
|
-
className:PropTypes.string,
|
|
100
|
-
data :PropTypes.arrayOf(PropTypes.shape({
|
|
101
|
-
[PropTypes.string]:PropTypes.oneOfType([
|
|
102
|
-
PropTypes.string,
|
|
103
|
-
PropTypes.number,
|
|
104
|
-
]),
|
|
105
|
-
})).isRequired,
|
|
106
|
-
title :PropTypes.string.isRequired,
|
|
107
|
-
valueKey :PropTypes.string.isRequired,
|
|
108
|
-
labelKey :PropTypes.string.isRequired,
|
|
109
|
-
colors :PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
110
|
-
height :PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
111
|
-
width :PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
112
|
-
innerRadius:PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
113
|
-
outerRadius:PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
PieChart.defaultProps = {
|
|
117
|
-
id :undefined,
|
|
118
|
-
className :undefined,
|
|
119
|
-
width :'100%',
|
|
120
|
-
height :300,
|
|
121
|
-
innerRadius:'0%',
|
|
122
|
-
outerRadius:'100%',
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export default PieChart
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PieChart } from './PieChart'
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
@use "@pareto-engineering/bem";
|
|
2
|
-
|
|
3
|
-
$default-margin: 1rem;
|
|
4
|
-
$default-padding: 1rem;
|
|
5
|
-
$default-box-shadow: 0 .25rem .75rem var(--ui-lines);
|
|
6
|
-
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
7
|
-
|
|
8
|
-
.#{bem.$base} {
|
|
9
|
-
&.pie-chart {
|
|
10
|
-
background-color: var(--background-far);
|
|
11
|
-
border-radius: var(--theme-default-border-radius);
|
|
12
|
-
box-shadow: $default-box-shadow;
|
|
13
|
-
margin: $default-margin 0;
|
|
14
|
-
padding: $default-padding;
|
|
15
|
-
|
|
16
|
-
.chart-header {
|
|
17
|
-
align-items: center;
|
|
18
|
-
display: flex;
|
|
19
|
-
justify-content: space-between;
|
|
20
|
-
margin-bottom: $default-margin;
|
|
21
|
-
|
|
22
|
-
h3 {
|
|
23
|
-
color: var(--subtitle);
|
|
24
|
-
margin: calc($default-margin / 5);
|
|
25
|
-
text-align: left;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.chart-content {
|
|
30
|
-
align-items: flex-start;
|
|
31
|
-
display: flex;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.recharts-wrapper {
|
|
35
|
-
.recharts-surface {
|
|
36
|
-
.recharts-text {
|
|
37
|
-
fill: var(--soft-paragraph);
|
|
38
|
-
font-size: calc($default-text-font-size * .75);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.recharts-text.recharts-label {
|
|
42
|
-
fill: var(--paragraph);
|
|
43
|
-
font-size: $default-text-font-size;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|