Repository navigation
SVG: read hsl() and hsla() colors - #2171
Conversation
andersonhc
left a comment
There was a problem hiding this comment.
Two small things I noticed:
- Could we preserve the floating-point RGB values instead of rounding to 8 bits? DeviceRGB supports them, and Python’s rounding gives some unexpected results: hsl(0 0% 30%) becomes #4c4c4c rather than #4d4d4d, while very dark colors can become black.
- The changelog entry landed under the released 2.9.0 section. Could you move it to the unreleased 2.9.1 section?
hsl() colors are now supported.
DeviceRGB takes fractions, so rounding to 8 bits only lost precision: hsl(0 0% 30%) was #4c4c4c instead of 0.3 gray.
b4c618e to
909adc6
Compare
# Conflicts: # CHANGELOG.md
|
Done: the RGB values are no longer rounded, so |
Thanks for addressing both points! I found one remaining edge case with the cache: for a -> b -> a, where only a has stops, defining a first caches b without stops, so shapes using b lose their gradient. Reversing the definitions makes both gradients resolve. Could we avoid caching incomplete results for cycle members and add a test with stops in the cycle, checking both definition orders? |
# Conflicts: # CHANGELOG.md
fill="hsl(120, 100%, 25%)"fails withValueError: unsupported color specification hsl(120, 100%, 25%).hsl()is a common way to write colors in stylesheets, and Mermaid computes the colors of its themes ashsl(...)strings.svgcolor()now readshsl()andhsla(), with commas or space-separated with an optional/ A, as in CSS Color 4: the hue may have an angle unit (deg,grad,rad,turn), a saturation or lightness without%is a percentage, and the alpha is a number from 0 to 1 or a percentage. The channels are rounded to 8 bits as browsers do, sohsl(120, 100%, 25%)is#008000.Added four cases to
test_svg_attribute_conversion:hsl(),hsl()space-separated with aturnhue and an alpha, an uppercasehsla()stroke and an invalidhsl(). The first three fail on master. The SVG tests, black, pylint and mypy pass