Skip to content

Function: categorySelection()

categorySelection(): Selection

Defined in: mosaic-selection.ts:613

Mint the dedicated Selection for ONE category-filter producer — a click-to-toggle bar, an interactive legend: any component whose own chart must keep showing every category while rendering the unselected ones muted.

Why a separate Selection at all (verified in mosaic-core/-plot 0.28.1): highlight({ by }) tests rows with selection.predicate(mark), and a CROSSFILTER resolver unconditionally drops every clause whose clients contain the mark — which is exactly the toggle's own clause (toggleY publishes clients: plot.markSet). Highlight over the shared crossfilter is therefore a silent no-op for the one clause it exists to render; mosaic's own examples never pair the two. The wiring that works:

ts
const depthClassSel = categorySelection();          // BEFORE the crossfilter
const brush = Selection.crossfilter({ include: [depthClassSel] });
// spec:  toggleY({ as: depthClassSel }), highlight({ by: depthClassSel })
// dim:   targets: [{ selection: depthClassSel, field, table }]

The include relay forwards the clause object verbatim (clients intact), so every OTHER view cross-filters exactly as before, the producing chart still self-excludes, and the clause appears in brush.clauses — one meeting point for the inspector, reports, and signals. One producer per categorySelection.

INTERSECT resolution, deliberately not single (measured live): the origin has TWO writers — the component and the dimension's headless clause, which adoption retracts right after each component publish — and single resolution lets that null-predicate retraction (a different source) DISPLACE the component clause it just published. The origin goes empty and un-grays while the relayed copy keeps filtering the crossfilter: the exact divergence this module exists to prevent. Intersect replaces by source, which is the semantics both writers assume.

Two consequences of the relay being ONE-WAY (origin → crossfilter): clearing must reset the ORIGIN (clearSelectionFor resolves this; removing only the relayed copy leaves the origin — and its Highlight — stale), and a whole-state clear must reset origins alongside the crossfilter (resetSelectionDimTargets covers both when a dimension targets this selection, as it should).

Returns

Selection