/** * @upsetjs/react * https://github.com/upsetjs/upsetjs * * Copyright (c) 2021 Samuel Gratzl */ import type { ISetLike } from '@upsetjs/model'; import React, { PropsWithChildren } from 'react'; import { mergeColor } from '../../components/utils'; import { clsx } from '../../utils'; import type { KMapDataInfo } from '../derive/deriveDataDependent'; import type { KMapStyleInfo } from '../derive/deriveStyleDependent'; function KMapQueries({ data, style, elemOverlap, secondary, tooltip, suffix, empty, }: PropsWithChildren<{ data: KMapDataInfo; style: KMapStyleInfo; suffix: string; empty?: boolean; elemOverlap: (s: ISetLike) => number; secondary?: boolean; tooltip?: string; }>) { const width = data.cs.bandWidth; const offset = (data.cell - width) / 2; const className = clsx(`fill${suffix}`, !tooltip && `pnone-${style.id}`, style.classNames.bar); return ( {data.cs.v.map((d, i) => { const l = data.cs.l[i]; const key = data.cs.keys[i]; if (empty && !secondary) { return ( {tooltip && } ); } const o = elemOverlap(d); if (o === 0) { return null; } const y = data.cs.scale(o); const title = tooltip && {`${d.name} ∩ ${tooltip}: ${o}`}; return secondary ? ( {title} ) : ( {title} ); })} ); } export default KMapQueries;