Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic svg export #238

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion fastplotlib/layouts/_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from inspect import signature, getfullargspec
from warnings import warn
import traceback
from pathlib import Path

from pygfx import Scene, OrthographicCamera, PanZoomController, OrbitController, \
AxesHelper, GridHelper, WgpuRenderer, Texture
AxesHelper, GridHelper, WgpuRenderer, Texture, SvgRenderer
from wgpu.gui.auto import WgpuCanvas
from wgpu.gui.base import WgpuCanvasBase

Expand Down Expand Up @@ -327,6 +328,31 @@ def set_grid_visibility(self, visible: bool):
else:
self.scene.remove(self._grid)

def export_svg(self, path: [str, Path], overwrite: bool = False):
"""
CURRENTLY BUGGY. Export the plot area to an svg file.

Parameters
----------
path: str
path to save svg file

overwrite: bool, default False
overwrite file if exists

"""

if not overwrite and Path(path).exists():
raise FileExistsError(
f"The file at the specific path exists: {path}\n"
f"provide a path to a new file or use `overwrite=True`"
)

w, h = map(int, self.canvas.get_logical_size())

renderer = SvgRenderer(w, h, str(path))
renderer.render(self.scene, self.camera)


class _DockedViewport(PlotArea):
_valid_positions = [
Expand Down