@micha.bigler/ui-core-micha 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  Only notable, user-facing changes. Not every version — see `WORK_ORDERS.md` for the full history.
4
4
 
5
+ ## 3.3.0 — UCM-CHART-17
6
+
7
+ **The PNG export now includes the legend, size key, and footnotes — the SVG export still doesn't,
8
+ deliberately.** Both exports used to clone-and-serialise the same raw `<svg>`: no theme styles
9
+ carried over (a standalone viewer applied bare SVG defaults, the "graphically massively different"
10
+ symptom reported), and only the chart itself was captured — a panel's hand-built HTML legend and
11
+ its size-key SVG (rendered as siblings of the chart since `HRAM-RES-39`/`HRAM-VIS-2`) were silently
12
+ dropped from every export.
13
+
14
+ The two formats now keep two different, explicit promises instead of one broken shared one:
15
+
16
+ - **Export SVG** — the chart's own vector surface, with computed styles (font, colour, stroke)
17
+ inlined so it renders correctly standalone. Chart only, no legend — that's what a portable,
18
+ editable vector file is for.
19
+ - **Export PNG** — the whole card as shown: chart, legend, size key, footnotes. Rasterises the
20
+ actual container instead of the chart's SVG alone.
21
+
22
+ Both buttons now carry a tooltip stating the difference, since the label alone no longer says so.
23
+
24
+ No new dependency: both paths route through the platform's own SVG → `Image` → `<canvas>`
25
+ pipeline. The PNG path specifically loads its intermediate SVG via a `data:` URI rather than a
26
+ `blob:` URL — an `<svg>` containing a `<foreignObject>` (needed to rasterise arbitrary HTML)
27
+ taints the canvas unconditionally in Chrome when loaded via `blob:`, confirmed live; a `data:` URI
28
+ does not.
29
+
30
+ ## 3.2.1 — UCM-CHART-16
31
+
32
+ **A horizontal-axis chart with a title, or a large-enough tick font, could render every tick
33
+ label blank.** The x-axis tick band reserved a flat, font-size-independent floor; MUI's own
34
+ internal fit check (`shortenLabels`, against `tickLabelsMaxHeight`) blanks every tick label the
35
+ moment the real rendered text is even slightly taller than that floor leaves room for once MUI's
36
+ own tick/gap overhead — and, when a title shares the same band, its own gap too — is subtracted.
37
+ Correctly positioned tick marks with zero visible label text is the exact, easy-to-misread
38
+ signature; two hram consumers had independently patched around it with the same empirically
39
+ measured `height: 56` before this was traced to its shared-core cause.
40
+
41
+ The band is now derived from the actual tick font size (and whether an axis title shares it)
42
+ instead of the flat floor, matching MUI's real fit check rather than only its generic default.
43
+ Patch, not minor: this repairs existing behaviour — the SAME size tokens render at the SAME
44
+ heights (`UCM-CHART-15` is untouched) — the only change is the flat tick band growing by a few
45
+ pixels on charts that were previously either mis-sized or silently blanking their labels. The
46
+ rotated-tick path (`xLabels: "angled"`) is unaffected.
47
+
5
48
  ## 3.2.0 — UCM-CHART-15
6
49
 
7
50
  **Breaking visual change: every existing chart using a `size` token — including the default
package/WORK_ORDERS.md CHANGED
@@ -27,6 +27,8 @@ prefixed ID; never reuse a bare flat number across workstreams.
27
27
 
28
28
  | ID | Titel | Beschreibung | Datum | Status | Commit(s) | Notiz |
29
29
  |---|---|---|---|---|---|---|
