Skip to content

Commit 91bd5b6

Browse files
authored
Merge pull request #93 from Carifio24/dot-radius-finite
Prevent non-finite dot radius
2 parents 478712c + 272f20c commit 91bd5b6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

glue_plotly/common/dotplot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from uuid import uuid4
22

3+
from numpy import isfinite
34
from plotly.graph_objs import Scatter
45

56
from glue.core import BaseData
@@ -17,6 +18,8 @@ def dot_radius(viewer, layer_state):
1718
max_diam_world_v = 1
1819
diam_pixel_v = max_diam_world_v * height / abs(viewer_state.y_max - viewer_state.y_min)
1920
diam = min(diam_pixel_v, diam)
21+
if not isfinite(diam):
22+
diam = 1
2023
return diam / 2
2124

2225

glue_plotly/common/tests/test_dotplot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from glue_qt.viewers.histogram import HistogramViewer
77

88
from glue_plotly.common import sanitize
9-
from glue_plotly.common.dotplot import traces_for_layer
9+
from glue_plotly.common.dotplot import dot_radius, traces_for_layer
1010

1111
from glue_plotly.viewers.histogram.viewer import PlotlyHistogramView
1212
from glue_plotly.viewers.histogram.dotplot_layer_artist import PlotlyDotplotLayerArtist
@@ -76,3 +76,15 @@ def test_basic_dots(self):
7676

7777
assert dots.y == expected_y
7878
assert dots.marker.size == 16 # Default figure is 640x480
79+
80+
def test_dot_radius_defined(self):
81+
"""
82+
This test makes sure that we correctly get the default value for the dot radius
83+
when both axes have no range.
84+
"""
85+
self.viewer.state.x_min = 1
86+
self.viewer.state.x_max = 1
87+
self.viewer.state.y_min = 1
88+
self.viewer.state.y_max = 1
89+
90+
assert dot_radius(self.viewer, self.layer.state) == 0.5

0 commit comments

Comments
 (0)