Skip to content

Instantly share code, notes, and snippets.

@asinghvi17
Created June 25, 2024 21:42
Show Gist options
  • Save asinghvi17/dbb897df23c52f543e0ee5d20cc57b89 to your computer and use it in GitHub Desktop.
Save asinghvi17/dbb897df23c52f543e0ee5d20cc57b89 to your computer and use it in GitHub Desktop.
Implementing colormaps in SVG via passing colors as grays (allowing value based interpolation)
using Colors
function cgrad2svgf(cgrad)
stops = LinRange(0, 1, 256)
colors = cgrad[stops]
# no Alpha support yet
# but soon!
# <feFuncA type="table" tableValues="$(join(alpha.(colors), ","))"></feFuncA>
return """
<filter id="table" x="0" y="0" width="100%" height="100%">
<feComponentTransfer>
<feFuncR type="table" tableValues="$(join(red.(colors), ","))"></feFuncR>
<feFuncG type="table" tableValues="$(join(green.(colors), ","))"></feFuncG>
<feFuncB type="table" tableValues="$(join(blue.(colors), ","))"></feFuncB>
</feComponentTransfer>
</filter>
"""
end
f, a, p = heatmap(Makie.peaks(); colormap = [Gray(0), Gray(1)])
hidedecorations!(a)
hidespines!(a)
f
save("try1.svg", f)
# now, edit the SVG so that everything contains the xml filter!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment