From 813dbbb050db46b45b088ac4912867b938a720a4 Mon Sep 17 00:00:00 2001 From: Harald Schilly Date: Sat, 21 Dec 2013 19:15:19 +0000 Subject: [PATCH 1/2] make iplot() work in http://cloud.sagemath.com --- plotly/plotly.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plotly/plotly.py b/plotly/plotly.py index 96a081ef764..1529a0b822f 100644 --- a/plotly/plotly.py +++ b/plotly/plotly.py @@ -41,7 +41,14 @@ def iplot(self, *args, **kwargs): res = self.__callplot(*args, **kwargs) width = kwargs.get('width', 600) height = kwargs.get('height', 600) - s = '' + s = '' %\ + (height+50, "/".join(map(str, [res['url'], width, height])), width+50) + try: + # see, if we are in the SageMath Cloud + from sage_salvus import html + return html(s, hide=False) + except: + pass try: from IPython.display import HTML return HTML(s) From 4a0eac75acbd8dbb867f0e0c8339b6920df8eaef Mon Sep 17 00:00:00 2001 From: Harald Schilly Date: Sat, 21 Dec 2013 19:58:11 +0000 Subject: [PATCH 2/2] add JSONEncoder for native Sage number types (float reals and integers) --- plotly/plotly.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plotly/plotly.py b/plotly/plotly.py index 1529a0b822f..07154d1fcb6 100644 --- a/plotly/plotly.py +++ b/plotly/plotly.py @@ -176,11 +176,21 @@ def pandasJSONEncoder(self, obj): except: pass return None + def sageJSONEncoder(self, obj): + try: + from sage.all import RR, ZZ + if obj in RR: + return float(obj) + elif obj in ZZ: + return int(obj) + except: + pass + return None def default(self, obj): try: return json.dumps(obj) except TypeError as e: - encoders = (self.datetimeJSONEncoder, self.numpyJSONEncoder, self.pandasJSONEncoder) + encoders = (self.datetimeJSONEncoder, self.numpyJSONEncoder, self.pandasJSONEncoder, self.sageJSONEncoder) for encoder in encoders: s = encoder(obj) if s is not None: