Skip to content

Commit

Permalink
feat(colors): update package typings according to TypeScript migration
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Nov 11, 2020
1 parent 7bb42c6 commit e98d8e0
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 82 deletions.
10 changes: 5 additions & 5 deletions packages/bar/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
CartesianMarkerProps,
} from '@nivo/core'
import { AxisProps, GridValues } from '@nivo/axes'
import { OrdinalColorsInstruction, InheritedColor } from '@nivo/colors'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import { Scale } from '@nivo/scales'

Expand Down Expand Up @@ -115,13 +115,13 @@ declare module '@nivo/bar' {
enableLabel: boolean
label: string | AccessorFunc
labelFormat: string | LabelFormatter
labelLinkColor: InheritedColor<BarDatumWithColor>
labelLinkColor: InheritedColorConfig<BarDatumWithColor>
labelSkipWidth: number
labelSkipHeight: number
labelTextColor: InheritedColor<BarDatumWithColor>
labelTextColor: InheritedColorConfig<BarDatumWithColor>

colors: OrdinalColorsInstruction
borderColor: InheritedColor<BarDatumWithColor>
colors: OrdinalColorScaleConfig
borderColor: InheritedColorConfig<BarDatumWithColor>
borderRadius: number
borderWidth: number
theme: Theme
Expand Down
20 changes: 10 additions & 10 deletions packages/bump/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import { Component, MouseEvent } from 'react'
import { Dimensions, Box, Theme, MotionProps, SvgDefsAndFill, CssMixBlendMode } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColor } from '@nivo/colors'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'

