UNPKG

@tanstack/charts

Version:

A chart grammar for TypeScript and JavaScript. Marks consume your data directly, channels describe visual encodings, and the engine compiles them into a renderer-neutral keyed scene. TanStack's compact scales cover common numeric and categorical mappings.

25 lines (24 loc) 616 B
import { valueKey } from "./scales.js"; function resolveCategoricalLegendItems(colors, format = String) { return colors.domain.map((value) => ({ key: valueKey(value), value, label: format(value), color: colors.map(value) })); } function layoutCategoricalLegendItems(itemCount, width, minimumItemWidth) { const columns = Math.max( 1, Math.min(itemCount || 1, Math.floor(width / minimumItemWidth) || 1) ); return { columns, rows: Math.ceil(itemCount / columns), itemWidth: width / columns }; } export { layoutCategoricalLegendItems, resolveCategoricalLegendItems };