Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scales): fix timeScale min/max values and typings #743

Merged
merged 2 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/scales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ declare module '@nivo/scales' {
type: 'point'
}

export interface TimeScaleFormatted {
type: 'time'
format: string
precision?: 'millisecond' | 'second' | 'minute' | 'hour' | 'month' | 'year' | 'day'
useUTC?: boolean
min?: 'auto' | string
max?: 'auto' | string
}

export interface TimeScale {
type: 'time'
format?: string
precision?: 'millisecond' | 'second' | 'minute' | 'hour' | 'month' | 'year' | 'day'
useUTC?: boolean
min?: 'auto' | Date
max?: 'auto' | Date
}

export interface LogScale {
Expand All @@ -33,7 +43,7 @@ declare module '@nivo/scales' {
max?: 'auto' | number
}

export type Scale = LinearScale | PointScale | TimeScale | LogScale
export type Scale = LinearScale | PointScale | TimeScale | TimeScaleFormatted | LogScale

export type ScaleFunc = (value: string | number | Date) => number
}
4 changes: 2 additions & 2 deletions packages/scales/src/timeScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export const timeScale = (
if (min === 'auto') {
minValue = values.min
} else if (format !== 'native') {
minValue = normalize(values.min)
minValue = normalize(min)
}

let maxValue = max
if (max === 'auto') {
maxValue = values.max
} else if (format !== 'native') {
maxValue = normalize(values.max)
maxValue = normalize(max)
}

const scale = useUTC ? scaleUtc() : scaleTime()
Expand Down