@@ -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 ( / f o n t c o l o r \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+
585684export 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