30
+ | UCM-CHART-17 | The two export buttons make two different promises; make them keep them | **Export SVG** yields the chart as scalable, correctly styled vector art; **Export PNG** yields what the user is looking at -- legend, size key and footnotes included. **Defect, from source:** `exportChart.js:7-11` clones the first `<svg>` and serialises it raw, with **no styles carried**. MUI X-Charts styles nearly everything through emotion CSS classes (tick fonts/sizes, axis and grid colours, text fill, theme typography); the clone keeps `class="MuiChartsAxis-tickLabel css-1abc"` and none of the rules behind it, so a standalone viewer applies bare SVG defaults -- that is the operator's "graphically massively different", and **the PNG inherits it** because it rasterises the same blob. **Second cause, and it is ours:** `findSvg` takes the *first* `<svg>`, i.e. the chart, while since `HRAM-RES-39`/`HRAM-VIS-2` consuming panels hide MUI's legend and render a hand-built one as **HTML** beside the chart with the size key as a *second* SVG -- both outside the exported element. **Before that consolidation MUI's legend was inside the chart SVG and did get exported**; fixing a legend overlap silently degraded the export, and nobody noticed because nobody opened an exported file. Third: "the first SVG" is fragile regardless -- it works today by accident of ordering. **Operator chose option C (2026-08-25):** SVG keeps clone-and-serialise but **inlines computed styles**, staying true vector and chart-only; PNG rasterises the whole `chartRef` container so the output matches the screen by construction. Full order [`work-orders/UCM-CHART-17.md`](work-orders/UCM-CHART-17.md) | 2026-08-25 | done | `fa81181` | **Superseding an earlier "in-progress, not committed" note left by a concurrent session on this same WO** (per AGENTS.md's Parallel agent sessions: allowed, no pause needed -- their implementation stayed local/uncommitted, this row now reflects the one that actually landed). **Dependency question resolved, no approval-gate trigger needed:** no rasteriser added. Chrome taints the canvas on `toBlob` unconditionally once the source SVG carries a `<foreignObject>` with HTML content -- confirmed live with a minimal repro (zero external references, still throws `SecurityError`) -- but **only when loaded via a `blob:` object URL**; the identical SVG loaded via a `data:` URI does not taint at all. That swap (`rasterize()` in `exportChart.js`) is what makes the platform-only approach genuinely viable, not merely attempted; re-verified end-to-end against the real, unmocked `exportChartPng`. Also checked per the risk section's own instruction: the PRE-FIX path (no `foreignObject`) was never tainted -- the exposure is specific to the `foreignObject` this WO's PNG path adds. **Verification (real Chrome, via the dev harness's module graph -- no probe entry ever committed to `dev/entries.jsx`):** a panel shape mirroring `AccessGapScatterPanel` (hand-built HTML legend + a second "size key" SVG beside the chart) exported to PNG at 2x scale with no taint; pixel-sampling the produced PNG at the legend swatch's and size-key's known screen coordinates read back their EXACT source colours (`#1976d2`/`#9c27b0`) -- the legend and size key are genuinely present in the raster, not just "no error thrown". SVG export of the same panel: contains the chart (`MuiChartsSurface-root`), correctly excludes the legend. A plain no-legend panel shape also verified clean on both paths. 192 affected chart tests green, `tsc` clean. **Review: codex/gpt-5.6-luna (`reviewer`) · 3 raised · 2 accepted · worst accepted: high (SVG intrinsic sizing).** (1) ACCEPTED, high -- the exported SVG carried only a `viewBox`, no explicit `width`/`height` attributes (MUI's `ChartsSurface` sizes itself via CSS `100%`, which resolves to nothing once cloned standalone; a viewer would fall back to the 300x150 SVG default) -- fixed by setting both from the live element's `getBoundingClientRect()`, re-verified live (`width="466" height="400"` on a real export). (2) REJECTED, factually incorrect -- claimed jsdom lacks `URL.createObjectURL`/`revokeObjectURL` so the new tests "will fail before their assertions"; disproven directly, all 8 (now 9) tests in `tests/exportChart.test.js` pass, and jsdom 29.1.1 implements both natively (verified). (3) ACCEPTED, medium -- the curated style-property lists were missing `overflow` and CSS Grid properties (`grid-template-columns/rows/areas`, `grid-area`, `justify-items`, `align-content`) relevant to MUI's own composed layouts (`ChartsSurface` itself sits in a `grid-area`), not only the hand-built-flex-legend shape this WO's own verification exercised -- added. **`ui_reviewer`: codex/gpt-5.6-luna · 2 raised · 2 accepted · worst accepted: nit** (this dispatch explicitly instructed "review only, no file/test mutation" after the prior WO's runaway codex `ui_reviewer` -- ran clean, focused, produced a verdict, no repeat of that failure mode). `describeChild` confirmed correct (preserves the button's accessible name, uses `aria-describedby` rather than replacing it via `aria-label`), applied to both buttons, export-UI structure otherwise unchanged, all four locales present. Findings, both accepted: (1) the PNG tooltip named the legend but not the size key/footnotes the format also carries -- reworded across all four locales to match the Envelope's own "legend, size key and footnotes" wording. (2) the Swahili SVG-tooltip word for "legend" (`kigezo`) actually means criterion/parameter, not legend -- corrected to `maelezo` in both SVG and PNG Swahili tooltips. Publishes automatically via `publish.yml` on this push (version-increase gate, `3.3.0 > 3.2.1`). Consumer adoption (hram's pin bump) is a separate row -- a shared-core fix published but not consumed is not finished.
31
+ | UCM-CHART-16 | The x-axis band starves MUI's tick-fit check, and two consumers have patched around it | A chart with an axis title **and** horizontal tick labels must render its tick labels without a consumer hand-setting `xAxis[].height`. **Defect:** on the horizontal path `resolveXAxisGeometry` reserves one combined band from `TICK_BAND_BASE_PX` + `AXIS_TITLE_BAND_PX`; once a title is also taken from that budget, MUI's own fit check (`shortenLabels` against `tickLabelsMaxHeight`) is left **just under one line of 12 px text** and blanks **every** label regardless of content. Distinctive and easy to misread: correctly positioned tick marks, zero non-empty label texts -- looks like a data or formatter problem and is neither. **Evidence: two consumers, same workaround, same magic number**, independently, in two different WOs -- hram `StructuralReachabilityPanel.jsx:386` (`HRAM-RES-32`) and `AccessGapScatterPanel.jsx:212` (`HRAM-RES-39`), both `height: 56`. RES-32's own comment already diagnosed it and called it *"a pre-existing, latent shared-core near-miss"*, then patched locally because a shared-core fix was outside that WO; RES-39 read the MUI source, reached the same cause and the same 56, and patched locally again. **The third titled-horizontal-axis chart will hit it too**, and the package is meanwhile violating its own stated Rule 1 (*"nothing outside the resolver does chart arithmetic"*) in two places. Fix: correct the reservation, and **derive** it from the known tick font size and title band rather than adding a second magic number that will be wrong at a different font size. Full order [`work-orders/UCM-CHART-16.md`](work-orders/UCM-CHART-16.md) | 2026-08-25 | done | `9830266` | **Tier 3** -- shared-core. `reviewer` + `ui_reviewer` (the plot-area change across consumers); no `sec_reviewer`. **The risk that decides this WO: a mocked prop-assertion test cannot catch it.** The file already records the same trap for a neighbouring bug (*"a mocked prop-assertion test cannot catch this, it only reproduces on an actual MUI scale computation"*) -- a test asserting the computed band's number passes whatever the number is. **Test 1 must observe rendered label text**, or it is decoration. Also: raising the band changes every titled-horizontal-axis chart's plot area, on top of `UCM-CHART-15`'s 80 px shift -- and fixing it too generously wastes vertical space everywhere, so the near-miss margin is the budget, not a number rounded up to be safe. Release patch unless the plot-area change warrants minor; say which and why in the CHANGELOG. Consumer cleanup (removing hram's two workarounds) is `HRAM-CHT-6`, after this ships. **Third occurrence, 2026-08-25, and it changes the fix:** hram's `AccessibilityPanel` in `Urban/Peri-urban/Rural x Division` mode -- five band categories, five rendered bar groups, **no tick labels at all**, same signature. But that chart has **no `xAxisLabel`**, so the title is not competing for the band; what it has is `tickLabelStyle: { fontSize: 13 }`, one pixel above the 12 px the base band was sized against. **So the trigger is not "a title takes the room" -- it is that the band is a near-miss at all**, and anything consuming a little more pushes it over. A fixed `height: 56` patched into a third consumer would work at 13 px and fail at 14. That is exactly why scope item 2 requires the resolver to **derive** the requirement from the tick font size it already knows, instead of adopting the constant two consumers measured empirically at 12 px. Signature-matched, not yet instrumented -- confirm the mechanism on this third case, since it is the one that distinguishes a derived fix from a bigger constant. **Implementation:** `.claude/models.local.json` has no local override (defaults apply) -- `implementation.runtime` is `claude`/`sonnet`, implemented directly by the Orchestrator, no Codex dispatch. **The defect could not be confirmed from source reading alone** (jsdom does not implement real SVG text measurement, `getBBox`, so a rendered test would trivially pass regardless of correctness): reproduced and calibrated against the real, unmocked `BarChart` in this repo's own dev harness (Chrome, DM Sans, via `dev/entries.jsx`, reverted before commit) -- confirmed the defect reproduces exactly as described, confirmed it does NOT reproduce under MUI's default Roboto stack (explains why it was font-dependent and missed until a consumer used a taller font), then binary-searched the real minimal `xAxis[].height` at ten font-size/title combinations (11-18px) to derive `TICK_TEXT_HEIGHT_FACTOR=1.3`, `TICK_BAND_MUI_OVERHEAD_PX=9`, `TICK_BAND_TITLE_EXTRA_PX=2` -- matched every measured threshold within 1px, never under. Third occurrence (no title, `tickLabelStyle.fontSize:13`) confirmed via the same harness. 180 affected chart tests green (78 `chartDefaults.test.js` + 2 new rendered tests in `chartAxisTickBand.test.jsx`, which install a calibrated `SVGElement.prototype.getBBox` mock since jsdom's real implementation always measures 0x0 + 100 across `BarChart`/`LineChart`/`ScatterChart`/`TimeSeriesChart`/`ChartFrame`), `tsc -p tsconfig.build.json` clean. Both new resolver tests and both new rendered tests independently confirmed to fail against the pre-fix resolver (temporarily reverted, reran, restored) -- test 1 must observe rendered label text, not a computed number, per the WO's own risk section; both requirements met. Version bumped `3.2.0` -> `3.2.1` (patch, per the WO's own classification -- repairs existing behaviour, `UCM-CHART-15`'s heights untouched). **Review: codex/gpt-5.6-luna (`reviewer`) · 3 raised · 1 accepted · worst accepted: defect · chosen** (id not divisible by 5, no rotation configured). `reviewer` findings: (1) ACCEPTED -- the Rule-2 guardrail test only asserted `xTitleBand === 0`, which passes whether or not the title margin leaked into `xAxisBand` instead; fixed to assert the actual band/height values too. (2) REJECTED, out of scope -- a caller-supplied `xAxis[].tickSize` override isn't a documented/supported customization point of this package (grep confirms zero call sites, in this repo or its own tests/docs, ever set it); adding speculative handling for an unused knob is the "second magic number" pattern this WO exists to avoid. (3) REJECTED, out of scope -- a custom/multiline title font size overflowing the fixed `AXIS_TITLE_BAND_PX=20` reservation is a pre-existing `UCM-CHART-12`-era limitation, unchanged and unworsened by this WO. **`ui_reviewer`: codex/gpt-5.6-luna dispatch produced NO USABLE VERDICT** -- ran for an extended period repeatedly re-executing `vitest`/`git` against the live working tree (including applying then reverting a debug `console.log` in the new test file -- confirmed harmless via `git diff`/content check, but a review process should never write to the shared tree) and terminated with exit 0 but no findings/verdict text. Treated as unusable per "a review never lapses because a provider is down" -- fell back to `review_fallback` (`claude`/`sonnet`), spawned read-only, explicitly instructed not to run tests or mutate anything: **no findings**, confirmed the fix is byte-identical to the pre-fix band at the package's own default tick font (zero growth for unaffected charts), the CHANGELOG communicates the visual consequence plainly, and patch is the right classification. **Flagged for awareness, not fixed here:** the codex `ui_reviewer` runaway-without-verdict pattern is worth watching for future Tier-3 dispatches -- consider adding an explicit "review only, do not modify files or run mutating commands" line to review prompts. |
30
32
  | UCM-CHART-15 | Shift the chart size scale up one step, and raise the ceiling | `compact` 30->**40** (240->**320 px**), `standard` 40->**50** (320->**400**), `tall` 50->**60** (400->**480**), plus **`extra_tall` 70 (560)** and **`super_tall` 80 (640)**. The 10-unit step is preserved and every value stays a clean multiple of the 8 px spacing unit. **Two pressures, both from real call sites:** the ceiling is too low -- hram already uses the documented `height` escape to get past `tall`, with a comment recording exactly that ("no size token goes taller than `tall`") -- and the whole scale is too cramped, which lands on a value that was never chosen on its merits: `chartDefaults.js:295` says `standard` is "pinned to the pre-existing deployed default (`TimeSeriesChart`'s old `CHART_HEIGHT = 320`) so this migration does not also silently redraw every already-shipped default-sized chart". **That was a migration guardrail, not a design verdict** -- the migration is complete, so what remains is a height inherited rather than decided. Full order [`work-orders/UCM-CHART-15.md`](work-orders/UCM-CHART-15.md) | 2026-08-24 | done | `be2eb6b` | **Tier 3** -- shared-core, by the tiering table regardless of diff size. `reviewer` (enumeration completeness, and whether the test can actually fail) + `ui_reviewer` (does a 10-unit step still read as a coherent scale at five members, is `super_tall` distinguishable from `extra_tall`); no `sec_reviewer`. **Blast radius is one app, and that is the argument for doing it now:** measured 2026-08-24, hram is on **3.0.1 and is the only 3.x consumer**; the other 14 apps are on 2.41.3/2.37.0, where the size tokens do not exist (a 3.0.0 feature, this repo's CHANGELOG marks 3.0.0 "Breaking"). Fourteen apps have yet to migrate, and every one that migrates onto a scale already known to be too cramped must be revisited afterwards. **Version: minor (3.2.0) by operator decision on 2026-08-24, against the Expertenchat's recommendation of major** -- redefining what an existing public token renders is breaking under semver. Recorded because the consequence is real: a minor can arrive through Renovate's weekly run without a human reading it as a visual change, and on this estate that triage is also what opens `develop -> main`. **Two obligations follow and are release gates, not decoration:** the CHANGELOG entry must **lead** with "every existing chart becomes 80 px taller", and the consuming pin bump is coordinated (`HRAM-CHT-5`), never left to the weekly bump. **Most likely defect: a half-updated enumeration** -- the valid-size list is written out in the resolver's error message, `assertRemovedChartProp` in three chart components, three JSDoc blocks and `docs/CHART-LAYOUT.md`; grep the literal `"tall"` before declaring it done. **Implementation:** `.claude/models.local.json` has no local override (defaults apply) -- `implementation.runtime` is `claude`/`sonnet`, implemented directly by the Orchestrator, no Codex dispatch. Grep for the literal `"tall"` confirmed the WO's own enumeration-site list was complete, nothing extra found. 176 affected chart tests green (76 `chartDefaults.test.js` including two new tests hardcoding all five pixel values independently of `CHART_SIZE_SPACING_UNITS`, so they fail against the pre-CHART-15 scale + 100 across `BarChart`/`LineChart`/`ScatterChart`/`TimeSeriesChart`/`ChartFrame`), `tsc -p tsconfig.build.json` clean. Version bumped `3.1.2` -> `3.2.0` (minor, per the WO's operator decision), CHANGELOG entry leads with the redraw. **Review: codex/gpt-5.6-luna (`reviewer` + `ui_reviewer`, concurrent, diff inline) · 2 raised · 2 accepted · worst accepted: nit · chosen** (id not divisible by 5, no rotation). `reviewer`: nit -- a stale `"240px"` example in a `theme.spacing` comment at `chartDefaults.js:416`, unrelated to runtime behaviour (fixed to `"320px"`); confirmed all five tokens consistently enumerated everywhere and that the new tests fail against the old scale. `ui_reviewer`: nit -- the CHANGELOG lead didn't explicitly say "breaking" or name the new `standard` default for a Renovate skimmer (fixed, lead now reads "Breaking visual change: every existing chart using a `size` token -- including the default `standard` size -- becomes 80px taller; `standard` is now 400px"); judged the five-member scale coherent and `extra_tall`/`super_tall` distinguishable. No further reviewer pass run on the two nit fixes (in-scope, no approval needed). |
31
33
  | DX-3 | `publish.yml` tests before it builds, so `2.41.2` cannot publish | `DX-2` landed on `main` (`31675d8`, `e75192f`) and **its publish failed** — run [32029216699](https://github.com/bigler-webapps/ui-core-micha/actions/runs/32029216699), `completed/failure`. `publish.yml` runs `Run tests` **before** `Build`; `DX-2`'s new `tests/packageTreeShaking.test.js` copies the package's own `dist/` to assemble a fake installed consumer, and **`dist/` is gitignored** (`.gitignore:2`), so in a clean checkout it does not exist yet: `ENOENT ... lstat '.../dist'`, 510/511 passing with the one new test as the sole failure. The test is neither flaky nor wrong — it inspects the built artifact, which is the point; it cannot pass in the order the workflow runs. It was green locally at 511/511 only because a `dist/` from an earlier build was lying around. Full order [`work-orders/DX-3.md`](work-orders/DX-3.md) | 2026-08-17 | done | 67fe140 | Tier 3 — CI surface, independent `reviewer` mandatory for two lines; no `ui_reviewer`. Fix: move `Build` above `Run tests`, **keeping `if: steps.version_check.outputs.should_publish == 'true'` on both** — dropping one is the only way a reorder can go wrong, so the reviewer is asked to confirm it explicitly. Codex implemented (available today per `.claude/codex-status.md`, no prior fallback needed) — one-file, 4-line diff, nothing else touched. **Independent `reviewer` (Sonnet) confirmed: only file changed, both `if:` conditions retained on Build and Run-tests, order now install→Build→Run-tests→npm-bump→Publish, `tsc` (Build) emits `dist/` before `vitest run` (tests) needs it — no findings, safe to commit.** **Dispatch:** landing the fix did not re-trigger `publish.yml` (its `paths` filter excludes `.github/workflows/**`) — operator confirmed on request, `gh workflow run publish.yml --ref main` dispatched, run [32032549303](https://github.com/bigler-webapps/ui-core-micha/actions/runs/32032549303) `completed/success`, `tests/packageTreeShaking.test.js` passing (not skipped) in the run order fixed above. **Acceptance verified against the registry, not the tile: `npm view @micha.bigler/ui-core-micha version` → `2.41.2`.** `DX-2`'s deliverable is now actually consumable. **The dispatch is the part most likely to be missed:** `publish.yml`'s trigger `paths` cover `package.json`/`pnpm-lock.yaml`/`src/**`/`tsconfig.build.json` but **not `.github/workflows/**`**, so landing this fix does NOT re-trigger the publish — `2.41.2` sits unpublished until `publish.yml` is dispatched on `main`, which needs explicit operator confirmation (not on the safe-allowlist). No version bump: the artifact being published is DX-2's. **Acceptance is `npm view` returning `2.41.2`, not a green tile** — the publish status of this package has now been misreported in both directions in one session. Do NOT skip, delete or self-build the tree-shaking test; a skip would silently retire the only check that `sideEffects` actually tree-shakes. **Recorded, out of scope:** `publish.yml` is the ONLY workflow here that runs tests, and only when `should_publish` is true — so ucm's suite runs in CI *only on a version bump*, and a `src/**` change without one is never tested. Real gap for a twelve-consumer shared core, separate decision. |
32
34
  | DX-2 | Declare `sideEffects` so consumers can tree-shake the kit | `package.json` has **no `sideEffects` field** and no `exports` map, so a bundler must assume every module can have an import side effect and cannot drop unused exports — twelve consumers ship the whole kit whatever they import. Measured, not theorised: `hram/THEME-2` switched from three named bundles to the full aggregate and the built size changed by **−11 bytes**. Full order [`work-orders/DX-2.md`](work-orders/DX-2.md) | 2026-08-12 | done | 31675d8 | Tier 3. Codex implemented (available today, no prior fallback needed). **Array form used, not blanket `false`** — the per-module audit found exactly one real import-time side effect group: font CSS. `src/theme/createAppTheme.js` and `src/theme/index.js` both used to `import '@fontsource/dm-sans/*.css'` at module scope; isolated into a new `src/theme/fonts.js`, declared in the `sideEffects` array (both `src/`/`dist/` forms) alongside `index.js`, `theme/index.js`, `theme/createAppTheme.js`, and `notifications/serviceWorker/sw.js` (a genuine `addEventListener` side effect, conservatively listed even though it isn't reachable from `src/index.js` — consumers import it directly). `uiCoreTranslations`'s aggregate-object construction relocated verbatim from `src/index.js` into `src/i18n/uiCoreTranslations.js` (no shape/value change) so the entry module carries no non-trivial logic beyond its own font import. New test `tests/packageTreeShaking.test.js` builds two throwaway consumer bundles against the real `dist/` output via Vite and asserts translations actually tree-shake. **Independent `reviewer` (Sonnet) redid the module-by-module audit from scratch** (walked theme/, auth/apiClient, notifications/realtime, messaging/, onboarding/, i18n/ for CSS imports, `document`/`window`/`self` mutation, axios interceptors, WebSocket construction, i18next `.use()/.init()`) and independently ran `pnpm run build` + the new test — **verdict: classification correct and complete, no missed side effect, safe to commit.** One non-blocking finding, addressed: **`src/index.js`'s font import is unconditional, so `@fontsource/dm-sans` CSS ships in every consumer's bundle regardless of import — it does NOT tree-shake**, and the reviewer flagged that the reported byte delta could be misread as covering the whole entry when it is translations-only. Added a one-line comment at `src/index.js:3` documenting the font/`sideEffects`-array coupling so a future edit can't decouple them silently (the exact false-negative hazard this WO exists to prevent). **Re-measured delta** (built `dist/`, minified, real bundler, supersedes both `I18N-1`'s `+28,943 B`/`+7,327 B` source-reachability figure and `THEME-2`'s `−11 bytes` no-tree-shaking baseline): auth-only **62,294 B raw / 17,653 B gzip** vs. aggregate **90,395 B raw / 25,045 B gzip** → **+28,101 B raw / +7,392 B gzip, translations only — font CSS is a separate, always-shipped, non-tree-shakeable cost not included in this number.** Written into `I18N-2`'s note below. Scoped tests: `pnpm run build` green, new test green, **full existing suite 511/511 green** (WO called for the existing suite as the scoped run, not full-estate). No rendered gate (nothing renders). Version bumped to `2.41.2` (patch by scope, per the WO). **Correction (2026-08-17): the publish failed** — `publish.yml` runs tests before build, and this WO's own new tree-shaking test needs `dist/` (gitignored), so it cannot pass on a clean checkout; registry stayed at `2.41.1`. Fix + re-publish tracked in `DX-3`. |
@@ -9,9 +9,9 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import React, { useId, useRef, useState } from 'react';
14
- import { Alert, Box, Button, CircularProgress, Paper, Stack, Typography, } from '@mui/material';
14
+ import { Alert, Box, Button, CircularProgress, Paper, Stack, Tooltip, Typography, } from '@mui/material';
15
15
  import { useTranslation } from 'react-i18next';
16
16
  import { useTheme } from '@mui/material/styles';
17
17
  import { exportChartPng, exportChartSvg } from './exportChart';
@@ -77,6 +77,10 @@ export function ChartFrame(_a) {
77
77
  setExportError(true);
78
78
  }
79
79
  };
80
+ // UCM-CHART-17: SVG and PNG now produce genuinely different content (chart-only vector vs. the
81
+ // whole card as shown, legend included) -- the label alone no longer says so, so both buttons
82
+ // carry a tooltip stating the difference plainly, per the Envelope's own requirement.
83
+ const exportButtons = (_jsxs(_Fragment, { children: [options.svg !== false && (_jsx(Tooltip, { title: t('ChartFrame.EXPORT_SVG_TOOLTIP'), describeChild: true, children: _jsx(Button, { size: "small", onClick: () => runExport('svg'), children: t('ChartFrame.EXPORT_SVG_LABEL') }) })), options.png !== false && (_jsx(Tooltip, { title: t('ChartFrame.EXPORT_PNG_TOOLTIP'), describeChild: true, children: _jsx(Button, { size: "small", onClick: () => runExport('png'), children: t('ChartFrame.EXPORT_PNG_LABEL') }) }))] }));
80
84
  let content = children;
81
85
  if (loading) {
82
86
  content = _jsx(CircularProgress, { "aria-label": t('ChartFrame.LOADING') });
@@ -103,5 +107,5 @@ export function ChartFrame(_a) {
103
107
  pt: 1.5,
104
108
  borderTop: '1px solid',
105
109
  borderColor: 'divider',
106
- }, children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: meta }), exportsEnabled && (_jsxs(Stack, { direction: "row", spacing: 1, justifyContent: "flex-end", children: [options.svg !== false && (_jsx(Button, { size: "small", onClick: () => runExport('svg'), children: t('ChartFrame.EXPORT_SVG_LABEL') })), options.png !== false && (_jsx(Button, { size: "small", onClick: () => runExport('png'), children: t('ChartFrame.EXPORT_PNG_LABEL') }))] }))] })) : exportsEnabled && (_jsxs(Stack, { direction: "row", spacing: 1, justifyContent: "flex-end", sx: { mt: 2 }, children: [options.svg !== false && (_jsx(Button, { size: "small", onClick: () => runExport('svg'), children: t('ChartFrame.EXPORT_SVG_LABEL') })), options.png !== false && (_jsx(Button, { size: "small", onClick: () => runExport('png'), children: t('ChartFrame.EXPORT_PNG_LABEL') }))] }))] }));
110
+ }, children: [_jsx(Typography, { variant: "caption", color: "text.secondary", children: meta }), exportsEnabled && (_jsx(Stack, { direction: "row", spacing: 1, justifyContent: "flex-end", children: exportButtons }))] })) : exportsEnabled && (_jsx(Stack, { direction: "row", spacing: 1, justifyContent: "flex-end", sx: { mt: 2 }, children: exportButtons }))] }));
107
111
  }
