import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { Position , safeFormat } from '../../../../utils/common' ; import { isHorizontalAxis , isVerticalAxis } from '../../utils/axis_type_utils' ; import { AxisGeometry } from '../../utils/axis_utils' ; import { hasSMDomain } from '../../utils/panel' ; import { PerPanelMap , getPerPanelMap } from '../../utils/panel_utils' ; import { computeAxesGeometriesSelector } from './compute_axes_geometries' ; import { computeSmallMultipleScalesSelector , SmallMultipleScales } from './compute_small_multiple_scales' ; import { getSmallMultiplesIndexOrderSelector , SmallMultiplesGroupBy } from './get_specs' ; internal export type PerPanelAxisGeoms = { axesGeoms : AxisGeometry [ ] ; } & PerPanelMap ; const getPanelTitle = ( isVertical , verticalValue , horizontalValue , groupBy ? ) : string => { const formatter = isVertical ? groupBy ?. vertical ?. format : groupBy ?. horizontal ?. format ; const value = isVertical ? `${ verticalValue }` : `${ horizontalValue }` ; return safeFormat ( value , formatter ) ; } ; const isPrimaryColumnFn = ( { horizontal : { domain } } ) => ( position , horizontalValue ) => isVerticalAxis ( position ) && domain [ 0 ] === horizontalValue ; const isPrimaryRowFn = ( { vertical : { domain } } ) => ( position , verticalValue ) => isHorizontalAxis ( position ) && domain [ 0 ] === verticalValue ; internal export const computePerPanelAxesGeomsSelector = createCustomCachedSelector ( [ computeAxesGeometriesSelector , computeSmallMultipleScalesSelector , getSmallMultiplesIndexOrderSelector ] , ( axesGeoms , scales , groupBySpec ) : Array < PerPanelAxisGeoms > => { const { horizontal , vertical } = scales ; const isPrimaryColumn = isPrimaryColumnFn ( scales ) ; const isPrimaryRow = isPrimaryRowFn ( scales ) ; return getPerPanelMap ( scales , ( _ , h , v ) => ( { axesGeoms : axesGeoms . map ( ( geom ) => { const { position } = geom . axis ; const isVertical = isVerticalAxis ( position ) ; const usePanelTitle = isVertical ? hasSMDomain ( vertical ) : hasSMDomain ( horizontal ) ; const panelTitle = usePanelTitle ? getPanelTitle ( isVertical , v , h , groupBySpec ) : undefined ; const secondary = ! isPrimaryColumn ( position , h ) && ! isPrimaryRow ( position , v ) ; return { ... geom , axis : { ... geom . axis , panelTitle , secondary } } ; } ) , } ) ) ; } ) ;