Skip to content

Commit 97a5680

Browse files
committed
hacky way to ignore LineSlider in PlotArea.auto_scale()
1 parent 035430f commit 97a5680

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pygfx import TransformGizmo, Color
77
from ipywidgets import IntSlider
88

9-
from ..graphics._base import Graphic
9+
from ._base import Graphic
1010

1111

1212
class LineSlider(Graphic):

fastplotlib/layouts/_base.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from wgpu.gui.auto import WgpuCanvas
55
from warnings import warn
66
from ..graphics._base import Graphic
7+
from ..graphics.line_slider import LineSlider
78
from typing import *
89

910

@@ -49,6 +50,9 @@ def __init__(
4950

5051
self._graphics: List[Graphic] = list()
5152

53+
# hacky workaround for now to exclude from bbox calculations
54+
self._sliders: List[LineSlider] = list()
55+
5256
self.name = name
5357

5458
# need to think about how to deal with children better
@@ -124,6 +128,11 @@ def add_graphic(self, graphic: Graphic, center: bool = True):
124128
Center the camera on the newly added Graphic
125129
126130
"""
131+
if not isinstance(graphic, Graphic):
132+
raise TypeError(
133+
f"Can only add Graphic types to a PlotArea, you have passed a: {type(graphic)}"
134+
)
135+
127136
if graphic.name is not None: # skip for those that have no name
128137
graphic_names = list()
129138

@@ -133,12 +142,19 @@ def add_graphic(self, graphic: Graphic, center: bool = True):
133142
if graphic.name in graphic_names:
134143
raise ValueError(f"graphics must have unique names, current graphic names are:\n {graphic_names}")
135144

136-
self._graphics.append(graphic)
145+
if isinstance(graphic, LineSlider):
146+
self._sliders.append(graphic)
147+
else:
148+
self._graphics.append(graphic)
149+
137150
self.scene.add(graphic.world_object)
138151

139152
if center:
140153
self.center_graphic(graphic)
141154

155+
# if hasattr(graphic, "_add_plot_area_hook"):
156+
# graphic._add_plot_area_hook(self.viewport, self.camera)
157+
142158
def _refresh_camera(self):
143159
self.controller.update_camera(self.camera)
144160
if sum(self.renderer.logical_size) > 0:
@@ -214,8 +230,15 @@ def auto_scale(self, maintain_aspect: bool = False, zoom: float = 0.8):
214230
maintain_aspect = False # assume False
215231
self.camera.maintain_aspect = maintain_aspect
216232

233+
# hacky workaround for now until I figure out how to put it in its own scene
234+
for slider in self._sliders:
235+
self.scene.remove(slider.world_object)
236+
217237
width, height, depth = np.ptp(self.scene.get_world_bounding_box(), axis=0)
218238

239+
for slider in self._sliders:
240+
self.scene.add(slider.world_object)
241+
219242
self.camera.width = width
220243
self.camera.height = height
221244

0 commit comments

Comments
 (0)