Merge pull request #1386 from ellisonbg/jsd3

Adding Javascript output handling to the notebook.
Brian E. Granger 14 years ago
commit d0c445a63c

@ -563,14 +563,15 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.append_output = function (json) {
CodeCell.prototype.append_output = function (json, dynamic) {
// If dynamic is true, javascript output will be eval'd.
this.expand();
if (json.output_type === 'pyout') {
this.append_pyout(json);
this.append_pyout(json, dynamic);
} else if (json.output_type === 'pyerr') {
this.append_pyerr(json);
} else if (json.output_type === 'display_data') {
this.append_display_data(json);
this.append_display_data(json, dynamic);
} else if (json.output_type === 'stream') {
this.append_stream(json);
};
@ -585,11 +586,11 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.append_pyout = function (json) {
CodeCell.prototype.append_pyout = function (json, dynamic) {
n = json.prompt_number || ' ';
var toinsert = this.create_output_area();
toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
this.append_mime_type(json, toinsert);
this.append_mime_type(json, toinsert, dynamic);
this.element.find('div.output').append(toinsert);
// If we just output latex, typeset it.
if ((json.latex !== undefined) || (json.html !== undefined)) {
@ -641,9 +642,9 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.append_display_data = function (json) {
CodeCell.prototype.append_display_data = function (json, dynamic) {
var toinsert = this.create_output_area();
this.append_mime_type(json, toinsert);
this.append_mime_type(json, toinsert, dynamic);
this.element.find('div.output').append(toinsert);
// If we just output latex, typeset it.
if ( (json.latex !== undefined) || (json.html !== undefined) ) {
@ -652,8 +653,10 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.append_mime_type = function (json, element) {
if (json.html !== undefined) {
CodeCell.prototype.append_mime_type = function (json, element, dynamic) {
if (json.javascript !== undefined && dynamic) {
this.append_javascript(json.javascript, element, dynamic);
} else if (json.html !== undefined) {
this.append_html(json.html, element);
} else if (json.latex !== undefined) {
this.append_latex(json.latex, element);
@ -676,6 +679,14 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.append_javascript = function (js, e) {
// We just eval the JS code, element appears in the local scope.
var element = $("<div/>").addClass("box_flex1 output_subarea");
e.append(element);
eval(js);
}
CodeCell.prototype.append_text = function (data, element, extra_class) {
var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
// escape ANSI & HTML specials in plaintext:
@ -834,7 +845,8 @@ var IPython = (function (IPython) {
};
var len = data.outputs.length;
for (var i=0; i<len; i++) {
this.append_output(data.outputs[i]);
// append with dynamic=false.
this.append_output(data.outputs[i], false);
};
if (data.collapsed !== undefined) {
if (data.collapsed) {

@ -993,7 +993,6 @@ var IPython = (function (IPython) {
} else if (msg_type === 'status') {
if (content.execution_state === 'busy') {
$([IPython.events]).trigger('status_busy.Kernel');
IPython.kernel_status_widget.status_busy();
} else if (content.execution_state === 'idle') {
$([IPython.events]).trigger('status_idle.Kernel');
} else if (content.execution_state === 'dead') {
@ -1044,7 +1043,8 @@ var IPython = (function (IPython) {
json.evalue = content.evalue;
json.traceback = content.traceback;
};
cell.append_output(json);
// append with dynamic=true
cell.append_output(json, true);
this.dirty = true;
};

Loading…
Cancel
Save