Skip to content

[Enhancement]: Add a colorblind-safe theme to the TrustLens visualization system #135

Description

@Khanz9664

🟢 Problem

TrustLens ships a centralized styling system in trustlens/visualization/style.py built around a Theme dataclass. The module docstring explicitly states that the architecture exists so that "future themes (dark, colorblind, publication) can be added by registering a new Theme instance without touching plotting code."

The infrastructure is fully built — but no alternative themes exist yet. The default palette uses red/green distinctions (e.g., severity colors: green = acceptable, red = severe) that are indistinguishable to the ~8% of users with red-green color blindness (deuteranopia/protanopia).

This means a meaningful portion of TrustLens users are currently seeing ambiguous diagnostic output.

🎯 Expected Outcome

A new COLORBLIND_THEME exported from trustlens/visualization/style.py, usable like this:

from trustlens.visualization.style import COLORBLIND_THEME
report.summary_plot(theme=COLORBLIND_THEME)

The colorblind theme replaces the red/green severity pair with a blue/orange pair — the most reliable combination for all common forms of color vision deficiency (per the Wong 2011 palette, widely used in scientific publishing).

🧩 Where to Edit

File Change
trustlens/visualization/style.py Add COLORBLIND_THEME constant
tests/test_visualization_style.py Add tests for the new theme
docs/ Document the theme in the visualization guide

⚡ Proposed Steps

1. Open trustlens/visualization/style.py.

2. Define a new color palette based on the Wong (2011) colorblind-safe palette. The seven colors are: #0072B2 (blue), #E69F00 (orange), #009E73 (teal), #CC79A7 (pink), #56B4E9 (sky blue), #D55E00 (vermillion), #F0E442 (yellow).

3. Create a COLORBLIND_THEME by instantiating Theme(...) with overridden palette and semantic colors. The semantic["severity"] mapping is the most important to fix:

  • acceptable → blue (#0072B2) instead of green
  • severe → vermillion (#D55E00) instead of red
  • moderate → orange (#E69F00) — same role, different hue

4. Export COLORBLIND_THEME at module level alongside DEFAULT_THEME.

5. Write tests in tests/test_visualization_style.py:

  • test_colorblind_theme_is_theme_instanceCOLORBLIND_THEME is a Theme
  • test_colorblind_theme_has_no_pure_red#FF3B30 and #34C759 (default red/green) do not appear in the colorblind theme's semantic colors
  • test_colorblind_theme_palette_length — palette has at least 7 colors
  • test_apply_style_accepts_colorblind_themewith apply_style(COLORBLIND_THEME) as theme: does not raise

6. Add a one-paragraph note in docs/ (wherever visualization is documented) explaining when and how to use the colorblind theme.

🧪 How to Verify

pytest tests/test_visualization_style.py -v -k "colorblind"

Smoke test:

from trustlens.visualization.style import COLORBLIND_THEME, apply_style
import matplotlib.pyplot as plt

with apply_style(COLORBLIND_THEME) as theme:
    print(theme.semantic["severity"])
    # Should show blue/orange/teal — not red/green

🤝 Need Help?

Comment on this issue or join our Discussions.

Difficulty: 🟢 Beginner — No ML knowledge needed. Pure Python dictionary work. The Theme dataclass is already built; this issue is about filling in the right color values. The Wong (2011) palette is a widely cited standard — the colors are provided in the implementation notes below, no color theory research needed.

Reference: Wong, B. (2011). Color blindness. Nature Methods, 8(6), 441. The seven-color palette: #E69F00, #56B4E9, #009E73, #F0E442, #0072B2, #D55E00, #CC79A7.

PR checklist:

  • COLORBLIND_THEME defined and exported in style.py
  • Semantic severity/verdict colors use Wong palette (no pure red or green)
  • ≥ 4 tests in tests/test_visualization_style.py
  • Brief docs note added
  • CHANGELOG.md updated under [Unreleased]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions