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

Various optimizations #2096

Merged
merged 2 commits into from
Mar 17, 2021
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
17 changes: 13 additions & 4 deletions panel/layout/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, *objects, **params):
self._header_layout = Row(css_classes=['card-header-row'],
sizing_mode='stretch_width')
super().__init__(*objects, **params)
self._header = None
self.param.watch(self._update_header, ['title', 'header', 'title_css_classes'])
self._update_header()

Expand All @@ -76,12 +77,20 @@ def _process_param_change(self, params):
def _update_header(self, *events):
from ..pane import HTML, panel
if self.header is None:
item = HTML('%s' % (self.title or "​"),
css_classes=self.title_css_classes,
sizing_mode='stretch_width',
margin=(2, 5))
params = {
'object': '%s' % (self.title or "​"),
'css_classes': self.title_css_classes
}
if self._header is not None:
self._header.param.set_param(**params)
return
else:
self._header = item = HTML(
sizing_mode='stretch_width', margin=(2, 5), **params
)
else:
item = panel(self.header)
self._header = None
self._header_layout[:] = [item]

def _get_objects(self, model, old_objects, doc, root, comm=None):
Expand Down
4 changes: 3 additions & 1 deletion panel/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False, location=Tr
preprocess_root = col.get_root(doc, comm)
col._hooks.append(self._apply_hooks)
ref = preprocess_root.ref['id']
objs = []

for name, (obj, tags) in self._render_items.items():
if self._apply_hooks not in obj._hooks:
Expand All @@ -163,17 +164,18 @@ def _init_doc(self, doc=None, comm=None, title=None, notebook=False, location=Tr
sub._models[ref] = submodel
if isinstance(sub, HoloViews) and mref in sub._plots:
sub._plots[ref] = sub._plots.get(mref)
col.objects.append(obj)
obj._documents[doc] = model
model.name = name
model.tags = tags
self._apply_root(name, model, tags)
add_to_doc(model, doc, hold=bool(comm))
objs.append(obj)

# Here we ensure that the preprocessor is run across all roots
# and set up session cleanup hooks for the fake root.
state._fake_roots.append(ref)
state._views[ref] = (col, preprocess_root, doc, comm)
col.objects = objs
col._preprocess(preprocess_root)
col._documents[doc] = preprocess_root
doc.on_session_destroyed(col._server_destroy)
Expand Down