declare module '@nivo/bump' {
type SerieDerivedProp<Serie, T> = (serie: Serie) => T
Expand Down Expand Up @@ -42,23 +42,23 @@ declare module '@nivo/bump' {
xPadding?: number

theme?: Theme
colors?: OrdinalColorsInstruction
colors?: OrdinalColorScaleConfig

startLabel?: BumpLabel
startLabelPadding?: number
startLabelTextColor?: InheritedColor
startLabelTextColor?: InheritedColorConfig
endLabel?: BumpLabel
endLabelPadding?: number
endLabelTextColor?: InheritedColor
endLabelTextColor?: InheritedColorConfig

pointSize?: number
activePointSize?: number
inactivePointSize?: number
pointColor?: InheritedColor
pointColor?: InheritedColorConfig
pointBorderWidth?: number
activePointBorderWidth?: number
inactivePointBorderWidth?: number
pointBorderColor?: InheritedColor
pointBorderColor?: InheritedColorConfig

enableGridX?: boolean
enableGridY?: boolean
Expand Down Expand Up @@ -141,25 +141,25 @@ declare module '@nivo/bump' {
xPadding?: number

theme?: Theme
colors?: OrdinalColorsInstruction
colors?: OrdinalColorScaleConfig
blendMode?: CssMixBlendMode
fillOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>
activeFillOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>
inactiveFillOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>
borderWidth?: number | SerieDerivedProp<AreaBumpInputSerie, number>
activeBorderWidth?: number | SerieDerivedProp<AreaBumpInputSerie, number>
inactiveBorderWidth?: number | SerieDerivedProp<AreaBumpInputSerie, number>
borderColor?: InheritedColor
borderColor?: InheritedColorConfig
borderOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>
activeBorderOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>
inactiveBorderOpacity?: number | SerieDerivedProp<AreaBumpInputSerie, number>

startLabel?: AreaBumpLabel
startLabelPadding?: number
startLabelTextColor?: InheritedColor
startLabelTextColor?: InheritedColorConfig
endLabel?: AreaBumpLabel
endLabelPadding?: number
endLabelTextColor?: InheritedColor
endLabelTextColor?: InheritedColorConfig

enableGridX?: boolean
axisTop?: any
Expand Down
10 changes: 5 additions & 5 deletions packages/chord/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import { Component } from 'react'
import { Box, MotionProps, Dimensions, Theme } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColor } from '@nivo/colors'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'

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

Expand Down Expand Up @@ -55,14 +55,14 @@ declare module '@nivo/chord' {

layers: any[]

colors?: OrdinalColorsInstruction
colors?: OrdinalColorScaleConfig
theme?: Theme

arcOpacity?: number
arcHoverOpacity?: number
arcHoverOthersOpacity?: number
arcBorderWidth?: number
arcBorderColor?: InheritedColor
arcBorderColor?: InheritedColorConfig
onArcMouseEnter?: ChordArcMouseHandler
onArcMouseMove?: ChordArcMouseHandler
onArcMouseLeave?: ChordArcMouseHandler
Expand All @@ -73,12 +73,12 @@ declare module '@nivo/chord' {
ribbonHoverOpacity?: number
ribbonHoverOthersOpacity?: number
ribbonBorderWidth?: number
BorderColor?: InheritedColor
BorderColor?: InheritedColorConfig

enableLabel?: boolean
labelOffset?: number
labelRotation?: number
labelTextColor?: InheritedColor
labelTextColor?: InheritedColorConfig

isInteractive?: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion packages/colors/src/ordinalColorScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface OrdinalColorScaleConfigDatumProperty {
datum: string
}

export type OrdinalColorScaleConfig<Datum> =
export type OrdinalColorScaleConfig<Datum = any> =
| OrdinalColorScaleConfigStaticColor
| OrdinalColorScaleConfigCustomFunction<Datum>
| OrdinalColorScaleConfigScheme
Expand Down
8 changes: 4 additions & 4 deletions packages/funnel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import * as React from 'react'
import { Dimensions, Box, Theme, MotionProps } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColor } from '@nivo/colors'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'

declare module '@nivo/funnel' {
export interface Position {
Expand Down Expand Up @@ -89,14 +89,14 @@ declare module '@nivo/funnel' {
shapeBlending?: number

theme?: Theme
colors?: OrdinalColorsInstruction
colors?: OrdinalColorScaleConfig

borderWidth?: number
borderColor?: InheritedColor<Omit<Part, 'borderColor' | 'labelColor'>>
borderColor?: InheritedColorConfig<Omit<Part, 'borderColor' | 'labelColor'>>
borderOpacity?: number

enableLabel?: boolean
labelColor?: InheritedColor<Omit<Part, 'labelColor'>>
labelColor?: InheritedColorConfig<Omit<Part, 'labelColor'>>

enableBeforeSeparators?: boolean
beforeSeparatorLength?: number
Expand Down
6 changes: 3 additions & 3 deletions packages/heatmap/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Dimensions, Box, MotionProps, ColorProps, Theme } from '@nivo/core'
import { AxisProps } from '@nivo/axes'
import { InheritedColor } from '@nivo/colors'
import { InheritedColorConfig } from '@nivo/colors'
import { BasicTooltipProps } from '@nivo/tooltip'

declare module '@nivo/heatmap' {
Expand Down Expand Up @@ -35,7 +35,7 @@ declare module '@nivo/heatmap' {
cellShape: 'rect' | 'circle' | React.StatelessComponent<any>
cellOpacity: number
cellBorderWidth: number
cellBorderColor: InheritedColor<HeatMapDatumWithColor>
cellBorderColor: InheritedColorConfig<HeatMapDatumWithColor>

axisTop: AxisProps | null
axisRight: AxisProps | null
Expand All @@ -46,7 +46,7 @@ declare module '@nivo/heatmap' {
enableGridY: boolean

enableLabels: boolean
labelTextColor: InheritedColor<HeatMapDatumWithColor>
labelTextColor: InheritedColorConfig<HeatMapDatumWithColor>

isInteractive: boolean
hoverTarget: 'cell' | 'row' | 'column' | 'rowColumn'
Expand Down
4 changes: 2 additions & 2 deletions packages/line/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
DataFormatter,
DatumValue as CoreDatumValue,
} from '@nivo/core'
import { OrdinalColorsInstruction } from '@nivo/colors'
import { OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import { Scale, ScaleFunc } from '@nivo/scales'
import { AxisProps, GridValues } from '@nivo/axes'
Expand Down Expand Up @@ -154,7 +154,7 @@ declare module '@nivo/line' {

lineWidth?: number

colors?: OrdinalColorsInstruction
colors?: OrdinalColorScaleConfig
theme?: Theme

axisTop?: AxisProps | null
Expand Down
6 changes: 3 additions & 3 deletions packages/network/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import * as React from 'react'
import { Dimensions, Box, Theme, MotionProps } from '@nivo/core'
import { InheritedColor } from '@nivo/colors'
import { InheritedColorConfig } from '@nivo/colors'

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

Expand Down Expand Up @@ -67,10 +67,10 @@ declare module '@nivo/network' {

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

linkThickness?: number | LinkAccessor<ComputedLink, number>
linkColor?: InheritedColor<ComputedLink>
linkColor?: InheritedColorConfig<ComputedLink>

theme?: Theme

Expand Down
4 changes: 2 additions & 2 deletions packages/pie/src/Pie.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactNode, Fragment, createElement } from 'react'
// @ts-ignore
import { withContainer, SvgWrapper, bindDefs, useTheme, useDimensions } from '@nivo/core'
import { useInheritedColor, InheritedColor } from '@nivo/colors'
import { useInheritedColor, InheritedColorConfig } from '@nivo/colors'
import { PieSlice } from './PieSlice'
import { RadialLabels } from './RadialLabels'
import { SliceLabels } from './SliceLabels'
Expand Down Expand Up @@ -35,7 +35,7 @@ const Pie = <RawDatum, >({

// border
borderWidth = defaultProps.borderWidth,
borderColor: _borderColor = defaultProps.borderColor as InheritedColor<ComputedDatum<RawDatum>>,
borderColor: _borderColor = defaultProps.borderColor as InheritedColorConfig<ComputedDatum<RawDatum>>,

// radial labels
radialLabel = defaultProps.radialLabel,
Expand Down
4 changes: 2 additions & 2 deletions packages/pie/src/PieCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@nivo/core'
// @ts-ignore
import { renderLegendToCanvas } from '@nivo/legends'
import { useInheritedColor, InheritedColor } from '@nivo/colors'
import { useInheritedColor, InheritedColorConfig } from '@nivo/colors'
// @ts-ignore
import { useTooltip } from '@nivo/tooltip'
import { useNormalizedData, usePieFromBox, usePieRadialLabels, usePieSliceLabels } from './hooks'
Expand Down Expand Up @@ -95,7 +95,7 @@ const PieCanvas = <RawDatum, >({

// border
borderWidth = defaultProps.borderWidth,
borderColor = defaultProps.borderColor as InheritedColor<ComputedDatum<RawDatum>>,
borderColor = defaultProps.borderColor as InheritedColorConfig<ComputedDatum<RawDatum>>,

// radial labels
radialLabel = defaultProps.radialLabel,
Expand Down
22 changes: 13 additions & 9 deletions packages/pie/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import {
absoluteAngleDegrees,
} from '@nivo/core'
import {
// @ts-ignore
getOrdinalColorScale,
OrdinalColorScaleConfig,
useOrdinalColorScale,
InheritedColorConfig,
useInheritedColor,
OrdinalColorsInstruction,
InheritedColor,
} from '@nivo/colors'
import { defaultProps } from './props'
import {
Expand All @@ -56,7 +55,9 @@ export const useNormalizedData = <RawDatum extends MayHaveLabel>({
id = defaultProps.id,
value = defaultProps.value,
valueFormat,
colors = defaultProps.colors as OrdinalColorsInstruction,
colors = defaultProps.colors as OrdinalColorScaleConfig<
Omit<ComputedDatum<RawDatum>, 'arc' | 'color' | 'fill'>
>,
}: Pick<CompletePieSvgProps<RawDatum>, 'id' | 'value' | 'valueFormat' | 'colors'> & {
data: RawDatum[]
}): Omit<ComputedDatum<RawDatum>, 'arc' | 'fill'>[] => {
Expand All @@ -67,7 +68,10 @@ export const useNormalizedData = <RawDatum extends MayHaveLabel>({
)
const formatValue = useValueFormatter(valueFormat as any)

const getColor = useMemo(() => getOrdinalColorScale(colors, 'id'), [colors])
const getColor = useOrdinalColorScale<Omit<ComputedDatum<RawDatum>, 'arc' | 'color' | 'fill'>>(
colors,
'id'
)

return useMemo(
() =>
Expand Down Expand Up @@ -320,7 +324,7 @@ export const usePieSliceLabels = <RawDatum>({
innerRadius: number
radiusOffset: number
label: string | LabelAccessorFunction<RawDatum>
textColor: InheritedColor<ComputedDatum<RawDatum>>
textColor: InheritedColorConfig<ComputedDatum<RawDatum>>
}): SliceLabelData<RawDatum>[] => {
const theme = useTheme()
const getTextColor = useInheritedColor<ComputedDatum<RawDatum>>(textColor, theme)
Expand Down Expand Up @@ -364,13 +368,13 @@ export const usePieRadialLabels = <RawDatum>({
dataWithArc: ComputedDatum<RawDatum>[]
label: string | LabelAccessorFunction<RawDatum>
textXOffset: number
textColor: InheritedColor<ComputedDatum<RawDatum>>
textColor: InheritedColorConfig<ComputedDatum<RawDatum>>
radius: number
skipAngle: number
linkOffset: number
linkDiagonalLength: number
linkHorizontalLength: number
linkColor: InheritedColor<ComputedDatum<RawDatum>>
linkColor: InheritedColorConfig<ComputedDatum<RawDatum>>
}): RadialLabelData<RawDatum>[] => {
const getLabel = useMemo(() => getLabelGenerator(label), [label])

Expand Down
4 changes: 2 additions & 2 deletions packages/pie/src/props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrdinalColorsInstruction } from '@nivo/colors'
import { OrdinalColorScaleConfig } from '@nivo/colors'
import { PieTooltip } from './PieTooltip'

export const defaultProps = {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const defaultProps = {
sliceLabelsTextColor: { theme: 'labels.text.fill' },

// styling
colors: ({ scheme: 'nivo' } as unknown) as OrdinalColorsInstruction,
colors: ({ scheme: 'nivo' } as unknown) as OrdinalColorScaleConfig,
defs: [],
fill: [],

Expand Down
12 changes: 6 additions & 6 deletions packages/pie/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Box, Dimensions, Theme, SvgDefsAndFill } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColor } from '@nivo/colors'
import { OrdinalColorScaleConfig, InheritedColorConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'

export type DatumId = string | number
Expand Down Expand Up @@ -89,29 +89,29 @@ export type CommonPieProps<RawDatum> = {
fit: boolean

// colors, theme and border
colors: OrdinalColorsInstruction<Omit<ComputedDatum<RawDatum>, 'color' | 'fill'>>
colors: OrdinalColorScaleConfig<Omit<ComputedDatum<RawDatum>, 'color' | 'fill' | 'arc'>>
theme: Theme
borderWidth: number
borderColor: InheritedColor<ComputedDatum<RawDatum>>
borderColor: InheritedColorConfig<ComputedDatum<RawDatum>>

// radial labels
enableRadialLabels: boolean
radialLabel: string | LabelAccessorFunction<RawDatum>
radialLabelsSkipAngle: number
radialLabelsTextXOffset: number
radialLabelsTextColor: InheritedColor<ComputedDatum<RawDatum>>
radialLabelsTextColor: InheritedColorConfig<ComputedDatum<RawDatum>>
radialLabelsLinkOffset: number
radialLabelsLinkDiagonalLength: number
radialLabelsLinkHorizontalLength: number
radialLabelsLinkStrokeWidth: number
radialLabelsLinkColor: InheritedColor<ComputedDatum<RawDatum>>
radialLabelsLinkColor: InheritedColorConfig<ComputedDatum<RawDatum>>

// slices labels
enableSliceLabels: boolean
sliceLabel: string | LabelAccessorFunction<RawDatum>
sliceLabelsRadiusOffset: number
sliceLabelsSkipAngle: number
sliceLabelsTextColor: InheritedColor<ComputedDatum<RawDatum>>
sliceLabelsTextColor: InheritedColorConfig<ComputedDatum<RawDatum>>

// interactivity
isInteractive: boolean
Expand Down
Loading

0 comments on commit e98d8e0

Please sign in to comment.