Skip to content

Commit d2c13cd

Browse files
Merge pull request #14 from refactorfirst/ui-improvements
Dark Mode UI improvements & Disharmony Info Table fix
2 parents 2f93666 + f4e651e commit d2c13cd

11 files changed

Lines changed: 722 additions & 26 deletions

‎AGENTS.md‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ coverage there when introducing new markup patterns.
154154
identical dark blocks) in `app/globals.css`; mvp.css light overrides must
155155
stay on `html:root` (mvp loads after the bundle). Report-template
156156
widgets that hardcode light colors are re-driven from `main#app …`
157-
rules there (the mustache stays byte-identical).
157+
rules there (the mustache stays byte-identical); the vizdom graph
158+
SVGs' embedded black strokes/fills are likewise re-themed to
159+
`--graph-line` (`#9fb0c0` dark = `CHART_LEGEND_TEXT.dark`) via
160+
`path[stroke]`/`polygon` selectors on `.fullscreen-svg` — red cycle
161+
edges stay red. Edge labels are glyph paths baked by vizdom, so CSS
162+
can't reach them: `withEdgeFontColor` in `lib/report-view.js` rewrites
163+
the DOT with `fontcolor = "#9fb0c0"` per edge when the dark palette
164+
is active (vizdom uppercases the hex in the SVG), and theme switches
165+
re-parse the graphs via `redrawGraphsForTheme` alongside the chart
166+
legend redraw in `bindThemeChartRedraw`.
158167

159168
## Report Tables (Enhanced)
160169

