Skip to content

Kit: add useCategories and countFact - #225

Open
agorischek wants to merge 1 commit into
mainfrom
agorischek/kit-categories
Open

agorischek wants to merge 1 commit into
mainfrom
agorischek/kit-categories

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 240dcf6a4c55c97d025a28aaade63fcd3391bf29

Dimension Assessment Rationale
Change confidence 9/10 ↑ New, opt-in API; no built-in renderer changes.
↑ Kit tests cover ranking over both revisions, weights, language colors, the swatch markup and countFact's count, added, removed, ids, tone and single-extraction cases.
↓ No built-in uses them yet, so there's no browser coverage.

Superego feedback items 17 and 18.

useCategories(rows, key, {title, colorMode, …}) (and the framework-free categoriesOf) colors comparison rows' categories from the kit's categorical palette, ranked over both revisions. A category keeps its color and its legend place from Before to After and at every progress.

  • key(item) returns a key, a Category (languageCategory(name) keeps a language's own color) or undefined.
  • Items rank by count over both revisions, or by weight(item). distinct and pinned pass through to categoryPalette.
  • It returns color(key), the host legend (for useLegend), the palette, and in React swatch(key): a Swatch dot marked data-projections-category, as the checks expect of categorical colors.

countFact(rows, {id, noun, key?, description?, icon?, tone?}) is a summary-bar fact.

  • It counts distinct keys on After. added and removed are the keys only After or only Before has. ids are the rows counted on After, so the figure filters.
  • Each row counts by its ID by default. tone applies only while the count is above zero.

Documented in the components guide (a new Categories section, plus the summary-bar facts bullet) and the renderer-kit guide.

Not adopted in the built-ins:

  • code-statistics ranks a language by the larger of its two counts, takes one category per row (its After label), and lists only the series it shows. Switching would reorder its colors, including on the homepage carousel, so it keeps its own palette.
  • file-packing's palette is per packed leaf. It mixes kind and flag categories, pins definition kind colors and weighs by size. That's more than a per-item key.

categoriesOf and useCategories color comparison rows' categories from the
categorical palette, ranked over both revisions, and return each category's
color, the host legend and (in React) a swatch marked as a categorical color.
countFact counts distinct keys on After for the summary bar, with the keys
the comparison added and removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Colliding presentation row IDs can produce invalid filter IDs in count-fact.ts, causing summary validation failures and host filters that match nothing.

1 open issue
What changed in this PR

Adds opt-in renderer-kit helpers for stable category colors and summary counts, without changing built-in renderers.

Changes:

  • Adds categoriesOf, useCategories, and Swatch for categories ranked across both revisions.
  • Adds countFact for distinct After counts, added/removed keys, and filter IDs.
  • Documents the APIs and adds focused tests and swatch styling.
File Description
packages/​renderers/​kit/​test/​categories.test.mjs Tests category ranking, swatches, and count facts.
packages/​renderers/​kit/​styles/​layout.css Adds small and medium swatch styles.
packages/​renderers/​kit/​src/​react/​categories.tsx Adds the category hook and swatch component.
packages/​renderers/​kit/​src/​react.ts Exports the React category helpers.
packages/​renderers/​kit/​src/​index.ts Exports category and count-fact APIs.
packages/​renderers/​kit/​src/​count-fact.ts Builds distinct-count summary facts.
packages/​renderers/​kit/​src/​categories.ts Builds category palettes and legends across revisions.
docs/​reference/​renderer-kit.md Adds API reference entries.
docs/​guides/​renderer-kit.md Links palette guidance to the category helper.
docs/​guides/​renderer-kit-components.md Documents categories and count-fact usage.

Review effort: Balanced

if (was !== undefined) before.add(was)
if (now !== undefined) {
after.add(now)
ids.push(row.id)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants