2023-03-03 00:37:22 +09:00
|
|
|
import { createStyles, Title, useMantineTheme, getStylesRef } from '@mantine/core';
|
2023-02-14 13:01:12 +01:00
|
|
|
import { useTranslation } from 'next-i18next';
|
2023-02-10 18:20:28 +01:00
|
|
|
import { DashDotCompactNetwork, DashDotInfo } from './DashDotCompactNetwork';
|
|
|
|
|
import { DashDotCompactStorage } from './DashDotCompactStorage';
|
2022-12-10 22:14:31 +01:00
|
|
|
|
|
|
|
|
interface DashDotGraphProps {
|
2023-02-10 18:20:28 +01:00
|
|
|
graph: string;
|
|
|
|
|
graphHeight: number;
|
2022-12-10 22:14:31 +01:00
|
|
|
isCompact: boolean;
|
2023-02-10 18:20:28 +01:00
|
|
|
multiView: boolean;
|
2022-12-10 22:14:31 +01:00
|
|
|
dashDotUrl: string;
|
2023-01-31 20:12:03 +01:00
|
|
|
usePercentages: boolean;
|
2023-02-10 18:20:28 +01:00
|
|
|
info: DashDotInfo;
|
2022-12-10 22:14:31 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-31 20:12:03 +01:00
|
|
|
export const DashDotGraph = ({
|
|
|
|
|
graph,
|
2023-02-10 18:20:28 +01:00
|
|
|
graphHeight,
|
2023-01-31 20:12:03 +01:00
|
|
|
isCompact,
|
2023-02-10 18:20:28 +01:00
|
|
|
multiView,
|
2023-01-31 20:12:03 +01:00
|
|
|
dashDotUrl,
|
|
|
|
|
usePercentages,
|
2023-02-10 18:20:28 +01:00
|
|
|
info,
|
2023-01-31 20:12:03 +01:00
|
|
|
}: DashDotGraphProps) => {
|
2023-02-14 13:01:12 +01:00
|
|
|
const { t } = useTranslation('modules/dashdot');
|
2022-12-10 22:14:31 +01:00
|
|
|
const { classes } = useStyles();
|
2023-02-10 18:20:28 +01:00
|
|
|
|
2023-02-14 13:01:12 +01:00
|
|
|
if (graph === 'storage' && isCompact) {
|
|
|
|
|
return <DashDotCompactStorage info={info} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (graph === 'network' && isCompact) {
|
|
|
|
|
return <DashDotCompactNetwork info={info} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const title = t(`card.graphs.${graph}.title`);
|
|
|
|
|
|
|
|
|
|
return (
|
2023-02-10 18:20:28 +01:00
|
|
|
<div className={classes.graphContainer}>
|
2022-12-10 22:14:31 +01:00
|
|
|
<Title className={classes.graphTitle} order={4}>
|
2023-02-14 13:01:12 +01:00
|
|
|
{title}
|
2022-12-10 22:14:31 +01:00
|
|
|
</Title>
|
|
|
|
|
<iframe
|
|
|
|
|
className={classes.iframe}
|
2023-02-10 18:20:28 +01:00
|
|
|
key={graph}
|
2023-02-14 13:01:12 +01:00
|
|
|
title={title}
|
2023-02-10 18:20:28 +01:00
|
|
|
src={useIframeSrc(dashDotUrl, graph, multiView, usePercentages)}
|
|
|
|
|
style={{
|
|
|
|
|
height: `${graphHeight}px`,
|
|
|
|
|
}}
|
2022-12-10 22:14:31 +01:00
|
|
|
/>
|
2023-02-10 18:20:28 +01:00
|
|
|
</div>
|
2022-12-10 22:14:31 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-31 20:12:03 +01:00
|
|
|
const useIframeSrc = (
|
|
|
|
|
dashDotUrl: string,
|
2023-02-10 18:20:28 +01:00
|
|
|
graph: string,
|
|
|
|
|
multiView: boolean,
|
2023-01-31 20:12:03 +01:00
|
|
|
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
|
|
|
|
2022-12-10 22:14:31 +01:00
|
|
|
return (
|
|
|
|
|
`${dashDotUrl}` +
|
2023-02-10 18:20:28 +01:00
|
|
|
'?singleGraphMode=true' + // obsolete in newer versions
|
|
|
|
|
`&graph=${graph}` +
|
2022-12-10 22:14:31 +01:00
|
|
|
`&theme=${colorScheme}` +
|
|
|
|
|
`&surface=${surface}` +
|
2023-02-10 18:20:28 +01:00
|
|
|
'&gap=5' +
|
2022-12-10 22:14:31 +01:00
|
|
|
`&innerRadius=${radius.lg}` +
|
2023-02-10 18:20:28 +01:00
|
|
|
`&multiView=${multiView}` +
|
|
|
|
|
`&showPercentage=${usePercentages.toString()}` +
|
|
|
|
|
'&textOffset=16' +
|
|
|
|
|
'&textSize=12'
|
2022-12-10 22:14:31 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-03 00:37:22 +09:00
|
|
|
export const useStyles = createStyles((theme, _params) => ({
|
2022-12-10 22:14:31 +01:00
|
|
|
iframe: {
|
|
|
|
|
flex: '1 0 auto',
|
|
|
|
|
maxWidth: '100%',
|
2023-02-10 18:20:28 +01:00
|
|
|
width: '100%',
|
2022-12-10 22:14:31 +01:00
|
|
|
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: {
|
2023-03-03 00:37:22 +09:00
|
|
|
ref: getStylesRef('graphTitle'),
|
2022-12-10 22:14:31 +01:00
|
|
|
position: 'absolute',
|
|
|
|
|
right: 0,
|
2023-02-10 18:20:28 +01:00
|
|
|
bottom: 0,
|
2022-12-10 22:14:31 +01:00
|
|
|
opacity: 0,
|
|
|
|
|
transition: 'opacity .1s ease-in-out',
|
|
|
|
|
pointerEvents: 'none',
|
2023-02-10 18:20:28 +01:00
|
|
|
marginBottom: 12,
|
|
|
|
|
marginRight: 12,
|
2022-12-10 22:14:31 +01:00
|
|
|
},
|
2023-02-10 18:20:28 +01:00
|
|
|
graphContainer: {
|
2022-12-10 22:14:31 +01:00
|
|
|
position: 'relative',
|
2023-03-03 00:37:22 +09:00
|
|
|
[`&:hover .${getStylesRef('graphTitle')}`]: {
|
2022-12-10 22:14:31 +01:00
|
|
|
opacity: 0.5,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}));
|