Skip to content

Commit

Permalink
Merge pull request #93 from Carifio24/dot-radius-finite
Browse files Browse the repository at this point in the history
Prevent non-finite dot radius
  • Loading branch information
Carifio24 authored Oct 9, 2024
2 parents 478712c + 272f20c commit 91bd5b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions glue_plotly/common/dotplot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from uuid import uuid4

from numpy import isfinite
from plotly.graph_objs import Scatter

from glue.core import BaseData
Expand All @@ -17,6 +18,8 @@ def dot_radius(viewer, layer_state):
max_diam_world_v = 1
diam_pixel_v = max_diam_world_v * height / abs(viewer_state.y_max - viewer_state.y_min)
diam = min(diam_pixel_v, diam)
if not isfinite(diam):
diam = 1
return diam / 2


Expand Down
14 changes: 13 additions & 1 deletion glue_plotly/common/tests/test_dotplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from glue_qt.viewers.histogram import HistogramViewer

from glue_plotly.common import sanitize
from glue_plotly.common.dotplot import traces_for_layer
from glue_plotly.common.dotplot import dot_radius, traces_for_layer

from glue_plotly.viewers.histogram.viewer import PlotlyHistogramView
from glue_plotly.viewers.histogram.dotplot_layer_artist import PlotlyDotplotLayerArtist
Expand Down Expand Up @@ -76,3 +76,15 @@ def test_basic_dots(self):

assert dots.y == expected_y
assert dots.marker.size == 16 # Default figure is 640x480

def test_dot_radius_defined(self):
"""
This test makes sure that we correctly get the default value for the dot radius
when both axes have no range.
"""
self.viewer.state.x_min = 1
self.viewer.state.x_max = 1
self.viewer.state.y_min = 1
self.viewer.state.y_max = 1

assert dot_radius(self.viewer, self.layer.state) == 0.5

0 comments on commit 91bd5b6

Please sign in to comment.