@pareto-engineering/design-system 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a/{AreaChart → Charts/AreaChart}/AreaChart.js +89 -63
- package/dist/cjs/a/Charts/AreaChart/styles.scss +48 -0
- package/dist/cjs/a/Charts/BarChart/BarChart.js +135 -0
- package/dist/cjs/a/Charts/BarChart/index.js +13 -0
- package/dist/cjs/a/Charts/BarChart/styles.scss +48 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/CustomLegend.js +69 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/index.js +13 -0
- package/dist/cjs/a/Charts/Common/CustomLegend/styles.scss +40 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +86 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/index.js +13 -0
- package/dist/cjs/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +98 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/index.js +13 -0
- package/dist/cjs/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
- package/dist/cjs/a/Charts/Common/index.js +26 -0
- package/dist/cjs/a/Charts/index.js +19 -0
- package/dist/cjs/a/Tooltip/styles.scss +1 -1
- package/dist/cjs/a/index.js +8 -2
- package/dist/cjs/f/FormInput/FormInput.js +6 -0
- package/dist/cjs/f/fields/FileUpload/FileUpload.js +18 -4
- package/dist/cjs/f/fields/LatexPreviewInput/LatexPreviewInput.js +78 -0
- package/dist/cjs/f/fields/LatexPreviewInput/convertLatexToHtml.js +46 -0
- package/dist/cjs/f/fields/LatexPreviewInput/index.js +20 -0
- package/dist/cjs/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/dist/cjs/f/fields/index.js +13 -0
- package/dist/cjs/g/FormBuilder/FormBuilder.js +3 -6
- package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +1 -3
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +2 -4
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +2 -10
- package/dist/cjs/utils/formatting.js +111 -0
- package/dist/cjs/utils/index.js +20 -1
- package/dist/es/a/{AreaChart → Charts/AreaChart}/AreaChart.js +88 -59
- package/dist/es/a/Charts/AreaChart/styles.scss +48 -0
- package/dist/es/a/Charts/BarChart/BarChart.js +126 -0
- package/dist/es/a/Charts/BarChart/index.js +1 -0
- package/dist/es/a/Charts/BarChart/styles.scss +48 -0
- package/dist/es/a/Charts/Common/CustomLegend/CustomLegend.js +59 -0
- package/dist/es/a/Charts/Common/CustomLegend/index.js +1 -0
- package/dist/es/a/Charts/Common/CustomLegend/styles.scss +40 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.js +76 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/index.js +1 -0
- package/dist/es/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.js +88 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/index.js +1 -0
- package/dist/es/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
- package/dist/es/a/Charts/Common/index.js +3 -0
- package/dist/es/a/Charts/index.js +2 -0
- package/dist/es/a/Tooltip/styles.scss +1 -1
- package/dist/es/a/index.js +1 -1
- package/dist/es/f/FormInput/FormInput.js +7 -1
- package/dist/es/f/fields/FileUpload/FileUpload.js +18 -4
- package/dist/es/f/fields/LatexPreviewInput/LatexPreviewInput.js +70 -0
- package/dist/es/f/fields/LatexPreviewInput/convertLatexToHtml.js +31 -0
- package/dist/es/f/fields/LatexPreviewInput/index.js +3 -0
- package/dist/es/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/dist/es/f/fields/index.js +1 -0
- package/dist/es/g/FormBuilder/FormBuilder.js +3 -6
- package/dist/es/g/FormBuilder/common/Builder/Builder.js +1 -3
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +5 -7
- package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +2 -4
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +2 -4
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +32 -42
- package/dist/es/utils/formatting.js +102 -0
- package/dist/es/utils/index.js +2 -1
- package/jest.config.js +3 -0
- package/package.json +7 -3
- package/src/stories/a/BarChart.stories.jsx +89 -0
- package/src/ui/a/{AreaChart → Charts/AreaChart}/AreaChart.jsx +109 -54
- package/src/ui/a/Charts/AreaChart/styles.scss +48 -0
- package/src/ui/a/Charts/BarChart/BarChart.jsx +165 -0
- package/src/ui/a/Charts/BarChart/index.js +1 -0
- package/src/ui/a/Charts/BarChart/styles.scss +48 -0
- package/src/ui/a/Charts/Common/CustomLegend/CustomLegend.jsx +84 -0
- package/src/ui/a/Charts/Common/CustomLegend/index.js +1 -0
- package/src/ui/a/Charts/Common/CustomLegend/styles.scss +40 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/CustomTooltipContent.jsx +105 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/index.js +1 -0
- package/src/ui/a/Charts/Common/CustomTooltipContent/styles.scss +22 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/YlabelsDropDown.jsx +121 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/index.js +1 -0
- package/src/ui/a/Charts/Common/YLabelsDropDown/styles.scss +88 -0
- package/src/ui/a/Charts/Common/index.js +3 -0
- package/src/ui/a/Charts/index.js +2 -0
- package/src/ui/a/Tooltip/styles.scss +1 -1
- package/src/ui/a/index.js +1 -1
- package/src/ui/f/FormInput/FormInput.jsx +11 -0
- package/src/ui/f/fields/FileUpload/FileUpload.jsx +24 -4
- package/src/ui/f/fields/LatexPreviewInput/LatexPreviewInput.jsx +91 -0
- package/src/ui/f/fields/LatexPreviewInput/convertLatexToHtml.jsx +38 -0
- package/src/ui/f/fields/LatexPreviewInput/index.js +3 -0
- package/src/ui/f/fields/LatexPreviewInput/styles.scss +24 -0
- package/src/ui/f/fields/index.js +4 -0
- package/src/ui/g/FormBuilder/FormBuilder.jsx +0 -3
- package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +4 -7
- package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +0 -2
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +49 -64
- package/src/ui/utils/formatting.js +125 -0
- package/src/ui/utils/index.js +1 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +1257 -62
- package/tests/emptyMock.js +3 -0
- package/tests/mockTextEncoder.js +7 -0
- package/tests/test-setup.js +7 -0
- package/dist/cjs/a/AreaChart/styles.scss +0 -89
- package/dist/es/a/AreaChart/styles.scss +0 -89
- package/src/ui/a/AreaChart/styles.scss +0 -89
- /package/dist/cjs/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
- /package/dist/es/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
- /package/src/ui/a/{AreaChart → Charts/AreaChart}/index.js +0 -0
|
@@ -4,18 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var React = _react;
|
|
8
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
10
|
var _recharts = require("recharts");
|
|
10
11
|
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
12
|
+
var _utils = require("../../../utils");
|
|
13
|
+
var _Common = require("../Common");
|
|
11
14
|
require("./styles.scss");
|
|
12
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
16
|
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); }
|
|
14
17
|
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
|
-
// front/packages/design-system/src/ui/a/AreaChart/AreaChart.jsx
|
|
16
|
-
|
|
17
|
-
// Local Definitions
|
|
18
|
-
|
|
19
18
|
const baseClassName = _exports.default.base;
|
|
20
19
|
const componentClassName = 'area-chart';
|
|
21
20
|
const AreaChart = _ref => {
|
|
@@ -31,9 +30,16 @@ const AreaChart = _ref => {
|
|
|
31
30
|
colors,
|
|
32
31
|
filled,
|
|
33
32
|
height,
|
|
34
|
-
width
|
|
35
|
-
|
|
33
|
+
width,
|
|
34
|
+
isTimeFormat,
|
|
35
|
+
dateFormat,
|
|
36
|
+
capitalizedLegend
|
|
36
37
|
} = _ref;
|
|
38
|
+
const allYLabels = yKeys.map(key => ({
|
|
39
|
+
label: key,
|
|
40
|
+
color: colors[yKeys.indexOf(key)]
|
|
41
|
+
}));
|
|
42
|
+
const [selectedYLabels, setSelectedYLabels] = (0, _react.useState)(allYLabels);
|
|
37
43
|
const processedData = data.map(item => {
|
|
38
44
|
const yValues = yKeys.map(key => item[key]);
|
|
39
45
|
const lowerBound = Math.min(...yValues);
|
|
@@ -41,7 +47,8 @@ const AreaChart = _ref => {
|
|
|
41
47
|
const margin = (upperBound - lowerBound) * 0.1;
|
|
42
48
|
return {
|
|
43
49
|
...item,
|
|
44
|
-
bounds: [lowerBound - margin, upperBound + margin]
|
|
50
|
+
bounds: [lowerBound - margin, upperBound + margin],
|
|
51
|
+
isTimeFormat
|
|
45
52
|
};
|
|
46
53
|
});
|
|
47
54
|
const yAxisBounds = () => {
|
|
@@ -51,53 +58,19 @@ const AreaChart = _ref => {
|
|
|
51
58
|
const margin = (max - min) * 0.1;
|
|
52
59
|
return [min - margin, max + margin];
|
|
53
60
|
};
|
|
54
|
-
const CustomTooltipContent = _ref2 => {
|
|
55
|
-
let {
|
|
56
|
-
active,
|
|
57
|
-
payload,
|
|
58
|
-
label
|
|
59
|
-
} = _ref2;
|
|
60
|
-
if (active && payload && payload.length) {
|
|
61
|
-
const newPayload = payload.filter(item => item.name !== 'bounds');
|
|
62
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
-
className: "custom-tooltip"
|
|
64
|
-
}, /*#__PURE__*/React.createElement("p", {
|
|
65
|
-
className: "label"
|
|
66
|
-
}, `${xLabel}: ${label}`), newPayload.map(entry => /*#__PURE__*/React.createElement("p", {
|
|
67
|
-
className: "label",
|
|
68
|
-
key: `${entry.name}`,
|
|
69
|
-
style: {
|
|
70
|
-
color: entry.color
|
|
71
|
-
}
|
|
72
|
-
}, `${entry.name}: ${entry.value}`)));
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
};
|
|
76
|
-
const CustomLegend = _ref3 => {
|
|
77
|
-
let {
|
|
78
|
-
colorsArray,
|
|
79
|
-
yKeysArray
|
|
80
|
-
} = _ref3;
|
|
81
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
82
|
-
className: "custom-legend"
|
|
83
|
-
}, yKeysArray.map((key, index) => /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
key: key,
|
|
85
|
-
className: "item"
|
|
86
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
87
|
-
className: "line",
|
|
88
|
-
style: {
|
|
89
|
-
backgroundColor: colorsArray[index]
|
|
90
|
-
}
|
|
91
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
92
|
-
className: "text"
|
|
93
|
-
}, key))));
|
|
94
|
-
};
|
|
95
61
|
return /*#__PURE__*/React.createElement("div", {
|
|
96
62
|
id: id,
|
|
97
63
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
98
|
-
}, /*#__PURE__*/React.createElement("
|
|
64
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: "chart-header"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(_Common.YLabelsDropDown, {
|
|
67
|
+
allYLabels: allYLabels,
|
|
68
|
+
selectedYLabels: selectedYLabels,
|
|
69
|
+
setSelectedYLabels: setSelectedYLabels
|
|
70
|
+
})), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
99
71
|
colorsArray: colors,
|
|
100
|
-
yKeysArray: yKeys
|
|
72
|
+
yKeysArray: yKeys,
|
|
73
|
+
capitalizedLegend: capitalizedLegend
|
|
101
74
|
}), /*#__PURE__*/React.createElement(_recharts.ResponsiveContainer, {
|
|
102
75
|
width: width,
|
|
103
76
|
height: height
|
|
@@ -114,7 +87,8 @@ const AreaChart = _ref => {
|
|
|
114
87
|
},
|
|
115
88
|
axisLine: false,
|
|
116
89
|
tickLine: false,
|
|
117
|
-
tickCount: 3
|
|
90
|
+
tickCount: 3,
|
|
91
|
+
tickFormatter: value => (0, _utils.formatDate)(value, dateFormat)
|
|
118
92
|
}), /*#__PURE__*/React.createElement(_recharts.YAxis, {
|
|
119
93
|
domain: yAxisBounds,
|
|
120
94
|
scale: "linear",
|
|
@@ -123,7 +97,7 @@ const AreaChart = _ref => {
|
|
|
123
97
|
value: yLabel,
|
|
124
98
|
angle: -90,
|
|
125
99
|
position: 'left',
|
|
126
|
-
offset:
|
|
100
|
+
offset: -3,
|
|
127
101
|
style: {
|
|
128
102
|
textAnchor: 'middle'
|
|
129
103
|
}
|
|
@@ -133,10 +107,17 @@ const AreaChart = _ref => {
|
|
|
133
107
|
bottom: 10
|
|
134
108
|
},
|
|
135
109
|
axisLine: false,
|
|
136
|
-
tickLine:
|
|
137
|
-
tickFormatter: value =>
|
|
110
|
+
tickLine: false,
|
|
111
|
+
tickFormatter: value => {
|
|
112
|
+
if (isTimeFormat) {
|
|
113
|
+
return (0, _utils.formatTime)(value);
|
|
114
|
+
}
|
|
115
|
+
return value.toFixed(2);
|
|
116
|
+
}
|
|
138
117
|
}), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
139
|
-
content: /*#__PURE__*/React.createElement(CustomTooltipContent,
|
|
118
|
+
content: /*#__PURE__*/React.createElement(_Common.CustomTooltipContent, {
|
|
119
|
+
xLabel: xLabel
|
|
120
|
+
})
|
|
140
121
|
}), filled && /*#__PURE__*/React.createElement(_recharts.Area, {
|
|
141
122
|
id: "bounds",
|
|
142
123
|
type: "linear",
|
|
@@ -148,12 +129,12 @@ const AreaChart = _ref => {
|
|
|
148
129
|
dot: false,
|
|
149
130
|
label: false,
|
|
150
131
|
isAnimationActive: false
|
|
151
|
-
}),
|
|
152
|
-
id: key,
|
|
153
|
-
key: key,
|
|
132
|
+
}), selectedYLabels.map(key => /*#__PURE__*/React.createElement(_recharts.Area, {
|
|
133
|
+
id: key.label,
|
|
134
|
+
key: key.label,
|
|
154
135
|
type: "linear",
|
|
155
|
-
dataKey: key,
|
|
156
|
-
stroke:
|
|
136
|
+
dataKey: key.label,
|
|
137
|
+
stroke: key.color,
|
|
157
138
|
fill: "none",
|
|
158
139
|
connectNulls: true,
|
|
159
140
|
dot: false,
|
|
@@ -164,21 +145,66 @@ const AreaChart = _ref => {
|
|
|
164
145
|
})))));
|
|
165
146
|
};
|
|
166
147
|
AreaChart.propTypes = {
|
|
148
|
+
/**
|
|
149
|
+
* Array of data objects to be displayed in the chart.
|
|
150
|
+
*/
|
|
167
151
|
// eslint-disable-next-line react/forbid-prop-types
|
|
168
152
|
data: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
153
|
+
/**
|
|
154
|
+
* Title of the chart.
|
|
155
|
+
*/
|
|
169
156
|
title: _propTypes.default.string.isRequired,
|
|
157
|
+
/**
|
|
158
|
+
* Key for the x-axis data.
|
|
159
|
+
*/
|
|
170
160
|
xKey: _propTypes.default.string.isRequired,
|
|
161
|
+
/**
|
|
162
|
+
* Array of keys for the y-axis data.
|
|
163
|
+
*/
|
|
171
164
|
yKeys: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
165
|
+
/**
|
|
166
|
+
* Label for the x-axis.
|
|
167
|
+
*/
|
|
172
168
|
xLabel: _propTypes.default.string,
|
|
169
|
+
/**
|
|
170
|
+
* Label for the y-axis.
|
|
171
|
+
*/
|
|
173
172
|
yLabel: _propTypes.default.string,
|
|
173
|
+
/**
|
|
174
|
+
* Array of colors corresponding to the y-axis data keys.
|
|
175
|
+
*/
|
|
174
176
|
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
177
|
+
/**
|
|
178
|
+
* Boolean to determine if the area under the curve should be filled.
|
|
179
|
+
*/
|
|
175
180
|
filled: _propTypes.default.bool,
|
|
181
|
+
/**
|
|
182
|
+
* Height of the chart.
|
|
183
|
+
*/
|
|
176
184
|
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
177
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Width of the chart.
|
|
187
|
+
*/
|
|
188
|
+
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
189
|
+
/**
|
|
190
|
+
* Flag on whether to capitalize legend keys
|
|
191
|
+
*/
|
|
192
|
+
capitalizedLegend: _propTypes.default.bool,
|
|
193
|
+
/**
|
|
194
|
+
* Flag on whether it is a timeformat or not
|
|
195
|
+
*/
|
|
196
|
+
isTimeFormat: _propTypes.default.bool,
|
|
197
|
+
/**
|
|
198
|
+
* The type of format for the datetime value
|
|
199
|
+
*/
|
|
200
|
+
dateFormat: _propTypes.default.oneOf(Object.values(_utils.DATE_FORMATS))
|
|
178
201
|
};
|
|
179
202
|
AreaChart.defaultProps = {
|
|
180
203
|
filled: false,
|
|
181
204
|
width: '100%',
|
|
182
|
-
height: 300
|
|
205
|
+
height: 300,
|
|
206
|
+
capitalizedLegend: false,
|
|
207
|
+
isTimeFormat: false,
|
|
208
|
+
dateFormat: _utils.DATE_FORMATS.HUMAN_READABLE
|
|
183
209
|
};
|
|
184
210
|
var _default = exports.default = AreaChart;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
&.area-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
|
+
/* stylelint-disable selector-max-compound-selectors -- nested elements */
|
|
30
|
+
.recharts-wrapper {
|
|
31
|
+
.recharts-surface {
|
|
32
|
+
.recharts-cartesian-grid line {
|
|
33
|
+
stroke: var(--ui-lines);
|
|
34
|
+
}
|
|
35
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 React = _react;
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _recharts = require("recharts");
|
|
11
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
12
|
+
var _Common = require("../Common");
|
|
13
|
+
require("./styles.scss");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
// Local Definitions
|
|
18
|
+
|
|
19
|
+
const baseClassName = _exports.default.base;
|
|
20
|
+
const componentClassName = 'bar-chart';
|
|
21
|
+
const BarChart = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
id,
|
|
24
|
+
className: userClassName,
|
|
25
|
+
data,
|
|
26
|
+
title,
|
|
27
|
+
xKey,
|
|
28
|
+
yKeys,
|
|
29
|
+
xLabel,
|
|
30
|
+
yLabel,
|
|
31
|
+
colors,
|
|
32
|
+
height,
|
|
33
|
+
width
|
|
34
|
+
// ...otherProps
|
|
35
|
+
} = _ref;
|
|
36
|
+
const allYLabels = yKeys.map(key => ({
|
|
37
|
+
label: key,
|
|
38
|
+
color: colors[yKeys.indexOf(key)]
|
|
39
|
+
}));
|
|
40
|
+
const [selectedYLabels, setSelectedYLabels] = (0, _react.useState)(allYLabels);
|
|
41
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
id: id,
|
|
43
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
44
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: "chart-header"
|
|
46
|
+
}, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(_Common.YLabelsDropDown, {
|
|
47
|
+
allYLabels: allYLabels,
|
|
48
|
+
selectedYLabels: selectedYLabels,
|
|
49
|
+
setSelectedYLabels: setSelectedYLabels
|
|
50
|
+
})), /*#__PURE__*/React.createElement(_Common.CustomLegend, {
|
|
51
|
+
colorsArray: selectedYLabels.map(item => item.color),
|
|
52
|
+
yKeysArray: selectedYLabels.map(item => item.label)
|
|
53
|
+
}), /*#__PURE__*/React.createElement(_recharts.ResponsiveContainer, {
|
|
54
|
+
width: width,
|
|
55
|
+
height: height
|
|
56
|
+
}, /*#__PURE__*/React.createElement(_recharts.BarChart, {
|
|
57
|
+
data: data
|
|
58
|
+
}, /*#__PURE__*/React.createElement(_recharts.CartesianGrid, {
|
|
59
|
+
vertical: false
|
|
60
|
+
}), /*#__PURE__*/React.createElement(_recharts.XAxis, {
|
|
61
|
+
dataKey: xKey,
|
|
62
|
+
label: {
|
|
63
|
+
value: xLabel,
|
|
64
|
+
position: 'insideBottom',
|
|
65
|
+
offset: -5
|
|
66
|
+
} // Adjusted offset for padding
|
|
67
|
+
,
|
|
68
|
+
axisLine: false,
|
|
69
|
+
tickLine: false,
|
|
70
|
+
tickCount: 3
|
|
71
|
+
}), /*#__PURE__*/React.createElement(_recharts.YAxis, {
|
|
72
|
+
label: {
|
|
73
|
+
value: yLabel,
|
|
74
|
+
angle: -90,
|
|
75
|
+
position: 'insideLeft',
|
|
76
|
+
offset: 15
|
|
77
|
+
},
|
|
78
|
+
axisLine: false,
|
|
79
|
+
tickLine: false
|
|
80
|
+
}), /*#__PURE__*/React.createElement(_recharts.Tooltip, {
|
|
81
|
+
content: /*#__PURE__*/React.createElement(_Common.CustomTooltipContent, {
|
|
82
|
+
xLabel: xLabel
|
|
83
|
+
})
|
|
84
|
+
}), selectedYLabels.map(key => /*#__PURE__*/React.createElement(_recharts.Bar, {
|
|
85
|
+
stackId: "a",
|
|
86
|
+
id: key.label,
|
|
87
|
+
key: key.label,
|
|
88
|
+
dataKey: key.label,
|
|
89
|
+
fill: key.color
|
|
90
|
+
})))));
|
|
91
|
+
};
|
|
92
|
+
BarChart.propTypes = {
|
|
93
|
+
/**
|
|
94
|
+
* Array of data objects to be displayed in the chart.
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
97
|
+
data: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
98
|
+
/**
|
|
99
|
+
* Title of the chart.
|
|
100
|
+
*/
|
|
101
|
+
title: _propTypes.default.string.isRequired,
|
|
102
|
+
/**
|
|
103
|
+
* Key for the x-axis data.
|
|
104
|
+
*/
|
|
105
|
+
xKey: _propTypes.default.string.isRequired,
|
|
106
|
+
/**
|
|
107
|
+
* Array of keys for the y-axis data.
|
|
108
|
+
*/
|
|
109
|
+
yKeys: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
110
|
+
/**
|
|
111
|
+
* Label for the x-axis.
|
|
112
|
+
*/
|
|
113
|
+
xLabel: _propTypes.default.string,
|
|
114
|
+
/**
|
|
115
|
+
* Label for the y-axis.
|
|
116
|
+
*/
|
|
117
|
+
yLabel: _propTypes.default.string,
|
|
118
|
+
/**
|
|
119
|
+
* Array of colors corresponding to the y-axis data keys.
|
|
120
|
+
*/
|
|
121
|
+
colors: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
122
|
+
/**
|
|
123
|
+
* Height of the chart.
|
|
124
|
+
*/
|
|
125
|
+
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
126
|
+
/**
|
|
127
|
+
* Width of the chart.
|
|
128
|
+
*/
|
|
129
|
+
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
130
|
+
};
|
|
131
|
+
BarChart.defaultProps = {
|
|
132
|
+
width: '100%',
|
|
133
|
+
height: 300
|
|
134
|
+
};
|
|
135
|
+
var _default = exports.default = BarChart;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BarChart", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _BarChart.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _BarChart = _interopRequireDefault(require("./BarChart"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
&.bar-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
|
+
/* stylelint-disable selector-max-compound-selectors -- nested elements */
|
|
30
|
+
.recharts-wrapper {
|
|
31
|
+
.recharts-surface {
|
|
32
|
+
.recharts-cartesian-grid line {
|
|
33
|
+
stroke: var(--ui-lines);
|
|
34
|
+
}
|
|
35
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
const baseClassName = _exports.default.base;
|
|
15
|
+
const componentClassName = 'custom-legend';
|
|
16
|
+
const CustomLegend = _ref => {
|
|
17
|
+
let {
|
|
18
|
+
id,
|
|
19
|
+
className: userClassName,
|
|
20
|
+
colorsArray,
|
|
21
|
+
yKeysArray,
|
|
22
|
+
capitalizedLegend
|
|
23
|
+
} = _ref;
|
|
24
|
+
const capitalizeWord = word => {
|
|
25
|
+
if (!capitalizedLegend) return word;
|
|
26
|
+
const wordsToCapitalize = ['average', 'best', 'worst'];
|
|
27
|
+
return word.split(' ').map(part => wordsToCapitalize.includes(part.toLowerCase()) ? part.charAt(0).toUpperCase() + part.slice(1).toLowerCase() : part).join(' ');
|
|
28
|
+
};
|
|
29
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
id: id,
|
|
31
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' ')
|
|
32
|
+
}, yKeysArray.map((key, index) => /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
key: key,
|
|
34
|
+
className: "item"
|
|
35
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
className: "dot",
|
|
37
|
+
style: {
|
|
38
|
+
backgroundColor: colorsArray[index]
|
|
39
|
+
}
|
|
40
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
41
|
+
className: "text"
|
|
42
|
+
}, capitalizeWord(key)))));
|
|
43
|
+
};
|
|
44
|
+
CustomLegend.propTypes = {
|
|
45
|
+
/**
|
|
46
|
+
* The id of the dropdown component.
|
|
47
|
+
*/
|
|
48
|
+
id: _propTypes.default.string,
|
|
49
|
+
/**
|
|
50
|
+
* Additional class names for the dropdown component.
|
|
51
|
+
*/
|
|
52
|
+
className: _propTypes.default.string,
|
|
53
|
+
/**
|
|
54
|
+
* Array of colors corresponding to the y-axis data keys.
|
|
55
|
+
*/
|
|
56
|
+
colorsArray: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
57
|
+
/**
|
|
58
|
+
* Array of keys for the y-axis data.
|
|
59
|
+
*/
|
|
60
|
+
yKeysArray: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
|
|
61
|
+
/**
|
|
62
|
+
* Flag on whether to capitalize legend keys
|
|
63
|
+
*/
|
|
64
|
+
capitalizedLegend: _propTypes.default.bool
|
|
65
|
+
};
|
|
66
|
+
CustomLegend.defaultProps = {
|
|
67
|
+
capitalizedLegend: false
|
|
68
|
+
};
|
|
69
|
+
var _default = exports.default = CustomLegend;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CustomLegend", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _CustomLegend.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _CustomLegend = _interopRequireDefault(require("./CustomLegend"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@use "@pareto-engineering/bem";
|
|
2
|
+
|
|
3
|
+
$default-padding: 1rem;
|
|
4
|
+
$default-text-font-size: calc(var(--s-1) * 1rem);
|
|
5
|
+
$default-border-radius: .25rem;
|
|
6
|
+
$default-legend-gap: .625rem;
|
|
7
|
+
$default-legend-padding: calc($default-padding * .125) calc($default-padding * .625);
|
|
8
|
+
$default-legend-dot-width: .5rem;
|
|
9
|
+
$default-legend-dot-height: .5rem;
|
|
10
|
+
$default-legend-dot-margin-right: .3125rem;
|
|
11
|
+
|
|
12
|
+
.#{bem.$base} {
|
|
13
|
+
&.custom-legend {
|
|
14
|
+
display: flex;
|
|
15
|
+
gap: $default-legend-gap;
|
|
16
|
+
justify-content: flex-end;
|
|
17
|
+
padding-bottom: $default-padding;
|
|
18
|
+
padding-right: calc($default-padding * .25);
|
|
19
|
+
|
|
20
|
+
.item {
|
|
21
|
+
align-items: center;
|
|
22
|
+
border-radius: $default-border-radius;
|
|
23
|
+
display: flex;
|
|
24
|
+
padding: $default-legend-padding;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.dot {
|
|
28
|
+
border-radius: 50%;
|
|
29
|
+
display: inline-block;
|
|
30
|
+
height: $default-legend-dot-height;
|
|
31
|
+
margin-right: $default-legend-dot-margin-right;
|
|
32
|
+
width: $default-legend-dot-width;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.text {
|
|
36
|
+
color: var(--paragraph);
|
|
37
|
+
font-size: calc($default-text-font-size * .75);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|