Skip to content

Commit

Permalink
fix: add custom node type typing and expose state modification functi…
Browse files Browse the repository at this point in the history
…ons for custom nodes
  • Loading branch information
williamChen26 committed Aug 25, 2024
1 parent 0f5ac2f commit 740e928
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/sankey/src/Sankey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ const InnerSankey = <N extends DefaultNode, L extends DefaultLink>({
height,
outerWidth,
outerHeight,
nodeTooltip,
linkTooltip,
currentNode,
setCurrentNode,
currentLink,
setCurrentLink,
}

const layerById: Record<SankeyLayerId, ReactNode> = {
Expand Down
19 changes: 18 additions & 1 deletion packages/sankey/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MotionProps,
PropertyAccessor,
ValueFormat,
Margin,
} from '@nivo/core'
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
Expand Down Expand Up @@ -102,6 +103,22 @@ export type SankeySortFunction<N extends DefaultNode, L extends DefaultLink> = (
b: SankeyNodeDatum<N, L>
) => number

export interface LayerProps<N extends DefaultNode, L extends DefaultLink> {
links: SankeyLinkDatum<N, L>[]
nodes: SankeyNodeDatum<N, L>[]
margin: Margin
width: SankeySvgProps<N, L>
height: SankeySvgProps<N, L>
outerWidth: number
outerHeight: number
nodeTooltip: SankeySvgProps<N, L>
linkTooltip: SankeySvgProps<N, L>
currentNode: SankeyNodeDatum<N, L>
setCurrentNode: (node: SankeyNodeDatum<N, L>) => void
currentLink: SankeyLinkDatum<N, L>
setCurrentLink: (node: SankeyLinkDatum<N, L>) => void
}

export interface SankeyCommonProps<N extends DefaultNode, L extends DefaultLink> {
// formatting for link value
valueFormat: ValueFormat<number>
Expand All @@ -110,7 +127,7 @@ export interface SankeyCommonProps<N extends DefaultNode, L extends DefaultLink>
align: SankeyAlignType | SankeyAlignFunction
sort: SankeySortType | SankeySortFunction<N, L>

layers: SankeyLayerId[]
layers: (SankeyLayerId | ((props: LayerProps<N, L>) => React.ReactNode))[]

margin: Box

Expand Down

0 comments on commit 740e928

Please sign in to comment.