export interface Exclusion { from: number; to: number; ignore?: boolean; } export interface Filter { from?: number; to?: number; exclusions?: Exclusion[]; } export interface RectAnnotation { type: string; position: Array<{ x: number | string; y: string }>; strokeWidth: number; fillColor: string; } /** * Get filter annotations * @param filter - Filter with from, to, and exclusions * @returns Array of rectangle annotations */ export function getFilterAnnotations(filter: Filter = {}): RectAnnotation[] { const { exclusions = [], from, to } = filter; const filteredExclusions = exclusions.filter( (exclusion) => !exclusion.ignore, ); const annotations: RectAnnotation[] = filteredExclusions.map((exclusion) => { const annotation: RectAnnotation = { type: 'rect', position: [ { x: exclusion.from, y: '0px' }, { x: exclusion.to, y: '2000px' }, ], strokeWidth: 0, fillColor: 'rgba(255,255,128,1)', }; return annotation; }); if (from !== undefined) { annotations.push({ type: 'rect', position: [ { x: Number.MIN_SAFE_INTEGER, y: '0px' }, { x: from, y: '2000px' }, ], strokeWidth: 0, fillColor: 'rgba(255,255,224,1)', }); } if (to !== undefined) { annotations.push({ type: 'rect', position: [ { x: to, y: '0px' }, { x: Number.MAX_SAFE_INTEGER, y: '2000px' }, ], strokeWidth: 0, fillColor: 'rgba(255,255,224,1)', }); } return annotations; }