Skip to content

Commit

Permalink
Renamed log_x/y to x/y_log
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Apr 19, 2017
1 parent 58c25f3 commit 8e401ec
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions glue/plugins/exporters/plotly/export_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ def export_histogram(viewer):

xlabel = att.label
xmin, xmax = viewer.state.x_min, viewer.state.x_max
if viewer.state.log_x:
if viewer.state.x_log:
xlabel = 'Log ' + xlabel
xmin = np.log10(xmin)
xmax = np.log10(xmax)
xaxis = _axis(lo=xmin, hi=xmax, title=xlabel)
yaxis = _axis(log=viewer.state.log_y, lo=0 if not viewer.state.log_y else 1e-3,
yaxis = _axis(log=viewer.state.y_log, lo=0 if not viewer.state.y_log else 1e-3,
hi=ymax * 1.05)

return traces, xaxis, yaxis
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/common/mpl_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class MatplotlibDataViewerState(State):
y_min = DeferredDrawCallbackProperty()
y_max = DeferredDrawCallbackProperty()

log_x = DeferredDrawCallbackProperty(False)
log_y = DeferredDrawCallbackProperty(False)
x_log = DeferredDrawCallbackProperty(False)
y_log = DeferredDrawCallbackProperty(False)

layers = ListCallbackProperty()

Expand Down
12 changes: 6 additions & 6 deletions glue/viewers/common/qt/mpl_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(self, session, parent=None):
self.axes.callbacks.connect('xlim_changed', nonpartial(self.limits_from_mpl))
self.axes.callbacks.connect('ylim_changed', nonpartial(self.limits_from_mpl))

self.state.add_callback('log_x', nonpartial(self.update_log_x))
self.state.add_callback('log_y', nonpartial(self.update_log_y))
self.state.add_callback('x_log', nonpartial(self.update_x_log))
self.state.add_callback('y_log', nonpartial(self.update_y_log))

self.axes.set_autoscale_on(False)

Expand Down Expand Up @@ -80,11 +80,11 @@ def _sync_layer_artist_container(self):
if layer_artist.layer not in layer_states:
self._layer_artist_container.remove(layer_artist)

def update_log_x(self):
self.axes.set_xscale('log' if self.state.log_x else 'linear')
def update_x_log(self):
self.axes.set_xscale('log' if self.state.x_log else 'linear')

def update_log_y(self):
self.axes.set_yscale('log' if self.state.log_y else 'linear')
def update_y_log(self):
self.axes.set_yscale('log' if self.state.y_log else 'linear')

@avoid_circular
def limits_from_mpl(self):
Expand Down
20 changes: 10 additions & 10 deletions glue/viewers/common/qt/tests/test_mpl_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def test_limits_sync(self):
assert axes.get_xscale() == 'linear'
assert axes.get_yscale() == 'linear'

viewer_state.log_x = True
viewer_state.x_log = True

assert axes.get_xlim() == (3, 9)
assert axes.get_ylim() == (-2, 3)
assert axes.get_xscale() == 'log'
assert axes.get_yscale() == 'linear'

viewer_state.log_y = True
viewer_state.y_log = True

# FIXME: the limits for y don't seem right, should be adjusted because of log?
assert axes.get_xlim() == (3, 9)
Expand All @@ -315,35 +315,35 @@ def test_limits_sync(self):
# assert viewer_state.x_max == 9
# assert viewer_state.y_min == -2
# assert viewer_state.y_max == 3
# assert not viewer_state.log_x
# assert viewer_state.log_y
# assert not viewer_state.x_log
# assert viewer_state.y_log
#
axes.set_yscale('linear')
#
# assert viewer_state.x_min == 3
# assert viewer_state.x_max == 9
# assert viewer_state.y_min == -2
# assert viewer_state.y_max == 3
# assert not viewer_state.log_x
# assert not viewer_state.log_y
# assert not viewer_state.x_log
# assert not viewer_state.y_log

axes.set_xlim(-1, 4)

assert viewer_state.x_min == -1
assert viewer_state.x_max == 4
assert viewer_state.y_min == -2
assert viewer_state.y_max == 3
# assert not viewer_state.log_x
# assert not viewer_state.log_y
# assert not viewer_state.x_log
# assert not viewer_state.y_log

axes.set_ylim(5, 6)

assert viewer_state.x_min == -1
assert viewer_state.x_max == 4
assert viewer_state.y_min == 5
assert viewer_state.y_max == 6
# assert not viewer_state.log_x
# assert not viewer_state.log_y
# assert not viewer_state.x_log
# assert not viewer_state.y_log

def test_add_invalid_data(self):
data2 = Data()
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def update_viewer_state(rec, context):
viewer_state['hist_n_bin'] = int(properties['nbins'])
viewer_state['hist_x_min'] = properties['xmin']
viewer_state['hist_x_max'] = properties['xmax']
viewer_state['log_x'] = properties['xlog']
viewer_state['log_y'] = properties['ylog']
viewer_state['x_log'] = properties['xlog']
viewer_state['y_log'] = properties['ylog']
viewer_state['normalize'] = properties['normed']
viewer_state['cumulative'] = properties['cumulative']
viewer_state['x_att'] = properties['component']
Expand Down
12 changes: 6 additions & 6 deletions glue/viewers/histogram/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _calculate_histogram(self):

# For histogram
xmin, xmax = sorted([self._viewer_state.hist_x_min, self._viewer_state.hist_x_max])
if self._viewer_state.log_x:
if self._viewer_state.x_log:
range = None
bins = np.logspace(np.log10(xmin), np.log10(xmax), self._viewer_state.hist_n_bin)
else:
Expand All @@ -88,7 +88,7 @@ def _scale_histogram(self):
elif self._viewer_state.normalize:
self.mpl_hist /= (self.mpl_hist.sum() * dx)

bottom = 0 if not self._viewer_state.log_y else 1e-100
bottom = 0 if not self._viewer_state.y_log else 1e-100

for mpl_artist, y in zip(self.mpl_artists, self.mpl_hist):
mpl_artist.set_height(y)
Expand All @@ -105,7 +105,7 @@ def _scale_histogram(self):

self.state._y_max = self.mpl_hist.max()

if self._viewer_state.log_y:
if self._viewer_state.y_log:
self.state._y_max *= 2
else:
self.state._y_max *= 1.2
Expand All @@ -116,7 +116,7 @@ def _scale_histogram(self):
else:
self._viewer_state.y_max = self.state._y_max

if self._viewer_state.log_y:
if self._viewer_state.y_log:
self._viewer_state.y_min = self.mpl_hist[self.mpl_hist > 0].min() / 10
else:
self._viewer_state.y_min = 0
Expand Down Expand Up @@ -166,11 +166,11 @@ def _update_histogram(self, force=False, **kwargs):
self._last_viewer_state.update(self._viewer_state.as_dict())
self._last_layer_state.update(self.state.as_dict())

if force or any(prop in changed for prop in ('layer', 'x_att', 'hist_x_min', 'hist_x_max', 'hist_n_bin', 'log_x')):
if force or any(prop in changed for prop in ('layer', 'x_att', 'hist_x_min', 'hist_x_max', 'hist_n_bin', 'x_log')):
self._calculate_histogram()
force = True # make sure scaling and visual attributes are updated

if force or any(prop in changed for prop in ('log_y', 'normalize', 'cumulative')):
if force or any(prop in changed for prop in ('y_log', 'normalize', 'cumulative')):
self._scale_histogram()

if force or any(prop in changed for prop in ('alpha', 'color', 'zorder', 'visible')):
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/qt/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HistogramViewer(MatplotlibDataViewer):
def __init__(self, session, parent=None):
super(HistogramViewer, self).__init__(session, parent)
self.state.add_callback('x_att', nonpartial(self._update_axes))
self.state.add_callback('log_x', nonpartial(self._update_axes))
self.state.add_callback('x_log', nonpartial(self._update_axes))
self.state.add_callback('normalize', nonpartial(self._update_axes))

@defer_draw
Expand All @@ -46,7 +46,7 @@ def _update_axes(self):
# Update ticks, which sets the labels to categories if components are categorical
update_ticks(self.axes, 'x', self.state._get_x_components(), False)

if self.state.log_x:
if self.state.x_log:
self.axes.set_xlabel('Log ' + self.state.x_att.label)
else:
self.axes.set_xlabel(self.state.x_att.label)
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/qt/options_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def __init__(self, viewer_state, session, parent=None):
def _update_attribute(self):
# If at least one of the components is categorical, disable log button
log_enabled = not any(comp.categorical for comp in self.viewer_state._get_x_components())
self.ui.bool_log_x.setEnabled(log_enabled)
self.ui.bool_x_log.setEnabled(log_enabled)
if not log_enabled:
self.ui.bool_log_x.setChecked(False)
self.ui.bool_x_log.setChecked(False)

def _update_combo_data(self, *args):
# TODO: what about if only subset and not data is present?
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/qt/options_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<widget class="QLineEdit" name="valuetext_y_min"/>
</item>
<item row="7" column="6">
<widget class="QToolButton" name="bool_log_y">
<widget class="QToolButton" name="bool_y_log">
<property name="text">
<string>log</string>
</property>
Expand Down Expand Up @@ -162,7 +162,7 @@
<widget class="QLineEdit" name="valuetext_y_max"/>
</item>
<item row="1" column="6">
<widget class="QToolButton" name="bool_log_x">
<widget class="QToolButton" name="bool_x_log">
<property name="text">
<string>log</string>
</property>
Expand Down
26 changes: 13 additions & 13 deletions glue/viewers/histogram/qt/tests/test_viewer_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def test_basic(self):
assert not viewer_state.cumulative
assert not viewer_state.normalize

assert not viewer_state.log_x
assert not viewer_state.log_y
assert not viewer_state.x_log
assert not viewer_state.y_log

assert len(viewer_state.layers) == 1

Expand All @@ -92,8 +92,8 @@ def test_basic(self):
assert not viewer_state.cumulative
assert not viewer_state.normalize

assert not viewer_state.log_x
assert not viewer_state.log_y
assert not viewer_state.x_log
assert not viewer_state.y_log

def test_remove_data(self):
self.viewer.add_data(self.data)
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_axes_labels(self):
assert self.viewer.axes.get_xlabel() == 'x'
assert self.viewer.axes.get_ylabel() == 'Number'

viewer_state.log_x = True
viewer_state.x_log = True

assert self.viewer.axes.get_xlabel() == 'Log x'
assert self.viewer.axes.get_ylabel() == 'Number'
Expand Down Expand Up @@ -384,8 +384,8 @@ def test_session_back_compat(self, protocol):
assert_allclose(viewer1.state.hist_x_min, 0)
assert_allclose(viewer1.state.hist_x_max, 9)
assert_allclose(viewer1.state.hist_n_bin, 6)
assert not viewer1.state.log_x
assert not viewer1.state.log_y
assert not viewer1.state.x_log
assert not viewer1.state.y_log
assert viewer1.state.layers[0].visible
assert not viewer1.state.layers[1].visible
assert not viewer1.state.cumulative
Expand All @@ -400,8 +400,8 @@ def test_session_back_compat(self, protocol):
assert_allclose(viewer2.state.hist_x_min, 2)
assert_allclose(viewer2.state.hist_x_max, 16)
assert_allclose(viewer2.state.hist_n_bin, 8)
assert not viewer2.state.log_x
assert not viewer2.state.log_y
assert not viewer2.state.x_log
assert not viewer2.state.y_log
assert viewer2.state.layers[0].visible
assert viewer2.state.layers[1].visible
assert not viewer2.state.cumulative
Expand All @@ -416,8 +416,8 @@ def test_session_back_compat(self, protocol):
assert_allclose(viewer3.state.hist_x_min, 0)
assert_allclose(viewer3.state.hist_x_max, 9)
assert_allclose(viewer3.state.hist_n_bin, 10)
assert not viewer3.state.log_x
assert viewer3.state.log_y
assert not viewer3.state.x_log
assert viewer3.state.y_log
assert viewer3.state.layers[0].visible
assert viewer3.state.layers[1].visible
assert not viewer3.state.cumulative
Expand All @@ -432,8 +432,8 @@ def test_session_back_compat(self, protocol):
assert_allclose(viewer4.state.hist_x_min, -1)
assert_allclose(viewer4.state.hist_x_max, 10)
assert_allclose(viewer4.state.hist_n_bin, 4)
assert not viewer4.state.log_x
assert not viewer4.state.log_y
assert not viewer4.state.x_log
assert not viewer4.state.y_log
assert viewer4.state.layers[0].visible
assert viewer4.state.layers[1].visible
assert viewer4.state.cumulative
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HistogramViewerState(MatplotlibDataViewerState):
def __init__(self, **kwargs):
super(HistogramViewerState, self).__init__(**kwargs)
self.x_att_helper = StateAttributeLimitsHelper(self, 'x_att', lower='x_min',
upper='x_max', log='log_x')
upper='x_max', log='x_log')
self.hist_helper = StateAttributeHistogramHelper(self, 'x_att', lower='hist_x_min',
upper='hist_x_max', n_bin='hist_n_bin')

Expand All @@ -54,7 +54,7 @@ def _get_x_components(self):

@property
def bins(self):
if self.log_x:
if self.x_log:
return np.logspace(np.log10(self.hist_x_min),
np.log10(self.hist_x_max),
self.hist_n_bin + 1)
Expand Down
4 changes: 2 additions & 2 deletions glue/viewers/histogram/tests/test_layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def test_recalc_on_state_changes(self):
assert self.call_counter['_scale_histogram'] == 4

# xlog
self.viewer_state.log_x ^= True
self.viewer_state.x_log ^= True
assert self.call_counter['_calculate_histogram'] == 5
assert self.call_counter['_scale_histogram'] == 5

# ylog -- no call
self.viewer_state.log_y ^= True
self.viewer_state.y_log ^= True
assert self.call_counter['_calculate_histogram'] == 5
assert self.call_counter['_scale_histogram'] == 6

Expand Down

0 comments on commit 8e401ec

Please sign in to comment.