@@ -29,6 +29,7 @@ import type {
29
29
import isDataRecord from './isDataRecord.js' ;
30
30
31
31
import { createProjection } from './projection.js' ;
32
+ import { maybeInterval } from './autoTicks.js' ;
32
33
33
34
/**
34
35
* compute the plot scales
@@ -302,7 +303,7 @@ export function createScale<T extends ScaleOptions>(
302
303
const valueArray =
303
304
type === 'quantile' || type === 'quantile-cont' ? allDataValues . toSorted ( ) : valueArr ;
304
305
305
- const domain = scaleOptions . domain
306
+ let domain = scaleOptions . domain
306
307
? isOrdinal
307
308
? scaleOptions . domain
308
309
: extent ( scaleOptions . zero ? [ 0 , ...scaleOptions . domain ] : scaleOptions . domain )
@@ -317,6 +318,16 @@ export function createScale<T extends ScaleOptions>(
317
318
: valueArray
318
319
: extent ( scaleOptions . zero ? [ 0 , ...valueArray ] : valueArray ) ;
319
320
321
+ if ( scaleOptions . interval ) {
322
+ if ( isOrdinal ) {
323
+ domain = domainFromInterval ( domain , scaleOptions . interval ) ;
324
+ } else {
325
+ throw new Error (
326
+ 'Setting interval via axis options is only supported for ordinal scales'
327
+ ) ;
328
+ }
329
+ }
330
+
320
331
if ( ! scaleOptions . scale ) {
321
332
throw new Error ( `No scale function defined for ${ name } ` ) ;
322
333
}
@@ -350,6 +361,12 @@ export function createScale<T extends ScaleOptions>(
350
361
} ;
351
362
}
352
363
364
+ function domainFromInterval ( domain : RawValue [ ] , interval : string | number ) {
365
+ const interval_ = maybeInterval ( interval ) ;
366
+ const [ lo , hi ] = extent ( domain ) ;
367
+ return interval_ . range ( lo , interval_ . offset ( hi ) ) ;
368
+ }
369
+
353
370
/**
354
371
* Infer a scale type based on the scale name, the data values mapped to it and
355
372
* the mark types that are bound to the scale
0 commit comments