[sagemath] 02/02: Use offline threejs as the default 3D viewer
Ximin Luo
infinity0 at debian.org
Sun Mar 12 03:02:37 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository sagemath.
commit 7c92750dcf50f63b8ad5c700cfc2d493f742de43
Author: Ximin Luo <infinity0 at debian.org>
Date: Sun Mar 12 04:02:24 2017 +0100
Use offline threejs as the default 3D viewer
---
debian/patches/d0-disable-jsmol.patch | 8 +-
debian/patches/d1-install-paths.patch | 37 ++++++-
debian/patches/series | 1 +
debian/patches/u0-use-local-threejs.patch | 160 ++++++++++++++++++++++++++++++
4 files changed, 201 insertions(+), 5 deletions(-)
diff --git a/debian/patches/d0-disable-jsmol.patch b/debian/patches/d0-disable-jsmol.patch
index e3c99b3..4e6c5f5 100644
--- a/debian/patches/d0-disable-jsmol.patch
+++ b/debian/patches/d0-disable-jsmol.patch
@@ -28,17 +28,17 @@ Forwarded: not-needed
- dst = os.path.join(self.nbextensions_dir, 'jsmol')
- self.symlink(src, dst)
-
- def _kernel_cmd(self):
+ def use_local_threejs(self):
"""
- Helper to construct the SageMath kernel command.
-@@ -243,7 +226,6 @@
+ Symlink threejs to the Jupyter notebook.
+@@ -260,7 +243,6 @@
"""
instance = cls()
instance.use_local_mathjax()
- instance.use_local_jsmol()
+ instance.use_local_threejs()
instance._install_spec()
instance._symlink_resources()
-
--- a/sage/src/sage/repl/display/jsmol_iframe.py
+++ b/sage/src/sage/repl/display/jsmol_iframe.py
@@ -46,6 +46,9 @@
diff --git a/debian/patches/d1-install-paths.patch b/debian/patches/d1-install-paths.patch
index 71b6f72..f7d339b 100644
--- a/debian/patches/d1-install-paths.patch
+++ b/debian/patches/d1-install-paths.patch
@@ -129,7 +129,16 @@ This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
dst = os.path.join(self.nbextensions_dir, 'mathjax')
self.symlink(src, dst)
-@@ -142,7 +143,7 @@
+@@ -134,7 +135,7 @@
+ sage: os.path.isdir(threejs)
+ True
+ """
+- src = os.path.join(SAGE_LOCAL, 'share', 'threejs')
++ src = "/usr/share/javascript/three"
+ dst = os.path.join(self.nbextensions_dir, 'threejs')
+ self.symlink(src, dst)
+
+@@ -159,7 +160,7 @@
'{connection_file}']
"""
return [
@@ -220,3 +229,29 @@ This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
clean:
@echo "Deleting Sage library build artifacts..."
+--- a/sage/src/sage/plot/plot3d/base.pyx
++++ b/sage/src/sage/plot/plot3d/base.pyx
+@@ -388,19 +388,13 @@
+ if isinstance(backend, BackendIPythonNotebook):
+ scripts = ( """
+ <script src="/nbextensions/threejs/three.min.js"></script>
+-<script src="/nbextensions/threejs/OrbitControls.js"></script>
+-<script>
+- if ( !window.THREE ) document.write('\
+-<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/build/three.min.js"><\/script>\
+-<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/examples/js/controls/OrbitControls.js"><\/script>');
+-</script>
++<script src="/nbextensions/threejs/examples/js/controls/OrbitControls.js"></script>
+ """ )
+ else:
+- from sage.env import SAGE_SHARE
+ scripts = ( """
+-<script src="{0}/threejs/three.min.js"></script>
+-<script src="{0}/threejs/OrbitControls.js"></script>
+- """.format( SAGE_SHARE ) )
++<script src="{0}/three.min.js"></script>
++<script src="{0}/examples/js/controls/OrbitControls.js"></script>
++ """.format( "file:///usr/share/javascript/three" ) )
+
+ lights = "[{x:0, y:0, z:10}, {x:0, y:0, z:-10}]"
+
diff --git a/debian/patches/series b/debian/patches/series
index c7cbcec..6e2cd52 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -7,6 +7,7 @@ u0-fix-libgap-systemwide.patch
u0-singular-include-path-for-pynac.patch
u0-dont-test-glpk-version.patch
u0-fix-preexec-fn.patch
+u0-use-local-threejs.patch
# Patches that have open upstream tickets
u1-version-planarity-3.patch
diff --git a/debian/patches/u0-use-local-threejs.patch b/debian/patches/u0-use-local-threejs.patch
new file mode 100644
index 0000000..f39646d
--- /dev/null
+++ b/debian/patches/u0-use-local-threejs.patch
@@ -0,0 +1,160 @@
+Description: Use threejs as the default 3D viewer
+Author: paulmasson <paulmasson at analyticphysics.com>
+Applied-Upstream:
+ commit:5ddb9f154c1618039e60253e4e102a198d955af5
+ commit:93b0b0e293645b46f409c3514df70d337b16a88e
+ commit:efbd87751b8fd5b384c563026e3470bdb42429c2
+ commit:7c0c9cf8e7ccb3d9b09020ddf11615fcfac61780
+ commit:63f725d65fcd99c3a8669534efdd3114e31bf1ff
+
+--- a/sage/src/doc/en/reference/plot3d/threejs.rst
++++ b/sage/src/doc/en/reference/plot3d/threejs.rst
+@@ -18,7 +18,10 @@
+ on a touch pad
+
+ The generated HTML file contains all data for the scene apart from the JavaScript library
+-and can be saved to disk for sharing or embedding in a web page.
++and can be saved to disk for sharing or embedding in a web page. The option ``online``
++can be set to ``true`` to provide links to the required files in an online content delivery
++network. Alternately the required files can be downloaded from the Three.js GitHub repository
++and linked directly from the web server.
+
+ Options currently supported by the viewer:
+
+@@ -36,6 +39,9 @@
+
+ - ``frame`` -- (default: True) Boolean determining whether frame is drawn
+
++- ``online`` -- (default: False) Boolean determining whether the local standard package
++ files are replaced by links to an online content delivery network
++
+ - ``opacity`` -- (default: 1) numeric value for transparency of lines and surfaces
+
+ - ``radius`` -- (default: None) numeric value for radius of lines; use to render
+--- a/sage/src/ext/threejs/threejs_template.html
++++ b/sage/src/ext/threejs/threejs_template.html
+@@ -2,8 +2,8 @@
+ <html>
+ <head>
+ <title></title>
+-<meta charset=utf-8>
+-<meta name=viewport content='width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
++<meta charset="utf-8">
++<meta name=viewport content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+ <style>
+
+ body { margin: 0px; overflow: hidden; }
+@@ -12,10 +12,7 @@
+ </head>
+
+ <body>
+-
+-<script src=http://rawgit.com/mrdoob/three.js/r80/build/three.js></script>
+-<script src=http://rawgit.com/mrdoob/three.js/r80/examples/js/controls/OrbitControls.js></script>
+-
++SAGE_SCRIPTS
+ <script>
+
+ var scene = new THREE.Scene();
+--- a/sage/src/sage/plot/plot3d/base.pyx
++++ b/sage/src/sage/plot/plot3d/base.pyx
+@@ -367,10 +367,41 @@
+ options['axes_labels'] = kwds.get('axes_labels', ['x','y','z'])
+ options['decimals'] = int(kwds.get('decimals', 2))
+ options['frame'] = kwds.get('frame', True)
++ options['online'] = kwds.get('online', False)
+
+ if not options['frame']:
+ options['axes_labels'] = False
+
++ from sage.repl.rich_output import get_display_manager
++ backend = get_display_manager()._backend
++ from sage.repl.rich_output.backend_sagenb import BackendSageNB
++ if isinstance(backend, BackendSageNB):
++ options['online'] = True
++
++ if options['online']:
++ scripts = ( """
++<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/build/three.min.js"></script>
++<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/examples/js/controls/OrbitControls.js"></script>
++ """ )
++ else:
++ from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
++ if isinstance(backend, BackendIPythonNotebook):
++ scripts = ( """
++<script src="/nbextensions/threejs/three.min.js"></script>
++<script src="/nbextensions/threejs/OrbitControls.js"></script>
++<script>
++ if ( !window.THREE ) document.write('\
++<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/build/three.min.js"><\/script>\
++<script src="https://cdn.rawgit.com/mrdoob/three.js/r80/examples/js/controls/OrbitControls.js"><\/script>');
++</script>
++ """ )
++ else:
++ from sage.env import SAGE_SHARE
++ scripts = ( """
++<script src="{0}/threejs/three.min.js"></script>
++<script src="{0}/threejs/OrbitControls.js"></script>
++ """.format( SAGE_SHARE ) )
++
+ lights = "[{x:0, y:0, z:10}, {x:0, y:0, z:-10}]"
+
+ b = self.bounding_box()
+@@ -413,6 +444,7 @@
+ html = f.read()
+ f.close()
+
++ html = html.replace('SAGE_SCRIPTS', scripts)
+ html = html.replace('SAGE_OPTIONS', json.dumps(options))
+ html = html.replace('SAGE_LIGHTS', lights)
+ html = html.replace('SAGE_BOUNDS', bounds)
+@@ -1837,7 +1869,7 @@
+ return self
+
+ # if you add any default parameters you must update some code below
+-SHOW_DEFAULTS = {'viewer': 'jmol',
++SHOW_DEFAULTS = {'viewer': 'threejs',
+ 'verbosity': 0,
+ 'figsize': 5,
+ 'aspect_ratio': "automatic",
+--- a/sage/src/sage/repl/ipython_kernel/install.py
++++ b/sage/src/sage/repl/ipython_kernel/install.py
+@@ -1,5 +1,5 @@
+ """
+-Installing the SageMath Jupyter Kernel and extensions
++Installing the SageMath Jupyter Kernel and Extensions
+
+ Kernels have to register themselves with Jupyter so that they appear
+ in the Jupyter notebook's kernel drop-down. This is done by
+@@ -130,6 +130,23 @@
+ dst = os.path.join(self.nbextensions_dir, 'jsmol')
+ self.symlink(src, dst)
+
++ def use_local_threejs(self):
++ """
++ Symlink threejs to the Jupyter notebook.
++
++ EXAMPLES::
++
++ sage: from sage.repl.ipython_kernel.install import SageKernelSpec
++ sage: spec = SageKernelSpec()
++ sage: spec.use_local_threejs()
++ sage: threejs = os.path.join(spec.nbextensions_dir, 'threejs')
++ sage: os.path.isdir(threejs)
++ True
++ """
++ src = os.path.join(SAGE_LOCAL, 'share', 'threejs')
++ dst = os.path.join(self.nbextensions_dir, 'threejs')
++ self.symlink(src, dst)
++
+ def _kernel_cmd(self):
+ """
+ Helper to construct the SageMath kernel command.
+@@ -236,6 +253,7 @@
+ instance = cls()
+ instance.use_local_mathjax()
+ instance.use_local_jsmol()
++ instance.use_local_threejs()
+ instance._install_spec()
+ instance._symlink_resources()
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sagemath.git
More information about the debian-science-commits
mailing list