import { $Values } from 'utility-types' ; import { isNil } from '../../../utils/common' ; import { Bounds } from '../../../utils/d3-delaunay' ; import { IndexedGeometry , isPointGeometry } from '../../../utils/geometry' ; import { Point } from '../../../utils/point' ; import { PrimitiveValue } from '../../partition_chart/layout/utils/group_by_rollup' ; import { IndexedGeometryLinearMap } from './indexed_geometry_linear_map' ; import { IndexedGeometrySpatialMap } from './indexed_geometry_spatial_map' ; internal export const GeometryType = Object . freeze ( { linear : 'linear' as const , spatial : 'spatial' as const , } ) ; internal export type GeometryType = $Values < typeof GeometryType > ; internal export class IndexedGeometryMap { private linearMap = new IndexedGeometryLinearMap ( ) ; private spatialMap = new IndexedGeometrySpatialMap ( ) ; param bounds triangulation ( bounds ? ) { return this . spatialMap . triangulation ( bounds ) ; } keys ( ) { return [ ... this . linearMap . keys ( ) , ... this . spatialMap . keys ( ) ] ; } get size ( ) : number { return this . linearMap . size + this . spatialMap . size ; } set ( geometry , type = GeometryType . linear ) { if ( type === GeometryType . spatial && isPointGeometry ( geometry ) ) { this . spatialMap . set ( [ geometry ] ) ; } else { this . linearMap . set ( geometry ) ; } } find ( x , point ? , smHorizontalValue ? , smVerticalValue ? ) { if ( x === null && ! point ) { return [ ] ; } const spatialValues = point === undefined ? [ ] : this . spatialMap . find ( point ) ; return [ ... this . linearMap . find ( x ) , ... spatialValues ] . filter ( ( { seriesIdentifier : { smHorizontalAccessorValue , smVerticalAccessorValue } } ) => ( isNil ( smVerticalValue ) || smVerticalAccessorValue === smVerticalValue ) && ( isNil ( smHorizontalValue ) || smHorizontalAccessorValue === smHorizontalValue ) ) ; } getMergeData ( ) { return { spatialGeometries : this . spatialMap . getMergeData ( ) , linearGeometries : this . linearMap . getMergeData ( ) , } ; } param indexedMaps merge ( ... indexedMaps ) { for ( const indexedMap of indexedMaps ) { const { spatialGeometries , linearGeometries } = indexedMap . getMergeData ( ) ; this . spatialMap . set ( spatialGeometries ) ; linearGeometries . forEach ( ( geometry ) => { if ( Array . isArray ( geometry ) ) { geometry . forEach ( ( geometry ) => this . linearMap . set ( geometry ) ) ; } else { this . linearMap . set ( geometry ) ; } } ) ; } } }