def test_apply_options_when_backend_switched(self):
     obj = TestObj([])
     Store.current_backend = 'backend_2'
     obj.opts(style_opt1='A', plot_opt1='B')
     Store.current_backend = 'backend_1'
     obj.opts(style_opt1='C', plot_opt1='D', backend='backend_2')
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'D'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'C'}
    def test_overlay_options_complete(self):
        """
        Complete specification style.
        """
        data = [zip(range(10), range(10)), zip(range(5), range(5))]
        o = Overlay([Curve(c) for c in data])({"Curve.Curve": {"plot": {"show_grid": True}, "style": {"color": "b"}}})

        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "plot").kwargs["show_grid"], True)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "plot").kwargs["show_grid"], True)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "style").kwargs["color"], "b")
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "style").kwargs["color"], "b")
 def test_apply_options_explicit_backend_persists_other_backend_inverted(self):
     obj = TestObj([])
     obj.opts(style_opt1='A', plot_opt1='B', backend='backend_2')
     obj.opts(style_opt1='C', plot_opt1='D', backend='backend_1')
     plot_opts = Store.lookup_options('backend_1', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'D'}
     style_opts = Store.lookup_options('backend_1', obj, 'style')
     assert style_opts.options == {'style_opt1': 'C'}
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
    def test_overlay_options_partitioned(self):
        """
        The new style introduced in #73
        """
        data = [zip(range(10), range(10)), zip(range(5), range(5))]
        o = Overlay([Curve(c) for c in data])(
            dict(plot={"Curve.Curve": {"show_grid": False}}, style={"Curve.Curve": {"color": "k"}})
        )

        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "plot").kwargs["show_grid"], False)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "plot").kwargs["show_grid"], False)
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.I, "style").kwargs["color"], "k")
        self.assertEqual(Store.lookup_options("matplotlib", o.Curve.II, "style").kwargs["color"], "k")
Exemple #5
0
 def test_dynamic_opts_link_inputs(self):
     stream = LinkedStream()
     inputs = [DynamicMap(lambda: None, streams=[stream])]
     dmap = DynamicMap(Callable(lambda X: TestObj(None), inputs=inputs),
                       kdims=['X']).redim.range(X=(0,10))
     styled_dmap = dmap.options(plot_opt1='red', clone=False)
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})
     self.assertIs(styled_dmap, dmap)
     self.assertTrue(dmap.callback.link_inputs)
     unstyled_dmap = dmap.callback.inputs[0].callback.inputs[0]
     opts = Store.lookup_options('backend_1', unstyled_dmap[0], 'plot')
     self.assertEqual(opts.options, {})
     original_dmap = unstyled_dmap.callback.inputs[0]
     self.assertIs(stream, original_dmap.streams[0])
 def test_layout_options_short_style(self):
     """
     Short __call__ syntax.
     """
     im = Image(np.random.rand(10, 10))
     layout = (im + im)({"Layout": dict(plot={"hspace": 5})})
     self.assertEqual(Store.lookup_options("matplotlib", layout, "plot").kwargs["hspace"], 5)
 def test_layout_options_long_style(self):
     """
     The old (longer) syntax in __call__
     """
     im = Image(np.random.rand(10, 10))
     layout = (im + im)({"Layout": dict(plot={"hspace": 10})})
     self.assertEqual(Store.lookup_options("matplotlib", layout, "plot").kwargs["hspace"], 10)
 def test_layout_options_short_style(self):
     """
     Short __call__ syntax.
     """
     im = Image(np.random.rand(10,10))
     layout = (im + im)({'Layout':dict(plot={'hspace':5})})
     self.assertEqual(Store.lookup_options(
         layout, 'plot').kwargs['hspace'], 5)
 def test_layout_options_long_style(self):
     """
     The old (longer) syntax in __call__
     """
     im = Image(np.random.rand(10,10))
     layout = (im + im)({'Layout':dict(plot={'hspace':10})})
     self.assertEqual(Store.lookup_options(
         layout, 'plot').kwargs['hspace'], 10)
    def test_overlay_options_partitioned(self):
        """
        The new style introduced in #73
        """
        data = [zip(range(10),range(10)), zip(range(5),range(5))]
        o = Overlay([Curve(c) for c in data])(
            dict(plot={'Curve.Curve':{'show_grid':False}},
                 style={'Curve.Curve':{'color':'k'}}))

        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'plot').kwargs['show_grid'], False)
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'plot').kwargs['show_grid'], False)
        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'style').kwargs['color'], 'k')
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'style').kwargs['color'], 'k')
    def test_overlay_options_complete(self):
        """
        Complete specification style.
        """
        data = [zip(range(10),range(10)), zip(range(5),range(5))]
        o = Overlay([Curve(c) for c in data])(
            {'Curve.Curve':{'plot':{'show_grid':True},
                            'style':{'color':'b'}}})

        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'plot').kwargs['show_grid'], True)
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'plot').kwargs['show_grid'], True)
        self.assertEqual(Store.lookup_options(
            o.Curve.I, 'style').kwargs['color'], 'b')
        self.assertEqual(Store.lookup_options(
            o.Curve.II, 'style').kwargs['color'], 'b')
