Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add methods for offline scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Mar 31, 2017
1 parent 8725c63 commit 1d27bd0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
28 changes: 7 additions & 21 deletions src/sage/plot/plot3d/base.pyx
Expand Up @@ -377,28 +377,14 @@ cdef class Graphics3d(SageObject):
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>
""" )
from sage.misc.package import installed_packages
version = installed_packages()['threejs']
scripts = """
<script src="https://cdn.rawgit.com/mrdoob/three.js/{0}/build/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/{0}/examples/js/controls/OrbitControls.js"></script>
""".format(version)
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 ) )
scripts = backend.threejs_offline_scripts()

b = self.bounding_box()
bounds = '[{{"x":{}, "y":{}, "z":{}}}, {{"x":{}, "y":{}, "z":{}}}]'.format(
Expand Down
41 changes: 40 additions & 1 deletion src/sage/repl/rich_output/backend_ipython.py
Expand Up @@ -396,6 +396,24 @@ def is_in_terminal(self):
"""
return True

def threejs_offline_scripts(self):
"""
Three.js offline scripts for the IPython command line
EXAMPLES::
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
sage: backend = BackendIPythonCommandline()
sage: backend.threejs_offline_scripts()
'...<script ...</script>...'
"""
from sage.env import SAGE_SHARE
return """
<script src="{0}/threejs/three.min.js"></script>
<script src="{0}/threejs/OrbitControls.js"></script>
""".format(SAGE_SHARE)



IFRAME_TEMPLATE = \
"""
Expand Down Expand Up @@ -554,4 +572,25 @@ def displayhook(self, plain_text, rich_output):
else:
raise TypeError('rich_output type not supported')


def threejs_offline_scripts(self):
"""
Three.js offline scripts for the IPython notebook
EXAMPLES::
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook
sage: backend = BackendIPythonNotebook()
sage: backend.threejs_offline_scripts()
'...<script ...</script>...'
"""
from sage.misc.package import installed_packages
version = installed_packages()['threejs']
return """
<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/{0}/build/three.min.js"><\/script>\
<script src="https://cdn.rawgit.com/mrdoob/three.js/{0}/examples/js/controls/OrbitControls.js"><\/script>');
</script>
""".format(version)

0 comments on commit 1d27bd0

Please sign in to comment.