diff --git a/apps/dashboard/src/components/report/chart/ReportChartTooltip.tsx b/apps/dashboard/src/components/report/chart/ReportChartTooltip.tsx index 1ccb3413..eddc3905 100644 --- a/apps/dashboard/src/components/report/chart/ReportChartTooltip.tsx +++ b/apps/dashboard/src/components/report/chart/ReportChartTooltip.tsx @@ -10,6 +10,7 @@ import { useChartContext } from './ChartProvider'; type ReportLineChartTooltipProps = IToolTipProps<{ value: number; + name: string; dataKey: string; payload: Record; }>; @@ -34,6 +35,7 @@ export function ReportChartTooltip({ const sorted = payload .slice(0) .filter((item) => !item.dataKey.includes(':prev:count')) + .filter((item) => !item.name.includes(':noTooltip')) .sort((a, b) => b.value - a.value); const visible = sorted.slice(0, limit); const hidden = sorted.slice(limit); diff --git a/apps/dashboard/src/components/report/chart/ReportLineChart.tsx b/apps/dashboard/src/components/report/chart/ReportLineChart.tsx index 4deba94d..55d23962 100644 --- a/apps/dashboard/src/components/report/chart/ReportLineChart.tsx +++ b/apps/dashboard/src/components/report/chart/ReportLineChart.tsx @@ -7,6 +7,7 @@ import { useRechartDataModel } from '@/hooks/useRechartDataModel'; import { useVisibleSeries } from '@/hooks/useVisibleSeries'; import type { IChartData } from '@/trpc/client'; import { getChartColor } from '@/utils/theme'; +import { SplineIcon } from 'lucide-react'; import { CartesianGrid, Legend, @@ -34,6 +35,34 @@ interface ReportLineChartProps { lineType: IChartLineType; } +function CustomLegend(props: { + payload?: { value: string; payload: { fill: string } }[]; +}) { + if (!props.payload) { + return null; + } + + return ( +
+ {props.payload + .filter((entry) => !entry.value.includes('noTooltip')) + .filter((entry) => !entry.value.includes(':prev')) + .map((entry) => ( +
+ +
+ {entry.value} +
+
+ ))} +
+ ); +} + export function ReportLineChart({ lineType, interval, @@ -46,6 +75,29 @@ export function ReportLineChart({ const rechartData = useRechartDataModel(series); const number = useNumber(); + // great care should be taken when computing lastIntervalPercent + // the expression below works for data.length - 1 equal intervals + // but if there are numeric x values in a "linear" axis, the formula + // should be updated to use those values + const lastIntervalPercent = + ((rechartData.length - 2) * 100) / (rechartData.length - 1); + + const gradientTwoColors = ( + id: string, + col1: string, + col2: string, + percentChange: number + ) => ( + + + + + + + ); + + const useDashedLastLine = (series[0]?.data?.length || 0) > 2; + return ( <> @@ -80,7 +132,12 @@ export function ReportLineChart({ allowDecimals={false} tickFormatter={number.short} /> - + {series.length > 1 && ( + } + /> + )} } /> { return ( + + {gradientTwoColors( + `hideAllButLastInterval_${serie.id}`, + 'rgba(0,0,0,0)', + getChartColor(serie.index), + lastIntervalPercent + )} + {gradientTwoColors( + `hideJustLastInterval_${serie.id}`, + getChartColor(serie.index), + 'rgba(0,0,0,0)', + lastIntervalPercent + )} + + {useDashedLastLine && ( + <> + + + + )} {previous && ( )}