Commit 23ab069
observatory + fx_viewer: unify per-layer accuracy color scale, contrast-aware node text
The per-layer accuracy lens was coloring nodes and table cells with a color
range recomputed independently per record, so the same cosine/PSNR/MSE/abs_err
value mapped to different colors in different records and broke side-by-side
comparison. Separately, fx_viewer was drawing node labels in theme.text
regardless of node fill, so extension layers (e.g. this lens) that assigned
dark or near-white fills produced unreadable text.
Changes:
devtools/observatory/lenses/per_layer_accuracy.py — `_MetricNumericColorRule`
now accepts an optional `fixed_range`; range resolution is factored into
`_resolve_range()`. `analyze()` aggregates per-metric (vmin, vmax) across every
record's rows once via `_aggregate_metric_ranges()`, stashes them in
`AnalysisResult.global_data["metric_ranges"]`, and threads the cosine_sim range
into each per-record `_build_metric_extension(...)`. The HTML metrics table is
now parameterized by `metric_ranges` and the frontend `record()` reads them
from `analysis["global"]`, so table and graph extension share one scale and
the 5-point legend auto-reflects the unified range. Per-record fallback is
preserved for callers without analysis context.
devtools/fx_viewer/templates/runtime.js — new `fxReadableTextColor(hex)`
helper using WCAG 2.x relative luminance (0.2126·R + 0.7152·G + 0.0722·B on
linearized sRGB). Returns `#111111` or `#f8f8f8` by higher-contrast test, or
`null` on malformed input so callers can fall back to theme defaults. Palette
matches the lens HTML table's `_text_color_for_bg` for visual consistency.
devtools/fx_viewer/templates/canvas_renderer.js — the node draw loop now
tracks `renderedFill` through the selected/preview/hovered/input/output
shading branches and picks the label ink from `fxReadableTextColor(renderedFill)`
whenever the node carries a custom `fill_color` from any extension; nodes
without an extension color keep the theme default. No payload/schema changes,
so the contrast rule applies retroactively to every existing extension layer.
devtools/observatory/tests/test_per_layer_accuracy_lens.py — added
`test_analyze_produces_unified_metric_ranges_across_records`: builds two
synthetic digests, asserts `global_data["metric_ranges"]` spans the union
across records, and asserts that a node with the same metric value in both
records receives the same `fill_color` (proving the color no longer depends
on which record the node happens to appear in).
Review order: the lens module is the load-bearing change — start there, then
the matching test, then the two fx_viewer templates which are local and
additive.
Authored with Claude Code.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent e3ace6e commit 23ab069
4 files changed
Lines changed: 254 additions & 39 deletions
File tree
- devtools
- fx_viewer/templates
- observatory
- lenses
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
364 | 365 | | |
365 | | - | |
| 366 | + | |
| 367 | + | |
366 | 368 | | |
367 | 369 | | |
368 | | - | |
| 370 | + | |
| 371 | + | |
369 | 372 | | |
370 | | - | |
| 373 | + | |
| 374 | + | |
371 | 375 | | |
372 | | - | |
| 376 | + | |
| 377 | + | |
373 | 378 | | |
374 | | - | |
| 379 | + | |
| 380 | + | |
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
| |||
392 | 398 | | |
393 | 399 | | |
394 | 400 | | |
395 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
396 | 404 | | |
397 | 405 | | |
398 | 406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
21 | 36 | | |
22 | 37 | | |
23 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
| |||
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
99 | 121 | | |
100 | 122 | | |
101 | 123 | | |
| |||
104 | 126 | | |
105 | 127 | | |
106 | 128 | | |
107 | | - | |
108 | | - | |
109 | 129 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
113 | 134 | | |
114 | 135 | | |
115 | 136 | | |
| |||
236 | 257 | | |
237 | 258 | | |
238 | 259 | | |
239 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
240 | 264 | | |
241 | 265 | | |
242 | 266 | | |
| |||
268 | 292 | | |
269 | 293 | | |
270 | 294 | | |
271 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
272 | 299 | | |
273 | 300 | | |
274 | 301 | | |
| |||
302 | 329 | | |
303 | 330 | | |
304 | 331 | | |
305 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
306 | 335 | | |
307 | 336 | | |
308 | 337 | | |
| |||
311 | 340 | | |
312 | 341 | | |
313 | 342 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
317 | 352 | | |
318 | 353 | | |
319 | 354 | | |
320 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
321 | 359 | | |
322 | 360 | | |
323 | 361 | | |
| |||
455 | 493 | | |
456 | 494 | | |
457 | 495 | | |
458 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
459 | 500 | | |
460 | 501 | | |
461 | 502 | | |
| |||
526 | 567 | | |
527 | 568 | | |
528 | 569 | | |
| 570 | + | |
| 571 | + | |
529 | 572 | | |
530 | 573 | | |
531 | 574 | | |
| |||
583 | 626 | | |
584 | 627 | | |
585 | 628 | | |
| 629 | + | |
586 | 630 | | |
587 | 631 | | |
588 | 632 | | |
589 | 633 | | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
590 | 667 | | |
591 | 668 | | |
592 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
593 | 674 | | |
594 | 675 | | |
595 | 676 | | |
| |||
608 | 689 | | |
609 | 690 | | |
610 | 691 | | |
| 692 | + | |
| 693 | + | |
611 | 694 | | |
612 | | - | |
| 695 | + | |
613 | 696 | | |
614 | 697 | | |
615 | 698 | | |
| |||
672 | 755 | | |
673 | 756 | | |
674 | 757 | | |
675 | | - | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
676 | 761 | | |
677 | 762 | | |
678 | 763 | | |
| |||
688 | 773 | | |
689 | 774 | | |
690 | 775 | | |
691 | | - | |
692 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
693 | 784 | | |
694 | 785 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
699 | 790 | | |
700 | 791 | | |
701 | 792 | | |
| |||
794 | 885 | | |
795 | 886 | | |
796 | 887 | | |
797 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
798 | 893 | | |
799 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
800 | 902 | | |
801 | 903 | | |
802 | 904 | | |
| |||
834 | 936 | | |
835 | 937 | | |
836 | 938 | | |
837 | | - | |
| 939 | + | |
838 | 940 | | |
839 | 941 | | |
840 | 942 | | |
| |||
845 | 947 | | |
846 | 948 | | |
847 | 949 | | |
848 | | - | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
849 | 953 | | |
850 | 954 | | |
851 | 955 | | |
| |||
0 commit comments