Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contrast for mermaid diagram elements in dark-mode #11108

Merged

Conversation

vidbina
Copy link
Contributor

@vidbina vidbina commented Apr 13, 2023

Issue

When switching to dark mode on some diagram types, the backgrounds do not change to offer sufficient contrast to be able to read the text within some elements of those diagrams.

Relevant or related issues

Noticed no recent open issues for Mermaid diagrams other than #7047 (which was just a listing of the mermaid websites) and a bunch of older issues https://github.com/darkreader/darkreader/issues?q=mermaid that didn't seem too relevant.

Solution

Attempted to define generally applicable fixes for mermaid diagrams embedded in pages. Since mermaid diagrams can appear on a variety of pages, I reckoned that the top of the dynamic-theme-fixes.config file was a correct place for the changes. These fixes should be general enough but let me know if this design choice is not in line with the project design constraints/goals.

Changes

  • for mermaid controls: set the colors to the darkreader bg and fg values (mermaid adds navigation controls on some embedded diagrams)
  • for ER: set fills on different element types
  • for Gantt: set the task fill color to the darkreader selection bg
  • more generally, but likely just for Flow diagrams: set fill for rects and polygons

Testing

Tested on:

Examples

For the sake of completeness, I repeat some of the diagrams (from the live editor samples) that were causing issues for me in dark mode in Chromium. These show show up in GitHub with some elements having light backgrounds and light text, rendering the diagrams more-or-less unreadable (poor contrast between bg and text).

Flowcharts

flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
Loading
Problematic diagram

2023-04-13-022203_2277x1913_scrot
](url)

Fixed diagram

2023-04-13-031842_2282x1118_scrot

ER Diagrams

erDiagram
    CUSTOMER }|..|{ DELIVERY-ADDRESS : has
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER ||--o{ INVOICE : "liable for"
    DELIVERY-ADDRESS ||--o{ ORDER : receives
    INVOICE ||--|{ ORDER : covers
    ORDER ||--|{ ORDER-ITEM : includes
    PRODUCT-CATEGORY ||--|{ PRODUCT : contains
    PRODUCT ||--o{ ORDER-ITEM : "ordered in"
Loading
Problematic diagram

2023-04-13-023357_2278x1110_scrot

Fixed diagram

2023-04-13-023426_2279x1115_scrot

Gantt Diagrams

gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    another task      : 24d
Loading
Problematic diagram

2023-04-13-023434_2288x1112_scrot

Fixed diagram

2023-04-13-023604_2290x1118_scrot

Sequence Diagram

sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>-Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!
Loading
Problematic diagram

2023-04-16-191753_1517x1250_scrot

Solved diagram

2023-04-16-192501_1523x800_scrot

@vidbina vidbina changed the title fix: Fix contrast for mermaid diagram elements in dark-mode Fix contrast for mermaid diagram elements in dark-mode Apr 13, 2023
Noticed no recent open issues for Mermaid diagrams other than darkreader#7047 (which was just a listing of the mermaid websites) and a bunch of older issues https://github.com/darkreader/darkreader/issues?q=mermaid that didn't seem too relevant.

Attempted to define generally applicable fixes for mermaid diagrams embedded in pages. Not sure if the place where I listed this is too general, but I've tested it on:
- Mermaid Live Editor (https://mermaid-js.github.io/mermaid-live-editor)
- mermaid in Markdown or Orgdown on GitHub
- mermaid in Markdown or Orgdown on GitLab (see some docs at https://about.gitlab.com/handbook/tools-and-tips/mermaid/)

Changes made to:
- controls

For the sake of completeness, I repeat some of the diagrams (from the live editor samples) that were causing issues for me in dark mode in Chromium. These show show up in GitHub with some elements having light backgrounds and light text, rendering the diagrams more-or-less unreadable (poor contrast between bg and text).

```mermaid
flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
```

```mermaid
erDiagram
    CUSTOMER }|..|{ DELIVERY-ADDRESS : has
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER ||--o{ INVOICE : "liable for"
    DELIVERY-ADDRESS ||--o{ ORDER : receives
    INVOICE ||--|{ ORDER : covers
    ORDER ||--|{ ORDER-ITEM : includes
    PRODUCT-CATEGORY ||--|{ PRODUCT : contains
    PRODUCT ||--o{ ORDER-ITEM : "ordered in"
```

```mermaid
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    another task      : 24d
```
@vidbina vidbina force-pushed the vid/set-dark-bgs-for-mermaid-diagrams branch from edc6190 to 027f5eb Compare April 13, 2023 03:47
@vidbina
Copy link
Contributor Author

vidbina commented Apr 16, 2023

In GitHub, the mermaid diagrams is classes with mermaid and have some behavior that I didn't have on the Live Mermaid editor, so I provided some workarounds that these diagrams at least appear in a legible state on GitHub as well. I have edited my first message to outline the general mermaid sequence diagram points but am providing separate examples of the GitHub-only issue for which the commit is on the way.

Sequence Diagram

sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>-Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!
Loading
Problematic diagram

2023-04-16-193027_1238x737_scrot

Solved diagram

2023-04-16-193007_1218x715_scrot

@alexanderby alexanderby merged commit ec38a2a into darkreader:main Jun 18, 2023
bherila pushed a commit to bherila/darkreader that referenced this pull request Aug 20, 2023
)

* fix: Improve contrast for Mermaid diagrams elements and controls

Noticed no recent open issues for Mermaid diagrams other than darkreader#7047 (which was just a listing of the mermaid websites) and a bunch of older issues https://github.com/darkreader/darkreader/issues?q=mermaid that didn't seem too relevant.

Attempted to define generally applicable fixes for mermaid diagrams embedded in pages. Not sure if the place where I listed this is too general, but I've tested it on:
- Mermaid Live Editor (https://mermaid-js.github.io/mermaid-live-editor)
- mermaid in Markdown or Orgdown on GitHub
- mermaid in Markdown or Orgdown on GitLab (see some docs at https://about.gitlab.com/handbook/tools-and-tips/mermaid/)

Changes made to:
- controls

For the sake of completeness, I repeat some of the diagrams (from the live editor samples) that were causing issues for me in dark mode in Chromium. These show show up in GitHub with some elements having light backgrounds and light text, rendering the diagrams more-or-less unreadable (poor contrast between bg and text).

```mermaid
flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
```

```mermaid
erDiagram
    CUSTOMER }|..|{ DELIVERY-ADDRESS : has
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER ||--o{ INVOICE : "liable for"
    DELIVERY-ADDRESS ||--o{ ORDER : receives
    INVOICE ||--|{ ORDER : covers
    ORDER ||--|{ ORDER-ITEM : includes
    PRODUCT-CATEGORY ||--|{ PRODUCT : contains
    PRODUCT ||--o{ ORDER-ITEM : "ordered in"
```

```mermaid
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    another task      : 24d
```

* chore: Use only variables outlined in CONTRIBUTING

* feat: Set stroke for mermaid sequence diagram message lines

* fix: Also cover returning messages in mermaid sequence diagram

* feat: Set actor fill for mermaid diagrams on GitHub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants