pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.72k stars 500 forks source link

Error in svg export #901

Open deyanimay opened 4 years ago

deyanimay commented 4 years ago

When using the function below to export an image that contains label text with the "<" character in it, the output is an invalid .svg file since the save function does not seem to be properly escaping this character. I suspect a similar issue applies to the ">" character if they are used sequentially.

plotter.save_graphic('filename.svg', raster=False)

github-actions[bot] commented 4 years ago

Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, it may be automatically transferred to https://github.com/pyvista/pyvista-support

akaszynski commented 4 years ago

Could you please provide a basic minimum working example so I can debug this on my end? I know it sounds trivial for me to create it on my own, but I'm super busy at the moment.

Thanks!

deyanimay commented 4 years ago

@akaszynski This code should produce the error. After running it try opening test.svg in chrome and you will see the error and the label will be missing the "<" character.

import pyvista as pv
poly = pv.Polygon()
p1 = pv.Plotter(notebook=False)
p1.add_mesh(poly, label="Test label <")
p1.add_legend()
p1.save_graphic('test.svg', raster=False)
tkoyama010 commented 4 years ago

Thanks for good produce. I think it is the issue of the vtk because save_graphic uses vtk.vtkGL2PSExporter for exporting. https://github.com/pyvista/pyvista/blob/5462b37d0e6d9816b7243a3095c05e67ff038d50/pyvista/plotting/plotting.py#L3298

akaszynski commented 4 years ago

Looks like there's no real way to prevent this and your best option is to avoid including the start of a tag character < in your labels. I could add a warning anytime < is used, but I think this would lead to a lot of false positives for those not exporting graphics.

You might want to raise this issue at https://gitlab.kitware.com/vtk/vtk since, as @tkoyama010 pointed out, the issue is with vtkGL2PSExporter.

deyanimay commented 4 years ago

I've logged an issue there: https://gitlab.kitware.com/vtk/vtk/-/issues/18016