Skip to content

Commit

Permalink
ui,reports: Make the scaling update with time travel
Browse files Browse the repository at this point in the history
  • Loading branch information
jhf committed Oct 25, 2024
1 parent 3c4e6ca commit d46aac8
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions app/src/app/reports/ReportsPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,31 @@ export default function ReportsPageClient({
// Calculate max values only for unfiltered top-level data
useEffect(() => {
if (drillDown && !region && !activityCategory) {
const newMaxValues: Record<string, {region: number, activity: number}> = {};
setMaxStatValuesNoFiltering(prevMaxValues => {
const newMaxValues = { ...prevMaxValues };

statisticalVariables.forEach(({ value }) => {
const regionMax = Math.max(...drillDown.available.region.map(point =>
value === "count" ? point.count : (point.stats_summary?.[value]?.sum as number) ?? 0
));
const categoryMax = Math.max(...drillDown.available.activity_category.map(point =>
value === "count" ? point.count : (point.stats_summary?.[value]?.sum as number) ?? 0
));
newMaxValues[value] = {
region: regionMax,
activity: categoryMax
};
});
statisticalVariables.forEach(({ value }) => {
const regionMax = Math.max(...drillDown.available.region.map(point =>
value === "count" ? point.count : (point.stats_summary?.[value]?.sum as number) ?? 0
));
const categoryMax = Math.max(...drillDown.available.activity_category.map(point =>
value === "count" ? point.count : (point.stats_summary?.[value]?.sum as number) ?? 0
));

// Initialize if not exists
if (!newMaxValues[value]) {
newMaxValues[value] = { region: 0, activity: 0 };
}

setMaxStatValuesNoFiltering(newMaxValues);
// Update only if new values are larger
newMaxValues[value] = {
region: Math.max(newMaxValues[value].region, regionMax),
activity: Math.max(newMaxValues[value].activity, categoryMax)
};
});

return newMaxValues;
});
}
}, [drillDown, region, activityCategory]);

Expand Down

0 comments on commit d46aac8

Please sign in to comment.