Exemple #12
0
    def test_cell_opts_plot(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image [show_title=False]", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options, "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options(self.get_object('mat1'), 'plot').options.get('show_title',True),False)
Exemple #13
0
    def test_cell_opts_norm(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image {+axiswise}", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options, "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options(self.get_object('mat1'), 'norm').options.get('axiswise',True), True)
Exemple #14
0
    def test_cell_opts_style(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image (cmap='hot')", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options, "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options(self.get_object('mat1'), 'style').options.get('cmap',None),'hot')
Exemple #15
0
    def test_cell_opts_style_dynamic(self):

        self.cell("dmap = DynamicMap(lambda X: Curve(np.random.rand(5,2), name='dmap'), kdims=['x'])"
                  ".redim.range(x=(0, 10)).opts(style={'Curve': dict(linewidth=2, color='black')})")

        self.assertEqual(self.get_object('dmap').id, None)
        self.cell_magic('opts', " Curve (linewidth=3 alpha=0.5)", 'dmap')
        self.assertEqual(self.get_object('dmap').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        opts = Store.lookup_options('matplotlib', self.get_object('dmap')[0], 'style').options
        self.assertEqual(opts, {'linewidth': 3, 'alpha': 0.5, 'color': 'black'})
Exemple #16
0
    def test_cell_opts_plot_float_division(self):

        self.cell("mat1 = Image(np.random.rand(5,5), name='mat1')")

        self.assertEqual(self.get_object('mat1').id, None)
        self.cell_magic('opts', " Image [aspect=3/4]", 'mat1')
        self.assertEqual(self.get_object('mat1').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 self.get_object('mat1'), 'plot').options.get('aspect',False), 3/4.0)
Exemple #17
0
    def test_cell_opts_plot_dynamic(self):

        self.cell("dmap = DynamicMap(lambda X: Image(np.random.rand(5,5), name='dmap'), kdims=['x'])"
                  ".redim.range(x=(0, 10)).opts(plot={'Image': dict(xaxis='top', xticks=3)})")

        self.assertEqual(self.get_object('dmap').id, None)
        self.cell_magic('opts', " Image [xaxis=None yaxis='right']", 'dmap')
        self.assertEqual(self.get_object('dmap').id, 0)

        assert 0 in Store.custom_options(), "Custom OptionTree creation failed"
        opts = Store.lookup_options('matplotlib', self.get_object('dmap')[0], 'plot').options
        self.assertEqual(opts, {'xticks': 3, 'xaxis': None, 'yaxis': 'right'})
 def test_distribution_composite_transfer_opts_with_group(self):
     dist = Distribution(np.array([0, 1, 2]), group='Test').opts(style=dict(color='red'))
     area = Compositor.collapse_element(dist, backend='matplotlib')
     opts = Store.lookup_options('matplotlib', area, 'style').kwargs
     self.assertEqual(opts.get('color', None), 'red')
