1+ from glue_jupyter import JupyterApplication
12from numpy import unique
23from plotly .graph_objs import Scatter
34
67from glue_qt .viewers .histogram import HistogramViewer
78
89from glue_plotly .common import sanitize
9- from glue_plotly .common .dotplot import dot_radius , traces_for_layer
10+ from glue_plotly .common .dotplot import dot_size , traces_for_layer
1011
1112from glue_plotly .viewers .histogram .viewer import PlotlyHistogramView
1213from glue_plotly .viewers .histogram .dotplot_layer_artist import PlotlyDotplotLayerArtist
@@ -16,9 +17,89 @@ class SimpleDotplotViewer(PlotlyHistogramView):
1617 _data_artist_cls = PlotlyDotplotLayerArtist
1718 _subset_artist_cls = PlotlyDotplotLayerArtist
1819
20+ def close (self , warn = False ):
21+ self .figure .close ()
22+
1923
2024class TestDotplot :
2125
26+ def setup_method (self , method ):
27+ x = [86 , 86 , 76 , 78 , 93 , 100 , 90 , 87 , 73 , 61 , 71 , 68 , 78 ,
28+ 9 , 87 , 32 , 34 , 2 , 57 , 79 , 48 , 5 , 8 , 19 , 7 , 78 ,
29+ 16 , 15 , 58 , 34 , 20 , 63 , 96 , 97 , 86 , 92 , 35 , 59 , 75 ,
30+ 0 , 53 , 45 , 59 , 74 , 59 , 4 , 69 , 76 , 97 , 77 , 24 , 99 ,
31+ 50 , 6 , 1 , 55 , 13 , 40 , 27 , 17 , 92 , 72 , 40 , 29 , 64 ,
32+ 38 , 77 , 11 , 91 , 23 , 59 , 92 , 5 , 88 , 15 , 90 , 40 , 100 ,
33+ 47 , 28 , 3 , 44 , 89 , 75 , 13 , 94 , 95 , 43 , 17 , 88 , 6 ,
34+ 94 , 100 , 28 , 45 , 36 , 63 , 14 , 90 , 66 ]
35+ self .data = Data (label = "dotplot" , x = x )
36+ self .app = JupyterApplication ()
37+ self .app .session .data_collection .append (self .data )
38+ self .viewer = self .app .new_data_viewer (SimpleDotplotViewer )
39+ self .viewer .add_data (self .data )
40+ self .mask , self .sanitized = sanitize (self .data ['x' ])
41+
42+ viewer_state = self .viewer .state
43+ viewer_state .hist_n_bin = 18
44+ viewer_state .x_axislabel_size = 14
45+ viewer_state .y_axislabel_size = 8
46+ viewer_state .x_ticklabel_size = 18
47+ viewer_state .y_ticklabel_size = 20
48+ viewer_state .x_min = 0
49+ viewer_state .x_max = 100
50+ viewer_state .y_min = 0
51+ viewer_state .y_max = 15
52+ viewer_state .x_axislabel = 'X Axis'
53+ viewer_state .y_axislabel = 'Y Axis'
54+
55+ self .layer = self .viewer .layers [0 ]
56+ self .layer .state .color = '#0e1dab'
57+ self .layer .state .alpha = 0.85
58+
59+ def teardown_method (self , method ):
60+ self .viewer .close (warn = False )
61+ self .viewer = None
62+ self .app = None
63+
64+ def test_basic_dots (self ):
65+ traces = traces_for_layer (self .viewer , self .layer .state )
66+ assert len (traces ) == 1
67+ dots = traces [0 ]
68+ assert isinstance (dots , Scatter )
69+
70+ assert len (unique (dots .x )) == 18
71+ expected_y = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2 , 3 , 4 , 5 , 6 , 1 ,
72+ 2 , 3 , 4 , 5 , 6 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 ,
73+ 3 , 4 , 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 , 1 , 2 ,
74+ 3 , 4 , 5 , 1 , 2 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2 ,
75+ 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
76+ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2 , 3 ,
77+ 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 1 , 2 , 3 , 4 , 5 ,
78+ 6 , 7 , 8 )
79+
80+ assert dots .y == expected_y
81+
82+ # Default figure is 900x600, with margins of 50 on each side
83+ width = 900 - 50 - 50
84+ height = 600 - 50 - 50
85+ diam = 0.95 * min (height / 15 , width / 18 )
86+ assert dots .marker .size == diam
87+
88+ def test_dot_radius_defined (self ):
89+ """
90+ This test makes sure that we correctly get the default value for the dot radius
91+ when both axes have no range.
92+ """
93+ self .viewer .state .x_min = 1
94+ self .viewer .state .x_max = 1
95+ self .viewer .state .y_min = 1
96+ self .viewer .state .y_max = 1
97+
98+ assert dot_size (self .viewer , self .layer .state ) == 0.95
99+
100+
101+ class TestDotsHistogram :
102+
22103 def setup_method (self , method ):
23104 x = [86 , 86 , 76 , 78 , 93 , 100 , 90 , 87 , 73 , 61 , 71 , 68 , 78 ,
24105 9 , 87 , 32 , 34 , 2 , 57 , 79 , 48 , 5 , 8 , 19 , 7 , 78 ,
@@ -75,7 +156,12 @@ def test_basic_dots(self):
75156 6 , 7 , 8 )
76157
77158 assert dots .y == expected_y
78- assert dots .marker .size == 16 # Default figure is 640x480
159+
160+ # Default figure is 640x480
161+ width = 640
162+ height = 480
163+ diam = 0.95 * min (height / 15 , width / 18 )
164+ assert dots .marker .size == diam
79165
80166 def test_dot_radius_defined (self ):
81167 """
@@ -87,4 +173,4 @@ def test_dot_radius_defined(self):
87173 self .viewer .state .y_min = 1
88174 self .viewer .state .y_max = 1
89175
90- assert dot_radius (self .viewer , self .layer .state ) == 0.5
176+ assert dot_size (self .viewer , self .layer .state ) == 0.95
0 commit comments