@@ -164,8 +173,11 @@ coverage there when introducing new markup patterns.
164173
the `.rf-table-block` wrapper shrink-wraps the table and the toolbar uses
165174
`contain: inline-size` so controls align with the table's right edge),
166175
sortable th buttons with `aria-sort`, pagination below 20+ row tables, and
167-
click/Enter/Space cell copy with toast feedback. The filter's clear control
168-
is an × button (accessible name "Clear the … table filter").
176+
click/Enter/Space cell copy with toast feedback. The filter prompt lives in
177+
the input's placeholder ("Filter table...", with a screen-reader-only
178+
label); the clear control is an × button overlaid on the input's right
179+
edge (accessible name "Clear the … table filter"), revealed only while the
180+
box holds a term and invoked by click or Escape while the box has focus.
169181
- Tables open sorted by their Priority column ascending (▲, priority 1
170182
first), signalling both the report's priority ordering and that headers are
171183
sortable (`TABLE_CONFIG.sorting` defaults in lib/table-operations.js);
@@ -178,7 +190,12 @@ coverage there when introducing new markup patterns.
178190
after measuring `wrapper.scrollWidth > clientWidth` (re-measured on each
179191
re-render and on window resize). It MUST stay conditional — any overflow
180192
ancestor becomes the sticky constraint container and breaks the
181-
viewport-sticky `thead th`. Scrolling tables keep their header pinned
193+
viewport-sticky `thead th`. The unwrapped problem/solution tables (no
194+
`data-rf-table`, no `.rf-table-scroll`, no sticky header) instead get an
195+
unconditional `overflow-x: auto` from a `main#app` rule in globals.css so
196+
their nowrap rows scroll inside the 5px border on narrow screens
197+
(guarded by tests/unit/report-template-wcag.test.js and
198+
tests/e2e/report-overflow.spec.js). Scrolling tables keep their header pinned
182199
anyway: `refreshStickyHeaders` in lib/table-enhancer.js compensates by
183200
translating every `thead th` down by the viewport scroll offset (clamped to
184201
the table's bottom edge) on window scroll/resize; narrow tables keep pure

‎app/globals.css‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
--card-bg: #ffffff;
2929
--border-color: #dde4ea;
3030
--input-border: #c6d2dc;
31+
/* vizdom WASM graph edges bake black stroke/fill attributes into the SVG;
32+
palette-driven so the dark theme can swap them to a readable tint. */
33+
--graph-line: #000000;
3134
--error-color: #c0392b;
3235
--success-color: #1e8449;
3336
--error-bg: #fdf6f5;
@@ -91,6 +94,7 @@ html:root {
9194
--card-bg: #1a2330;
9295
--border-color: #2c3a4d;
9396
--input-border: #5b7396;
97+
--graph-line: #9fb0c0;
9498
--error-color: #f0928c;
9599
--success-color: #5bbd8b;
96100
--error-bg: #2b1d1f;
@@ -132,6 +136,7 @@ html:root {
132136
--card-bg: #1a2330;
133137
--border-color: #2c3a4d;
134138
--input-border: #5b7396;
139+
--graph-line: #9fb0c0;
135140
--error-color: #f0928c;
136141
--success-color: #5bbd8b;
137142
--error-bg: #2b1d1f;
@@ -836,3 +841,103 @@ main#app .rf-data-table td[data-rf-copy]:focus-visible {
836841
--surface-color, below the 3:1 of SC 2.4.11. */
837842
outline-color: var(--brand-accent);
838843
}
844+
845+
main#app .rf-table-search {
846+
/* Anchors the overlaid clear control inside the input's right edge. */
847+
position: relative;
848+
}
849+
850+
main#app .rf-table-search .rf-search-label {
851+
/* Screen-reader-only: the visible prompt is the input's placeholder. */
852+
position: absolute;
853+
width: 1px;
854+
height: 1px;
855+
margin: -1px;
856+
padding: 0;
857+
border: 0;
858+
overflow: hidden;
859+
clip-path: inset(50%);
860+
white-space: nowrap;
861+
}
862+
863+
main#app .rf-table-search input[type="search"] {
864+
/* mvp.css gives inputs a pale border that reads near-invisible on the
865+
white page (under 3:1, SC 1.4.11). --muted-color is a full palette
866+
role, so the border stays dark in light mode and bright on the dark
867+
background. Room for the overlaid ×. */
868+
border: 1px solid var(--muted-color);
869+
padding-right: 1.9rem;
870+
/* mvp.css also endows inputs with margin-bottom: 1rem; the flex slot
871+
would grow by that margin, so the overlaid ×'s "50%" anchor point
872+
would drop below the input and strand the button at its bottom edge.
873+
The slot must hug the input exactly. */
874+
margin: 0;
875+
}
876+
877+
/* We inject our own themed × (palette colours, reveal/clear logic);
878+
WebKit's native search-cancel button would otherwise sit beside it. */
879+
main#app .rf-table-search input[type="search"]::-webkit-search-cancel-button {
880+
-webkit-appearance: none;
881+
appearance: none;
882+
}
883+
884+
main#app .rf-table-search .rf-search-clear {
885+
/* Overlaid on the input's right edge (the enhancer reveals it via the
886+
`hidden` attribute only while the box holds a term). 1.6rem clears the
887+
24px pointer-target minimum (SC 2.5.8) and fits the input's height. */
888+
position: absolute;
889+
top: 50%;
890+
right: 0.1rem;
891+
transform: translateY(-50%);
892+
/* mvp.css gives buttons a ~0.5rem top margin, which for an absolutely
893+
positioned element shifts the box down off the input's centre line. */
894+
margin: 0;
895+
width: 1.6rem;
896+
height: 1.6rem;
897+
padding: 0;
898+
border: none;
899+
border-radius: 4px;
900+
background: transparent;
901+
color: var(--text-color);
902+
}
903+
904+
/* The flex centering must ride on :not([hidden]) — a plain `display` here
905+
would override the UA's [hidden] { display: none } and keep the empty
906+
state's × on screen. */
907+
main#app .rf-table-search .rf-search-clear:not([hidden]) {
908+
display: inline-flex;
909+
align-items: center;
910+
justify-content: center;
911+
}
912+
913+
main#app .rf-table-search .rf-search-clear:focus-visible {
914+
outline-color: var(--brand-accent);
915+
outline-offset: -2px;
916+
}
917+
918+
main#app table.rf-data-table:not([data-rf-table]) {
919+
/* Unwrapped problem/solution tables have no .rf-table-scroll wrapper, and
920+
mvp.css clamps them to max-width: 100% while rendering td/th with
921+
white-space: nowrap; the template's overflow: visible then lets the
922+
rows spill past the 5px border on narrow screens. Re-enable horizontal
923+
scrolling here so the bordered box hugs the column and the wider rows
924+
scroll inside it. The enhanced tables (data-rf-table) are excluded on
925+
purpose: any overflow container would capture their viewport-sticky
926+
table headers. */
927+
overflow-x: auto;
928+
}
929+
930+
/* vizdom WASM graphs (Class/Package/cycle maps): the layout bakes black
931+
stroke/fill presentation attributes onto the edge curves and arrowhead
932+
polygons, which vanish on the dark page. Only non-red elements re-drive
933+
from the palette --graph-line — red stays red (cycle edges) and the
934+
fill-only paths (text glyphs) are left alone: node labels stay black on
935+
their white ellipses. */
936+
main#app .fullscreen-svg path[stroke]:not([stroke="red"]) {
937+
stroke: var(--graph-line);
938+
}
939+
940+
main#app .fullscreen-svg polygon:not([fill="red"]) {
941+
stroke: var(--graph-line);
942+
fill: var(--graph-line);
943+
}

