@@ -15,10 +15,9 @@ import { GroupId } from '../../../../utils/ids';
1515import { convertXScaleTypes } from '../../domains/x_domain' ;
1616import { coerceYScaleTypes } from '../../domains/y_domain' ;
1717import { X_SCALE_DEFAULT , Y_SCALE_DEFAULT } from '../../scales/scale_defaults' ;
18- import { isHorizontalAxis , isVerticalAxis } from '../../utils/axis_type_utils ' ;
18+ import { isXDomain } from '../../utils/axis_utils ' ;
1919import { groupBy } from '../../utils/group_data_series' ;
2020import { AxisSpec , BasicSeriesSpec , CustomXDomain , XScaleType , YDomainRange } from '../../utils/specs' ;
21- import { isHorizontalRotation } from '../utils/common' ;
2221import { getSpecDomainGroupId } from '../utils/spec' ;
2322import { getAxisSpecsSelector , getSeriesSpecsSelector } from './get_specs' ;
2423import { mergeYCustomDomainsByGroupId } from './merge_y_custom_domains' ;
@@ -54,19 +53,17 @@ export function getScaleConfigsFromSpecs(
5453 seriesSpecs : BasicSeriesSpec [ ] ,
5554 settingsSpec : SettingsSpec ,
5655) : ScaleConfigs {
57- const isHorizontalChart = isHorizontalRotation ( settingsSpec . rotation ) ;
58-
5956 // x axis
60- const xAxes = axisSpecs . filter ( ( d ) => isHorizontalChart === isHorizontalAxis ( d . position ) ) ;
61- const xTicks = xAxes . reduce < number > ( ( acc , { ticks = X_SCALE_DEFAULT . desiredTickCount } ) => {
57+ const xAxesSpecs = axisSpecs . filter ( ( spec ) => isXDomain ( spec . position , settingsSpec . rotation ) ) ;
58+ const maxTickCountForXAxes = xAxesSpecs . reduce < number > ( ( acc , { ticks = X_SCALE_DEFAULT . desiredTickCount } ) => {
6259 return Math . max ( acc , ticks ) ;
63- } , X_SCALE_DEFAULT . desiredTickCount ) ;
60+ } , - Infinity ) ;
6461
6562 const xScaleConfig = convertXScaleTypes ( seriesSpecs ) ;
6663 const x : ScaleConfigs [ 'x' ] = {
6764 customDomain : settingsSpec . xDomain ,
6865 ...xScaleConfig ,
69- desiredTickCount : xTicks ,
66+ desiredTickCount : Number . isFinite ( maxTickCountForXAxes ) ? maxTickCountForXAxes : X_SCALE_DEFAULT . desiredTickCount ,
7067 } ;
7168
7269 // y axes
@@ -80,16 +77,19 @@ export function getScaleConfigsFromSpecs(
8077
8178 const customDomainByGroupId = mergeYCustomDomainsByGroupId ( axisSpecs , settingsSpec . rotation ) ;
8279
83- const yAxes = axisSpecs . filter ( ( d ) => isHorizontalChart === isVerticalAxis ( d . position ) ) ;
80+ const yAxisSpecs = axisSpecs . filter ( ( spec ) => ! isXDomain ( spec . position , settingsSpec . rotation ) ) ;
8481 const y = Object . keys ( scaleConfigsByGroupId ) . reduce < ScaleConfigs [ 'y' ] > ( ( acc , groupId ) => {
85- const axis = yAxes . find ( ( yAxis ) => yAxis . groupId === groupId ) ;
86- const desiredTickCount = axis ?. ticks ?? Y_SCALE_DEFAULT . desiredTickCount ;
87- const scaleConfig = scaleConfigsByGroupId [ groupId ] ;
88- const customDomain = customDomainByGroupId . get ( groupId ) ;
82+ const maxTickCountYAxes = yAxisSpecs . reduce < number > ( ( maxTickCount , yAxis ) => {
83+ return yAxis . groupId === groupId
84+ ? Math . max ( maxTickCount , yAxis . ticks ?? Y_SCALE_DEFAULT . desiredTickCount )
85+ : maxTickCount ;
86+ } , - Infinity ) ;
87+ const desiredTickCount = Number . isFinite ( maxTickCountYAxes ) ? maxTickCountYAxes : Y_SCALE_DEFAULT . desiredTickCount ;
88+
8989 if ( ! acc [ groupId ] ) {
9090 acc [ groupId ] = {
91- customDomain,
92- ...scaleConfig ,
91+ customDomain : customDomainByGroupId . get ( groupId ) ,
92+ ...scaleConfigsByGroupId [ groupId ] ,
9393 desiredTickCount,
9494 } ;
9595 }
0 commit comments