Skip to content

Commit 7b4c687

Browse files
authored
fix linear and linear region selectors offset when parent is None (#945)
1 parent f1db32f commit 7b4c687

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

fastplotlib/graphics/selectors/_linear.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,13 @@ def __init__(
183183
world_object.add(line_outer)
184184
world_object.add(line_inner)
185185

186-
if axis == "x":
187-
offset = (parent.offset[0], 0, 0)
188-
elif axis == "y":
189-
offset = (0, parent.offset[1], 0)
186+
if parent is None:
187+
offset = (0, 0, 0)
188+
else:
189+
if axis == "x":
190+
offset = (parent.offset[0], 0, 0)
191+
elif axis == "y":
192+
offset = (0, parent.offset[1], 0)
190193

191194
# init base selector
192195
BaseSelector.__init__(

fastplotlib/graphics/selectors/_linear_region.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ def __init__(
277277
outer_edges = (line0_outer, line1_outer)
278278
group.add(*edges, *outer_edges)
279279

280-
# TODO: if parent offset changes, we should set the selector offset too, use offset evented property
281-
# TODO: add check if parent is `None`, will throw error otherwise
282-
if axis == "x":
283-
offset = (parent.offset[0], center + parent.offset[1], 0)
284-
elif axis == "y":
285-
offset = (center + parent.offset[1], parent.offset[1], 0)
280+
if parent is None:
281+
offset = (0, 0, 0)
282+
else:
283+
# TODO: if parent offset changes, we should set the selector offset too, use offset evented property
284+
# TODO: add check if parent is `None`, will throw error otherwise
285+
if axis == "x":
286+
offset = (parent.offset[0], center + parent.offset[1], 0)
287+
elif axis == "y":
288+
offset = (center + parent.offset[1], parent.offset[1], 0)
286289

287290
# set the initial bounds of the selector
288291
# compensate for any offset from the parent graphic

0 commit comments

Comments
 (0)