Exemple #19
0
 def test_dynamic_options_no_clone(self):
     dmap = DynamicMap(lambda X: TestObj(None), kdims=['X']).redim.range(X=(0,10))
     dmap.options(plot_opt1='red', clone=False)
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})
Exemple #20
0
 def test_apply_options_explicit_backend_style_multiple(self):
     obj = TestObj([]).options(style_opt1='A',
                               style_opt2='B',
                               backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'style')
     assert opts.options == {'style_opt1': 'A', 'style_opt2': 'B'}
Exemple #21
0
 def test_apply_options_explicit_backend_plot(self):
     obj = TestObj([]).options(plot_opt1='A', backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A'}
Exemple #22
0
    def _update_layout(self):
        from holoviews.core.options import Store

        loc = self.widget_location
        if not len(self.widget_box):
            widgets = []
        elif loc in ('left', 'right'):
            widgets = Column(VSpacer(), self.widget_box, VSpacer())
        elif loc in ('top', 'bottom'):
            widgets = Row(HSpacer(), self.widget_box, HSpacer())
        elif loc in ('top_left', 'bottom_left'):
            widgets = Row(self.widget_box, HSpacer())
        elif loc in ('top_right', 'bottom_right'):
            widgets = Row(HSpacer(), self.widget_box)
        elif loc in ('left_top', 'right_top'):
            widgets = Column(self.widget_box, VSpacer())
        elif loc in ('left_bottom', 'right_bottom'):
            widgets = Column(VSpacer(), self.widget_box)

        # Do not center if content is responsive
        backend = self.backend or Store.current_backend
        if self.object is None:
            opts = {}
        else:
            try:
                opts = Store.lookup_options(backend, self.object,
                                            'plot').kwargs
            except KeyError:
                opts = {}
        responsive_modes = ('stretch_width', 'stretch_both', 'scale_width',
                            'scale_both')
        center = self.center
        if ((opts.get('responsive')
             and not (opts.get('width') or opts.get('frame_width')))
                or opts.get('sizing_mode') in responsive_modes):
            center = False

        self._widget_container = widgets
        if not widgets:
            if center:
                components = [HSpacer(), self, HSpacer()]
            else:
                components = [self]
        elif center:
            if loc.startswith('left'):
                components = [widgets, HSpacer(), self, HSpacer()]
            elif loc.startswith('right'):
                components = [HSpacer(), self, HSpacer(), widgets]
            elif loc.startswith('top'):
                components = [
                    HSpacer(),
                    Column(widgets, Row(HSpacer(), self, HSpacer())),
                    HSpacer()
                ]
            elif loc.startswith('bottom'):
                components = [
                    HSpacer(),
                    Column(Row(HSpacer(), self, HSpacer()), widgets),
                    HSpacer()
                ]
        else:
            if loc.startswith('left'):
                components = [widgets, self]
            elif loc.startswith('right'):
                components = [self, widgets]
            elif loc.startswith('top'):
                components = [Column(widgets, self)]
            elif loc.startswith('bottom'):
                components = [Column(self, widgets)]
        self.layout[:] = components
Exemple #23
0
 def test_bivariate_composite_transfer_opts_with_group(self):
     dist = Bivariate(np.random.rand(10, 2),
                      group='Test').opts(style=dict(cmap='Blues'))
     contours = Compositor.collapse_element(dist, backend='matplotlib')
     opts = Store.lookup_options('matplotlib', contours, 'style').kwargs
     self.assertEqual(opts.get('cmap', None), 'Blues')
Exemple #24
0
 def test_distribution_composite_transfer_opts_with_group(self):
     dist = Distribution(np.array([0, 1, 2]),
                         group='Test').opts(style=dict(color='red'))
     area = Compositor.collapse_element(dist, backend='matplotlib')
     opts = Store.lookup_options('matplotlib', area, 'style').kwargs
     self.assertEqual(opts.get('color', None), 'red')
Exemple #25
0
 def test_holomap_options(self):
     hmap = HoloMap({0: Image(np.random.rand(10, 10))}).options(xaxis=None)
     opts = Store.lookup_options('matplotlib', hmap.last, 'plot')
     self.assertIs(opts.kwargs['xaxis'], None)
 def test_bivariate_composite_transfer_opts_with_group(self):
     dist = Bivariate(np.random.rand(10, 2), group='Test').opts(style=dict(cmap='Blues'))
     contours = Compositor.collapse_element(dist, backend='matplotlib')
     opts = Store.lookup_options('matplotlib', contours, 'style').kwargs
     self.assertEqual(opts.get('cmap', None), 'Blues')
 def test_apply_options_explicit_backend_plot_and_style(self):
     obj = TestObj([]).options(style_opt1='A', plot_opt1='B', backend='backend_2')
     plot_opts = Store.lookup_options('backend_2', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_2', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
Exemple #28
0
 def test_apply_options_current_backend_style(self):
     obj = TestObj([]).options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj, 'style')
     assert opts.options == {'style_opt1': 'A'}
 def test_apply_options_current_backend_style_multiple(self):
     obj = TestObj([]).options(style_opt1='A', style_opt2='B')
     opts = Store.lookup_options('backend_1', obj, 'style')
     assert opts.options == {'style_opt1': 'A', 'style_opt2': 'B'}
Exemple #30
0
 def test_apply_options_cloned(self):
     obj1 = TestObj([])
     obj2 = obj1.options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj2, 'style')
     assert opts.options == {'style_opt1': 'A'}
     assert obj1 is not obj2
 def test_apply_options_explicit_backend_plot_multiple(self):
     obj = TestObj([]).options(plot_opt1='A', plot_opt2='B', backend='backend_2')
     opts = Store.lookup_options('backend_2', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A', 'plot_opt2': 'B'}
 def test_holomap_options(self):
     hmap = HoloMap({0: Image(np.random.rand(10,10))}).options(xaxis=None)
     opts = Store.lookup_options('matplotlib', hmap.last, 'plot')
     self.assertIs(opts.kwargs['xaxis'], None)
 def test_apply_options_cloned(self):
     obj1 = TestObj([])
     obj2 = obj1.options(style_opt1='A')
     opts = Store.lookup_options('backend_1', obj2, 'style')
     assert opts.options == {'style_opt1': 'A'}
     assert obj1 is not obj2
Exemple #34
0
 def test_apply_options_current_backend_plot_multiple(self):
     obj = TestObj([]).options(plot_opt1='A', plot_opt2='B')
     opts = Store.lookup_options('backend_1', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A', 'plot_opt2': 'B'}
Exemple #35
0
 def test_apply_options_current_backend_plot_and_style(self):
     obj = TestObj([]).options(style_opt1='A', plot_opt1='B')
     plot_opts = Store.lookup_options('backend_1', obj, 'plot')
     assert plot_opts.options == {'plot_opt1': 'B'}
     style_opts = Store.lookup_options('backend_1', obj, 'style')
     assert style_opts.options == {'style_opt1': 'A'}
Exemple #36
0
 def test_dynamic_options_no_clone(self):
     dmap = DynamicMap(lambda X: TestObj(None),
                       kdims=['X']).redim.range(X=(0, 10))
     dmap.options(plot_opt1='red', clone=False)
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})
 def test_apply_options_current_backend_plot(self):
     obj = TestObj([]).options(plot_opt1='A')
     opts = Store.lookup_options('backend_1', obj, 'plot')
     assert opts.options == {'plot_opt1': 'A'}
Exemple #38
0
 def test_dynamic_options(self):
     dmap = DynamicMap(lambda X: ExampleElement(None), kdims=['X']).redim.range(X=(0,10))
     dmap = dmap.options(plot_opt1='red')
     opts = Store.lookup_options('backend_1', dmap[0], 'plot')
     self.assertEqual(opts.options, {'plot_opt1': 'red'})