UNPKG

sankyy

Version:

<a href="https://nivo.rocks"><img alt="nivo" src="https://raw.githubusercontent.com/plouc/nivo/master/nivo.png" width="216" height="68"/></a>

39 lines 2 kB
import { DefaultLink, DefaultNode, SankeyAlignType } from './types'; export interface OptimalPositionOptions { width: number; height: number; /** horizontal | vertical */ layout?: 'horizontal' | 'vertical'; /** node thickness as passed to the Sankey component */ nodeThickness?: number; /** node spacing (padding) as passed to the Sankey component */ nodeSpacing?: number; /** alignment strategy as in Nivo props (only used to feed d3-sankey) */ align?: SankeyAlignType; /** per-node additional gap that will be applied when resolving link collisions */ collisionGap?: number; /** how much each successive intermediary node is shifted downwards */ staggerGap?: number; } /** * Produces an initial `nodePositions` map to be used as the `initialNodePositions` * prop for <DraggableSankey>. The algorithm is purposely lightweight: * 1. We run an internal d3-sankey layout to obtain the default coordinates. * 2. For every *intermediary* node (having both in- and out-going links) we add * a small vertical offset (stagger) so that these nodes are shifted further * down the diagram, column by column. * 3. We do a best-effort pass to ensure that links do not intersect unrelated * nodes. For every link that spans more than one column, we push down any * intermediate column node whose bounding box would overlap the link's * vertical band. * * The function returns a record mapping node.id → { y }. We don't override X * because the horizontal positions coming from d3-sankey are already optimal. */ export declare const calculateOptimalNodePositions: <N extends DefaultNode = DefaultNode, L extends DefaultLink = DefaultLink>(data: { nodes: readonly N[]; links: readonly L[]; }, { width, height, layout, nodeThickness, nodeSpacing, align, collisionGap, staggerGap, }: OptimalPositionOptions) => Record<string, { y: number; }>; //# sourceMappingURL=calculateOptimalNodePositions.d.ts.map