From fc7dd2b05189396bc02c9f6d74730ae79ac12cad Mon Sep 17 00:00:00 2001
From: philippjfr
Date: Thu, 4 Jun 2015 11:51:14 +0100
Subject: [PATCH] SelectionWidget now uses browser side caching
This is a major refactor of the SelectionWidget javascript
code, which now caches all figures inside the DOM. This avoids
flicker for almost all figure types and allows caching even
live widget output in the browser.
---
holoviews/ipython/jsslider.jinja | 133 +++++++++++++++++++------------
holoviews/ipython/widgets.py | 16 ++--
2 files changed, 90 insertions(+), 59 deletions(-)
diff --git a/holoviews/ipython/jsslider.jinja b/holoviews/ipython/jsslider.jinja
index f80fac50d4..01d133dc25 100644
--- a/holoviews/ipython/jsslider.jinja
+++ b/holoviews/ipython/jsslider.jinja
@@ -1,6 +1,6 @@
@@ -94,6 +128,7 @@
div.hololayout {
display: flex;
align-items: center;
+ margin: 0;
}
form.holoform {
@@ -204,7 +239,7 @@ div.hologroup {
var dim_val = valMap{{ id }}_{{ widget_data['dim'] }}[ui.value];
$('#textInput{{ id }}_{{ widget_data['dim'] }}').val(dim_val);
anim{{ id }}.set_frame(dim_val, {{ widget_data['dim_idx'] }});
- }, 50)
+ }, 100)
});
$('#_anim_widget{{ id }}_{{ widget_data['dim'] }}').keypress(function(event) {
if (event.which == 80 || event.which == 112) {
diff --git a/holoviews/ipython/widgets.py b/holoviews/ipython/widgets.py
index bc16e7382a..04468e5156 100644
--- a/holoviews/ipython/widgets.py
+++ b/holoviews/ipython/widgets.py
@@ -390,9 +390,6 @@ class SelectionWidget(NdWidget):
Whether to embed all plots in the Javascript, generating
a static widget not dependent on the IPython server.""")
- cache_size = param.Integer(default=100, doc="""
- Size of dynamic cache if frames are not embedded.""")
-
template = param.String('jsslider.jinja', doc="""
The jinja2 template used to generate the html output.""")
@@ -412,7 +409,10 @@ def __init__(self, plot, **params):
frames = {idx: self._plot_figure(idx)
for idx in range(len(self.keys))}
self.frames = self.encode_frames(frames)
- elif self.nbagg:
+ else:
+ SelectionWidget.widgets[self.id] = self
+
+ if self.nbagg:
fig = self.plot[0]
self.manager = new_figure_manager_given_figure(OutputMagic.nbagg_counter, fig)
# Need to call mouse_init on each 3D axis to enable rotation support
@@ -421,7 +421,6 @@ def __init__(self, plot, **params):
ax.mouse_init()
OutputMagic.nbagg_counter += 1
self.comm = CustomCommSocket(self.manager)
- SelectionWidget.widgets[self.id] = self
def get_widgets(self):
@@ -500,13 +499,10 @@ def update(self, n):
fig = self.plot[n]
fig.canvas.draw_idle()
return
- if n not in self.frames:
- if len(self.frames) >= self.cache_size:
- self.frames.popitem(last=False)
+ else:
frame = self._plot_figure(n)
if self.mpld3: frame = self.encode_frames({0: frame})
- self.frames[n] = frame
- return self.frames[n]
+ return frame