fix broken retention page

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-20 23:40:29 +02:00
parent cf8617e809
commit a43b3be588
4 changed files with 271 additions and 270 deletions

View File

@@ -4,6 +4,7 @@ import { useNumber } from '@/hooks/useNumerFormatter';
import { useRechartDataModel } from '@/hooks/useRechartDataModel'; import { useRechartDataModel } from '@/hooks/useRechartDataModel';
import { useVisibleSeries } from '@/hooks/useVisibleSeries'; import { useVisibleSeries } from '@/hooks/useVisibleSeries';
import type { IChartData } from '@/trpc/client'; import type { IChartData } from '@/trpc/client';
import { cn } from '@/utils/cn';
import { getChartColor } from '@/utils/theme'; import { getChartColor } from '@/utils/theme';
import { import {
Area, Area,
@@ -33,6 +34,7 @@ export function ReportAreaChart({ data }: ReportAreaChartProps) {
return ( return (
<> <>
<div className={cn(editMode && 'card p-4')}>
<ResponsiveContainer> <ResponsiveContainer>
{({ width, height }) => ( {({ width, height }) => (
<AreaChart width={width} height={height} data={rechartData}> <AreaChart width={width} height={height} data={rechartData}>
@@ -101,6 +103,7 @@ export function ReportAreaChart({ data }: ReportAreaChartProps) {
</AreaChart> </AreaChart>
)} )}
</ResponsiveContainer> </ResponsiveContainer>
</div>
{editMode && ( {editMode && (
<ReportTable <ReportTable
data={data} data={data}

View File

@@ -4,6 +4,7 @@ import { useNumber } from '@/hooks/useNumerFormatter';
import { useRechartDataModel } from '@/hooks/useRechartDataModel'; import { useRechartDataModel } from '@/hooks/useRechartDataModel';
import { useVisibleSeries } from '@/hooks/useVisibleSeries'; import { useVisibleSeries } from '@/hooks/useVisibleSeries';
import type { IChartData } from '@/trpc/client'; import type { IChartData } from '@/trpc/client';
import { cn } from '@/utils/cn';
import { getChartColor, theme } from '@/utils/theme'; import { getChartColor, theme } from '@/utils/theme';
import { Bar, BarChart, CartesianGrid, Tooltip, XAxis, YAxis } from 'recharts'; import { Bar, BarChart, CartesianGrid, Tooltip, XAxis, YAxis } from 'recharts';
@@ -40,6 +41,7 @@ export function ReportHistogramChart({ data }: ReportHistogramChartProps) {
return ( return (
<> <>
<div className={cn(editMode && 'card p-4')}>
<ResponsiveContainer> <ResponsiveContainer>
{({ width, height }) => ( {({ width, height }) => (
<BarChart width={width} height={height} data={rechartData}> <BarChart width={width} height={height} data={rechartData}>
@@ -91,6 +93,7 @@ export function ReportHistogramChart({ data }: ReportHistogramChartProps) {
</BarChart> </BarChart>
)} )}
</ResponsiveContainer> </ResponsiveContainer>
</div>
{editMode && ( {editMode && (
<ReportTable <ReportTable
data={data} data={data}

View File

@@ -7,6 +7,7 @@ import { useRechartDataModel } from '@/hooks/useRechartDataModel';
import { useVisibleSeries } from '@/hooks/useVisibleSeries'; import { useVisibleSeries } from '@/hooks/useVisibleSeries';
import { api } from '@/trpc/client'; import { api } from '@/trpc/client';
import type { IChartData } from '@/trpc/client'; import type { IChartData } from '@/trpc/client';
import { cn } from '@/utils/cn';
import { getChartColor } from '@/utils/theme'; import { getChartColor } from '@/utils/theme';
import { isSameDay, isSameHour, isSameMonth } from 'date-fns'; import { isSameDay, isSameHour, isSameMonth } from 'date-fns';
import { SplineIcon } from 'lucide-react'; import { SplineIcon } from 'lucide-react';
@@ -127,6 +128,7 @@ export function ReportLineChart({ data }: ReportLineChartProps) {
return ( return (
<> <>
<div className={cn(editMode && 'card p-4')}>
<ResponsiveContainer> <ResponsiveContainer>
{({ width, height }) => ( {({ width, height }) => (
<ComposedChart width={width} height={height} data={rechartData}> <ComposedChart width={width} height={height} data={rechartData}>
@@ -280,6 +282,7 @@ export function ReportLineChart({ data }: ReportLineChartProps) {
</ComposedChart> </ComposedChart>
)} )}
</ResponsiveContainer> </ResponsiveContainer>
</div>
{editMode && ( {editMode && (
<ReportTable <ReportTable
data={data} data={data}

View File

@@ -1,14 +1,10 @@
import { cn } from '@/utils/cn';
import AutoSizer from 'react-virtualized-auto-sizer'; import AutoSizer from 'react-virtualized-auto-sizer';
import { useChartContext } from './ChartProvider';
interface ResponsiveContainerProps { interface ResponsiveContainerProps {
children: (props: { width: number; height: number }) => React.ReactNode; children: (props: { width: number; height: number }) => React.ReactNode;
} }
export function ResponsiveContainer({ children }: ResponsiveContainerProps) { export function ResponsiveContainer({ children }: ResponsiveContainerProps) {
const { editMode } = useChartContext();
const maxHeight = 300; const maxHeight = 300;
const minHeight = 200; const minHeight = 200;
return ( return (
@@ -17,17 +13,13 @@ export function ResponsiveContainer({ children }: ResponsiveContainerProps) {
maxHeight, maxHeight,
minHeight, minHeight,
}} }}
className={cn('aspect-video w-full max-sm:-mx-3', editMode && 'card p-4')} className={'aspect-video w-full max-sm:-mx-3'}
> >
<AutoSizer disableHeight> <AutoSizer disableHeight>
{({ width }) => {({ width }) =>
children({ children({
width, width,
height: Math.min( height: Math.min(maxHeight, width * 0.5625),
Math.max(width * 0.5625, minHeight),
// we add p-4 (16px) padding in edit mode
editMode ? maxHeight - 16 : maxHeight
),
}) })
} }
</AutoSizer> </AutoSizer>