You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SVG output needs to be compatible with "dark mode", e.g. in docs #1150
With the ability to switch from dark to light mode, we need the SVGs to work both ways too.
The shaded background in a tree seq viz is easy: we can just make it a mid grey with a suitable alpha value.
The difficulty is going to be the switching the lines from black to white. I guess this can be done using css somehow. At the moment it's hard-coded into the CSS embedded in the SVG. Perhaps we could override that somehow, but only for dark mode.
I tested currentColor. I can't get it to to work. Damn. @benjeffery suggested for ease of use we should simply pick a colour scheme for trees that works OK in both dark and light. Not sure how easy that's going to be. The other option is simply to put a white background behind all the SVGs, but that's a bit horrible. I don't know how one would normally detect being in dark mode anyway. So I'm a bit stuck here.
Here's what I was hoping would work, but the lines are still black in Chrome dark mode on my Mac (chrome v 88.0.4324.96)
<html><body>Here you go:
<svg>
<defs>
<style type="text/css"><![CDATA[ path {stroke: currentColor; stroke-width: 4px; fill: none}]]>
</style>
</defs>
<path d="M 10 10 V 80.0 H 31.875"/>
<text transform="translate(15 15)">hello</text>
</svg></body></html>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@media (prefers-color-scheme: dark) {
body {
color: #eff;
background: #121212;
}
body a {
color: #809fff;
}
}
</style>
</head><body>
<h1>SVG below: lines take on the current colour</h1>
The line and "hello" text should be white when in dark mode, and black when in light mode
<svg>
<defs>
<style type="text/css"><![CDATA[ path {stroke: currentColor; stroke-width: 4px; fill: none} text {fill: currentColor}]]>
</style>
</defs>
<path d="M 10 10 V 80.0 H 31.875"/>
<text transform="translate(15 15)">hello</text>
</svg></body>
</html>
Yes - it's not in there, I just tried swapping currentColor in, and it seems to work OK on my browser. Maybe we should swap all the "black" for "currentColor" in the stylesheet. I guess everything else can be left the same?
Well, they can override anything in the stylesheet, but maybe it's not obvious what that is. We should probably provide user access to an array of the styles, so it can be inspected?
Activity
hyanwong commentedon Jan 29, 2021
I tested
currentColor. I can't get it to to work. Damn. @benjeffery suggested for ease of use we should simply pick a colour scheme for trees that works OK in both dark and light. Not sure how easy that's going to be. The other option is simply to put a white background behind all the SVGs, but that's a bit horrible. I don't know how one would normally detect being in dark mode anyway. So I'm a bit stuck here.Here's what I was hoping would work, but the lines are still black in Chrome dark mode on my Mac (chrome v 88.0.4324.96)
hyanwong commentedon Jan 29, 2021
Ha, so actually this does work, just not with the "force dark mode" in chrome (looks like that's being deprecated anyway, sorry @benjeffery ). If you switch the mode using the OS settings, it should work fine, I think. Unfortunately AFAIK not yet available in chromium/linux
benjeffery commentedon Feb 1, 2021
Gah, what will I do!
Thanks for looking into this - happy to have this solution.
benjeffery commentedon Jun 6, 2025
So currentColor works but isn't in the code currently?
hyanwong commentedon Jun 6, 2025
Yes - it's not in there, I just tried swapping
currentColorin, and it seems to work OK on my browser. Maybe we should swap all the "black" for "currentColor" in the stylesheet. I guess everything else can be left the same?benjeffery commentedon Jun 8, 2025
Looks like
currentColoris well supported, can this easily be tweaked by the person generating the SVG?hyanwong commentedon Jun 9, 2025
Well, they can override anything in the stylesheet, but maybe it's not obvious what that is. We should probably provide user access to an array of the styles, so it can be inspected?