@@ -20,10 +20,10 @@ export function defaultizeAxis(
20
20
dataset : Readonly < DatasetType > | undefined ,
21
21
axisName : 'y' ,
22
22
) : AxisConfig < ScaleName , any , ChartsYAxisProps > [ ] ;
23
- export function defaultizeAxis (
23
+ export function defaultizeAxis < Axis = 'x' | 'y' > (
24
24
inAxis : readonly MakeOptional < AxisConfig , 'id' > [ ] | undefined ,
25
25
dataset : Readonly < DatasetType > | undefined ,
26
- axisName : 'x' | 'y' ,
26
+ axisName : Axis ,
27
27
) : AxisConfig [ ] {
28
28
const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY ;
29
29
@@ -45,29 +45,25 @@ export function defaultizeAxis(
45
45
const position = axisConfig . position ?? 'none' ;
46
46
const dimension = axisName === 'x' ? 'height' : 'width' ;
47
47
48
- const height =
49
- axisName === 'x'
50
- ? DEFAULT_AXIS_SIZE_HEIGHT + ( axisConfig . label ? AXIS_LABEL_DEFAULT_HEIGHT : 0 )
51
- : 0 ;
52
- const width =
53
- axisName === 'y'
54
- ? DEFAULT_AXIS_SIZE_WIDTH + ( axisConfig . label ? AXIS_LABEL_DEFAULT_HEIGHT : 0 )
55
- : 0 ;
56
-
57
48
const sharedConfig = {
58
49
id : `defaultized-${ axisName } -axis-${ index } ` ,
59
50
// The fist axis is defaultized to the bottom/left
60
51
...( index === 0 ? { position : defaultPosition } : { } ) ,
61
- height,
62
- width,
63
52
offset : offsets [ position ] ,
64
53
...axisConfig ,
65
54
} ;
66
55
56
+ if ( axisName === 'x' ) {
57
+ const height = DEFAULT_AXIS_SIZE_HEIGHT + ( axisConfig . label ? AXIS_LABEL_DEFAULT_HEIGHT : 0 ) ;
58
+ ( sharedConfig as any ) . height = ( axisConfig as any ) . height ?? height ;
59
+ } else if ( axisName === 'y' ) {
60
+ const width = DEFAULT_AXIS_SIZE_WIDTH + ( axisConfig . label ? AXIS_LABEL_DEFAULT_HEIGHT : 0 ) ;
61
+ ( sharedConfig as any ) . width = ( axisConfig as any ) . width ?? width ;
62
+ }
63
+
67
64
// Increment the offset for the next axis
68
65
if ( position !== 'none' ) {
69
- offsets [ position ] +=
70
- ( axisConfig as any ) [ dimension ] ?? ( dimension === 'height' ? height : width ) ;
66
+ offsets [ position ] += ( sharedConfig as any ) [ dimension ] ;
71
67
}
72
68
73
69
// If `dataKey` is NOT provided
0 commit comments