import type { ReactNode } from 'react'; import type { ChartDatapoint } from '../../core/types/chart-data.js'; import type { SankeyDropOff as D3SankeyDropOff, SankeyLink as D3SankeyEdge, SankeyNode as D3SankeyNode } from '../vendor/d3-sankey/index.js'; /** A node in the resolved domain graph model (accessor join output). * @internal **/ export interface SankeyGraphNode extends Record { id: string; /** Resolved from `nodeLabelAccessor`, falling back to the node id. */ label: string; /** Resolved from `columnIdAccessor`; undefined when topology-inferred. */ columnId?: string; /** * First-appearance index of `columnId`. The d3-sankey layout reads it as the * pinned depth of the node. */ column?: number; /** The consumer's original `nodes` row; absent for topology-inferred nodes. */ __row?: ChartDatapoint; } /** A directed edge in the resolved domain graph model. */ export interface SankeyGraphEdge extends Record { from: string; to: string; value: number; } /** The resolved domain graph model exposed via the data context. */ export interface SankeyGraphModel { nodes: SankeyGraphNode[]; edges: SankeyGraphEdge[]; } /** * Maps a node id to its color token. Tokens are resolved to concrete colors at * read time so they follow the active theme. * @internal */ export type SankeyColorTokenByNodeId = Map; /** * Maps a column first-appearance index to its palette color token, used by the column headers. * @internal */ export type SankeyColorTokenByColumn = Map; /** * A node after the d3-sankey layout pass: carries the domain fields plus the * computed geometry (`x0`/`x1`/`y0`/`y1`, `depth`, `value`, edge references). */ export type SankeyLayoutNode = D3SankeyNode>; /** * An edge after the d3-sankey layout pass: `source`/`target` are resolved to * node objects and `width`/`y0`/`y1` describe the ribbon geometry. * @internal */ export type SankeyLayoutEdge = D3SankeyEdge>; /** * The volume a node loses between its incoming and outgoing edges, with the * pixel geometry of its drop-off rectangle. * @internal */ export type SankeyDropOff = D3SankeyDropOff>; /** The computed layout model exposed via the layout context. */ export interface SankeyLayoutModel { nodes: SankeyLayoutNode[]; edges: SankeyLayoutEdge[]; /** * The drop-offs, one per node that loses volume. Nodes in the first and last * column and clustered nodes have none. */ dropOffs: SankeyDropOff[]; } /** * A neighbor node entry in a Sankey node tooltip, describing one upstream or * downstream connection. * @internal */ export type SankeyNeighborEntry = { /** * The neighbor node's display label. */ label: string; /** * The neighbor node's id — used to look up its color token in `SankeyNodeColorTokensContext`. */ nodeId: string; /** * The edge value, formatted with formatter and unit. */ formattedValue: string; /** * `edge.value / totalNodeFlow * 100`, formatted as `"X.X%"`. For a source * entry `totalNodeFlow` is the sum of all incoming edge values of the hovered * node; for a target entry it is the node's total volume (the larger of * inflow and outflow), so the target percentages of a node that loses volume * do not add up to 100%. */ formattedPercentage: string; /** * The neighbor node's total inflow (sum of all its incoming edge values). */ totalInflow: number; /** * The neighbor node's total outflow (sum of all its outgoing edge values). */ totalOutflow: number; /** * The original consumer-provided datapoint record for the neighbor node. */ data: ChartDatapoint | undefined; }; /** * Data provided to the custom tooltip render function for a hovered node. * @internal */ export type SankeyNodeTooltipPayload = { type: 'sankeyNode'; /** * The hovered node's unique identifier — used to look up its color token in `SankeyNodeColorTokensContext`. */ nodeId: string; /** * The hovered node's display label. */ label: string; /** * The hovered node's resolved color. */ color: string; /** * The hovered node's total inflow (sum of all incoming edge values). */ totalInflow: number; /** * The hovered node's total outflow (sum of all outgoing edge values). */ totalOutflow: number; /** * The hovered node's total volume (max of inflow and outflow), formatted with the chart's * formatter and unit. Handles source-boundary nodes (no inflow) and sink-boundary nodes * (no outflow) correctly by taking the non-zero side. */ formattedValue: string; /** * The hovered node's total inflow (sum of all incoming edge values), formatted with the * chart's formatter and unit. */ formattedInflow: string; /** * The hovered node's total outflow (sum of all outgoing edge values), formatted with the * chart's formatter and unit. */ formattedOutflow: string; /** * Direct upstream neighbors (nodes flowing INTO this node, one level to the left). */ sources: SankeyNeighborEntry[]; /** * Direct downstream neighbors (nodes this node flows TO, one level to the right). */ targets: SankeyNeighborEntry[]; /** * The original consumer-provided datapoint record for this node, containing any * extra fields beyond `id`, `label`, and `column`. */ data: ChartDatapoint | undefined; }; /** * Data provided to the custom tooltip render function for a hovered edge. * @internal */ export type SankeyEdgeTooltipPayload = { type: 'sankeyEdge'; /** The id of the edge's start node. */ fromId: string; /** The label of the edge's start node. */ fromLabel: string; /** The id of the edge's end node. */ toId: string; /** The label of the edge's end node. */ toLabel: string; /** The raw edge value. */ value: number; /** The edge value, formatted with `formatter` and `unit`. */ formattedValue: string; /** * The consumer-provided datapoint for this edge, carrying every field of the * corresponding row of the `edges` prop. D3-internal geometry fields are excluded. */ data: ChartDatapoint; }; /** * Data provided to the custom tooltip render function for the drop-off * indicator of a node, which has no end node. * @internal */ export type SankeyDropOffTooltipPayload = { type: 'dropOff'; /** The id of the node that loses volume. */ fromId: string; /** The label of the node that loses volume. */ fromLabel: string; /** The lost volume. */ value: number; /** The lost volume, formatted with `formatter` and `unit`. */ formattedValue: string; }; /** * Discriminated union of all Sankey tooltip payloads passed to the custom * tooltip render function. * @internal */ export type SankeyTooltipPayload = SankeyNodeTooltipPayload | SankeyEdgeTooltipPayload | SankeyDropOffTooltipPayload; /** * Props for the `SankeyChart.Tooltip` slot. * @internal */ export type SankeyChartTooltipProps = { /** When true, suppresses the tooltip entirely. */ hidden?: boolean; /** Custom render function receiving the hovered shape's typed payload. */ children?: (payload: SankeyTooltipPayload) => ReactNode; }; /** @internal */ export type SankeyCustomTooltipConfig = { hidden?: boolean; template?: SankeyChartTooltipProps['children']; }; //# sourceMappingURL=sankey-internal.d.ts.map