def test_theme_options_should_be_merged(): spec = gg.ggplot() + _geom('foo') + theme(axis_tooltip='blank') + theme(legend_position='bottom') expected_theme = { 'axis_tooltip': 'blank', 'legend_position': 'bottom' } assert expected_theme == spec.as_dict()['theme']
def test_global_theme(): gg.LetsPlot.set_theme(theme(axis_tooltip=element_blank())) spec = gg.ggplot() + _geom('foo') assert spec.as_dict()['theme']['axis_tooltip']['blank'] assert isinstance(spec.props()['theme']['axis_tooltip'], dict)
def test_ggsize(): spec = gg.ggplot() + gg.ggsize(5, 10) assert spec.as_dict() == {'data': None, 'mapping': None, 'kind': 'plot', 'ggsize': {'height': 10, 'width': 5}, 'layers': [], 'scales': []}
def test_element_values_merged(): spec = (gg.ggplot() + _geom('foo') + theme(panel_background=element_rect(color='a', fill='b')) + theme(panel_background=element_rect(color='c', size=1))) rect = spec.props()['theme']['panel_background'] assert isinstance(rect, dict) assert 'c' == rect['color'] assert 'b' == rect['fill'] assert 1 == rect['size']
def test_plot_ggtitle(): plot = gg.ggplot() ggtitle = gg.labs(title="New plot title") expect = { 'ggtitle': {'text': 'New plot title'}, 'kind': 'plot', 'data_meta': {}, 'layers': [], 'mapping': {}, 'scales': [] } assert (plot + ggtitle).as_dict() == expect
def test_plot_geom_scale(): geom = _geom('geom') scale = _scale('A') plot = gg.ggplot() expect = { 'kind': 'plot', 'data': None, 'mapping': None, 'layers': [geom.as_dict()], 'scales': [scale.as_dict()] } assert (plot + geom + scale).as_dict() == expect assert (plot + scale + geom).as_dict() == expect assert (plot + (scale + geom)).as_dict() == expect
def test_plot_geom_geom(): geom1 = _geom('geom1') geom2 = _geom('geom2') plot = gg.ggplot() expect = { 'kind': 'plot', 'data': None, 'mapping': None, 'layers': [geom1.as_dict(), geom2.as_dict()], 'scales': [] } assert (plot + geom1 + geom2).as_dict() == expect assert (plot + (geom1 + geom2)).as_dict() == expect assert ((plot + geom1) + geom2).as_dict() == expect
def test_override_theme_None_option_with_value(): spec = gg.ggplot() + _geom('foo') + theme(legend_position=None) + theme(legend_position='bottom') assert 'bottom' == spec.as_dict()['theme']['legend_position']
def test_override_theme_option(): spec = gg.ggplot() + _geom('foo') + theme(legend_position='bottom') + theme(legend_position='none') assert 'none' == spec.as_dict()['theme']['legend_position']
def test_plot_with_dummy(): plot = gg.ggplot() expect = plot.as_dict() assert (plot + DummySpec()).as_dict() == expect assert (DummySpec() + plot).as_dict() == expect
def test_named_theme_overrides_all(): spec = gg.ggplot() + _geom('foo') + theme( legend_position='bottom') + theme_classic() assert 'legend_position' not in spec.as_dict()['theme']
def test_ggplot(args, expected): spec = gg.ggplot(*args) assert spec.as_dict() == expected
def test_overriding_global_theme_with_named(): gg.LetsPlot.set_theme(theme(legend_position='top')) spec = gg.ggplot() + _geom('foo') + theme_classic() assert 'legend_position' not in spec.as_dict()['theme']
def test_global_theme_overriding(): gg.LetsPlot.set_theme(theme(legend_position='bottom')) spec = gg.ggplot() + _geom('foo') + theme(legend_position='top') assert 'top' == spec.as_dict()['theme']['legend_position']
def test_named_theme_is_modified_by_theme(): spec = gg.ggplot() + _geom('foo') + theme_classic() + theme( legend_position='bottom') assert 'bottom' == spec.as_dict()['theme']['legend_position']
def test_None_theme_option_not_override_the_previous(): spec = gg.ggplot() + _geom('foo') + theme(legend_position='bottom') + theme(legend_position=None) assert 'bottom' == spec.as_dict()['theme']['legend_position']
def test_element_blank_in_theme_option(): spec = gg.ggplot() + _geom('foo') + theme(axis_tooltip=element_blank()) assert 'blank' == spec.as_dict()['theme']['axis_tooltip']['name'] assert isinstance(spec.props()['theme']['axis_tooltip'], FeatureSpec)
def test_map_join(args, expected): # ggplot is required - it normalizes map_join on before_append spec = gg.ggplot() + gg.geom_livemap(map_join=args, tooltips=gg.layer_tooltips()) assert spec.as_dict()['layers'][0]['map_join'] == expected