diff --git a/glue_plotly/common/base_3d.py b/glue_plotly/common/base_3d.py index 26c15c4..4130c7d 100644 --- a/glue_plotly/common/base_3d.py +++ b/glue_plotly/common/base_3d.py @@ -59,11 +59,13 @@ def axis(viewer_state, ax): title = getattr(viewer_state, f'{ax}_att').label range = [getattr(viewer_state, f'{ax}_min'), getattr(viewer_state, f'{ax}_max')] return dict( - title=title, - titlefont=dict( - family=DEFAULT_FONT, - size=20, - color=settings.FOREGROUND_COLOR + title=dict( + text=title, + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) ), backgroundcolor=settings.BACKGROUND_COLOR, showspikes=False, diff --git a/glue_plotly/common/common.py b/glue_plotly/common/common.py index b9269d2..0d110f1 100644 --- a/glue_plotly/common/common.py +++ b/glue_plotly/common/common.py @@ -64,11 +64,13 @@ def base_rectilinear_axis(viewer_state, axis): range = [getattr(viewer_state, f'{axis}_min'), getattr(viewer_state, f'{axis}_max')] log = getattr(viewer_state, f'{axis}_log') axis_dict = dict( - title=title, - titlefont=dict( - family=DEFAULT_FONT, - size=2 * axislabel_size, - color=settings.FOREGROUND_COLOR + title=dict( + text=title, + font=dict( + family=DEFAULT_FONT, + size=2 * axislabel_size, + color=settings.FOREGROUND_COLOR + ) ), showspikes=False, linecolor=settings.FOREGROUND_COLOR, diff --git a/glue_plotly/common/image.py b/glue_plotly/common/image.py index a3b47ac..65c04a8 100644 --- a/glue_plotly/common/image.py +++ b/glue_plotly/common/image.py @@ -92,21 +92,25 @@ def axes_data_from_mpl(viewer): if axis == 'b': axis_info.update( - title=viewer.axes.get_xlabel(), - titlefont=dict( - family=DEFAULT_FONT, - size=2 * axes.xaxis.get_label().get_size(), - color=settings.FOREGROUND_COLOR + title=dict( + text=viewer.axes.get_xlabel(), + font=dict( + family=DEFAULT_FONT, + size=2 * axes.xaxis.get_label().get_size(), + color=settings.FOREGROUND_COLOR + ) ) ) axes_data['xaxis'] = axis_info elif axis == 'l': axis_info.update( - title=viewer.axes.get_ylabel(), - titlefont=dict( - family=DEFAULT_FONT, - size=2 * axes.yaxis.get_label().get_size(), - color=settings.FOREGROUND_COLOR + title=dict( + text=viewer.axes.get_ylabel(), + font=dict( + family=DEFAULT_FONT, + size=2 * axes.yaxis.get_label().get_size(), + color=settings.FOREGROUND_COLOR + ) ) ) axes_data['yaxis'] = axis_info diff --git a/glue_plotly/common/tests/test_histogram.py b/glue_plotly/common/tests/test_histogram.py index 8b114d1..ba4180c 100644 --- a/glue_plotly/common/tests/test_histogram.py +++ b/glue_plotly/common/tests/test_histogram.py @@ -67,8 +67,8 @@ def test_axes(self, log_x, log_y): assert common_items.items() <= x_axis.items() assert common_items.items() <= y_axis.items() - assert x_axis['title'] == 'X Axis' - assert y_axis['title'] == 'Y Axis' + assert x_axis['title']['text'] == 'X Axis' + assert y_axis['title']['text'] == 'Y Axis' assert x_axis['type'] == 'log' if log_x else 'linear' assert y_axis['type'] == 'log' if log_y else 'linear' @@ -82,8 +82,8 @@ def test_axes(self, log_x, log_y): assert y_axis['range'] == expected_y_range base_font_dict = dict(family=DEFAULT_FONT, color=settings.FOREGROUND_COLOR) - assert x_axis['titlefont'] == dict(**base_font_dict, size=28) - assert y_axis['titlefont'] == dict(**base_font_dict, size=16) + assert x_axis['title']['font'] == dict(**base_font_dict, size=28) + assert y_axis['title']['font'] == dict(**base_font_dict, size=16) assert x_axis['tickfont'] == dict(**base_font_dict, size=27) assert y_axis['tickfont'] == dict(**base_font_dict, size=30) diff --git a/glue_plotly/common/tests/test_profile.py b/glue_plotly/common/tests/test_profile.py index 9676be8..6a1dee7 100644 --- a/glue_plotly/common/tests/test_profile.py +++ b/glue_plotly/common/tests/test_profile.py @@ -71,8 +71,8 @@ def test_axes(self, log_x, log_y): assert common_items.items() <= x_axis.items() assert common_items.items() <= y_axis.items() - assert x_axis['title'] == 'X Axis' - assert y_axis['title'] == 'Y Axis' + assert x_axis['title']['text'] == 'X Axis' + assert y_axis['title']['text'] == 'Y Axis' assert x_axis['type'] == 'log' if log_x else 'linear' assert y_axis['type'] == 'log' if log_y else 'linear' @@ -86,8 +86,8 @@ def test_axes(self, log_x, log_y): assert y_axis['range'] == expected_y_range base_font_dict = dict(family=DEFAULT_FONT, color=settings.FOREGROUND_COLOR) - assert x_axis['titlefont'] == dict(**base_font_dict, size=30) - assert y_axis['titlefont'] == dict(**base_font_dict, size=20) + assert x_axis['title']['font'] == dict(**base_font_dict, size=30) + assert y_axis['title']['font'] == dict(**base_font_dict, size=20) assert x_axis['tickfont'] == dict(**base_font_dict, size=9) assert y_axis['tickfont'] == dict(**base_font_dict, size=18) diff --git a/glue_plotly/common/tests/test_scatter2d.py b/glue_plotly/common/tests/test_scatter2d.py index 95daf60..33822c8 100644 --- a/glue_plotly/common/tests/test_scatter2d.py +++ b/glue_plotly/common/tests/test_scatter2d.py @@ -88,8 +88,8 @@ def test_axes(self, log_x, log_y): assert common_items.items() <= x_axis.items() assert common_items.items() <= y_axis.items() - assert x_axis['title'] == 'X Axis' - assert y_axis['title'] == 'Y Axis' + assert x_axis['title']['text'] == 'X Axis' + assert y_axis['title']['text'] == 'Y Axis' assert x_axis['type'] == 'log' if log_x else 'linear' assert y_axis['type'] == 'log' if log_y else 'linear' @@ -105,8 +105,8 @@ def test_axes(self, log_x, log_y): assert y_axis['range'] == expected_y_range base_font_dict = dict(family=DEFAULT_FONT, color=settings.FOREGROUND_COLOR) - assert x_axis['titlefont'] == dict(**base_font_dict, size=24) - assert y_axis['titlefont'] == dict(**base_font_dict, size=16) + assert x_axis['title']['font'] == dict(**base_font_dict, size=24) + assert y_axis['title']['font'] == dict(**base_font_dict, size=16) assert x_axis['tickfont'] == dict(**base_font_dict, size=9) assert y_axis['tickfont'] == dict(**base_font_dict, size=18) diff --git a/glue_plotly/web/qt/tests/test_plotly.py b/glue_plotly/web/qt/tests/test_plotly.py index e81ac52..af023dc 100644 --- a/glue_plotly/web/qt/tests/test_plotly.py +++ b/glue_plotly/web/qt/tests/test_plotly.py @@ -1,11 +1,13 @@ from __future__ import absolute_import, division, print_function -from glue_qt.app.application import get_icon import pytest import numpy as np +from glue.config import settings from glue.core import Data, DataCollection +from glue_plotly.common.common import DEFAULT_FONT + pytest.importorskip('qtpy') from glue_qt.app import GlueApplication # noqa: E402 @@ -16,8 +18,6 @@ from ...export_plotly import build_plotly_call # noqa: E402 from ....common.tests.utils import SimpleCoordinates # noqa: E402 -get_icon - class TestPlotly(object): @@ -98,12 +98,35 @@ def test_axes(self): viewer.state.y_max = 4 viewer.state.y_att = self.data.id['y'] + viewer.state.x_axislabel_size = 10 + viewer.state.y_axislabel_size = 15 + args, kwargs = build_plotly_call(self.app) - xaxis = dict(type='log', rangemode='normal', - range=[1, 2], title=viewer.state.x_axislabel, zeroline=False) - yaxis = dict(type='linear', rangemode='normal', - range=[2, 4], title=viewer.state.y_axislabel, zeroline=False) + xaxis = dict(type='log', + rangemode='normal', + range=[1, 2], + title=dict( + text=viewer.state.x_axislabel, + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) + yaxis = dict(type='linear', + rangemode='normal', + range=[2, 4], + title=dict( + text=viewer.state.y_axislabel, + font=dict( + family=DEFAULT_FONT, + size=30, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) layout = args[0]['layout'] for k, v in layout['xaxis'].items(): assert xaxis.get(k, v) == v @@ -186,10 +209,30 @@ def test_scatter_categorical(self): args, kwargs = build_plotly_call(self.app) - xaxis = dict(type='linear', rangemode='normal', - range=[0.92, 3.08], title='x', zeroline=False) - yaxis = dict(type='linear', rangemode='normal', - range=[-0.62, 2.62], title='z', zeroline=False) + xaxis = dict(type='linear', + rangemode='normal', + range=[0.92, 3.08], + title=dict( + text='x', + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) + yaxis = dict(type='linear', + rangemode='normal', + range=[-0.62, 2.62], + title=dict( + text='z', + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) layout = args[0]['layout'] for k, v in layout['xaxis'].items(): assert xaxis.get(k, v) == v @@ -206,10 +249,30 @@ def test_histogram_categorical(self): args, kwargs = build_plotly_call(self.app) - xaxis = dict(type='linear', rangemode='normal', - range=[-0.5, 2.5], title=viewer.state.x_axislabel, zeroline=False) - yaxis = dict(type='linear', rangemode='normal', - range=[0, 1.2], title=viewer.state.y_axislabel, zeroline=False) + xaxis = dict(type='linear', + rangemode='normal', + range=[-0.5, 2.5], + title=dict( + text=viewer.state.x_axislabel, + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) + yaxis = dict(type='linear', + rangemode='normal', + range=[0, 1.2], + title=dict( + text=viewer.state.y_axislabel, + font=dict( + family=DEFAULT_FONT, + size=20, + color=settings.FOREGROUND_COLOR + ) + ), + zeroline=False) layout = args[0]['layout'] for k, v in layout['xaxis'].items(): assert xaxis.get(k, v) == v diff --git a/tox.ini b/tox.ini index f8ddb98..33b3bf4 100644 --- a/tox.ini +++ b/tox.ini @@ -25,6 +25,7 @@ deps = devdeps: git+https://github.com/glue-viz/glue-jupyter devdeps: git+https://github.com/glue-viz/glue-vispy-viewers devdeps: git+https://github.com/plotly/plotly.py/\#subdirectory=packages/python/plotly + devdeps: anywidget # Should be temporary [testenv:codestyle] deps = flake8