-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Carifio24/histogram-viewer-gaps
Histogram viewer gaps and axis label fix
- Loading branch information
Showing
6 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from glue.viewers.histogram.state import DDCProperty, HistogramViewerState | ||
|
||
|
||
__all__ = ["PlotlyHistogramViewerState"] | ||
|
||
|
||
class PlotlyHistogramViewerState(HistogramViewerState): | ||
|
||
gaps = DDCProperty(False, docstring='Whether to include gaps between histogram bars') | ||
gap_fraction = DDCProperty(0.15, | ||
docstring='The gap fraction if using gaps. For example, ' | ||
'0 means that no gap between bars, 0.5 means ' | ||
'that the bars and gaps are evenly sized, and 1 ' | ||
'means that the entire bar mark is gap.') | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from glue.core import Data | ||
from glue_jupyter import JupyterApplication | ||
from plotly.graph_objects import Bar | ||
|
||
from glue_plotly.common import DEFAULT_FONT | ||
from glue_plotly.viewers.histogram import PlotlyHistogramView | ||
|
||
|
||
class TestHistogramViewer: | ||
|
||
def setup_method(self, method): | ||
self.data = Data(label="histogram", x=[1, 1, 1, 2, 2, 3, 3, 3, 4, 6, 6]) | ||
self.app = JupyterApplication() | ||
self.app.session.data_collection.append(self.data) | ||
self.viewer = self.app.new_data_viewer(PlotlyHistogramView) | ||
self.viewer.add_data(self.data) | ||
|
||
viewer_state = self.viewer.state | ||
viewer_state.x_min = 0.5 | ||
viewer_state.hist_x_min = 0.5 | ||
viewer_state.x_max = 6.5 | ||
viewer_state.hist_x_max = 6.5 | ||
viewer_state.hist_n_bin = 6 | ||
viewer_state.y_min = 0 | ||
viewer_state.y_max = 5 | ||
viewer_state.x_axislabel = 'X Axis' | ||
viewer_state.y_axislabel = 'Y Axis' | ||
viewer_state.normalize = False | ||
|
||
self.layer = self.viewer.layers[0] | ||
self.layer.state.color = "#abcdef" | ||
self.layer.state.alpha = 0.75 | ||
|
||
def teardown_method(self, method): | ||
self.viewer = None | ||
self.app = None | ||
|
||
def test_basic(self): | ||
assert len(self.viewer.layers) == 1 | ||
traces = list(self.layer.traces()) | ||
assert len(traces) == 1 | ||
bars = traces[0] | ||
assert isinstance(bars, Bar) | ||
assert bars.marker.color == "#abcdef" | ||
assert bars.marker.opacity == 0.75 | ||
assert bars.x == tuple(range(1, 7)) | ||
expected_y = [3, 2, 3, 1, 0, 2] | ||
assert all(a == b for a, b in zip(bars.y, expected_y)) | ||
|
||
def test_axes(self): | ||
x_axis = self.viewer.figure.layout.xaxis | ||
y_axis = self.viewer.figure.layout.yaxis | ||
|
||
assert x_axis.title.text == 'X Axis' | ||
assert y_axis.title.text == 'Y Axis' | ||
assert x_axis.type == 'linear' | ||
assert y_axis.type == 'linear' | ||
|
||
assert x_axis.range == (0.5, 6.5) | ||
assert y_axis.range == (0, 5) | ||
|
||
assert all(f.family == DEFAULT_FONT for f in | ||
(x_axis.title.font, x_axis.tickfont, y_axis.title.font, y_axis.tickfont)) | ||
|
||
common_items = dict(showgrid=False, showline=False, mirror=True, rangemode='normal', | ||
zeroline=False, showspikes=False, showticklabels=True) | ||
for axis in x_axis, y_axis: | ||
assert all(axis[key] == value for key, value in common_items.items()) | ||
|
||
def test_gaps(self): | ||
assert self.viewer.figure.layout.bargap == 0 | ||
self.viewer.state.gaps = True | ||
assert self.viewer.figure.layout.bargap == 0.15 | ||
self.viewer.state.gap_fraction = 0.36 | ||
assert self.viewer.figure.layout.bargap == 0.36 | ||
self.viewer.state.gaps = False | ||
assert self.viewer.figure.layout.bargap == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters