import type { Domain } from '@h5web/shared' ; import { createArrayFromView } from '@h5web/shared' ; import { isNumber } from 'lodash' ; import type { NdArray } from 'ndarray' ; import ndarray from 'ndarray' ; import type { Axis , DimensionMapping } from '../../dimension-mapper/models' ; import { isAxis } from '../../dimension-mapper/utils' ; export const DEFAULT_DOMAIN = [ 0.1 , 1 ] ; export function getBaseArray < T , U extends T [ ] | undefined > ( value , rawDims ) ; export function getBaseArray < T > ( value , rawDims ) { return value && ndarray ( value , rawDims ) ; } export function applyMapping < T , U extends NdArray < T [ ] > | undefined > ( baseArray , mapping ) ; export function applyMapping < T > ( baseArray , mapping ) { if ( ! baseArray ) { return undefined ; } const isXBeforeY = mapping . includes ( 'y' ) && mapping . includes ( 'x' ) && mapping . indexOf ( 'x' ) < mapping . indexOf ( 'y' ) ; const slicingState = mapping . map ( ( val ) => ( isNumber ( val ) ? val : null ) ) ; const slicedView = baseArray . pick ( ... slicingState ) ; const mappedView = isXBeforeY ? slicedView . transpose ( 1 , 0 ) : slicedView ; return createArrayFromView ( mappedView ) ; } export function getSliceSelection ( dimMapping ? ) { if ( ! dimMapping || ! dimMapping . some ( isNumber ) ) { return undefined ; } return dimMapping . map ( ( dim ) => ( isAxis ( dim ) ? ':' : dim ) ) . join ( ',' ) ; }