2022-12-10 22:14:31 +01:00
|
|
|
import { createStyles, Stack, Title, useMantineTheme } from '@mantine/core';
|
|
|
|
|
import { DashDotGraph as GraphType } from './types';
|
|
|
|
|
|
|
|
|
|
interface DashDotGraphProps {
|
|
|
|
|
graph: GraphType;
|
|
|
|
|
isCompact: boolean;
|
|
|
|
|
dashDotUrl: string;
|
2023-01-31 20:12:03 +01:00
|
|
|
usePercentages: boolean;
|
2022-12-10 22:14:31 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-31 20:12:03 +01:00
|
|
|
export const DashDotGraph = ({
|
|
|
|
|
graph,
|
|
|
|
|
isCompact,
|
|
|
|
|
dashDotUrl,
|
|
|
|
|
usePercentages,
|
|
|
|
|
}: DashDotGraphProps) => {
|
2022-12-10 22:14:31 +01:00
|
|
|
const { classes } = useStyles();
|
|
|
|
|
return (
|
|
|
|
|
<Stack
|
|
|
|
|
className={classes.graphStack}
|
|
|
|
|
w="100%"
|
|
|
|
|
maw="251px"
|
|
|
|
|
style={{
|
|
|
|
|
width: isCompact ? (graph.twoSpan ? '100%' : 'calc(50% - 10px)') : undefined,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Title className={classes.graphTitle} order={4}>
|
|
|
|
|
{graph.name}
|
|
|
|
|
</Title>
|
|
|
|
|
<iframe
|
|
|
|
|
className={classes.iframe}
|
|
|
|
|
key={graph.name}
|
|
|
|
|
title={graph.name}
|
2023-01-31 20:12:03 +01:00
|
|
|
src={useIframeSrc(dashDotUrl, graph, isCompact, usePercentages)}
|
2022-12-10 22:14:31 +01:00
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-31 20:12:03 +01:00
|
|
|
const useIframeSrc = (
|
|
|
|
|
dashDotUrl: string,
|
|
|
|
|
graph: GraphType,
|
|
|
|
|
isCompact: boolean,
|
|
|
|
|
usePercentages: boolean
|
|
|
|
|
) => {
|
2022-12-10 22:14:31 +01:00
|
|
|
const { colorScheme, colors, radius } = useMantineTheme();
|
|
|
|
|
const surface = (colorScheme === 'dark' ? colors.dark[7] : colors.gray[0]).substring(1); // removes # from hex value
|
2022-12-18 21:21:23 +01:00
|
|
|
|
|
|
|
|
const graphId = graph.id === 'memory' ? 'ram' : graph.id;
|
|
|
|
|
|
2022-12-10 22:14:31 +01:00
|
|
|
return (
|
|
|
|
|
`${dashDotUrl}` +
|
2022-12-30 15:28:30 +01:00
|
|
|
'?singleGraphMode=true' +
|
2022-12-18 21:21:23 +01:00
|
|
|
`&graph=${graphId}` +
|
2022-12-10 22:14:31 +01:00
|
|
|
`&theme=${colorScheme}` +
|
|
|
|
|
`&surface=${surface}` +
|
|
|
|
|
`&gap=${isCompact ? 10 : 5}` +
|
|
|
|
|
`&innerRadius=${radius.lg}` +
|
2023-01-31 20:12:03 +01:00
|
|
|
`&multiView=${graph.isMultiView}` +
|
|
|
|
|
`&showPercentage=${usePercentages ? 'true' : 'false'}`
|
2022-12-10 22:14:31 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useStyles = createStyles((theme, _params, getRef) => ({
|
|
|
|
|
iframe: {
|
|
|
|
|
flex: '1 0 auto',
|
|
|
|
|
maxWidth: '100%',
|
|
|
|
|
height: '140px',
|
|
|
|
|
borderRadius: theme.radius.lg,
|
2022-12-30 15:28:30 +01:00
|
|
|
border: 'none',
|
|
|
|
|
colorScheme: 'light', // fixes white borders around iframe
|
2022-12-10 22:14:31 +01:00
|
|
|
},
|
|
|
|
|
graphTitle: {
|
|
|
|
|
ref: getRef('graphTitle'),
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: 0,
|
|
|
|
|
opacity: 0,
|
|
|
|
|
transition: 'opacity .1s ease-in-out',
|
|
|
|
|
pointerEvents: 'none',
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
marginRight: 25,
|
|
|
|
|
},
|
|
|
|
|
graphStack: {
|
|
|
|
|
position: 'relative',
|
|
|
|
|
[`&:hover .${getRef('graphTitle')}`]: {
|
|
|
|
|
opacity: 0.5,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}));
|