Skip to content

Commit

Permalink
fix(core / swarmplot): Improve core and swarmplot typedefs (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
areese159 committed Oct 15, 2020
1 parent 42adacd commit e370ea8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/index.d.ts
Expand Up @@ -194,5 +194,9 @@ declare module '@nivo/core' {
defs: Def[]
}

export function PatternLines(props: Omit<PatternLinesDef, 'type'>): JSX.Element
export function PatternSquares(props: Omit<PatternSquaresDef, 'type'>): JSX.Element
export function PatternDots(props: Omit<PatternDotsDef, 'type'>): JSX.Element

export function Defs(props: DefsProps): JSX.Element
}
31 changes: 29 additions & 2 deletions packages/swarmplot/index.d.ts
Expand Up @@ -26,6 +26,30 @@ declare module '@nivo/swarmplot' {
data: Datum
}

export interface LayerProps<Datum> {
nodes: ComputedNode<Datum>[]
xScale: (input: number) => number
yScale: (input: number) => number
innerWidth: number
innerHeight: number
outerWidth: number
outerHeight: number
margin: number
getBorderColor: () => string
getBorderWidth: () => number
animate: boolean
motionStiffness: number
motionDamping: number
}

export enum SwarmPlotLayerType {
Grid = 'grid',
Axes = 'axes',
Nodes = 'nodes',
Mesh = 'mesh',
Annotations = 'annotations'
}

type DatumAccessor<Datum, T> = (datum: Datum) => T
type ComputedNodeAccessor<Datum, T> = (node: ComputedNode<Datum>) => T

Expand All @@ -40,6 +64,9 @@ declare module '@nivo/swarmplot' {
event: React.MouseEvent<any>
) => void

export type SwarmPlotCustomLayer<Datum> = (props: LayerProps<Datum>) => JSX.Element
export type Layers<Datum> = SwarmPlotCustomLayer<Datum> | SwarmPlotLayerType

type ValueFormatter<Datum> = (datum: Datum) => string | number

interface CommonSwarmPlotProps<Datum = any> {
Expand All @@ -48,7 +75,7 @@ declare module '@nivo/swarmplot' {
margin?: Box

groups: string[]
groupBy?: string
groupBy?: string | DatumAccessor<Datum, string>
identity?: string | DatumAccessor<Datum, string>
label?: string | DatumAccessor<Datum, string>
value?: string | DatumAccessor<Datum, number>
Expand All @@ -62,7 +89,7 @@ declare module '@nivo/swarmplot' {
forceStrength?: number
simulationIterations?: number

layers: any[]
layers?: Layers<Datum>[]

colors?: OrdinalColorsInstruction
colorBy?: string | ComputedNodeAccessor<Datum, string | number>
Expand Down

0 comments on commit e370ea8

Please sign in to comment.