Skip to content

Commit f77a23d

Browse files
committed
Merge pull request ipython#1386 from ellisonbg/jsd3
Adding Javascript output handling to the notebook.
2 parents 0a50e77 + bd9501b commit f77a23d

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

IPython/frontend/html/notebook/static/js/codecell.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,15 @@ var IPython = (function (IPython) {
563563
};
564564

565565

566-
CodeCell.prototype.append_output = function (json) {
566+
CodeCell.prototype.append_output = function (json, dynamic) {
567+
// If dynamic is true, javascript output will be eval'd.
567568
this.expand();
568569
if (json.output_type === 'pyout') {
569-
this.append_pyout(json);
570+
this.append_pyout(json, dynamic);
570571
} else if (json.output_type === 'pyerr') {
571572
this.append_pyerr(json);
572573
} else if (json.output_type === 'display_data') {
573-
this.append_display_data(json);
574+
this.append_display_data(json, dynamic);
574575
} else if (json.output_type === 'stream') {
575576
this.append_stream(json);
576577
};
@@ -585,11 +586,11 @@ var IPython = (function (IPython) {
585586
};
586587

587588

588-
CodeCell.prototype.append_pyout = function (json) {
589+
CodeCell.prototype.append_pyout = function (json, dynamic) {
589590
n = json.prompt_number || ' ';
590591
var toinsert = this.create_output_area();
591592
toinsert.find('div.prompt').addClass('output_prompt').html('Out[' + n + ']:');
592-
this.append_mime_type(json, toinsert);
593+
this.append_mime_type(json, toinsert, dynamic);
593594
this.element.find('div.output').append(toinsert);
594595
// If we just output latex, typeset it.
595596
if ((json.latex !== undefined) || (json.html !== undefined)) {
@@ -641,9 +642,9 @@ var IPython = (function (IPython) {
641642
};
642643

643644

644-
CodeCell.prototype.append_display_data = function (json) {
645+
CodeCell.prototype.append_display_data = function (json, dynamic) {
645646
var toinsert = this.create_output_area();
646-
this.append_mime_type(json, toinsert);
647+
this.append_mime_type(json, toinsert, dynamic);
647648
this.element.find('div.output').append(toinsert);
648649
// If we just output latex, typeset it.
649650
if ( (json.latex !== undefined) || (json.html !== undefined) ) {
@@ -652,8 +653,10 @@ var IPython = (function (IPython) {
652653
};
653654

654655

655-
CodeCell.prototype.append_mime_type = function (json, element) {
656-
if (json.html !== undefined) {
656+
CodeCell.prototype.append_mime_type = function (json, element, dynamic) {
657+
if (json.javascript !== undefined && dynamic) {
658+
this.append_javascript(json.javascript, element, dynamic);
659+
} else if (json.html !== undefined) {
657660
this.append_html(json.html, element);
658661
} else if (json.latex !== undefined) {
659662
this.append_latex(json.latex, element);
@@ -676,6 +679,14 @@ var IPython = (function (IPython) {
676679
};
677680

678681

682+
CodeCell.prototype.append_javascript = function (js, e) {
683+
// We just eval the JS code, element appears in the local scope.
684+
var element = $("<div/>").addClass("box_flex1 output_subarea");
685+
e.append(element);
686+
eval(js);
687+
}
688+
689+
679690
CodeCell.prototype.append_text = function (data, element, extra_class) {
680691
var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
681692
// escape ANSI & HTML specials in plaintext:
@@ -834,7 +845,8 @@ var IPython = (function (IPython) {
834845
};
835846
var len = data.outputs.length;
836847
for (var i=0; i<len; i++) {
837-
this.append_output(data.outputs[i]);
848+
// append with dynamic=false.
849+
this.append_output(data.outputs[i], false);
838850
};
839851
if (data.collapsed !== undefined) {
840852
if (data.collapsed) {

IPython/frontend/html/notebook/static/js/notebook.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ var IPython = (function (IPython) {
993993
} else if (msg_type === 'status') {
994994
if (content.execution_state === 'busy') {
995995
$([IPython.events]).trigger('status_busy.Kernel');
996-
IPython.kernel_status_widget.status_busy();
997996
} else if (content.execution_state === 'idle') {
998997
$([IPython.events]).trigger('status_idle.Kernel');
999998
} else if (content.execution_state === 'dead') {
@@ -1044,7 +1043,8 @@ var IPython = (function (IPython) {
10441043
json.evalue = content.evalue;
10451044
json.traceback = content.traceback;
10461045
};
1047-
cell.append_output(json);
1046+
// append with dynamic=true
1047+
cell.append_output(json, true);
10481048
this.dirty = true;
10491049
};
10501050

0 commit comments

Comments
 (0)