Skip to content

Commit

Permalink
feat(network): add TypeScript definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed May 9, 2019
1 parent 862fa0b commit f2d4ec3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ packages-tslint: ##@1 packages run tslint on all packages
./packages/heatmap/index.d.ts \
./packages/legends/index.d.ts \
./packages/line/index.d.ts \
./packages/network/index.d.ts \
./packages/pie/index.d.ts \
./packages/radar/index.d.ts \
./packages/sankey/index.d.ts \
Expand Down
91 changes: 91 additions & 0 deletions packages/network/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import * as React from 'react'
import { Dimensions, Box, Theme, MotionProps } from '@nivo/core'
import { InheritedColorProp } from '@nivo/colors'

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

declare module '@nivo/network' {
export interface InputNode {
id: string
[key: string]: any
}

export interface ComputedNode {
id: string
x: string
y: string
radius: string
color: string
[key: string]: any
}

export interface InputLink {
source: string
target: string
[key: string]: any
}

export interface ComputedLink {
id: string
source: ComputedNode
target: ComputedNode
[key: string]: any
}

export type LayerType = 'links' | 'nodes'
export interface CustomLayerProps extends Omit<NetworkProps, 'nodes' | 'links'> {
nodes: ComputedNode[]
links: ComputedLink[]
}
export type CustomLayer = (props: CustomLayerProps) => React.ReactNode
export type Layer = LayerType | CustomLayer

type NodeAccessor<N, T> = (node: N) => T
type LinkAccessor<L, T> = (link: L) => T

export interface NetworkProps {
nodes: InputNode[]
links: InputLink[]

margin?: Box

linkDistance?: number | LinkAccessor<InputLink, number>
repulsivity?: number
distanceMin?: number
distanceMax?: number
iterations?: number

layers?: Layer[]

nodeColor: string | NodeAccessor<ComputedNode, string>
nodeBorderWidth?: number
nodeBorderColor?: InheritedColorProp<ComputedNode>

linkThickness?: number | LinkAccessor<ComputedLink, number>
linkColor?: InheritedColorProp<ComputedLink>

theme?: Theme

isInteractive?: boolean
}

export interface NetworkSvgProps extends NetworkProps, MotionProps {}

export class Network extends React.Component<NetworkSvgProps & Dimensions> {}
export class ResponsiveNetwork extends React.Component<NetworkSvgProps> {}

export interface NetworkCanvasProps extends NetworkProps {
pixelRatio?: number
}

export class NetworkCanvas extends React.Component<NetworkCanvasProps & Dimensions> {}
export class ResponsiveNetworkCanvas extends React.Component<NetworkCanvasProps> {}
}

0 comments on commit f2d4ec3

Please sign in to comment.