Show More
@@ -585,19 +585,45 b' var IPython = (function (IPython) {' | |||||
585 | }; |
|
585 | }; | |
586 |
|
586 | |||
587 |
|
587 | |||
588 | var append_svg = function (svg, md, element) { |
|
588 | var append_svg = function (svg_html, md, element) { | |
589 | var type = 'image/svg+xml'; |
|
589 | var type = 'image/svg+xml'; | |
590 | var toinsert = this.create_output_subarea(md, "output_svg", type); |
|
590 | var toinsert = this.create_output_subarea(md, "output_svg", type); | |
591 | toinsert.append(svg); |
|
591 | ||
|
592 | // Get the svg element from within the HTML. | |||
|
593 | var svg = $('<div />').html(svg_html).find('svg'); | |||
|
594 | var svg_area = $('<div />'); | |||
|
595 | var width = svg.attr('width'); | |||
|
596 | var height = svg.attr('height'); | |||
|
597 | svg | |||
|
598 | .width('100%') | |||
|
599 | .height('100%'); | |||
|
600 | svg_area | |||
|
601 | .width(width) | |||
|
602 | .height(height); | |||
|
603 | ||||
|
604 | // The jQuery resize handlers don't seem to work on the svg element. | |||
|
605 | // When the svg renders completely, measure it's size and set the parent | |||
|
606 | // div to that size. Then set the svg to 100% the size of the parent | |||
|
607 | // div and make the parent div resizable. | |||
|
608 | this._dblclick_to_reset_size(svg_area, true, false); | |||
|
609 | ||||
|
610 | svg_area.append(svg); | |||
|
611 | toinsert.append(svg_area); | |||
592 | element.append(toinsert); |
|
612 | element.append(toinsert); | |
|
613 | ||||
593 | return toinsert; |
|
614 | return toinsert; | |
594 | }; |
|
615 | }; | |
595 |
|
616 | |||
596 |
|
617 | OutputArea.prototype._dblclick_to_reset_size = function (img, immediately, resize_parent) { | ||
597 | OutputArea.prototype._dblclick_to_reset_size = function (img) { |
|
618 | // Add a resize handler to an element | |
598 | // wrap image after it's loaded on the page, |
|
619 | // | |
599 | // otherwise the measured initial size will be incorrect |
|
620 | // img: jQuery element | |
600 | img.on("load", function (){ |
|
621 | // immediately: bool=False | |
|
622 | // Wait for the element to load before creating the handle. | |||
|
623 | // resize_parent: bool=True | |||
|
624 | // Should the parent of the element be resized when the element is | |||
|
625 | // reset (by double click). | |||
|
626 | var callback = function (){ | |||
601 | var h0 = img.height(); |
|
627 | var h0 = img.height(); | |
602 | var w0 = img.width(); |
|
628 | var w0 = img.width(); | |
603 | if (!(h0 && w0)) { |
|
629 | if (!(h0 && w0)) { | |
@@ -610,12 +636,20 b' var IPython = (function (IPython) {' | |||||
610 | }); |
|
636 | }); | |
611 | img.dblclick(function () { |
|
637 | img.dblclick(function () { | |
612 | // resize wrapper & image together for some reason: |
|
638 | // resize wrapper & image together for some reason: | |
613 | img.parent().height(h0); |
|
|||
614 | img.height(h0); |
|
639 | img.height(h0); | |
615 | img.parent().width(w0); |
|
|||
616 | img.width(w0); |
|
640 | img.width(w0); | |
|
641 | if (resize_parent === undefined || resize_parent) { | |||
|
642 | img.parent().height(h0); | |||
|
643 | img.parent().width(w0); | |||
|
644 | } | |||
617 | }); |
|
645 | }); | |
618 |
} |
|
646 | }; | |
|
647 | ||||
|
648 | if (immediately) { | |||
|
649 | callback(); | |||
|
650 | } else { | |||
|
651 | img.on("load", callback); | |||
|
652 | } | |||
619 | }; |
|
653 | }; | |
620 |
|
654 | |||
621 | var set_width_height = function (img, md, mime) { |
|
655 | var set_width_height = function (img, md, mime) { |
General Comments 0
You need to be logged in to leave comments.
Login now