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