From 12d582b0fe955cc4cb5cdf9c9134f09a9757eb43 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 28 Jan 2016 17:08:30 +0000 Subject: [PATCH 1/9] Removed require.js code from slider widget --- holoviews/plotting/widgets/jsslider.jinja | 51 +---------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/holoviews/plotting/widgets/jsslider.jinja b/holoviews/plotting/widgets/jsslider.jinja index 6c61389fb1..902977a4dc 100644 --- a/holoviews/plotting/widgets/jsslider.jinja +++ b/holoviews/plotting/widgets/jsslider.jinja @@ -24,53 +24,7 @@ + {% elif widget_data['type']=='dropdown' %}
From 8a779a4e3efa7f7af317b9a811e05186a7869ebb Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 28 Jan 2016 17:09:49 +0000 Subject: [PATCH 2/9] Improved handling of JS dependencies --- holoviews/ipython/__init__.py | 5 ++- holoviews/ipython/load_notebook.html | 8 ++--- holoviews/plotting/bokeh/renderer.py | 4 +-- holoviews/plotting/renderer.py | 51 ++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/holoviews/ipython/__init__.py b/holoviews/ipython/__init__.py index 90264211c4..d30df3680d 100644 --- a/holoviews/ipython/__init__.py +++ b/holoviews/ipython/__init__.py @@ -81,7 +81,7 @@ def load_hvjs(logo=False, JS=True, message='HoloViewsJS successfully loaded.'): """ # Evaluate load_notebook.html template with widgetjs code if JS: - widgetjs, widgetcss = Renderer.embed_assets() + widgetjs, widgetcss = Renderer.embed_assets(extras=False, backends=[]) else: widgetjs, widgetcss = '', '' templateLoader = jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__))) @@ -165,8 +165,7 @@ def __call__(self, *args, **params): loaded = ', '.join(js_names[r] if r in js_names else r.capitalize()+'JS' for r in resources) - load_hvjs(logo=p.logo, - JS=('holoviews' in resources), + load_hvjs(logo=p.logo, JS=('holoviews' in resources), message = '%s successfully loaded in this cell.' % loaded) for r in [r for r in resources if r != 'holoviews']: Store.renderers[r].load_nb(inline=p.inline) diff --git a/holoviews/ipython/load_notebook.html b/holoviews/ipython/load_notebook.html index 12504ffbe0..92139da2b9 100644 --- a/holoviews/ipython/load_notebook.html +++ b/holoviews/ipython/load_notebook.html @@ -1,10 +1,6 @@ - +{{ widgetjs }} - +{{ widgetcss }} {% if logo %}
diff --git a/holoviews/plotting/bokeh/renderer.py b/holoviews/plotting/bokeh/renderer.py index b581f37785..80d8ef6c47 100644 --- a/holoviews/plotting/bokeh/renderer.py +++ b/holoviews/plotting/bokeh/renderer.py @@ -37,9 +37,7 @@ class BokehRenderer(Renderer): widgets = {'scrubber': BokehScrubberWidget, 'widgets': BokehSelectionWidget} - js_dependencies = Renderer.js_dependencies + CDN.js_files - - css_dependencies = Renderer.css_dependencies + CDN.css_files + backend_dependencies = {'js': CDN.js_files, 'css': CDN.css_files} _loaded = False diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py index a4c16dd5ed..40879c6f8a 100644 --- a/holoviews/plotting/renderer.py +++ b/holoviews/plotting/renderer.py @@ -123,10 +123,15 @@ class Renderer(Exporter): # Define appropriate widget classes widgets = {'scrubber': ScrubberWidget, 'widgets': SelectionWidget} - js_dependencies = ['https://code.jquery.com/jquery-2.1.4.min.js', - 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.20/require.min.js'] + core_dependencies = {'jQueryUI': {'js': ['https://code.jquery.com/ui/1.10.4/jquery-ui.min.js'], + 'css': ['https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css']}} - css_dependencies = ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'] + extra_dependencies = {'jQuery': {'js': ['https://code.jquery.com/jquery-2.1.4.min.js']}, + 'underscore': {'js': ['https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js']}, + 'bootstrap': {'css': ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css']}} + + # Any additional JS and CSS dependencies required by a specific backend + backend_dependencies = {} def __init__(self, **params): super(Renderer, self).__init__(**params) @@ -239,17 +244,9 @@ def static_html(self, obj, fmt=None, template=None): with fields to interpolate 'js', 'css' and the main 'html'. """ css_html, js_html = '', '' - js, css = self.embed_assets() - for url in self.js_dependencies: - js_html += '' % url - js_html += '' % js - - for url in self.css_dependencies: - css_html += '' % url - css_html += '' % css - + js, css = self.embed_assets(jQuery=True) if template is None: template = static_template - + js_html, css_html = self.embed_assets() html = self.html(obj, fmt) return template.format(js=js_html, css=css_html, html=html) @@ -340,10 +337,13 @@ class needed to render it with the current renderer. @classmethod - def embed_assets(cls): + def embed_assets(cls, core=True, extras=True, jQuery=False, backends=None): """ Returns JS and CSS and for embedding of widgets. """ + if backends is None: + backends = [cls.backend] if cls.backend else [] + # Get all the widgets and find the set of required js widget files widgets = [wdgt for r in Renderer.__subclasses__() for wdgt in r.widgets.values()] @@ -358,7 +358,28 @@ def embed_assets(cls): if f is not None ) widgetcss = '\n'.join(open(find_file(path, f), 'r').read() for f in css if f is not None) - return widgetjs, widgetcss + + dependencies = {} + if core: + dependencies.update(cls.core_dependencies) + if extras: + dependencies.update(cls.extra_dependencies) + if not jQuery: + dependencies.pop('jQuery', None) + for backend in backends: + dependencies['backend'] = Store.renderers[backend].backend_dependencies + + js_html, css_html = '', '' + for _, dep in sorted(dependencies.items(), key=lambda x: x[0]): + for js in dep.get('js', []): + js_html += '\n' % js + for css in dep.get('css', []): + css_html += '\n' % css + + js_html += '\n' % widgetjs + css_html += '\n' % widgetcss + + return js_html, css_html @classmethod From 94dd0c497098e6267cc24992ecbb801a9b327c65 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Thu, 28 Jan 2016 17:11:20 +0000 Subject: [PATCH 3/9] Renamed Renderer.embed_assets to Renderer.html_assets --- holoviews/ipython/__init__.py | 2 +- holoviews/plotting/renderer.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/holoviews/ipython/__init__.py b/holoviews/ipython/__init__.py index d30df3680d..a92c21af74 100644 --- a/holoviews/ipython/__init__.py +++ b/holoviews/ipython/__init__.py @@ -81,7 +81,7 @@ def load_hvjs(logo=False, JS=True, message='HoloViewsJS successfully loaded.'): """ # Evaluate load_notebook.html template with widgetjs code if JS: - widgetjs, widgetcss = Renderer.embed_assets(extras=False, backends=[]) + widgetjs, widgetcss = Renderer.html_assets(extras=False, backends=[]) else: widgetjs, widgetcss = '', '' templateLoader = jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__))) diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py index 40879c6f8a..c8d1e1b2d5 100644 --- a/holoviews/plotting/renderer.py +++ b/holoviews/plotting/renderer.py @@ -243,10 +243,8 @@ def static_html(self, obj, fmt=None, template=None): supplied format. Allows supplying a template formatting string with fields to interpolate 'js', 'css' and the main 'html'. """ - css_html, js_html = '', '' - js, css = self.embed_assets(jQuery=True) + js_html, css_html = self.html_assets(jQuery=True) if template is None: template = static_template - js_html, css_html = self.embed_assets() html = self.html(obj, fmt) return template.format(js=js_html, css=css_html, html=html) @@ -337,7 +335,7 @@ class needed to render it with the current renderer. @classmethod - def embed_assets(cls, core=True, extras=True, jQuery=False, backends=None): + def html_assets(cls, core=True, extras=True, jQuery=False, backends=None): """ Returns JS and CSS and for embedding of widgets. """ From 9616d44cd5e4aa13d5b9804bf057b88d14f17ab6 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 14:08:58 +0000 Subject: [PATCH 4/9] Readded require.js config for slider widget --- holoviews/plotting/widgets/jsslider.jinja | 52 ++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/holoviews/plotting/widgets/jsslider.jinja b/holoviews/plotting/widgets/jsslider.jinja index 902977a4dc..bf5a894278 100644 --- a/holoviews/plotting/widgets/jsslider.jinja +++ b/holoviews/plotting/widgets/jsslider.jinja @@ -24,7 +24,53 @@
+ }); + // Slider JS Block END + {% elif widget_data['type']=='dropdown' %}
From 54ff7a17f84a48d683aaba480b04842e5964e28b Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 14:10:43 +0000 Subject: [PATCH 5/9] Removed special handling of jQuery on Renderer.html_assets --- holoviews/plotting/renderer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py index c8d1e1b2d5..7e48b7a2d7 100644 --- a/holoviews/plotting/renderer.py +++ b/holoviews/plotting/renderer.py @@ -243,7 +243,7 @@ def static_html(self, obj, fmt=None, template=None): supplied format. Allows supplying a template formatting string with fields to interpolate 'js', 'css' and the main 'html'. """ - js_html, css_html = self.html_assets(jQuery=True) + js_html, css_html = self.html_assets() if template is None: template = static_template html = self.html(obj, fmt) return template.format(js=js_html, css=css_html, html=html) @@ -335,7 +335,7 @@ class needed to render it with the current renderer. @classmethod - def html_assets(cls, core=True, extras=True, jQuery=False, backends=None): + def html_assets(cls, core=True, extras=True, backends=None): """ Returns JS and CSS and for embedding of widgets. """ @@ -362,8 +362,6 @@ def html_assets(cls, core=True, extras=True, jQuery=False, backends=None): dependencies.update(cls.core_dependencies) if extras: dependencies.update(cls.extra_dependencies) - if not jQuery: - dependencies.pop('jQuery', None) for backend in backends: dependencies['backend'] = Store.renderers[backend].backend_dependencies From c4c1e3e588b9954d55c68268dc1a13ee54e91735 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 14:43:24 +0000 Subject: [PATCH 6/9] Adjustments to slider widget CSS --- holoviews/plotting/widgets/jsslider.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/widgets/jsslider.css b/holoviews/plotting/widgets/jsslider.css index e6de73dfe1..25b9371e0b 100644 --- a/holoviews/plotting/widgets/jsslider.css +++ b/holoviews/plotting/widgets/jsslider.css @@ -11,6 +11,10 @@ form.holoform { padding: 0.8em; } +div.holowidgets { + padding-right: 0; +} + div.holoslider { min-height: 0 !important; height: 0.8em; @@ -24,7 +28,7 @@ div.holoformgroup { div.hologroup { padding-left: 0; - padding-right: 0.6em; + padding-right: 0; } .holoselect { From 2455dba87cedce49c042280fc56240c2dae63d04 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 14:43:39 +0000 Subject: [PATCH 7/9] Improved rounding of slider widget text --- holoviews/plotting/widgets/jsslider.jinja | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/holoviews/plotting/widgets/jsslider.jinja b/holoviews/plotting/widgets/jsslider.jinja index bf5a894278..a5a3bf6b0f 100644 --- a/holoviews/plotting/widgets/jsslider.jinja +++ b/holoviews/plotting/widgets/jsslider.jinja @@ -102,7 +102,8 @@ } else { var dim_val = vals[ui.value]; } - $('#textInput{{ id }}_{{ widget_data['dim'] }}').val(dim_val); + console.log((dim_val*1).toString()) + $('#textInput{{ id }}_{{ widget_data['dim'] }}').val((dim_val*1).toString()); anim{{ id }}.set_frame(dim_val, {{ widget_data['dim_idx'] }}); if (Object.keys(next_vals).length > 0) { var new_vals = next_vals[dim_val]; @@ -141,7 +142,7 @@ } } }); - $('#textInput{{ id }}_{{ widget_data['dim'] }}').val(vals[0]); + $('#textInput{{ id }}_{{ widget_data['dim'] }}').val((vals[0]*1).toString()); }); // Slider JS Block END From 1b7bde32abc445ff74448b9767ed802333b6f53a Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 15:21:17 +0000 Subject: [PATCH 8/9] Readded require.js dependency to extra dependencies --- holoviews/plotting/renderer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py index 7e48b7a2d7..c3f648c317 100644 --- a/holoviews/plotting/renderer.py +++ b/holoviews/plotting/renderer.py @@ -128,6 +128,7 @@ class Renderer(Exporter): extra_dependencies = {'jQuery': {'js': ['https://code.jquery.com/jquery-2.1.4.min.js']}, 'underscore': {'js': ['https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js']}, + 'require': {'js': ['https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.20/require.min.js']}, 'bootstrap': {'css': ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css']}} # Any additional JS and CSS dependencies required by a specific backend From 3a17f2a4a6ec22f62a5f8620dff89661c348bb21 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 1 Feb 2016 18:40:29 +0000 Subject: [PATCH 9/9] Removed stray console.log --- holoviews/plotting/widgets/jsslider.jinja | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/holoviews/plotting/widgets/jsslider.jinja b/holoviews/plotting/widgets/jsslider.jinja index a5a3bf6b0f..b20495b411 100644 --- a/holoviews/plotting/widgets/jsslider.jinja +++ b/holoviews/plotting/widgets/jsslider.jinja @@ -102,8 +102,7 @@ } else { var dim_val = vals[ui.value]; } - console.log((dim_val*1).toString()) - $('#textInput{{ id }}_{{ widget_data['dim'] }}').val((dim_val*1).toString()); + $('#textInput{{ id }}_{{ widget_data['dim'] }}').val((dim_val*1).toString()); anim{{ id }}.set_frame(dim_val, {{ widget_data['dim_idx'] }}); if (Object.keys(next_vals).length > 0) { var new_vals = next_vals[dim_val];