Skip to content

Commit

Permalink
Merge pull request #42 from hanjinliu/vispy-blending
Browse files Browse the repository at this point in the history
Fix vispy blending
  • Loading branch information
hanjinliu authored Mar 8, 2024
2 parents 056ad7a + 4b755bc commit 1bc0a45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/test_canvas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pathlib import Path
import tempfile
import numpy as np
Expand Down Expand Up @@ -324,4 +325,5 @@ def test_screenshot(backend: str):
backend += ":qt"
canvas = new_canvas(backend=backend)
canvas.add_line([0, 1, 2], [0, 1, 2], name="line")
canvas._repr_png_()
if sys.platform != "win32": # NOTE: testing in GitHub Actions fails for some reason
canvas._repr_png_()
4 changes: 3 additions & 1 deletion whitecanvas/backend/vispy/_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Axis(scene.AxisWidget):
axis: AxisVisual

def __init__(self, canvas: Canvas, dim: int, **kwargs):
kwargs.setdefault("axis_width", 2)
kwargs.setdefault("tick_width", 1)
super().__init__(**kwargs)
self.unfreeze()
self._dim = dim
Expand Down Expand Up @@ -152,7 +154,7 @@ def _plt_set_visible(self, visible: bool):
def _plt_get_size(self) -> float:
return self._text.font_size

def _plt_set_size(self, size: str):
def _plt_set_size(self, size: float):
self._text.font_size = size

def _plt_get_fontfamily(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion whitecanvas/backend/vispy/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(
self._mesh.set_gl_state(
polygon_offset_fill=True,
polygon_offset=(1, 1),
cull_face=False,
)
self.freeze()

Expand Down
8 changes: 7 additions & 1 deletion whitecanvas/backend/vispy/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ def _plt_set_aspect_ratio(self, ratio: float | None):
self._camera.aspect = ratio

def _plt_add_layer(self, layer: visuals.visuals.Visual):
layer.set_gl_state("opaque", depth_test=False)
layer.set_gl_state(
depth_test=False,
cull_face=False,
blend=True,
blend_func=("src_alpha", "one_minus_src_alpha", "one", "one"),
blend_equation="func_add",
)
layer.parent = self._viewbox.scene

def _plt_remove_layer(self, layer):
Expand Down

0 comments on commit 1bc0a45

Please sign in to comment.