Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for inline svg dumping. Now pylab works!

  • Loading branch information...
commit 8b70aade355df01752229e71356114f848d914fb 1 parent 3001fb5
james authored committed
View
116 IPython/frontend/html/js/notebook.js
@@ -22,19 +22,21 @@ function fixConsole(txt) {
function comet() {
$.ajax({
success: function(json, status, request) {
- comet()
- var msg = manager.get(json.parent_header.msg_id)
- if (json.msg_type == "status") {
- statusbar.set(json.content.execute_state)
- } else if (json.msg_type == "stream") {
- msg.setOutput(fixConsole(json.content.data))
- } else if (json.msg_type == "pyin") {
- msg.setInput(json.content.code)
- } else if (json.msg_type == "pyout") {
- msg.setOutput(json.content.data, true)
- } else if (json.msg_type == "pyerr") {
- msg.setOutput(fixConsole(json.content.traceback.join("\n")))
- }
+ comet()
+ if (json.msg_type == "status") {
+ statusbar.set(json.content.execution_state)
+ } else {
+ var msg = manager.get(json.parent_header.msg_id)
+ if (json.msg_type == "stream") {
+ msg.setOutput(fixConsole(json.content.data))
+ } else if (json.msg_type == "pyin") {
+ msg.setInput(fixConsole(json.content.code))
+ } else if (json.msg_type == "pyout") {
+ msg.setOutput(fixConsole(json.content.data), true)
+ } else if (json.msg_type == "pyerr") {
+ msg.setOutput(fixConsole(json.content.traceback.join("\n")))
+ }
+ }
}
})
}
@@ -52,8 +54,20 @@ function execute(code) {
type: "POST",
data: {type:"execute", code:code},
success: function(json, status, request) {
- exec_count = json.content.execution_count
-// $("#messages").append("<pre class='headers xreq'>"+inspect(json)+"</pre>")
+ if (json != null) {
+ exec_count = json.content.execution_count
+ if (json.content.payload.length > 0 &&
+ json.content.payload[0]['format'] == "svg") {
+ var svg = document.createElement('object')
+ svg.setAttribute('class', "inlinesvg")
+ svg.setAttribute('type', 'image/svg+xml')
+ svg.setAttribute('data', 'data:image/svg+xml,'+
+ json.content.payload[0]['data'])
+ manager.get(json.parent_header.msg_id).setOutput("<br />")
+ manager.get(json.parent_header.msg_id).setOutput(svg)
+ }
+ }
+
}
})
}
@@ -64,7 +78,7 @@ function inspect(obj) {
str.push(i+": "+inspect(obj[i]).replace("\n", "\n\t"))
return "{\n\t"+str.join("\n\t")+"\n}\n"
} else {
- try {
+ try {
return obj.toString()
} catch (e) {
}
@@ -73,54 +87,54 @@ function inspect(obj) {
}
function StatusBar(obj) {
- $("#"+obj).append("<span class='txt'></span>")
- $("#"+obj).append("<span class='bullet'>&#8226;</span>")
- this.text = $("#"+obj+" .txt")
- this.bullet = $("#"+obj+" .bullet")
+ $("#"+obj).append("<span class='txt'></span>")
+ $("#"+obj).append("<span class='bullet'>&#8226;</span>")
+ this.text = $("#"+obj+" .txt")
+ this.bullet = $("#"+obj+" .bullet")
}
StatusBar.prototype.map = { "idle":"cgreen", "busy":"cyellow", "dead":"cred" }
StatusBar.prototype.set = function(status) {
- this.bullet.removeClass()
- this.bullet.addClass("bullet "+this.map[status])
- this.text.text(status)
+ this.bullet.removeClass()
+ this.bullet.addClass("bullet "+this.map[status])
+ this.text.text(status)
}
function Manager(obj) {
- this.messages = {}
- this.obj = "#"+obj
+ this.messages = {}
+ this.obj = "#"+obj
}
Manager.prototype.get = function (msg_id) {
- if (typeof(this.messages[msg_id]) == "undefined") {
- this.messages[msg_id] = new Message(msg_id, this.obj)
- }
- return this.messages[msg_id]
+ if (typeof(this.messages[msg_id]) == "undefined") {
+ this.messages[msg_id] = new Message(msg_id, this.obj)
+ }
+ return this.messages[msg_id]
}
function Message(msg_id, obj) {
- this.num = exec_count
- $(obj).append("<div id='msg_"+msg_id+"' class='message'></div>")
- this.obj = $(obj+" #msg_"+msg_id)
-
- this.in_head = "<div class='input_header'>In [<span class='cbold'>"
- this.in_head += this.num+"</span>]:</div>"
- this.obj.append(this.in_head)
- this.in_head = $(obj+" #msg_"+msg_id +" .input_header")
- this.obj.append("<pre class='input'></pre><div class='clear'></div>")
- this.input = $(obj+" #msg_"+msg_id +" .input")
-
- this.out_head = "<div class='output_header'></div>"
- this.obj.append(this.out_head)
- this.out_head = $(obj+" #msg_"+msg_id +" .output_header")
- this.obj.append("<pre class='output'></pre><div class='clear'></div>")
- this.output = $(obj+" #msg_"+msg_id +" .output")
+ this.num = exec_count
+ $(obj).append("<div id='msg_"+msg_id+"' class='message'></div>")
+ this.obj = $(obj+" #msg_"+msg_id)
+
+ this.in_head = "<div class='input_header'>In [<span class='cbold'>"
+ this.in_head += this.num+"</span>]:</div>"
+ this.obj.append(this.in_head)
+ this.in_head = $(obj+" #msg_"+msg_id +" .input_header")
+ this.obj.append("<pre class='input'></pre><div class='clear'></div>")
+ this.input = $(obj+" #msg_"+msg_id +" .input")
+
+ this.out_head = "<div class='output_header'></div>"
+ this.obj.append(this.out_head)
+ this.out_head = $(obj+" #msg_"+msg_id +" .output_header")
+ this.obj.append("<pre class='output'></pre><div class='clear'></div>")
+ this.output = $(obj+" #msg_"+msg_id +" .output")
}
Message.prototype.setInput = function(value) {
- this.input.text(value)
+ this.input.append(value)
}
Message.prototype.setOutput = function(value, header) {
- if (header) {
- var o = "Out [<span class='cbold'>"+this.num+"</span>]:"
- this.out_head.html(o)
- }
- this.output.html(this.output.html() + value)
+ if (header) {
+ var o = "Out [<span class='cbold'>"+this.num+"</span>]:"
+ this.out_head.html(o)
+ }
+ this.output.append(value)
}
View
1  IPython/frontend/html/notebook.html
@@ -42,6 +42,7 @@
width:80px;
}
.message .output { float:left; }
+ .inlinesvg { width:432pt; height:288pt; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/notebook.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.