import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { ShapeViewModel } from '../../layout/types/viewmodel_types' ; import { STATISTICS_KEY } from '../../layout/utils/group_by_rollup' ; import { PartitionSpec } from '../../specs' ; import { partitionMultiGeometries } from './geometries' ; import { getPartitionSpecs } from './get_partition_specs' ; internal export interface PartitionSectionData { panelTitle ? : string ; label : string ; parentName : string | undefined ; depth : number ; percentage : string ; value : number ; valueText : string ; } internal export interface PartitionData { hasMultipleLayers : boolean ; isSmallMultiple : boolean ; data : PartitionSectionData [ ] ; } internal const getScreenReaderDataForPartitions = ( [ { valueFormatter } ] , shapeViewModels ) : PartitionSectionData [ ] => { return shapeViewModels . flatMap ( ( { quadViewModel , layers , panel } ) => quadViewModel . map ( ( { depth , value , dataName , parent , path } ) => { const label = layers [ depth - 1 ] ?. nodeLabel ?. ( dataName ) ?? dataName ; const parentValue = path . length > 1 ? path [ path . length - 2 ] . value : undefined ; const parentName = depth > 1 && parentValue ? layers [ depth - 2 ] ?. nodeLabel ?. ( parentValue ) ?? path [ path . length - 1 ] . value : 'none' ; return { panelTitle : panel . title , depth , label , parentName , percentage : `${ Math . round ( ( value / parent [ STATISTICS_KEY ] . globalAggregate ) * 100 ) }%` , value , valueText : valueFormatter ? valueFormatter ( value ) : `${ value }` , } ; } ) ) ; } ; internal export const getScreenReaderDataSelector = createCustomCachedSelector ( [ getPartitionSpecs , partitionMultiGeometries ] , ( specs , shapeViewModel ) : PartitionData => { if ( specs . length === 0 ) { return { hasMultipleLayers : false , isSmallMultiple : false , data : [ ] , } ; } return { hasMultipleLayers : specs [ 0 ] . layers . length > 1 , isSmallMultiple : shapeViewModel . length > 1 , data : getScreenReaderDataForPartitions ( specs , shapeViewModel ) , } ; } ) ;