Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 8x 8x | import { formatAmount } from "../../shared/model/economicsFormatters";
import { uniqueWarnings, visibleResultWarnings } from "../model/resultWarnings";
import type { ChartAssumption, WarningRef } from "../model/types";
import {
formatAssumptionLabel,
mergeAssumptions,
tooltipUnit,
} from "./chartFormatters";
export function EconomicsChartTooltip({
active,
payload,
label,
}: {
active?: boolean;
payload?: Array<{
name?: string;
value?: number | string | null;
dataKey?: string | number;
payload?: {
unit?: string;
assumptions?: ChartAssumption[];
sourceRowKey?: string;
warningRefs?: WarningRef[];
sourceRows?: Record<
string,
{
unit?: string;
assumptions?: ChartAssumption[];
warningRefs?: WarningRef[];
}
>;
};
}>;
label?: string | number;
}) {
Iif (!active || !payload?.length) return null;
const assumptions = mergeAssumptions(
payload.flatMap((item) => {
const sourceRow = item.payload?.sourceRows?.[String(item.dataKey)];
return [
...(item.payload?.assumptions ?? []),
...(sourceRow?.assumptions ?? []),
];
}),
);
const warnings = visibleResultWarnings(
uniqueWarnings(
payload.flatMap((item) => {
const seriesWarnings =
item.payload?.sourceRows?.[String(item.dataKey)]?.warningRefs ?? [];
return [...(item.payload?.warningRefs ?? []), ...seriesWarnings];
}),
),
);
return (
<div className="min-w-[12rem] rounded-md border bg-background p-2 text-xs shadow-xl">
{label != null && <div className="mb-1 font-medium">{label}</div>}
<div className="space-y-1">
{payload.map((item) => (
<div key={`${item.name}-${item.dataKey}`} className="flex gap-2">
<span className="text-muted-foreground">
{String(item.name ?? item.dataKey)}
</span>
<span className="font-mono">
{formatAmount(item.value)} {tooltipUnit(item)}
</span>
</div>
))}
</div>
{assumptions.length > 0 && (
<div className="mt-2 space-y-1 text-muted-foreground">
{assumptions.map((assumption) => (
<div key={assumption.key}>
{formatAssumptionLabel(assumption.key)}:{" "}
{String(assumption.value ?? "")}
</div>
))}
</div>
)}
{warnings.length > 0 && (
<div className="mt-2 space-y-1 text-amber-900">
{warnings.map((warning) => (
<div key={`${warning.code}-${warning.message}`}>
{warning.message}
</div>
))}
</div>
)}
</div>
);
}
|