@balena/ui-shared-components 12.2.0-build-add-horizontal-bar-chart-db8d21032600e1691b782f35738d157b23185b6e-1 → 12.2.0-build-add-horizontal-bar-chart-6ee5a259ba1b19526e22819624d07c39f1e8b246-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.
|
@@ -2,10 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Stack, styled, Tooltip, Typography } from '@mui/material';
|
|
3
3
|
import { token } from '../../utils/token';
|
|
4
4
|
import { useTranslation } from '../../hooks/useTranslations';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
slot: 'bar',
|
|
8
|
-
})({
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
const Bar = styled('div')({
|
|
9
7
|
width: '100%',
|
|
10
8
|
height: 24,
|
|
11
9
|
display: 'flex',
|
|
@@ -13,10 +11,9 @@ const Bar = styled('div', {
|
|
|
13
11
|
overflow: 'hidden',
|
|
14
12
|
gap: 2,
|
|
15
13
|
});
|
|
16
|
-
const BarItem = styled('span'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})({});
|
|
14
|
+
const BarItem = styled('span')({
|
|
15
|
+
minWidth: 3,
|
|
16
|
+
});
|
|
20
17
|
const Legend = styled('ul')({
|
|
21
18
|
display: 'inline',
|
|
22
19
|
listStyle: 'none',
|
|
@@ -39,7 +36,7 @@ const LegendItem = styled('li')({
|
|
|
39
36
|
});
|
|
40
37
|
export const HorizontalBarChart = ({ items }) => {
|
|
41
38
|
const { t } = useTranslation();
|
|
42
|
-
const
|
|
39
|
+
const totalItems = useMemo(() => items.reduce((sum, item) => sum + item.count, 0), [items]);
|
|
43
40
|
const getTotalDevicesLabel = (count) => count > 1
|
|
44
41
|
? t('labels.total_devices_other', { count })
|
|
45
42
|
: t('labels.total_devices_one', { count });
|
|
@@ -47,7 +44,7 @@ export const HorizontalBarChart = ({ items }) => {
|
|
|
47
44
|
.filter((item) => item.count > 0)
|
|
48
45
|
.map((item) => (_jsx(Tooltip, { title: `${item.title}: ${getTotalDevicesLabel(item.count)}`, children: _jsx(BarItem, { sx: {
|
|
49
46
|
backgroundColor: item.color,
|
|
50
|
-
width: `${(item.count /
|
|
47
|
+
width: `${(item.count / totalItems) * 100}%`,
|
|
51
48
|
} }) }, item.title))) }), _jsx(Legend, { children: items
|
|
52
49
|
.filter((item) => item.count > 0)
|
|
53
50
|
.map((item) => (_jsx(Tooltip, { title: getTotalDevicesLabel(item.count), children: _jsx(LegendItem, { style: { color: item.color }, children: _jsx(Typography, { variant: "bodySm", color: token('color.text.subtle'), children: item.title }) }) }, item.title))) })] }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "12.2.0-build-add-horizontal-bar-chart-
|
|
3
|
+
"version": "12.2.0-build-add-horizontal-bar-chart-6ee5a259ba1b19526e22819624d07c39f1e8b246-1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -138,6 +138,6 @@
|
|
|
138
138
|
},
|
|
139
139
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
140
140
|
"versionist": {
|
|
141
|
-
"publishedAt": "2025-04-10T20:
|
|
141
|
+
"publishedAt": "2025-04-10T20:57:05.228Z"
|
|
142
142
|
}
|
|
143
143
|
}
|