Skip to content

Commit

Permalink
Set the min & max of the Y axis based on the dataset (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
predatorray authored Jan 5, 2025
1 parent ab9ec14 commit 42507ff
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/IndividualPluginDownloadStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ function StatsLineChart({ dataset, labelY }: {
});
}, []);

const minY = useMemo(() => {
return dataset.map(d => d.y).filter(y => y && !Number.isNaN(y)).reduce((a, b) => a ? Math.min(a, b) : b, 0);
}, [dataset]);

const maxY = useMemo(() => {
return dataset.map(d => d.y).filter(y => y && !Number.isNaN(y)).reduce((a, b) => a ? Math.max(a, b) : 0, 0);
}, [dataset]);

console.log(`dataset: ${JSON.stringify(dataset)}, minY: ${minY}, maxY: ${maxY}`);

return (
<Box sx={{ height: "400px", width: "100%" }}>
<LineChart
Expand All @@ -64,15 +74,18 @@ function StatsLineChart({ dataset, labelY }: {
dataKey: 'x',
valueFormatter: (date: Date) => date.toDateString(),
}]}
yAxis={[{
min: minY === 0 ? undefined : minY,
max: maxY === 0 ? undefined : maxY,
}]}
series={[{
dataKey: 'y',
baseline: 0,
connectNulls: true,
label: labelY,
color: '#121212'
color: '#121212',
}]}
grid={{ vertical: true, horizontal: true }}
margin={{left: 100}}
margin={{ left: 100 }}
/>
<Typography variant="body2" color="text.secondary" component="div" sx={{
fontSize: 12,
Expand Down

0 comments on commit 42507ff

Please sign in to comment.