Skip to content

Commit

Permalink
Merge pull request spotify#33 from spotify/fix_datetime_axis_orientation
Browse files Browse the repository at this point in the history
Fix subgroup orientation error that occurs with non-categorical axes
  • Loading branch information
cphalpert authored Nov 21, 2018
2 parents 95cde54 + 02527db commit 41b0d8e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 72 deletions.
11 changes: 9 additions & 2 deletions chartify/_core/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,15 @@ def set_xaxis_tick_orientation(self, orientation='horizontal'):
level_3 = self._convert_subgroup_orientation_labels(level_3)

self._chart.figure.xaxis.major_label_orientation = level_1
self._chart.figure.xaxis.subgroup_label_orientation = level_2
self._chart.figure.xaxis.group_label_orientation = level_3

xaxis = self._chart.figure.xaxis[0]
has_subgroup_label = getattr(xaxis, 'subgroup_label_orientation', None)
if has_subgroup_label is not None:
self._chart.figure.xaxis.subgroup_label_orientation = level_2

has_group_label = getattr(xaxis, 'group_label_orientation', None)
if has_group_label is not None:
self._chart.figure.xaxis.group_label_orientation = level_3
return self._chart


Expand Down
11 changes: 6 additions & 5 deletions chartify/_core/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def _initialize_figure(self, x_axis_type, y_axis_type):
def _add_subtitle_to_figure(self, subtitle_text=None):
"""Create the subtitle glyph and add it to the bokeh figure."""
if subtitle_text is None:
subtitle_text = """ch.set_subtitle('Data Description')"""
if self._blank_labels:
subtitle_text = ""
if self._blank_labels:
subtitle_text = ""
else:
subtitle_text = """ch.set_subtitle('Data Description')"""
subtitle_settings = self.style._get_settings('subtitle')
_subtitle_glyph = bokeh.models.Title(
text=subtitle_text,
Expand All @@ -186,7 +187,7 @@ def _add_source_to_figure(self):
source_font_size = '10px'
_source = bokeh.models.Label(
x=self.style.plot_width * .9,
y=-55,
y=0,
x_units='screen',
y_units='screen',
level='overlay',
Expand All @@ -195,7 +196,7 @@ def _add_source_to_figure(self):
text_font_size=source_font_size,
text_align='right',
name='subtitle')
self.figure.add_layout(_source)
self.figure.add_layout(_source, 'below')
return _source

@property
Expand Down
130 changes: 65 additions & 65 deletions examples/Examples.ipynb

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ def test_xaxis_tick_orientation(self):
assert ch.figure.yaxis[0].major_label_orientation == 'horizontal'
assert ch.figure.yaxis[0].subgroup_label_orientation == 'normal'
assert ch.figure.yaxis[0].group_label_orientation == 'normal'

quantity_by_date = data.groupby('date')['quantity'].sum().reset_index()
ch = chartify.Chart(x_axis_type='datetime')
ch.plot.line(quantity_by_date, 'date', 'quantity')
assert ch.figure.xaxis[0].major_label_orientation == 'horizontal'

ch.axes.set_xaxis_tick_orientation('vertical')
assert np.allclose(ch.figure.xaxis[0].major_label_orientation,
1.5707963267948966)

0 comments on commit 41b0d8e

Please sign in to comment.