Skip to content

Commit 7c22d28

Browse files
authored
feat: Add shouldNice option to AxisOptionsBase and fix checks for extrema in buildTimeAxis (#235)
1 parent c8a5867 commit 7c22d28

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export type AxisOptionsBase = {
241241
minTickPaddingForRotation?: number
242242
tickLabelRotationDeg?: number
243243
tickCount?: number
244+
shouldNice?: boolean
244245
innerBandPadding?: number
245246
outerBandPadding?: number
246247
innerSeriesBandPadding?: number

src/utils/buildAxis.linear.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function defaultAxisOptions<TDatum>(
4242
outerSeriesBandPadding: options.outerSeriesBandPadding ?? 0,
4343
show: options.show ?? true,
4444
stacked: options.stacked ?? false,
45+
shouldNice: options.shouldNice ?? true,
4546
}
4647
}
4748

@@ -117,24 +118,25 @@ function buildTimeAxis<TDatum>(
117118
return value
118119
})
119120

120-
let shouldNice = true
121+
let shouldNice = options.shouldNice
121122

122-
if (typeof options.min === 'number') {
123+
// see https://stackoverflow.com/a/2831422
124+
if (Object.prototype.toString.call(options.min) === '[object Date]') {
123125
minValue = min([options.min, minValue as Date])
124126
shouldNice = false
125127
}
126128

127-
if (typeof options.max === 'number') {
129+
if (Object.prototype.toString.call(options.max) === '[object Date]') {
128130
maxValue = max([options.max, maxValue as Date])
129131
shouldNice = false
130132
}
131133

132-
if (typeof options.hardMin === 'number') {
134+
if (Object.prototype.toString.call(options.hardMin) === '[object Date]') {
133135
minValue = options.hardMin
134136
shouldNice = false
135137
}
136138

137-
if (typeof options.hardMax === 'number') {
139+
if (Object.prototype.toString.call(options.hardMax) === '[object Date]') {
138140
maxValue = options.hardMax
139141
shouldNice = false
140142
}
@@ -245,7 +247,7 @@ function buildLinearAxis<TDatum>(
245247
return value
246248
})
247249

248-
let shouldNice = true
250+
let shouldNice = options.shouldNice
249251

250252
if (typeof options.min === 'number') {
251253
minValue = min([options.min, minValue as number])

0 commit comments

Comments
 (0)