Skip to content

Commit

Permalink
make public and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Jul 2, 2024
1 parent 6d86fc1 commit 21e6ac5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 7 additions & 4 deletions holonote/annotate/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ class AnnotationDisplay(param.Parameterized):

data = param.DataFrame(doc="Combined dataframe of annotation data", constant=True)

_nearest_2d_point_threshold = param.Number(
default=1,
nearest_2d_point_threshold = param.Number(
default=None,
bounds=(0, None),
doc="""
Threshold In the distance in data coordinates between the two dimensions;
it does not consider the unit and magnitude differences between the dimensions
for selecting an existing 2D point; anything over this threshold will create
a new point instead.
a new point instead. This parameter is experimental and is subject to change.
""",
)

Expand Down Expand Up @@ -445,7 +445,10 @@ def get_indices_by_position(self, **inputs) -> list[Any]:
xdist = (df[f"point[{xk}]"] - inputs[xk]) ** 2
ydist = (df[f"point[{yk}]"] - inputs[yk]) ** 2
distance_squared = xdist + ydist
if (distance_squared > self._nearest_2d_point_threshold**2).all():
if (
self.nearest_2d_point_threshold
and (distance_squared > self.nearest_2d_point_threshold**2).all()
):
return []
out = [df.loc[distance_squared.idxmin()].name] # index == name of series
elif "point" in self.region_format:
Expand Down
18 changes: 16 additions & 2 deletions holonote/tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ def test_get_indices_by_position_exact(self, annotator_point2d):

def test_get_indices_by_position_nearest_2d_point_threshold(self, annotator_point2d):
x, y = 0.5, 0.3
annotator_point2d.get_display("x", "y").nearest_2d_point_threshold = 1
description = "A test annotation!"
annotator_point2d.set_regions(x=x, y=y)
annotator_point2d.add_annotation(description=description)
display = annotator_point2d.get_display("x", "y")
indices = display.get_indices_by_position(x=x + 1.5, y=y + 1.5)
assert len(indices) == 0

display._nearest_2d_point_threshold = 5
display.nearest_2d_point_threshold = 5
indices = display.get_indices_by_position(x=x + 0.5, y=y + 0.5)
assert len(indices) == 1

def test_get_indices_by_position_nearest(self, annotator_point2d):
x, y = 0.5, 0.3
description = "A test annotation!"
annotator_point2d.set_regions(x=x, y=y)
annotator_point2d.add_annotation(description=description)
display = annotator_point2d.get_display("x", "y")
indices = display.get_indices_by_position(x=x + 1.5, y=y + 1.5)
assert len(indices) == 1

display.nearest_2d_point_threshold = 5
indices = display.get_indices_by_position(x=x + 0.5, y=y + 0.5)
assert len(indices) == 1

Expand All @@ -48,7 +62,7 @@ def test_get_indices_by_position_multi_choice(self, annotator_point2d):
annotator_point2d.add_annotation(description=description)

display = annotator_point2d.get_display("x", "y")
display._nearest_2d_point_threshold = 1000
display.nearest_2d_point_threshold = 1000

indices = display.get_indices_by_position(x=x, y=y)
assert len(indices) == 1

0 comments on commit 21e6ac5

Please sign in to comment.