Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 133 additions & 97 deletions src/components/Charts/Histogram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid, Paper, Typography } from '@mui/material';
import { Grid, Paper, Popover, Typography } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { Box } from '@mui/system';
import { BarDatum, ResponsiveBar } from '@nivo/bar';
Expand Down Expand Up @@ -37,6 +37,9 @@ export const Histogram: React.FC<Props> = ({
}) => {
const theme = useTheme();
const [xAxisValues, setXAxisValues] = useState<(string | number)[]>([]);
const [popoverBucket, setPopoverBucket] = useState<any>(undefined);
const [anchorEl, setAnchorEl] = useState(null);
const [open, setOpen] = useState(false);

colors.push(getIsCappedColor(theme.palette.mode === 'light'));

Expand All @@ -47,6 +50,48 @@ export const Histogram: React.FC<Props> = ({
}
}, [data]);

const handleMouseLeave = () => {
setOpen(false);
setAnchorEl(null);
setPopoverBucket(undefined);
};

const handleMouseEnter = (bucket: any, event: any) => {
setAnchorEl(event.currentTarget);
setPopoverBucket(bucket);
setOpen(true);
};

const makePopoverContent = () => {
return (
<Paper
key={popoverBucket.key}
sx={{
borderRadius: DEFAULT_BORDER_RADIUS,
padding: 1,
backgroundColor: 'background.paper',
}}
>
{Object.entries(popoverBucket.data).map(([key, value], idx) => {
return (
key !== 'isCapped' &&
key !== 'timestamp' && (
<Typography key={key} sx={{ color: colors[idx] }}>
{`${key.toUpperCase()}: ${value ?? 0}`}
</Typography>
)
);
})}
<Typography variant="subtitle1" color="secondary">
{getFFTime(popoverBucket.data.timestamp.toString())}
</Typography>
<Typography variant="subtitle2" color="secondary">
{getFFTime(popoverBucket.data.timestamp.toString(), true)}
</Typography>
</Paper>
);
};

return (
<Box
borderRadius={DEFAULT_BORDER_RADIUS}
Expand All @@ -62,108 +107,99 @@ export const Histogram: React.FC<Props> = ({
<EmptyStateCard
height={height ?? DEFAULT_HIST_HEIGHT}
text={emptyText}
></EmptyStateCard>
/>
) : (
<Grid height="100%" width="100%" sx={{ cursor: 'pointer' }}>
<ResponsiveBar
data={data}
colors={colors}
keys={keys}
indexBy={indexBy}
margin={{ top: 10, right: 5, bottom: 60, left: 40 }}
padding={0.1}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
format: (v) =>
xAxisValues?.find((vts) => vts === v)
? dayjs(v).format('h:mm')
: '',
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
tickValues: 5,
}}
legends={
includeLegend
? [
{
dataFrom: 'keys',
anchor: 'bottom',
direction: 'row',
justify: false,
translateX: 0,
translateY: 50,
itemsSpacing: 2,
itemWidth: 100,
itemHeight: 10,
itemDirection: 'left-to-right',
itemOpacity: 1,
itemTextColor: theme.palette.text.primary,
symbolSize: 15,
symbolShape: 'circle',
<>
<Grid height="100%" width="100%">
<ResponsiveBar
data={data}
colors={colors}
keys={keys}
indexBy={indexBy}
margin={{ top: 10, right: 5, bottom: 60, left: 40 }}
padding={0.1}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
axisTop={null}
axisRight={null}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
format: (v) =>
xAxisValues?.find((vts) => vts === v)
? dayjs(v).format('h:mm')
: '',
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
tickValues: 5,
}}
legends={
includeLegend
? [
{
dataFrom: 'keys',
anchor: 'bottom',
direction: 'row',
justify: false,
translateX: 0,
translateY: 50,
itemsSpacing: 2,
itemWidth: 100,
itemHeight: 10,
itemDirection: 'left-to-right',
itemOpacity: 1,
itemTextColor: theme.palette.text.primary,
symbolSize: 15,
symbolShape: 'circle',
},
]
: undefined
}
motionConfig="stiff"
enableLabel={false}
role="application"
theme={{
background: theme.palette.background.paper,
axis: {
ticks: {
line: {
stroke: theme.palette.background.default,
},
text: {
fill: theme.palette.text.disabled,
},
]
: undefined
}
motionConfig="stiff"
enableLabel={false}
role="application"
theme={{
background: theme.palette.background.paper,
axis: {
ticks: {
},
},
grid: {
line: {
stroke: theme.palette.background.default,
},
text: {
fill: theme.palette.text.disabled,
},
},
},
grid: {
line: {
stroke: theme.palette.background.default,
},
},
}}
tooltip={({ data }, idx) => {
return (
<Paper
key={idx}
sx={{
borderRadius: DEFAULT_BORDER_RADIUS,
padding: 1,
backgroundColor: 'background.paper',
}}
>
{keys.map((key, idx) => {
return (
key !== 'isCapped' && (
<Typography key={idx} sx={{ color: colors[idx] }}>
{`${key.toUpperCase()}: ${data[key] ?? 0}`}
</Typography>
)
);
})}
<Typography variant="subtitle1" color="secondary">
{getFFTime(data.timestamp.toString())}
</Typography>
<Typography variant="subtitle2" color="secondary">
{getFFTime(data.timestamp.toString(), true)}
</Typography>
</Paper>
);
}}
/>
</Grid>
}}
// disable tooltip in favor of popover
tooltip={() => <></>}
/>
</Grid>
{anchorEl && (
<Popover
open={open}
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'center',
horizontal: 'center',
}}
style={{ pointerEvents: 'none' }}
>
{makePopoverContent()}
</Popover>
)}
</>
)}
</Box>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/NetworkMap/NetworkMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const NetworkMap: React.FC<Props> = ({ size }) => {
left: number;
}>();
const [popoverNode, setPopoverNode] = useState<any>(undefined);
const [anchorEl, setAnchorEl] = React.useState(null);
const [anchorEl, setAnchorEl] = useState(null);
const handleClick = (node: any, event: any) => {
setAnchorPosition({
top: node.x,
Expand Down