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

3D canvas #53

Merged
merged 10 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 3 additions & 29 deletions whitecanvas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__version__ = "0.2.7"
__version__ = "0.3.0.dev0"

from whitecanvas import theme
from whitecanvas.canvas import link_axes
from whitecanvas.core import (
new_canvas,
new_canvas_3d,
new_col,
new_grid,
new_jointgrid,
Expand All @@ -13,6 +14,7 @@

__all__ = [
"new_canvas",
"new_canvas_3d",
"new_col",
"new_grid",
"new_row",
Expand All @@ -21,31 +23,3 @@
"theme",
"link_axes",
]


def __getattr__(name: str): # pragma: no cover
import warnings

if name in ("grid", "grid_nonuniform"):
warnings.warn(
f"{name!r} is deprecated. Use `new_grid` instead",
DeprecationWarning,
stacklevel=2,
)
return new_grid
elif name in ("vgrid", "vgrid_nonuniform"):
warnings.warn(
f"{name!r} is deprecated. Use `new_col` instead",
DeprecationWarning,
stacklevel=2,
)
return new_col
elif name in ("hgrid", "hgrid_nonuniform"):
warnings.warn(
f"{name!r} is deprecated. Use `new_row` instead",
DeprecationWarning,
stacklevel=2,
)
return new_row
else:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
13 changes: 12 additions & 1 deletion whitecanvas/backend/_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
raise RuntimeError(f"Backend {self._name!r} does not implement {attr!r}")
return out

def get_submodule(self, attr: str):
"""Get a submodule from the current backend."""
import importlib

Check warning on line 77 in whitecanvas/backend/_instance.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_instance.py#L77

Added line #L77 was not covered by tests

if self.is_dummy():
return _dummy_backend_module
out = importlib.import_module(f"whitecanvas.backend.{self._name}.{attr}")

Check warning on line 81 in whitecanvas/backend/_instance.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_instance.py#L80-L81

Added lines #L80 - L81 were not covered by tests
if out is None:
raise RuntimeError(f"Backend {self._name!r} does not implement {attr!r}")
return out

Check warning on line 84 in whitecanvas/backend/_instance.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_instance.py#L83-L84

Added lines #L83 - L84 were not covered by tests

def is_dummy(self) -> bool:
"""True is the backend is a dummy backend."""
return self.name.startswith(".")
Expand All @@ -87,7 +98,7 @@
self.Canvas = DummyObject

def __getattr__(self, key):
raise RuntimeError(f"Cannot install {key!r} before finishing layouting.")
return DummyObject

Check warning on line 101 in whitecanvas/backend/_instance.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_instance.py#L101

Added line #L101 was not covered by tests


_dummy_backend_module = DummyBackendModule()
Expand Down
36 changes: 30 additions & 6 deletions whitecanvas/backend/_not_implemented.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import numpy as np

from whitecanvas.types import Hatch, LineStyle


Expand Down Expand Up @@ -27,25 +29,47 @@
return _getter, _setter


def face_pattern():
def edge_width():
def _getter(self):
return getattr(self, "__edge_width_value", 1.0)

Check warning on line 34 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L33-L34

Added lines #L33 - L34 were not covered by tests

def _setter(self, value: float):
setattr(self, "__edge_width_value", value)

Check warning on line 37 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L36-L37

Added lines #L36 - L37 were not covered by tests

return _getter, _setter

Check warning on line 39 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L39

Added line #L39 was not covered by tests


def edge_color():
def _getter(self):
return getattr(

Check warning on line 44 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L43-L44

Added lines #L43 - L44 were not covered by tests
self, "__edge_color_value", np.array([0, 0, 0, 255], dtype=np.float32)
)

def _setter(self, value: float):
setattr(self, "__edge_color_value", value)

Check warning on line 49 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L48-L49

Added lines #L48 - L49 were not covered by tests

return _getter, _setter

Check warning on line 51 in whitecanvas/backend/_not_implemented.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/_not_implemented.py#L51

Added line #L51 was not covered by tests


def face_hatch():
def _getter(self):
return getattr(self, "__face_pattern_value", Hatch.SOLID)
return getattr(self, "__face_hatch_value", Hatch.SOLID)

def _setter(self, value: Hatch):
setattr(self, "__face_pattern_value", value)
setattr(self, "__face_hatch_value", value)

return _getter, _setter


def face_patterns():
def face_hatches():
def _getter(self):
return getattr(
self, "__face_pattern_value", [Hatch.SOLID] * self._plt_get_ndata()
self, "__face_hatch_value", [Hatch.SOLID] * self._plt_get_ndata()
)

def _setter(self, value: Hatch | list[Hatch]):
if isinstance(value, Hatch):
value = [value] * self._plt_get_ndata()
setattr(self, "__face_pattern_value", value)
setattr(self, "__face_hatch_value", value)

return _getter, _setter
1 change: 1 addition & 0 deletions whitecanvas/backend/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from whitecanvas.backend.matplotlib.line import MonoLine, MultiLine
from whitecanvas.backend.matplotlib.markers import Markers
from whitecanvas.backend.matplotlib.text import Texts
from whitecanvas.backend.matplotlib.vectors import Vectors
6 changes: 6 additions & 0 deletions whitecanvas/backend/matplotlib/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
self.set_zorder(zorder)


class FakeAxes:
def __init__(self):
self.transData = None
self.transAxes = None

Check warning on line 28 in whitecanvas/backend/matplotlib/_base.py

View check run for this annotation

Codecov / codecov/patch

whitecanvas/backend/matplotlib/_base.py#L27-L28

Added lines #L27 - L28 were not covered by tests


def symbol_to_path(symbol: Symbol):
marker_obj = mmarkers.MarkerStyle(symbol.value)
return marker_obj.get_path().transformed(marker_obj.get_transform())
Expand Down
Loading
Loading