import { ScaleType , getValidDomainForScale } from '@h5web/shared' ; import type { Domain , H5WebComplex } from '@h5web/shared' ; import type { NdArray } from 'ndarray' ; import ndarray from 'ndarray' ; import { useMemo } from 'react' ; import { createMemo } from 'react-use' ; import { DEFAULT_DOMAIN } from '../utils' ; import { getPhaseAmplitudeValues } from './utils' ; export function usePhaseAmplitudeArrays ( mappedArray , scaleType = ScaleType . Linear ) { const [ phaseArray , phaseBounds , amplitudeArray , amplitudeBounds ] = useMemo ( ( ) => { const { phaseValues , phaseBounds , amplitudeValues , amplitudeBounds } = getPhaseAmplitudeValues ( mappedArray . data ) ; return [ ndarray ( phaseValues , mappedArray . shape ) , phaseBounds , ndarray ( amplitudeValues , mappedArray . shape ) , amplitudeBounds , ] ; } , [ mappedArray ] ) ; const [ phaseDomain , amplitudeDomain ] = useMemo ( ( ) => [ getValidDomainForScale ( phaseBounds , scaleType ) || DEFAULT_DOMAIN , getValidDomainForScale ( amplitudeBounds , scaleType ) || DEFAULT_DOMAIN , ] , [ amplitudeBounds , phaseBounds , scaleType ] ) ; return { phaseArray , phaseDomain , amplitudeArray , amplitudeDomain , } ; } export const usePhaseAmplitudeValues = createMemo ( getPhaseAmplitudeValues ) ;