MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.38k stars 302 forks source link

SVG in Makie Window #268

Closed wsrinin closed 2 years ago

wsrinin commented 5 years ago

Hello,

Is there a way to render SVG file in Makie window?

Best,

SimonDanisch commented 5 years ago

No, only by converting it to png... But actually, it shouldn't be tooo hard to implement a function svg -> Makie.Scene, since svg doesn't have that many drawing operations and they should be all supported by Makie. I actually tried that some time ago, but admittedly failed at parsing the xml and getting any meaningful paths + attributes out of it... Someone with more xml experience could probably do this quite a bit faster!

wsrinin commented 5 years ago

That is what I figure out as well. The infrastructure is there but it is gonna quite a bit of work to make it work because I was thinking about rendering the math equation as SVG or PNG use it as a texture to plot on Makie scene. I can't remember why precisely I don't want to use PNG format.

Isn't Cairo capable of doing SVG?

SimonDanisch commented 5 years ago

I guess if you stay with the cairo backend, there could be a simpler way ;) Png is resolution dependent, so if you zoom you will see ugly pixels + edges - so yeah, perfect solution would be to directly turn an svg into a makie plot!

lobingera commented 5 years ago

@wsrinin Cairo is able to output SVG and librsvg can render SVG to Cairo surfaces (https://github.com/lobingera/Rsvg.jl) Do you think of 'just' putting this as background picture?

dehann commented 5 years ago

Moving SVG export discussion from #256

Unfortunately I'm having another issue with the svg export.

Looks like the backend call:

using AbstractPlotting, CairoMakie, FileIO
AbstractPlotting.current_backend[] = CairoMakie.CairoBackend("/tmp/test.svg")

#intention is to get here
#open("/tmp/test.svg","w") do io
#   show(io, MIME"image/svg+xml"(), scene)
#end

changes the behavior of plotting, resulting in incorrect plots. The best way to describe is: it looks like a canvas sizing error where the original plot becomes tiled with repetition inside the original axes. For example, the correct image looks something like this (a png):

test

But ends up looking like this (screen grab of svg opened via eog on Ubuntu 16.04):

screenshot from 2019-02-09 11-59-46

Note, the Makie Window no longer shows the plots (as per this issue), but working through Juno the plot pane shows the same funky canvas version. I'm pretty sure it is related to changing to the Cairo backend.

kskyten commented 5 years ago

Manim implements an SVG parser that does pretty much this in Python. What are the primitive plotting commands that should be used to make the Makie scene?

asinghvi17 commented 5 years ago

That's interesting, I will definitely give it a look!

We currently decompose all plotting commands into several 'atomic' drawing operations within AbstractPlotting - for 2d plotting, all you really need is linesegments, lines, mesh, heatmap/image, and text.

asinghvi17 commented 5 years ago

Also, @dehann, the issue with Cairo is being investigated in JuliaPlots/CairoMakie.jl#11.

kskyten commented 5 years ago

There are probably better parsers to look at as well. This looks promising, although it parses everything into bezier curves, so semantic information is lost. Shouldn't matter just for plotting, though.

kskyten commented 5 years ago

I wonder if we can use resvg directly? If not, usvg should at least make parsing easier.

asinghvi17 commented 5 years ago

Looking at the resvg repo, it seems that it statically links harfbuzz at runtime. That, and figuring out the C API, would be the only hiccups in getting it wrapped in Julia.

behinger commented 1 month ago

Because I found this via google - you can render SVG/Latex/Typst via MakieTex