Skip to content

Commit

Permalink
fix(sankey): improve Sankey types
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze authored and Raphaël Benitte committed May 23, 2019
1 parent 6d300ab commit 9d5c728
Showing 1 changed file with 80 additions and 10 deletions.
90 changes: 80 additions & 10 deletions packages/sankey/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* file that was distributed with this source code.
*/
import * as React from 'react'
import { Theme, CssMixBlendMode } from '@nivo/core'
import { OrdinalColorsInstruction } from '@nivo/colors'
import { Theme, CssMixBlendMode, Box } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColorProp } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'

declare module '@nivo/sankey' {
Expand All @@ -31,20 +31,90 @@ declare module '@nivo/sankey' {
}
}

export interface SankeyLinkProps {
source: {
id?: string | number
label: string | number
}
target: {
id?: string | number
label: string | number
}
thickness: number
color: string
value: number
}

export interface SankeyNodeProps {
id: string | number
x: number
y: number
width: number
height: number
label: string
color: string
}

export interface SankeyLinkDatum {
color: string
index: number
pos0: number
pos1: number
source: SankeyNodeDatum
target: SankeyNodeDatum
thickness: number
value: number
}

export interface SankeyNodeDatum {
color: string
depth: number
height: number
id: string
index: number
label: string
layer: number
sourceLinks: SankeyLinkDatum[]
targetLinks: SankeyLinkDatum[]
value: number
width: number
x: number
x0: number
x1: number
y: number
y0: number
y1: number
}

export type SankeyMouseHandler = (
data: SankeyNodeDatum | SankeyLinkDatum,
event: React.MouseEvent
) => void

export type SankeySortFunction = (nodeA: SankeyDataNode, nodeB: SankeyDataNode) => number

export type TooltipRenderer<T> = (data: T) => React.ReactNode

export type TooltipFormat = (value: number) => React.ReactNode

export type AccessorFunc = (datum: SankeyNodeDatum) => string

export type LabelFormatter = (label: string | number) => string | number

export type SankeyProps = Partial<{
align: 'center' | 'justify' | 'start' | 'end'
sort: 'auto' | 'input' | 'ascending' | 'descending' | SankeySortFunction

margin: Box

nodeOpacity: number
nodeHoverOpacity: number
nodeHoverOthersOpacity: number
nodeThickness: number
nodeSpacing: number
nodeInnerPadding: number
nodeBorderWidth: number
nodeBorderColor: any
nodeBorderColor: InheritedColorProp<SankeyNodeDatum>

linkOpacity: number
linkHoverOpacity: number
Expand All @@ -54,18 +124,18 @@ declare module '@nivo/sankey' {
enableLinkGradient: boolean

enableLabels: boolean
label: any
label: string | AccessorFunc
labelPosition: 'inside' | 'outside'
labelPadding: number
labelOrientation: 'horizontal' | 'vertical'
labelTextColor: any
labelFormat: any
labelTextColor: InheritedColorProp<SankeyNodeDatum>
labelFormat: string | LabelFormatter

isInteractive: boolean
onClick: any
tooltipFormat: any
nodeTooltip: any
linkTooltip: any
onClick: SankeyMouseHandler
tooltipFormat: TooltipFormat
nodeTooltip: TooltipRenderer<SankeyNodeProps>
linkTooltip: TooltipRenderer<SankeyLinkProps>

colors: OrdinalColorsInstruction
theme: Theme
Expand Down

0 comments on commit 9d5c728

Please sign in to comment.