Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gave panes simpler names #20

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .layout import Row, Column # noqa
from .panes import Pane # noqa
from .param import ParamPane # noqa
from .param import Param # noqa
from .util import load_notebook as _load_nb
from .viewable import Viewable

Expand Down
3 changes: 2 additions & 1 deletion panel/models/plotly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export class PlotlyPlotView extends LayoutDOMView {
let array = cds.get_array(column)
if (shape.length > 1) {
const arrays = []
for (s = 0; s < shape[0].length; s++)
for (const s = 0; s < shape[0]; s++) {
arrays.push(array.slice(s*shape[1], (s+1)*shape[1]))
}
array = arrays
}
trace[column] = array
Expand Down
41 changes: 20 additions & 21 deletions panel/panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def update_models():
self._callbacks[model.ref['id']]['object'] = update_pane


class BokehPane(PaneBase):
class Bokeh(PaneBase):
"""
BokehPane allows including any bokeh model in a panel.
Bokeh panes allow including any bokeh model in a panel.
"""

@classmethod
Expand All @@ -167,9 +167,9 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
return model


class HoloViewsPane(PaneBase):
class HoloViews(PaneBase):
"""
HoloViewsPane renders any HoloViews object to a corresponding
HoloViews panes render any HoloViews object to a corresponding
bokeh model while respecting the currently selected backend.
"""

Expand Down Expand Up @@ -204,7 +204,7 @@ def _cleanup(self, model, final=False):
owner = get_method_owner(sub)
if owner.state is model:
owner.cleanup()
super(HoloViewsPane, self)._cleanup(model, final)
super(HoloViews, self)._cleanup(model, final)

def _get_model(self, doc, root=None, parent=None, comm=None):
"""
Expand All @@ -222,9 +222,9 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
return model


class ParamMethodPane(PaneBase):
class ParamMethod(PaneBase):
"""
ParamMethodPane wraps methods annotated with the param.depends
ParamMethod panes wrap methods annotated with the param.depends
decorator and rerenders the plot when any of the methods parameters
change. The method may return any object which itself can be rendered
as a Pane.
Expand All @@ -233,7 +233,7 @@ class ParamMethodPane(PaneBase):
def __init__(self, object, **params):
self._kwargs = {p: params.pop(p) for p in list(params)
if p not in self.params()}
super(ParamMethodPane, self).__init__(object, **params)
super(ParamMethod, self).__init__(object, **params)
self._pane = Pane(self.object(), name=self.name,
**dict(_temporary=True, **self._kwargs))

Expand Down Expand Up @@ -293,10 +293,10 @@ def _cleanup(self, model, final=False):
for p, cb in callbacks.items():
parameterized.param.unwatch(cb, p)
self._pane._cleanup(model, final)
super(ParamMethodPane, self)._cleanup(model, final)
super(ParamMethod, self)._cleanup(model, final)


class DivBasePane(PaneBase):
class DivPaneBase(PaneBase):
"""
Baseclass for Panes which render HTML inside a Bokeh Div.
See the documentation for Bokeh Div for more detail about
Expand Down Expand Up @@ -333,7 +333,7 @@ def _update(self, model):
div.update(**self._get_properties())


class PNGPane(DivBasePane):
class PNG(DivPaneBase):
"""
Encodes a PNG as base64 and wraps it in a Bokeh Div model. This
base class supports anything with a _repr_png_ method, a local
Expand Down Expand Up @@ -372,17 +372,17 @@ def _get_properties(self):
src = "data:image/png;base64,{b64}".format(b64=b64)
html = "<img src='{src}'></img>".format(src=src)

p = super(PNGPane,self)._get_properties()
p = super(PNG,self)._get_properties()
width, height = self._pngshape(data)
if self.width is None: p["width"] = width
if self.height is None: p["height"] = height
p["text"]=html
return p


class MatplotlibPane(PNGPane):
class Matplotlib(PNG):
"""
A MatplotlibPane renders a matplotlib figure to png and wraps
A Matplotlib panes render a matplotlib figure to png and wraps
the base64 encoded data in a bokeh Div model.
"""

Expand All @@ -403,10 +403,9 @@ def _png(self):
return b.getvalue()



class HTMLPane(DivBasePane):
class HTML(DivPaneBase):
"""
HTMLPane renders any object which has a _repr_html_ method and wraps
HTML panes render any object which has a _repr_html_ method and wraps
the HTML in a bokeh Div model. The height and width can optionally
be specified, to allow room for whatever is being wrapped.
"""
Expand All @@ -418,13 +417,13 @@ def applies(cls, obj):
return hasattr(obj, '_repr_html_')

def _get_properties(self):
return dict(text=self.object._repr_html_(),
**super(HTMLPane,self)._get_properties())
properties = super(HTML, self)._get_properties()
return dict(properties, text=self.object._repr_html_())


class RGGPlotPane(PNGPane):
class RGGPlot(PNG):
"""
An RGGPlotPane renders an r2py-based ggplot2 figure to png
An RGGPlot panes render an r2py-based ggplot2 figure to png
and wraps the base64-encoded data in a bokeh Div model.
"""

Expand Down
16 changes: 8 additions & 8 deletions panel/param.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Defines the ParamPane which converts Parameterized classes into a
Defines the Param pane which converts Parameterized classes into a
set of widgets.
"""
from __future__ import absolute_import
Expand All @@ -21,10 +21,10 @@
)


class ParamPane(PaneBase):
class Param(PaneBase):
"""
ParamPane renders a Parameterized class to a set of widgets which
are linke to the parameter values on the class.
Param panes render a Parameterized class to a set of widgets which
are linked to the parameter values on the class.
"""

height = param.Integer(default=None, bounds=(0, None))
Expand Down Expand Up @@ -75,7 +75,7 @@ class ParamPane(PaneBase):
def __init__(self, object, **params):
if 'name' not in params:
params['name'] = object.name
super(ParamPane, self).__init__(object, **params)
super(Param, self).__init__(object, **params)
self._widgets = self._get_widgets()
self._widget_box = WidgetBox(*self._widgets.values(), height=self.height,
width=self.width, name=self.name)
Expand All @@ -98,16 +98,16 @@ def update_panes(change, parameter=pname):
"Adds or removes subpanel from layout"
parameterized = getattr(self.object, parameter)
existing = [p for p in self._layout.objects
if isinstance(p, ParamPane)
if isinstance(p, Param)
and p.object is parameterized]
if existing:
if not change.new:
self._layout.pop(existing[0])
elif change.new:
kwargs = {k: v for k, v in self.get_param_values()
if k not in ['name', 'object']}
pane = ParamPane(parameterized, name=parameterized.name,
_temporary=True, **kwargs)
pane = Param(parameterized, name=parameterized.name,
_temporary=True, **kwargs)
self._layout.append(pane)

widget.param.watch(update_panes, 'active')
Expand Down
8 changes: 4 additions & 4 deletions panel/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class PlotlyPlot(LayoutDOM):
data_sources = List(Instance(ColumnDataSource))


class PlotlyPane(PaneBase):
class Plotly(PaneBase):
"""
PlotlyPane allows rendering a plotly Figure.
Plotly panes allow rendering plotly Figures and traces.

For efficiency any array objects found inside a Figure are added
to a ColumnDataSource which allows using binary transport to sync
Expand All @@ -37,8 +37,8 @@ class PlotlyPane(PaneBase):
_updates = True

def __init__(self, object, layout=None, **params):
super(PlotlyPane, self).__init__(self._to_figure(object, layout),
layout=layout, **params)
super(Plotly, self).__init__(self._to_figure(object, layout),
layout=layout, **params)

@classmethod
def applies(cls, obj):
Expand Down
4 changes: 2 additions & 2 deletions panel/tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from bokeh.models import Div, Row as BkRow, Tabs as BkTabs, Column as BkColumn, Panel as BkPanel
from panel.layout import Column, Row, Tabs, Spacer
from panel.panes import BokehPane, Pane
from panel.panes import Bokeh, Pane


@pytest.mark.parametrize('panel', [Column, Row])
Expand All @@ -13,7 +13,7 @@ def test_layout_constructor(panel):
div2 = Div()
layout = panel(div1, div2)

assert all(isinstance(p, BokehPane) for p in layout.objects)
assert all(isinstance(p, Bokeh) for p in layout.objects)


@pytest.mark.parametrize(['panel', 'model_type'], [(Column, BkColumn), (Row, BkRow)])
Expand Down
20 changes: 10 additions & 10 deletions panel/tests/test_panes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from bokeh.models import (Div, Row as BkRow, WidgetBox as BkWidgetBox,
GlyphRenderer, Circle, Line)
from bokeh.plotting import Figure
from panel.panes import (Pane, PaneBase, BokehPane, HoloViewsPane,
MatplotlibPane, ParamMethodPane)
from panel.panes import (Pane, PaneBase, Bokeh, HoloViews, Matplotlib,
ParamMethod)

try:
import holoviews as hv
Expand All @@ -27,7 +27,7 @@

def test_get_bokeh_pane_type():
div = Div()
assert PaneBase.get_pane_type(div) is BokehPane
assert PaneBase.get_pane_type(div) is Bokeh


def test_bokeh_pane(document, comm):
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_bokeh_pane(document, comm):
@hv_available
def test_get_holoviews_pane_type():
curve = hv.Curve([1, 2, 3])
assert PaneBase.get_pane_type(curve) is HoloViewsPane
assert PaneBase.get_pane_type(curve) is HoloViews


@pytest.mark.usefixtures("hv_mpl")
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_holoviews_pane_bokeh_renderer(document, comm):

@mpl_available
def test_get_matplotlib_pane_type():
assert PaneBase.get_pane_type(mpl_figure()) is MatplotlibPane
assert PaneBase.get_pane_type(mpl_figure()) is Matplotlib


@mpl_available
Expand Down Expand Up @@ -181,14 +181,14 @@ def mixed_view(self):


def test_get_param_method_pane_type():
assert PaneBase.get_pane_type(View().view) is ParamMethodPane
assert PaneBase.get_pane_type(View().view) is ParamMethod


def test_param_method_pane(document, comm):
test = View()
pane = Pane(test.view)
inner_pane = pane._pane
assert isinstance(inner_pane, BokehPane)
assert isinstance(inner_pane, Bokeh)

# Create pane
row = pane._get_root(document, comm=comm)
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_param_method_pane_mpl(document, comm):
test = View()
pane = Pane(test.mpl_view)
inner_pane = pane._pane
assert isinstance(inner_pane, MatplotlibPane)
assert isinstance(inner_pane, Matplotlib)

# Create pane
row = pane._get_root(document, comm=comm)
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_param_method_pane_changing_type(document, comm):
test = View()
pane = Pane(test.mixed_view)
inner_pane = pane._pane
assert isinstance(inner_pane, MatplotlibPane)
assert isinstance(inner_pane, Matplotlib)

# Create pane
row = pane._get_root(document, comm=comm)
Expand All @@ -269,7 +269,7 @@ def test_param_method_pane_changing_type(document, comm):
model = row.children[0]
new_pane = pane._pane
assert pane._callbacks == {}
assert isinstance(new_pane, BokehPane)
assert isinstance(new_pane, Bokeh)
div = row.children[0]
assert isinstance(div, Div)
assert div.text != text
Expand Down
Loading