‎lib/report-view.js‎

Lines changed: 106 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ const CHART_LEGEND_TEXT = Object.freeze({
377377
dark: '#9fb0c0' // 8.2:1 on #10161d
378378
});
379379

380+
// U+27F6 LONG RIGHTWARDS ARROW (compart.com/en/unicode/U+27F6): suffixed
381+
// onto every chart axis title so the direction of each axis reads at a
382+
// glance.
383+
const AXIS_ARROW = ' \u27F6';
384+
385+
/**
386+
* Builds a chart axis title: the (data-provided or fallback) label with the
387+
* long arrow suffix appended.
388+
*
389+
* @param {string} label - Axis label from the report data or the fallback.
390+
* @returns {string} Label suffixed with U+27F6.
391+
*/
392+
function axisTitle(label) {
393+
return `${label}${AXIS_ARROW}`;
394+
}
395+
380396
/**
381397
* Returns 'light' or 'dark' for the active palette, mirroring the pure-CSS
382398
* selection in app/globals.css: the explicit radios win, the system radio
@@ -466,9 +482,13 @@ export function bindThemeChartRedraw() {
466482
const doc = typeof document === 'undefined' ? null : document;
467483
if (!doc || doc.documentElement.hasAttribute('data-rf-theme-redraw-bound')) return;
468484
doc.documentElement.setAttribute('data-rf-theme-redraw-bound', '');
485+
const redrawForTheme = () => {
486+
redrawChartsForTheme();
487+
redrawGraphsForTheme();
488+
};
469489
doc.addEventListener('change', event => {
470490
const target = event.target;
471-
if (target && target.name === 'rf-theme') redrawChartsForTheme();
491+
if (target && target.name === 'rf-theme') redrawForTheme();
472492
});
473493
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
474494
try {
@@ -477,9 +497,9 @@ export function bindThemeChartRedraw() {
477497
// engines that never grew the modern one.
478498
systemThemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
479499
if (systemThemeMediaQuery && typeof systemThemeMediaQuery.addEventListener === 'function') {
480-
systemThemeMediaQuery.addEventListener('change', redrawChartsForTheme);
500+
systemThemeMediaQuery.addEventListener('change', redrawForTheme);
481501
} else if (systemThemeMediaQuery && typeof systemThemeMediaQuery.addListener === 'function') {
482-
systemThemeMediaQuery.addListener(redrawChartsForTheme);
502+
systemThemeMediaQuery.addListener(redrawForTheme);
483503
}
484504
} catch {
485505
// Older engines without MQL listeners: explicit radios still redraw.
@@ -556,11 +576,24 @@ export function initBubbleChart(canvas, title, chartData) {
556576
},
557577
scales: {
558578
x: {
559-
title: {display: true, text: chartData.xaxisLabel || 'Effort to refactor'},
579+
title: {
580+
display: true,
581+
text: axisTitle(chartData.xaxisLabel || 'Effort to refactor'),
582+
// Scriptable option: re-resolved on every update(),
583+
// so the theme-change redraw keeps the axis title
584+
// color in sync with the canvas-drawn legend text
585+
// (>= 4.5:1 on each palette's --bg-color, which no
586+
// single color can achieve for both).
587+
color: () => resolveLegendTextColor()
588+
},
560589
grid: {color: '#e0e0e0'}
561590
},
562591
y: {
563-
title: {display: true, text: chartData.yaxisLabel || 'Relative churn (impact)'},
592+
title: {
593+
display: true,
594+
text: axisTitle(chartData.yaxisLabel || 'Relative churn (impact)'),
595+
color: () => resolveLegendTextColor()
596+
},
564597
grid: {color: '#e0e0e0'}
565598
}
566599
}
@@ -582,6 +615,72 @@ export function initDisharmonyCharts(disharmonies) {
582615
// vizdom WASM graph rendering (inline, pan/zoom-able SVGs).
583616
// ---------------------------------------------------------------------------
584617

618+
/**
619+
* Appends a Graphviz `fontcolor` attribute to every edge attribute list in
620+
* a DOT string so vizdom bakes the label color into the SVG at parse time
621+
* (the default black is unreadable on the dark palette). Edges that already
622+
* carry fontcolor are left untouched; node statements have no `->` in the
623+
* matched segment and are preserved verbatim.
624+
*
625+
* @param {string} dot - DOT graph source.
626+
* @param {string} color - Graphviz color value for edge labels.
627+
* @returns {string} DOT with fontcolor appended to each labeled edge.
628+
*/
629+
export function withEdgeFontColor(dot, color) {
630+
if (typeof dot !== 'string' || !color) return dot;
631+
return dot.replace(/(->[^;[\]{}]*?\[)([^\]]*?)(\s*\])/g, (match, open, attrs, close) => {
632+
if (/fontcolor\s*=/.test(attrs)) return match;
633+
return `${open}${attrs} fontcolor = "${color}"${close}`;
634+
});
635+
}
636+
637+
// Rendered graphs keyed by container id, so a theme switch can re-parse the
638+
// dots with the new palette's edge-label color — vizdom bakes fontcolor into
639+
// the SVG at parse time, so recoloring needs a re-render, like the charts.
640+
const wasmGraphDots = new Map();
641+
642+
/**
643+
* Re-renders every live WASM graph so edge labels re-resolve against the
644+
* newly active palette. Entries whose container left the DOM (report
645+
* re-rendered or torn down) are pruned instead of redrawn.
646+
*
647+
* @returns {void}
648+
*/
649+
function redrawGraphsForTheme() {
650+
const vizdom = typeof window !== 'undefined' ? window.Vizdom : null;
651+
if (!vizdom || !vizdom.DotParser) return;
652+
const parser = new vizdom.DotParser();
653+
for (const [containerId, dotString] of wasmGraphDots) {
654+
const el = typeof document !== 'undefined' ? document.getElementById(containerId) : null;
655+
if (!el || !el.isConnected) {
656+
wasmGraphDots.delete(containerId);
657+
continue;
658+
}
659+
try {
660+
renderGraphInto(parser, el, containerId, dotString);
661+
} catch (error) {
662+
console.warn('WASM graph re-render failed:', error);
663+
}
664+
}
665+
}
666+
667+
/**
668+
* Parses a dot string (recolored for the active palette) into the graph
669+
* container's innerHTML and re-wires pan/zoom on the freshly injected SVG.
670+
*/
671+
function renderGraphInto(parser, el, containerId, dotString) {
672+
const themedDot = activeChartTheme() === 'dark'
673+
? withEdgeFontColor(dotString, CHART_LEGEND_TEXT.dark)
674+
: dotString;
675+
const parsed = parser.parse(themedDot).to_directed().layout();
676+
const svg = parsed.to_svg().to_string()
677+
.replace('<svg ', '<svg class="fullscreen-svg" ');
678+
el.innerHTML = svg;
679+
if (window.svgPanZoom) {
680+
window.svgPanZoom(`#${containerId} svg`, {zoomEnabled: true, controlIconsEnabled: true});
681+
}
682+
}
683+
585684
export async function initWasmGraphs(data) {
586685
try {
587686
// The vizdom WASM module is vendored and initialized by the bridge in
@@ -593,13 +692,8 @@ export async function initWasmGraphs(data) {
593692
const renderGraph = (containerId, dotString) => {
594693
const el = document.getElementById(containerId);
595694
if (!el || !dotString) return;
596-
const parsed = parser.parse(dotString).to_directed().layout();
597-
const svg = parsed.to_svg().to_string()
598-
.replace('<svg ', '<svg class="fullscreen-svg" ');
599-
el.innerHTML = svg;
600-
if (window.svgPanZoom) {
601-
window.svgPanZoom(`#${containerId} svg`, {zoomEnabled: true, controlIconsEnabled: true});
602-
}
695+
renderGraphInto(parser, el, containerId, dotString);
696+
wasmGraphDots.set(containerId, dotString);
603697
};
604698

605699
if (data.classMap && !data.classMap.dotThresholdExceeded) {

0 commit comments

Comments
 (0)