truncate tooltip container name if very long

This commit is contained in:
henrygd
2025-04-22 20:16:11 -04:00
parent aab5725d82
commit 358e05d544
2 changed files with 12 additions and 4 deletions

View File

@@ -157,6 +157,7 @@ export default memo(function ContainerChart({
<ChartTooltip <ChartTooltip
animationEasing="ease-out" animationEasing="ease-out"
animationDuration={150} animationDuration={150}
truncate={true}
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)} labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
// @ts-ignore // @ts-ignore
itemSorter={(a, b) => b.value - a.value} itemSorter={(a, b) => b.value - a.value}

View File

@@ -99,6 +99,7 @@ const ChartTooltipContent = React.forwardRef<
unit?: string unit?: string
filter?: string filter?: string
contentFormatter?: (item: any, key: string) => React.ReactNode | string contentFormatter?: (item: any, key: string) => React.ReactNode | string
truncate?: boolean
} }
>( >(
( (
@@ -119,6 +120,7 @@ const ChartTooltipContent = React.forwardRef<
filter, filter,
itemSorter, itemSorter,
contentFormatter: content = undefined, contentFormatter: content = undefined,
truncate = false,
}, },
ref ref
) => { ) => {
@@ -214,10 +216,15 @@ const ChartTooltipContent = React.forwardRef<
nestLabel ? "items-end" : "items-center" nestLabel ? "items-end" : "items-center"
)} )}
> >
<div className="grid gap-1.5"> {nestLabel ? tooltipLabel : null}
{nestLabel ? tooltipLabel : null} <span
<span className="text-muted-foreground">{itemConfig?.label || item.name}</span> className={cn(
</div> "text-muted-foreground",
truncate ? "max-w-40 truncate leading-normal -my-1" : ""
)}
>
{itemConfig?.label || item.name}
</span>
{item.value !== undefined && ( {item.value !== undefined && (
<span className="font-medium tabular-nums text-foreground"> <span className="font-medium tabular-nums text-foreground">
{content && typeof content === "function" {content && typeof content === "function"