@@ -2,6 +2,7 @@ import { scaleLinear } from 'd3-scale';
22import { useCallback } from 'react' ;
33
44import { useChartData } from '../../context/ChartContext.js' ;
5+ import type { ScaleLinearNumberOptions } from '../../context/ScaleContext.tsx' ;
56import type {
67 Domains ,
78 Margin ,
@@ -16,7 +17,7 @@ interface ScaleInsetXOptions {
1617 xDomain : number [ ] ;
1718 mode : SpectraDirection ;
1819}
19- interface ScaleXOptions extends ScaleInsetXOptions {
20+ interface ScaleXOptions extends ScaleInsetXOptions , ScaleLinearNumberOptions {
2021 xDomains : Domains ;
2122}
2223
@@ -27,7 +28,7 @@ interface InsetYScaleOptions {
2728 spectraBottomMargin : number ;
2829}
2930
30- interface ScaleYOptions extends InsetYScaleOptions {
31+ interface ScaleYOptions extends InsetYScaleOptions , ScaleLinearNumberOptions {
3132 yDomains : Domains ;
3233 verticalAlign : VerticalAlignment ;
3334}
@@ -47,34 +48,40 @@ function getInsetYScale(options: InsetYScaleOptions) {
4748 return scaleLinear ( yDomain , [ innerHeight , margin . top ] ) ;
4849}
4950
50- function getXScale (
51- options : ScaleXOptions ,
52- spectrumId : number | null | string = null ,
53- ) {
54- const { width, margin, xDomains, xDomain, mode } = options ;
51+ function getXScale ( options : ScaleXOptions ) {
52+ const { width, margin, xDomains, xDomain, mode, spectrumId, customDomain } =
53+ options ;
54+
5555 const range =
5656 mode === 'RTL'
5757 ? [ width - margin . right , margin . left ]
5858 : [ margin . left , width - margin . right ] ;
59- return scaleLinear ( spectrumId ? xDomains [ spectrumId ] : xDomain , range ) ;
59+
60+ let domain = spectrumId ? xDomains [ spectrumId ] : xDomain ;
61+ if ( customDomain ) {
62+ domain = customDomain ;
63+ }
64+ return scaleLinear ( domain , range ) ;
6065}
6166
62- function getYScale (
63- options : ScaleYOptions ,
64- spectrumId : number | null | string = null ,
65- ) {
67+ function getYScale ( options : ScaleYOptions ) {
6668 const {
6769 height,
6870 margin,
6971 verticalAlign,
7072 yDomain,
7173 yDomains,
7274 spectraBottomMargin = 10 ,
75+ spectrumId = null ,
76+ customDomain,
7377 } = options ;
7478 let domainY : number [ ] = yDomain ;
7579 if ( spectrumId && yDomains ?. [ spectrumId ] ) {
7680 domainY = yDomains [ spectrumId ] ;
7781 }
82+ if ( customDomain ) {
83+ domainY = customDomain ;
84+ }
7885 const [ min , max ] = domainY ;
7986 let bottomShift = spectraBottomMargin ;
8087
@@ -126,7 +133,7 @@ function useScaleX() {
126133 return getInsetXScale ( { margin, mode, width, xDomain } ) ;
127134 }
128135
129- return getXScale ( { margin, mode, width, xDomain, xDomains } , spectrumId ) ;
136+ return getXScale ( { margin, mode, width, xDomain, xDomains, spectrumId } ) ;
130137 } ,
131138 [ isInset , margin , mode , width , xDomain , xDomains ] ,
132139 ) ;
0 commit comments