From 9d5c7285748f44ce8c146d41643d21ed2b55f957 Mon Sep 17 00:00:00 2001 From: Neil Kistner Date: Fri, 17 May 2019 07:45:29 -0500 Subject: [PATCH] fix(sankey): improve Sankey types --- packages/sankey/index.d.ts | 90 +++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/packages/sankey/index.d.ts b/packages/sankey/index.d.ts index ef9714d39..5857026cc 100644 --- a/packages/sankey/index.d.ts +++ b/packages/sankey/index.d.ts @@ -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' { @@ -31,12 +31,82 @@ 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 = (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 @@ -44,7 +114,7 @@ declare module '@nivo/sankey' { nodeSpacing: number nodeInnerPadding: number nodeBorderWidth: number - nodeBorderColor: any + nodeBorderColor: InheritedColorProp linkOpacity: number linkHoverOpacity: number @@ -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 + labelFormat: string | LabelFormatter isInteractive: boolean - onClick: any - tooltipFormat: any - nodeTooltip: any - linkTooltip: any + onClick: SankeyMouseHandler + tooltipFormat: TooltipFormat + nodeTooltip: TooltipRenderer + linkTooltip: TooltipRenderer colors: OrdinalColorsInstruction theme: Theme