@@ -43,7 +43,14 @@ def iplot(self, *args, **kwargs):
43
43
res = self .__callplot (* args , ** kwargs )
44
44
width = kwargs .get ('width' , 600 )
45
45
height = kwargs .get ('height' , 600 )
46
- s = '<iframe height="' + str (height + 50 )+ '" id="igraph" scrolling="no" seamless="seamless" src="' + res ['url' ]+ '/' + str (width )+ '/' + str (height )+ '" width="' + str (width + 50 )+ '"></iframe>'
46
+ s = '<iframe height="%s" id="igraph" scrolling="no" seamless="seamless" src="%s" width="%s"></iframe>' % \
47
+ (height + 50 , "/" .join (map (str , [res ['url' ], width , height ])), width + 50 )
48
+ try :
49
+ # see, if we are in the SageMath Cloud
50
+ from sage_salvus import html
51
+ return html (s , hide = False )
52
+ except :
53
+ pass
47
54
try :
48
55
from IPython .display import HTML
49
56
return HTML (s )
@@ -171,11 +178,21 @@ def pandasJSONEncoder(self, obj):
171
178
except :
172
179
pass
173
180
return None
181
+ def sageJSONEncoder (self , obj ):
182
+ try :
183
+ from sage .all import RR , ZZ
184
+ if obj in RR :
185
+ return float (obj )
186
+ elif obj in ZZ :
187
+ return int (obj )
188
+ except :
189
+ pass
190
+ return None
174
191
def default (self , obj ):
175
192
try :
176
193
return json .dumps (obj )
177
194
except TypeError as e :
178
- encoders = (self .datetimeJSONEncoder , self .numpyJSONEncoder , self .pandasJSONEncoder )
195
+ encoders = (self .datetimeJSONEncoder , self .numpyJSONEncoder , self .pandasJSONEncoder , self . sageJSONEncoder )
179
196
for encoder in encoders :
180
197
s = encoder (obj )
181
198
if s is not None :
0 commit comments