/** * @upsetjs/react * https://github.com/upsetjs/upsetjs * * Copyright (c) 2021 Samuel Gratzl */ import type { ISet } from '@upsetjs/model'; import React, { PropsWithChildren, ReactElement } from 'react'; import type { UpSetDataInfo } from '../derive/deriveDataDependent'; import type { UpSetSizeInfo } from '../derive/deriveSizeDependent'; import type { UpSetStyleInfo } from '../derive/deriveStyleDependent'; import type { UpSetSelection } from './interfaces'; import { addonPositionGenerator, mergeColor } from './utils'; import { clsx } from '../utils'; import { OVERFLOW_PADDING_FACTOR } from '../defaults'; import { computeOverflowValues } from './CombinationChart'; export type SetChartProps = PropsWithChildren<{ d: ISet; i: number; className?: string; size: UpSetSizeInfo; style: UpSetStyleInfo; data: UpSetDataInfo; h: UpSetSelection; }>; const SetChart = /*!#__PURE__*/ React.memo(function SetChart({ d, i, h, className, size, data, style, children, }: SetChartProps) { const xValues = computeOverflowValues(d.cardinality, data.sets.max, data.sets.x); const genPosition = addonPositionGenerator(size.sets.w + size.labels.w + size.cs.w, size.sets.addonPadding); const anchorOffset = style.setLabelAlignment === 'center' ? size.labels.w / 2 : style.setLabelAlignment === 'left' ? 2 : size.labels.w - 2; return ( {style.tooltips && ( {d.name}: {data.sets.format(d.cardinality)} )} {i % 2 === 1 && ( )} {size.sets.w > 0 && ( <> {xValues.map((x, i) => { const offset = i > 0 ? Math.floor(data.sets.bandWidth * OVERFLOW_PADDING_FACTOR[i - 1]) : 0; return ( ); })} {data.sets.format(d.cardinality)} )} {d.name} {size.sets.addons.map((addon) => ( {addon.render({ set: d, width: addon.size, height: data.sets.bandWidth, theme: style.theme })} ))} {children} ); }); export default SetChart as (props: SetChartProps) => ReactElement;