Fixed the tool tip.
This commit is contained in:
1 parent
7b963ca877
commit
10c5463892
4 files changed
+85
-23
No files matched your search
@@ -112,6 +112,7 @@ export const InfrastructureTooltip = ({
|
|||||||
yLabel,
|
yLabel,
|
||||||
dotColor,
|
dotColor,
|
||||||
dateRange,
|
dateRange,
|
||||||
|
formatter = getFormattedPercentage,
|
||||||
}) => {
|
}) => {
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -166,8 +167,8 @@ export const InfrastructureTooltip = ({
|
|||||||
sx={{ opacity: 0.8 }}
|
sx={{ opacity: 0.8 }}
|
||||||
>
|
>
|
||||||
{yIdx >= 0
|
{yIdx >= 0
|
||||||
? `${yLabel} ${getFormattedPercentage(payload[0].payload[hardwareType][yIdx][metric])}`
|
? `${yLabel} ${formatter(payload[0].payload[hardwareType][yIdx][metric])}`
|
||||||
: `${yLabel} ${getFormattedPercentage(payload[0].payload[yKey])}`}
|
: `${yLabel} ${formatter(payload[0].payload[yKey])}`}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Grid, Card, CardContent, Typography } from "@mui/material";
|
import { Grid, Card, CardContent, Typography } from "@mui/material";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import AreaChart from "../../../../../Components/Charts/AreaChart";
|
import AreaChart from "../../../../../Components/Charts/AreaChart";
|
||||||
import { TzTick } from '../../../../../Components/Charts/Utils/chartUtils';
|
import { TzTick, InfrastructureTooltip } from '../../../../../Components/Charts/Utils/chartUtils';
|
||||||
|
|
||||||
const BytesTick = ({ x, y, payload }) => {
|
const BytesTick = ({ x, y, payload }) => {
|
||||||
const value = payload.value;
|
const value = payload.value;
|
||||||
@@ -16,37 +16,89 @@ const BytesTick = ({ x, y, payload }) => {
|
|||||||
return <text x={x} y={y} textAnchor="end" fill="#888">{label}</text>;
|
return <text x={x} y={y} textAnchor="end" fill="#888">{label}</text>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getFormattedNetworkMetric = (value) => {
|
||||||
|
if (typeof value !== "number" || isNaN(value)) return "0";
|
||||||
|
if (value >= 1024 ** 3) return `${(value / 1024 ** 3).toFixed(1)} GB/s`;
|
||||||
|
if (value >= 1024 ** 2) return `${(value / 1024 ** 2).toFixed(1)} MB/s`;
|
||||||
|
if (value >= 1024) return `${(value / 1024).toFixed(1)} KB/s`;
|
||||||
|
return `${Math.round(value)} B/s`;
|
||||||
|
};
|
||||||
|
|
||||||
const NetworkCharts = ({ eth0Data, dateRange }) => {
|
const NetworkCharts = ({ eth0Data, dateRange }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const textColor = theme.palette.primary.contrastTextTertiary;
|
const textColor = theme.palette.primary.contrastTextTertiary;
|
||||||
|
|
||||||
const charts = [
|
const charts = [
|
||||||
{ title: "eth0 Bytes/sec", key: "bytesPerSec", color: theme.palette.info.main, yTick: <BytesTick /> },
|
{ title: "Bytes per second", key: "bytesPerSec", color: theme.palette.info.main, yTick: <BytesTick /> },
|
||||||
{ title: "eth0 Packets/sec", key: "packetsPerSec", color: theme.palette.success.main },
|
{ title: "Packets per second", key: "packetsPerSec", color: theme.palette.success.main },
|
||||||
{ title: "eth0 Errors", key: "errors", color: theme.palette.error.main },
|
{ title: "Errors", key: "errors", color: theme.palette.error.main },
|
||||||
{ title: "eth0 Drops", key: "drops", color: theme.palette.warning.main }
|
{ title: "Drops", key: "drops", color: theme.palette.warning.main }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const formatYAxis = (key, value) => {
|
||||||
|
if (key === "bytesPerSec") {
|
||||||
|
// Format as MB/s or GB/s if large
|
||||||
|
if (value >= 1024 ** 3) return `${(value / 1024 ** 3).toFixed(1)} GB/s`;
|
||||||
|
if (value >= 1024 ** 2) return `${(value / 1024 ** 2).toFixed(1)} MB/s`;
|
||||||
|
if (value >= 1024) return `${(value / 1024).toFixed(1)} KB/s`;
|
||||||
|
return `${Math.round(value)} B/s`;
|
||||||
|
}
|
||||||
|
return Math.round(value).toLocaleString();
|
||||||
|
};
|
||||||
|
|
||||||
|
const CustomTick = ({ x, y, payload, chartKey }) => {
|
||||||
|
// Ensure value is always rounded for display
|
||||||
|
let value = payload.value;
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
value = Math.round(value);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<text x={x} y={y} textAnchor="end" fill="#888">
|
||||||
|
{formatYAxis(chartKey, value)}
|
||||||
|
</text>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const chartConfigs = charts.map((chart) => ({
|
||||||
|
data: eth0Data,
|
||||||
|
dataKeys: [chart.key],
|
||||||
|
heading: chart.title,
|
||||||
|
strokeColor: chart.color,
|
||||||
|
gradientStartColor: chart.color,
|
||||||
|
yTick: chart.yTick || <CustomTick chartKey={chart.key} />,
|
||||||
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={chart.color}
|
||||||
|
yKey={chart.key}
|
||||||
|
yLabel={chart.title}
|
||||||
|
dateRange={dateRange}
|
||||||
|
formatter={getFormattedNetworkMetric}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={3}>
|
<Grid container spacing={3}>
|
||||||
{charts.map((chart) => (
|
{chartConfigs.map((config, idx) => (
|
||||||
<Grid item xs={12} md={6} key={chart.key}>
|
<Grid item xs={12} md={6} key={config.heading}>
|
||||||
<Card variant="outlined">
|
<Card variant="outlined">
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography variant="h6" sx={{ color: textColor }} mb={2}>
|
<Typography variant="h6" sx={{ color: textColor }} mb={2}>
|
||||||
{chart.title}
|
{config.heading}
|
||||||
</Typography>
|
</Typography>
|
||||||
<AreaChart
|
<AreaChart
|
||||||
data={eth0Data}
|
data={config.data}
|
||||||
dataKeys={[chart.key]}
|
dataKeys={config.dataKeys}
|
||||||
xKey="time"
|
xKey="time"
|
||||||
yTick={chart.yTick || null}
|
yTick={config.yTick}
|
||||||
xTick={<TzTick dateRange={dateRange} />}
|
xTick={config.xTick}
|
||||||
strokeColor={chart.color}
|
strokeColor={config.strokeColor}
|
||||||
gradient
|
gradient
|
||||||
gradientStartColor={chart.color}
|
gradientStartColor={config.gradientStartColor}
|
||||||
gradientEndColor="#fff"
|
gradientEndColor="#fff"
|
||||||
height={200}
|
height={200}
|
||||||
|
customTooltip={config.toolTip}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
+6
-4
@@ -25,16 +25,18 @@ function formatNumber(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const NetworkStatBoxes = ({ shouldRender, net }) => {
|
const NetworkStatBoxes = ({ shouldRender, net }) => {
|
||||||
const filtered = net?.filter(
|
const filtered =
|
||||||
(iface) => iface.name === "en0" || iface.name === "wlan0"
|
net?.filter((iface) => iface.name === "en0" || iface.name === "wlan0") || [];
|
||||||
) || [];
|
|
||||||
|
|
||||||
if (!net?.length) {
|
if (!net?.length) {
|
||||||
return <Typography>No network stats available.</Typography>;
|
return <Typography>No network stats available.</Typography>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatusBoxes shouldRender={shouldRender} flexWrap="wrap">
|
<StatusBoxes
|
||||||
|
shouldRender={shouldRender}
|
||||||
|
flexWrap="wrap"
|
||||||
|
>
|
||||||
{filtered.map((iface) => (
|
{filtered.map((iface) => (
|
||||||
<>
|
<>
|
||||||
<StatBox
|
<StatBox
|
||||||
|
|||||||
@@ -32,13 +32,19 @@ const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NetworkStatBoxes shouldRender={!isLoading} net={net} />
|
<NetworkStatBoxes
|
||||||
|
shouldRender={!isLoading}
|
||||||
|
net={net}
|
||||||
|
/>
|
||||||
<MonitorTimeFrameHeader
|
<MonitorTimeFrameHeader
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
dateRange={dateRange}
|
dateRange={dateRange}
|
||||||
setDateRange={setDateRange}
|
setDateRange={setDateRange}
|
||||||
/>
|
/>
|
||||||
<NetworkCharts eth0Data={filteredEth0Data} xAxisFormatter={xAxisFormatter} />
|
<NetworkCharts
|
||||||
|
eth0Data={filteredEth0Data}
|
||||||
|
xAxisFormatter={xAxisFormatter}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -90,7 +96,8 @@ function getXAxisFormatter(checks) {
|
|||||||
const diffDays = (last - first) / (1000 * 60 * 60 * 24);
|
const diffDays = (last - first) / (1000 * 60 * 60 * 24);
|
||||||
|
|
||||||
return diffDays > 2
|
return diffDays > 2
|
||||||
? (val) => new Date(val).toLocaleDateString(undefined, { month: "short", day: "numeric" })
|
? (val) =>
|
||||||
|
new Date(val).toLocaleDateString(undefined, { month: "short", day: "numeric" })
|
||||||
: (val) =>
|
: (val) =>
|
||||||
new Date(val).toLocaleTimeString(undefined, {
|
new Date(val).toLocaleTimeString(undefined, {
|
||||||
hour: "2-digit",
|
hour: "2-digit",
|
||||||
|
|||||||
Reference in new issue
Block a user