From 04547846b9a803c3d64bbec8249aef4a163ae8b2 Mon Sep 17 00:00:00 2001 From: Jakob Guddas Date: Sat, 1 May 2021 04:10:54 +0200 Subject: [PATCH] fix(line): update type for custom line canvas layers (#1499) Co-authored-by: Neil Kistner --- packages/line/index.d.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/line/index.d.ts b/packages/line/index.d.ts index 771a134cb..d64dfc28d 100644 --- a/packages/line/index.d.ts +++ b/packages/line/index.d.ts @@ -22,6 +22,7 @@ import { LegendProps } from '@nivo/legends' import { Scale, ScaleFunc } from '@nivo/scales' import { AxisProps, GridValues } from '@nivo/axes' import { CrosshairType } from '@nivo/tooltip' +import { Line as D3Line } from 'd3-shape' type Omit = Pick> @@ -68,7 +69,7 @@ declare module '@nivo/line' { export interface CustomLayerProps extends Omit { innerHeight: number innerWidth: number - lineGenerator: (data: Datum[]) => string + lineGenerator: D3Line<[number, number]> points: Point[] series: ComputedSerie[] xScale: ScaleFunc @@ -213,8 +214,16 @@ declare module '@nivo/line' { export class Line extends React.Component {} export class ResponsiveLine extends React.Component {} + export interface CustomCanvasLayerProps extends CustomLayerProps { + ctx: CanvasRenderingContext2D + } + + export type CustomCanvasLayer = (props: CustomCanvasLayerProps) => void + export type CanvasLayer = LineLayerType | CustomCanvasLayer + export interface LineCanvasProps extends LineProps { pixelRatio?: number + layers?: CanvasLayer[] } export class LineCanvas extends React.Component {}