upsetjs import type { ISetLike } from './model' ; import { setOverlapFactory , SetOverlap , setElemOverlapFactory , SetElemOverlap , setElemIntersectionFactory , } from './data/setOverlap' ; export interface UpSetElemQuery < T = any > { /**
     * name of this query for the tooltip
     */ readonly name : string ; /**
     * color for highlighting
     */ readonly color : string ; /**
     * elements within this query
     */ readonly elems : readonly T [ ] | Set < T > ; } export interface UpSetSetQuery < T = any > { /**
     * name of this query for the tooltip
     */ readonly name : string ; /**
     * color for highlighting
     */ readonly color : string ; /**
     * set to highlight
     */ readonly set : ISetLike < T > ; } export interface UpSetCalcQuery < T = any > { /**
     * name of this query for the tooltip
     */ readonly name : string ; /**
     * color for highlighting
     */ readonly color : string ; param s return overlap ( s ) : number ; } export type UpSetQuery < T = any > = UpSetElemQuery < T > | UpSetCalcQuery < T > | UpSetSetQuery < T > ; export type UpSetQueries < T = any > = readonly UpSetQuery < T > [ ] ; export function isElemQuery < T > ( q ) { return Array . isArray ( ( q as UpSetElemQuery < T > ) . elems ) ; } export function isCalcQuery < T > ( q ) { return typeof ( q as UpSetCalcQuery < T > ) . overlap === 'function' ; } export function isSetQuery < T > ( q ) { return ( q as UpSetSetQuery < T > ) . set != null ; } param query param what param toElemKey export function queryOverlap < T > ( query , what , toElemKey ? ) { if ( isCalcQuery ( query ) ) { return query . overlap ; } if ( isSetQuery ( query ) && query . set . overlap ) { return query . set . overlap ; } const f = setOverlapFactory ( isElemQuery ( query ) ? query . elems : query . set . elems , toElemKey ) ; return ( s ) => { if ( s . overlap && isElemQuery ( query ) && Array . isArray ( query . elems ) ) { return s . overlap ( query . elems ) ; } if ( s . overlap && isSetQuery ( query ) ) { return s . overlap ( query . set ) ; } return f ( s . elems ) [ what ] ; } ; } param query param what param toElemKey export function queryElemOverlap < T > ( query , what , toElemKey ? ) { if ( isCalcQuery ( query ) ) { return ( ) => null ; } if ( what === 'intersection' ) { const f = setElemIntersectionFactory ( isElemQuery ( query ) ? query . elems : query . set . elems , toElemKey ) ; return ( s ) => f ( s . elems ) ; } const f = setElemOverlapFactory ( isElemQuery ( query ) ? query . elems : query . set . elems , toElemKey ) ; return ( s ) => { return f ( s . elems ) [ what ] ; } ; }