Skip to content

Commit

Permalink
fix: #389 initial PoC of SVG backend
Browse files Browse the repository at this point in the history
  • Loading branch information
rvodden committed Mar 12, 2022
1 parent ef7a148 commit e90282a
Show file tree
Hide file tree
Showing 21 changed files with 679 additions and 81 deletions.
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from tests.strategies import make_float, make_angle


def pytest_addoption(parser):
parser.addoption("--backend", choices=['matplotlib', 'svg'], default='matplotlib')
parser.addoption("--show", const=True, default=False, action="store_const")

@pytest.fixture(scope="session", autouse=True)
def setup_testing(request):
np.seterr(over="warn", divide="warn")
Expand All @@ -20,3 +24,4 @@ def add_np(doctest_namespace):
doctest_namespace["np"] = np
doctest_namespace["ps"] = ps
doctest_namespace["MatplotlibBackend"] = MatplotlibBackend

34 changes: 30 additions & 4 deletions examples/hatch_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import argparse
import logging

from typing import Type

import pysketcher as ps
from pysketcher.backend.matplotlib import MatplotlibBackend
from pysketcher.backend.svg import SvgBackend


def main(
backend: Type[ps.backend.Backend] = MatplotlibBackend,
show: bool = False,
filename: str = None
) -> None:

def main() -> None:
i = 1
shapes_dict = {}
for fill_pattern in ps.Style.FillPattern:
Expand All @@ -16,10 +25,27 @@ def main() -> None:

shapes = ps.Composition(shapes_dict)

fig = ps.Figure(0.0, 20.0, 0.0, 3.0, backend=MatplotlibBackend)
fig = ps.Figure(0.0, 20.0, 0.0, 3.0, backend=backend)
fig.add(shapes)
fig.show()

if show:
fig.show()
if filename:
fig.save(filename)


if __name__ == "__main__":
main()
parser = argparse.ArgumentParser(description='PySketcher Hatching Example.')
parser.add_argument('--backend', choices=['svg', 'matplotlib'],
default='matplotlib')
parser.add_argument('--show', const=True, default=False, action='store_const')
parser.add_argument('--filename', default=None)

backend_map = {
'matplotlib': MatplotlibBackend,
'svg': SvgBackend
}

args = parser.parse_args()

main(backend=backend_map[args.backend], show=args.show, filename=args.filename)
9 changes: 5 additions & 4 deletions examples/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
from pysketcher.backend.matplotlib import MatplotlibBackend


def main() -> None:
def main(backend=MatplotlibBackend) -> ps.Figure:
code = ps.Text("print 'Hello, World!'", ps.Point(2.5, 1.5))

code.style.fontsize = 24
code.style.font_family = ps.TextStyle.FontFamily.MONO
code.style.fill_color = ps.TextStyle.Color.GREY

fig = ps.Figure(0.0, 5.0, 0.0, 3.0, backend=MatplotlibBackend)
fig = ps.Figure(0.0, 5.0, 0.0, 3.0, backend=backend)
fig.add(code)
fig.show()
return fig


if __name__ == "__main__":
main()
fig = main()
fig.show()
57 changes: 57 additions & 0 deletions hatch_test.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e90282a

Please sign in to comment.