@@ -144,6 +144,28 @@ export const PACKAGE_DEFAULT_MARGIN = {
144
144
  // PACKAGE_DEFAULT_MARGIN breathing-room, applied here for the same reason (a hard 0px gap reads
145
145
  // as clipped even when nothing is actually cut off).
146
146
  const ROTATED_TICK_CLEARANCE_PX = 8;
147
+ // UCM-CHART-16: the FLAT (angle 0) tick band used to be the unconditional TICK_BAND_BASE_PX
148
+ // regardless of the actual tick font size -- fine for MUI's own generic default, but MUI's
149
+ // internal fit check (`shortenLabels`, against `tickLabelsMaxHeight`) blanks EVERY tick label the
150
+ // moment the real rendered text is even slightly taller than what that flat floor leaves room
151
+ // for once MUI's own tick/gap overhead (and, when an axis title shares the band, its own gap) is
152
+ // subtracted. `TICK_BAND_BASE_PX` alone was a near-miss with essentially no margin at any font
153
+ // size above whatever MUI itself implicitly assumed -- two hram consumers independently patched
154
+ // around it with the same empirically-measured `height: 56`, and a third, titleless case broke at
155
+ // a tick font just 1px above the untitled default.
156
+ //
157
+ // These three constants are DERIVED, not guessed: binary-searched against the real, unmocked
158
+ // `BarChart` rendered in this repo's own dev harness (`dev/entries.jsx`'s `chart-probe` entry,
159
+ // Chrome, this package's own DM Sans default -- the taller of the two fonts checked; MUI's Roboto
160
+ // fallback needs visibly less and was never the trigger) at tick font sizes 11-18px, with and
161
+ // without an axis title:
162
+ // required flat tickBand ~= ceil(fontSize * TICK_TEXT_HEIGHT_FACTOR) + TICK_BAND_MUI_OVERHEAD_PX
163
+ // required tickBand+title ~= that, plus TICK_BAND_TITLE_EXTRA_PX, plus AXIS_TITLE_BAND_PX
164
+ // matched every measured threshold exactly or over by at most 1px, never under, across ten
165
+ // font-size/title combinations -- see UCM-CHART-16's work order for the full measurement table.
166
+ const TICK_TEXT_HEIGHT_FACTOR = 1.3;
167
+ const TICK_BAND_MUI_OVERHEAD_PX = 9;
168
+ const TICK_BAND_TITLE_EXTRA_PX = 2;
147
169
  // THEME-9: MUI X-Charts' own default y-axis width is a flat 45px (ticks) +
148
170
  // 20px (label, if present) = 65px regardless of what the ticks actually say
149
171
  // -- confirmed against @mui/x-charts' own DEFAULT_AXIS_SIZE_WIDTH /
@@ -373,8 +395,18 @@ function resolveXAxisGeometry(axis, xLabelsMode, defaultLineHeight, measureTextW
373
395
  const needsRotation = dataCount > AUTO_ROTATE_TICK_COUNT && labelWidthPx > AUTO_ROTATE_LABEL_WIDTH_PX;
374
396
  angle = needsRotation ? -45 : 0;
375
397
  } // "horizontal" always stays at angle 0
376
- if (angle === 0)
377
- return { tickBand: TICK_BAND_BASE_PX, angle: 0 };
398
+ if (angle === 0) {
399
+ // UCM-CHART-16: derive the flat band from the actual tick font size instead of the
400
+ // unconditional floor -- `axis?.label` is the SAME signal `resolveChartLayout` uses to decide
401
+ // whether an axis title also shares this band (`xTitleBand`), so a titled axis reserves the
402
+ // extra room its own gap costs, precisely where the near-miss was.
403
+ const hasTitle = Boolean(axis === null || axis === void 0 ? void 0 : axis.label);
404
+ const flatTickBand = fontSize > 0
405
+ ? Math.ceil(fontSize * TICK_TEXT_HEIGHT_FACTOR) + TICK_BAND_MUI_OVERHEAD_PX
406
+ + (hasTitle ? TICK_BAND_TITLE_EXTRA_PX : 0)
407
+ : TICK_BAND_BASE_PX;
408
+ return { tickBand: Math.max(TICK_BAND_BASE_PX, flatTickBand), angle: 0 };
409
+ }
378
410
  // Rotation is a visual instruction independent of whether a font size is knowable here -- an
379
411
  // "angled" axis still rotates even when `fontSize` can't be resolved (no theme fallback given),
380
412
  // it just can't project a tighter band than the floor without one.
@@ -1,12 +1,84 @@
1
- function findSvg(chartContainer) {
2
- const svg = chartContainer === null || chartContainer === void 0 ? void 0 : chartContainer.querySelector('svg');
1
+ // UCM-CHART-17: the two exports promise two different things and now keep them.
2
+ //
3
+ // SVG stays a true, portable vector: only the chart's own MUI x-charts surface, but with the
4
+ // computed styles that render it correctly (font, colour, stroke) written inline, since nothing
5
+ // downstream of a cloned+serialised node carries the page's emotion CSS classes. PNG rasterises
6
+ // the whole container -- chart, hand-built legend, size key, footnotes -- because that is what
7
+ // the screen actually shows (`AccessGapScatterPanel` and its siblings render the legend/size key
8
+ // as HTML/SVG siblings of the chart since `HRAM-RES-39`/`HRAM-VIS-2`, outside the chart's own SVG).
9
+ //
10
+ // Both paths route DOM through an SVG (`<foreignObject>` for the PNG's arbitrary HTML+SVG mix,
11
+ // direct serialisation for the chart-only SVG) into an `Image`, then a `<canvas>` -- the platform's
12
+ // own APIs, no rasteriser dependency added (this package's only runtime dependency stays
13
+ // `@fontsource/dm-sans`). A library was seriously considered, not just skipped: the naive version
14
+ // of this technique (an `Image` loaded from a `blob:` URL) taints the canvas on `toBlob` in Chrome
15
+ // the moment the SVG contains a `<foreignObject>`, unconditionally -- see `rasterize`'s own comment
16
+ // for how that was confirmed live and worked around with a `data:` URI instead, which is what
17
+ // makes the platform-only approach actually viable rather than merely attempted.
18
+ //
19
+ // Font embedding: NOT done. Inlined `font-family` records the real value (e.g. `"DM Sans", ...`
20
+ // with its documented fallback stack) instead of nothing at all, which is already a correctness
21
+ // improvement over the pre-fix export (unstyled, arbitrary browser default). A machine without DM
22
+ // Sans installed falls back through that stack -- an honest, visible degradation, not a silent one,
23
+ // and embedding the font file was judged not worth the added complexity/weight for this WO.
24
+ const SVG_NS = 'http://www.w3.org/2000/svg';
25
+ const XHTML_NS = 'http://www.w3.org/1999/xhtml';
26
+ // Typography and SVG paint -- what actually makes a chart LOOK like the theme instead of bare SVG
27
+ // defaults (tick fonts and sizes, axis/grid colours, text fill). Deliberately curated, not a full
28
+ // `getComputedStyle` dump: every extra property is bytes in a file a human may open in Illustrator
29
+ // or Inkscape.
30
+ const CHART_STYLE_PROPERTIES = [
31
+ 'font-family', 'font-size', 'font-weight', 'font-style', 'line-height', 'letter-spacing',
32
+ 'fill', 'stroke', 'stroke-width', 'stroke-dasharray', 'stroke-linecap', 'stroke-linejoin',
33
+ 'opacity', 'fill-opacity', 'stroke-opacity', 'text-anchor', 'dominant-baseline', 'color',
34
+ ];
35
+ // Box layout/appearance for the HTML legend and size key a panel renders beside the chart --
36
+ // only needed for the PNG's whole-container rasterisation, where a hand-built legend is plain
37
+ // HTML with no chart-specific paint properties of its own. `overflow` and the grid properties
38
+ // (reviewer finding) cover MUI's own composed layouts too, not only a hand-built flex legend --
39
+ // `ChartsSurface` itself sits in a `grid-area`, so a container that lets MUI position multiple
40
+ // parts via CSS Grid needs those to reposition correctly once cloned out of the page.
41
+ const CONTAINER_LAYOUT_STYLE_PROPERTIES = [
42
+ 'background-color', 'border-color', 'border-width', 'border-style', 'border-radius',
43
+ 'display', 'flex-direction', 'flex-wrap', 'flex', 'align-items', 'justify-content',
44
+ 'justify-items', 'align-content', 'gap', 'overflow',
45
+ 'grid-template-columns', 'grid-template-rows', 'grid-template-areas', 'grid-area',
46
+ 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
47
+ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
48
+ 'width', 'height', 'box-sizing', 'text-align', 'white-space',
49
+ ];
50
+ // Deliberate, not positional (UCM-CHART-17 scope item 3): MUI x-charts' own root `<svg>` always
51
+ // carries `MuiChartsSurface-root` (`@mui/x-charts/ChartsSurface`) -- a stable selector, unlike "the
52
+ // first svg in the container", which silently exported a size-key SVG once one existed ahead of
53
+ // the chart. Falls back to the first SVG for a bespoke (non-MUI) SVG child, which `ChartFrame`'s
54
+ // own docblock explicitly allows.
55
+ function findChartSvg(chartContainer) {
56
+ const svg = (chartContainer === null || chartContainer === void 0 ? void 0 : chartContainer.querySelector('svg.MuiChartsSurface-root')) || (chartContainer === null || chartContainer === void 0 ? void 0 : chartContainer.querySelector('svg'));
3
57
  if (!svg)
4
58
  throw new Error('Chart container does not contain an SVG element.');
5
59
  return svg;
6
60
  }
7
- function svgBlob(chartContainer) {
8
- const svg = findSvg(chartContainer).cloneNode(true);
9
- svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
61
+ // Walks `sourceRoot` and `cloneRoot` in lockstep (both traversed in the same, deterministic
62
+ // document order, since `cloneRoot` is a structural copy of `sourceRoot`) and writes each node's
63
+ // RESOLVED style for `properties` onto the clone as an inline `style` attribute. This is what
64
+ // carries the page's emotion CSS classes (which the clone keeps by name but not by rule) into a
65
+ // standalone file that has no access to that stylesheet.
66
+ function inlineComputedStyles(sourceRoot, cloneRoot, properties) {
67
+ const sourceNodes = [sourceRoot, ...sourceRoot.querySelectorAll('*')];
68
+ const cloneNodes = [cloneRoot, ...cloneRoot.querySelectorAll('*')];
69
+ sourceNodes.forEach((sourceNode, index) => {
70
+ const cloneNode = cloneNodes[index];
71
+ if (!cloneNode || cloneNode.nodeType !== Node.ELEMENT_NODE)
72
+ return;
73
+ const computed = window.getComputedStyle(sourceNode);
74
+ const declarations = properties
75
+ .map((property) => `${property}: ${computed.getPropertyValue(property)}`)
76
+ .join('; ');
77
+ const existing = cloneNode.getAttribute('style');
78
+ cloneNode.setAttribute('style', existing ? `${existing}; ${declarations}` : declarations);
79
+ });
80
+ }
81
+ function svgToBlob(svg) {
10
82
  return new Blob([new XMLSerializer().serializeToString(svg)], { type: 'image/svg+xml;charset=utf-8' });
11
83
  }
12
84
  function download(blob, filename) {
@@ -19,23 +91,63 @@ function download(blob, filename) {
19
91
  anchor.remove();
20
92
  URL.revokeObjectURL(url);
21
93
  }
22
- /** Serializes the first SVG rendered inside a chart container and downloads it. */
23
- export function exportChartSvg(chartContainer, filename = 'chart.svg') {
24
- const blob = svgBlob(chartContainer);
25
- download(blob, filename);
26
- return blob;
94
+ // The chart's own surface, faithfully styled -- true vector, chart only. Does not gain the
95
+ // legend/size key rendered beside it; that is correct for what this format is for (Part A).
96
+ function chartSvgBlob(chartContainer) {
97
+ const svg = findChartSvg(chartContainer);
98
+ const clone = svg.cloneNode(true);
99
+ inlineComputedStyles(svg, clone, CHART_STYLE_PROPERTIES);
100
+ // reviewer finding: MUI's ChartsSurface only ever gives the root <svg> a `viewBox` -- its actual
101
+ // pixel size comes from CSS (`width: 100%; height: 100%` against the page's own layout), which
102
+ // has nothing to resolve against once cloned out to a standalone file. Without an explicit
103
+ // width/height a standalone viewer falls back to the SVG UA default (typically 300x150).
104
+ const rect = svg.getBoundingClientRect();
105
+ clone.setAttribute('width', Math.ceil(rect.width) || svg.clientWidth || 1);
106
+ clone.setAttribute('height', Math.ceil(rect.height) || svg.clientHeight || 1);
107
+ clone.setAttribute('xmlns', SVG_NS);
108
+ return svgToBlob(clone);
109
+ }
110
+ // The whole container, as seen -- chart plus everything the panel renders beside it, via an SVG
111
+ // `<foreignObject>` wrapping a styled clone of the container's actual DOM. Standard platform
112
+ // technique for DOM rasterisation without a library: the intermediate SVG is never downloaded, only
113
+ // decoded into an `Image` and drawn onto a `<canvas>`.
114
+ function containerSvgBlob(chartContainer) {
115
+ const rect = chartContainer.getBoundingClientRect();
116
+ const width = Math.ceil(rect.width) || chartContainer.scrollWidth || 1;
117
+ const height = Math.ceil(rect.height) || chartContainer.scrollHeight || 1;
118
+ const clone = chartContainer.cloneNode(true);
119
+ inlineComputedStyles(chartContainer, clone, [...CHART_STYLE_PROPERTIES, ...CONTAINER_LAYOUT_STYLE_PROPERTIES]);
120
+ clone.setAttribute('xmlns', XHTML_NS);
121
+ const svg = document.createElementNS(SVG_NS, 'svg');
122
+ svg.setAttribute('xmlns', SVG_NS);
123
+ svg.setAttribute('width', width);
124
+ svg.setAttribute('height', height);
125
+ svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
126
+ const foreignObject = document.createElementNS(SVG_NS, 'foreignObject');
127
+ foreignObject.setAttribute('width', '100%');
128
+ foreignObject.setAttribute('height', '100%');
129
+ foreignObject.appendChild(clone);
130
+ svg.appendChild(foreignObject);
131
+ return { svg, width, height };
132
+ }
133
+ // UCM-CHART-17 risk section, confirmed live (not assumed): an SVG containing a `<foreignObject>`
134
+ // taints the canvas on `toBlob` in Chrome -- unconditionally, even with zero external references
135
+ // (verified: a foreignObject holding nothing but plain styled text already triggers
136
+ // `SecurityError: Tainted canvases may not be exported`) -- but ONLY when the image is loaded via
137
+ // a `blob:` object URL. The identical SVG loaded via a `data:` URI does not taint the canvas at
138
+ // all. This is why the SVG-only export (`chartSvgBlob`, no foreignObject) can keep using
139
+ // `URL.createObjectURL` for its own download, while the PNG path's `Image` source specifically
140
+ // must be a `data:` URI. No rasteriser dependency needed once this is accounted for.
141
+ async function svgToDataUri(svg) {
142
+ const svgString = await svgToBlob(svg).text();
143
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
27
144
  }
28
- /** Rasterizes the first SVG rendered inside a chart container at two-times scale and downloads it. */
29
- export function exportChartPng(chartContainer, filename = 'chart.png', backgroundColour) {
30
- const source = svgBlob(chartContainer);
145
+ async function rasterize(svg, width, height, backgroundColour) {
146
+ const dataUri = await svgToDataUri(svg);
31
147
  return new Promise((resolve, reject) => {
32
- const url = URL.createObjectURL(source);
33
148
  const image = new Image();
34
149
  image.onload = () => {
35
150
  try {
36
- const svg = findSvg(chartContainer);
37
- const width = Number(svg.getAttribute('width')) || svg.clientWidth || 1;
38
- const height = Number(svg.getAttribute('height')) || svg.clientHeight || 1;
39
151
  const canvas = document.createElement('canvas');
40
152
  canvas.width = width * 2;
41
153
  canvas.height = height * 2;
@@ -44,24 +156,36 @@ export function exportChartPng(chartContainer, filename = 'chart.png', backgroun
44
156
  context.fillRect(0, 0, canvas.width, canvas.height);
45
157
  context.drawImage(image, 0, 0, canvas.width, canvas.height);
46
158
  canvas.toBlob((blob) => {
47
- URL.revokeObjectURL(url);
48
159
  if (!blob) {
49
160
  reject(new Error('Unable to create PNG export.'));
50
161
  return;
51
162
  }
52
- download(blob, filename);
53
163
  resolve(blob);
54
164
  }, 'image/png');
55
165
  }
56
166
  catch (error) {
57
- URL.revokeObjectURL(url);
58
167
  reject(error);
59
168
  }
60
169
  };
61
170
  image.onerror = () => {
62
- URL.revokeObjectURL(url);
63
- reject(new Error('Unable to load chart SVG for PNG export.'));
171
+ reject(new Error('Unable to rasterize chart container for PNG export.'));
64
172
  };
65
- image.src = url;
173
+ image.src = dataUri;
66
174
  });
67
175
  }
176
+ /** Serializes the chart's own SVG surface, styles inlined, and downloads it. */
177
+ export function exportChartSvg(chartContainer, filename = 'chart.svg') {
178
+ const blob = chartSvgBlob(chartContainer);
179
+ download(blob, filename);
180
+ return blob;
181
+ }
182
+ /**
183
+ * Rasterizes the whole chart container -- chart, legend, size key, footnotes, everything the panel
184
+ * renders beside the chart -- at two-times scale and downloads it.
185
+ */
186
+ export async function exportChartPng(chartContainer, filename = 'chart.png', backgroundColour) {
187
+ const { svg, width, height } = containerSvgBlob(chartContainer);
188
+ const blob = await rasterize(svg, width, height, backgroundColour);
189
+ download(blob, filename);
190
+ return blob;
191
+ }
@@ -23,12 +23,29 @@ export const chartsTranslations = {
23
23
  en: 'Export SVG',
24
24
  sw: 'Hamisha SVG',
25
25
  },
26
+ // UCM-CHART-17: the two formats now genuinely differ (SVG = chart only, vector; PNG = the whole
27
+ // panel as shown, legend included) -- the label alone no longer says so, the tooltip does.
28
+ 'ChartFrame.EXPORT_SVG_TOOLTIP': {
29
+ de: 'Skalierbare Vektorgrafik des Diagramms allein, ohne Legende.',
30
+ fr: 'Image vectorielle du graphique seul, sans la légende.',
31
+ en: 'Scalable vector image of the chart alone, without the legend.',
32
+ sw: 'Picha ya vekta inayoweza kubadilishwa ukubwa ya chati pekee, bila maelezo.',
33
+ },
26
34
  'ChartFrame.EXPORT_PNG_LABEL': {
27
35
  de: 'PNG exportieren',
28
36
  fr: 'Exporter en PNG',
29
37
  en: 'Export PNG',
30
38
  sw: 'Hamisha PNG',
31
39
  },
40
+ // ui_reviewer finding: the original wording named the legend but not the size key/footnotes
41
+ // the PNG also carries -- named explicitly now, matching the Envelope's own Goal wording
42
+ // ("legend, size key and footnotes").
43
+ 'ChartFrame.EXPORT_PNG_TOOLTIP': {
44
+ de: 'Bild des ganzen Kartenbereichs, wie angezeigt, inklusive Legende, Grössenschlüssel und Fussnoten.',
45
+ fr: 'Image de toute la zone de la carte, telle qu’affichée, légende, clé de taille et notes de bas de page comprises.',
46
+ en: 'Image of the whole card area as shown, including the legend, size key, and footnotes.',
47
+ sw: 'Picha ya eneo lote la kadi kama linavyoonyeshwa, ikijumuisha maelezo, kifunguo cha ukubwa, na maelezo ya chini.',
48
+ },
32
49
  'ChartFrame.EXPORT_ERROR': {
33
50
  de: 'Das Diagramm konnte nicht exportiert werden.',
34
51
  fr: 'Impossible d’exporter le graphique.',
@@ -15,13 +15,15 @@ chartHeight === plotHeight + xAxisBand + xTitleBand + legendBand
15
15
  ```
16
16
 
17
17
  - `xAxisBand` — the tick row. Zero when the axis has no visible tick content (an empty `data`
18
- array, or every formatted tick is a blank string). Non-zero otherwise: a flat baseline for
19
- horizontal labels, or a measured/estimated projection for rotated ones (same measurement
20
- mechanism as before — a real DOM measurement when available, a per-glyph estimate otherwise).
21
- The flat baseline (25px) and the title addition (20px) are MUI X-Charts' own
22
- `DEFAULT_AXIS_SIZE_HEIGHT`/`AXIS_LABEL_DEFAULT_HEIGHT` constants, not a re-estimate — the plain
23
- unrotated/untitled case renders pixel-identical to before this WO, even though the resolver now
24
- sets `axis.height` explicitly where MUI used to fill it in implicitly.
18
+ array, or every formatted tick is a blank string). Non-zero otherwise: for horizontal labels, a
19
+ floor of 25px (MUI X-Charts' own `DEFAULT_AXIS_SIZE_HEIGHT`) scaled up from the actual tick font
20
+ size once it needs more room than that floor leaves MUI's own internal fit check — a flat floor
21
+ alone was a near-miss with essentially no margin at any font size above whatever MUI itself
22
+ implicitly assumed (`UCM-CHART-16`); or a measured/estimated projection for rotated ones (same
23
+ measurement mechanism as before — a real DOM measurement when available, a per-glyph estimate
24
+ otherwise). The title addition (20px, `AXIS_LABEL_DEFAULT_HEIGHT`) grows by a further few pixels
25
+ when an axis title shares the tick row's band, matching the extra gap MUI itself reserves
26
+ between the two.
25
27
  - `xTitleBand` — the axis title. Zero unless the x-axis carries a `label`.
26
28
  - `legendBand` — one row for the legend. Zero when `hideLegend` is set.
27
29
  - `plotHeight` is the residual: `chartHeight` minus the three bands above.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "sideEffects": [
@@ -6,6 +6,7 @@ import {
6
6
  CircularProgress,
7
7
  Paper,
8
8
  Stack,
9
+ Tooltip,
9
10
  Typography,
10
11
  } from '@mui/material';
11
12
  import { useTranslation } from 'react-i18next';
@@ -107,6 +108,32 @@ export function ChartFrame({
107
108
  }
108
109
  };
109
110
 
111
+ // UCM-CHART-17: SVG and PNG now produce genuinely different content (chart-only vector vs. the
112
+ // whole card as shown, legend included) -- the label alone no longer says so, so both buttons
113
+ // carry a tooltip stating the difference plainly, per the Envelope's own requirement.
114
+ const exportButtons = (
115
+ <>
116
+ {options.svg !== false && (
117
+ // `describeChild`: the tooltip DESCRIBES the button, it must not REPLACE its accessible
118
+ // name -- MUI's default (`aria-label` = title) would silently rename "Export SVG" to
119
+ // whatever the tooltip says, breaking both the button's own identity and every existing
120
+ // `getByRole('button', { name: 'Export SVG' })` query.
121
+ <Tooltip title={t('ChartFrame.EXPORT_SVG_TOOLTIP')} describeChild>
122
+ <Button size="small" onClick={() => runExport('svg')}>
123
+ {t('ChartFrame.EXPORT_SVG_LABEL')}
124
+ </Button>
125
+ </Tooltip>
126
+ )}
127
+ {options.png !== false && (
128
+ <Tooltip title={t('ChartFrame.EXPORT_PNG_TOOLTIP')} describeChild>
129
+ <Button size="small" onClick={() => runExport('png')}>
130
+ {t('ChartFrame.EXPORT_PNG_LABEL')}
131
+ </Button>
132
+ </Tooltip>
133
+ )}
134
+ </>
135
+ );
136
+
110
137
  let content = children;
111
138
  if (loading) {
112
139
  content = <CircularProgress aria-label={t('ChartFrame.LOADING')} />;
@@ -173,31 +200,13 @@ export function ChartFrame({
173
200
  <Typography variant="caption" color="text.secondary">{meta}</Typography>
174
201
  {exportsEnabled && (
175
202
  <Stack direction="row" spacing={1} justifyContent="flex-end">
176
- {options.svg !== false && (
177
- <Button size="small" onClick={() => runExport('svg')}>
178
- {t('ChartFrame.EXPORT_SVG_LABEL')}
179
- </Button>
180
- )}
181
- {options.png !== false && (
182
- <Button size="small" onClick={() => runExport('png')}>
183
- {t('ChartFrame.EXPORT_PNG_LABEL')}
184
- </Button>
185
- )}
203
+ {exportButtons}
186
204
  </Stack>
187
205
  )}
188
206
  </Box>
189
207
  ) : exportsEnabled && (
190
208
  <Stack direction="row" spacing={1} justifyContent="flex-end" sx={{ mt: 2 }}>
191
- {options.svg !== false && (
192
- <Button size="small" onClick={() => runExport('svg')}>
193
- {t('ChartFrame.EXPORT_SVG_LABEL')}
194
- </Button>
195
- )}
196
- {options.png !== false && (
197
- <Button size="small" onClick={() => runExport('png')}>
198
- {t('ChartFrame.EXPORT_PNG_LABEL')}
199
- </Button>
200
- )}
209
+ {exportButtons}
201
210
  </Stack>
202
211
  )}
203
212
  </Paper>
@@ -153,6 +153,29 @@ export const PACKAGE_DEFAULT_MARGIN = {
153
153
  // as clipped even when nothing is actually cut off).
154
154
  const ROTATED_TICK_CLEARANCE_PX = 8;
155
155
 
156
+ // UCM-CHART-16: the FLAT (angle 0) tick band used to be the unconditional TICK_BAND_BASE_PX
157
+ // regardless of the actual tick font size -- fine for MUI's own generic default, but MUI's
158
+ // internal fit check (`shortenLabels`, against `tickLabelsMaxHeight`) blanks EVERY tick label the
159
+ // moment the real rendered text is even slightly taller than what that flat floor leaves room
160
+ // for once MUI's own tick/gap overhead (and, when an axis title shares the band, its own gap) is
161
+ // subtracted. `TICK_BAND_BASE_PX` alone was a near-miss with essentially no margin at any font
162
+ // size above whatever MUI itself implicitly assumed -- two hram consumers independently patched
163
+ // around it with the same empirically-measured `height: 56`, and a third, titleless case broke at
164
+ // a tick font just 1px above the untitled default.
165
+ //
166
+ // These three constants are DERIVED, not guessed: binary-searched against the real, unmocked
167
+ // `BarChart` rendered in this repo's own dev harness (`dev/entries.jsx`'s `chart-probe` entry,
168
+ // Chrome, this package's own DM Sans default -- the taller of the two fonts checked; MUI's Roboto
169
+ // fallback needs visibly less and was never the trigger) at tick font sizes 11-18px, with and
170
+ // without an axis title:
171
+ // required flat tickBand ~= ceil(fontSize * TICK_TEXT_HEIGHT_FACTOR) + TICK_BAND_MUI_OVERHEAD_PX
172
+ // required tickBand+title ~= that, plus TICK_BAND_TITLE_EXTRA_PX, plus AXIS_TITLE_BAND_PX
173
+ // matched every measured threshold exactly or over by at most 1px, never under, across ten
174
+ // font-size/title combinations -- see UCM-CHART-16's work order for the full measurement table.
175
+ const TICK_TEXT_HEIGHT_FACTOR = 1.3;
176
+ const TICK_BAND_MUI_OVERHEAD_PX = 9;
177
+ const TICK_BAND_TITLE_EXTRA_PX = 2;
178
+
156
179
  // THEME-9: MUI X-Charts' own default y-axis width is a flat 45px (ticks) +
157
180
  // 20px (label, if present) = 65px regardless of what the ticks actually say
158
181
  // -- confirmed against @mui/x-charts' own DEFAULT_AXIS_SIZE_WIDTH /
@@ -389,7 +412,18 @@ function resolveXAxisGeometry(axis, xLabelsMode, defaultLineHeight, measureTextW
389
412
  angle = needsRotation ? -45 : 0;
390
413
  } // "horizontal" always stays at angle 0
391
414
 
392
- if (angle === 0) return { tickBand: TICK_BAND_BASE_PX, angle: 0 };
415
+ if (angle === 0) {
416
+ // UCM-CHART-16: derive the flat band from the actual tick font size instead of the
417
+ // unconditional floor -- `axis?.label` is the SAME signal `resolveChartLayout` uses to decide
418
+ // whether an axis title also shares this band (`xTitleBand`), so a titled axis reserves the
419
+ // extra room its own gap costs, precisely where the near-miss was.
420
+ const hasTitle = Boolean(axis?.label);
421
+ const flatTickBand = fontSize > 0
422
+ ? Math.ceil(fontSize * TICK_TEXT_HEIGHT_FACTOR) + TICK_BAND_MUI_OVERHEAD_PX
423
+ + (hasTitle ? TICK_BAND_TITLE_EXTRA_PX : 0)
424
+ : TICK_BAND_BASE_PX;
425
+ return { tickBand: Math.max(TICK_BAND_BASE_PX, flatTickBand), angle: 0 };
426
+ }
393
427
  // Rotation is a visual instruction independent of whether a font size is knowable here -- an
394
428
  // "angled" axis still rotates even when `fontSize` can't be resolved (no theme fallback given),
395
429
  // it just can't project a tighter band than the floor without one.