##// END OF EJS Templates
SVG images are now resizable in Chrome+FF.
Brian Granger -
Show More
@@ -275,14 +275,37 var IPython = (function (IPython) {
275
275
276 OutputArea.prototype.append_svg = function (svg, element) {
276 OutputArea.prototype.append_svg = function (svg, element) {
277 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_svg");
277 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_svg");
278 // The <svg> tag cannot be made resizable so we wrap it in a resizable <div>.
279 // The problem with this is that we need to 1) set the initial size of the
280 // <div> based on the size of the <svg> and 2) we need to tie the size of the
281 // <div> and the <svg>.
278 var img = $('<div/>');
282 var img = $('<div/>');
279 img.append(svg);
283 img.html(svg);
280 var h = img.find('svg').attr('height');
281 var w = img.find('svg').attr('width');
282 img.width(w).height(h);
283 img.resizable({'aspectRatio': true});
284 toinsert.append(img);
284 toinsert.append(img);
285 element.append(toinsert);
285 element.append(toinsert);
286 svg = img.find('svg');
287 // The width and height returned here will be a string with units. Any units
288 // could be used and there is no way to reliably compute the equivalent pixels.
289 // Because of this the calls to width and height below simply pass on the unit
290 // information.
291 var w = svg.attr('width');
292 var h = svg.attr('height');
293 // Here we remove the attr versions of the width/height and set the css verions
294 // that we will be using later in the resize callback.
295 svg.removeAttr('height').removeAttr('width');
296 img.width(w).height(h);
297 svg.width(w).height(h);
298 img.resizable({
299 // We can't pass the minHeight/maxHeight options as they are required to
300 // be in pixels and we have no way to determining those numbers.
301 'autoHide': true,
302 'aspectRatio': true,
303 'resize': function () {
304 $(this).find('svg').height($(this).height());
305 $(this).find('svg').width($(this).width());
306 }
307 });
308
286 };
309 };
287
310
288
311
@@ -290,7 +313,7 var IPython = (function (IPython) {
290 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
313 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_png");
291 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
314 var img = $("<img/>").attr('src','data:image/png;base64,'+png);
292 img.load(function () {
315 img.load(function () {
293 $(this).resizable({'aspectRatio': true})
316 $(this).resizable({'aspectRatio': true, 'autoHide': true})
294 });
317 });
295 toinsert.append(img);
318 toinsert.append(img);
296 element.append(toinsert);
319 element.append(toinsert);
@@ -301,7 +324,7 var IPython = (function (IPython) {
301 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
324 var toinsert = $("<div/>").addClass("box-flex1 output_subarea output_jpeg");
302 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
325 var img = $("<img/>").attr('src','data:image/jpeg;base64,'+jpeg);
303 img.load(function () {
326 img.load(function () {
304 $(this).resizable({'aspectRatio': true})
327 $(this).resizable({'aspectRatio': true, 'autoHide': true})
305 });
328 });
306 toinsert.append(img);
329 toinsert.append(img);
307 element.append(toinsert);
330 element.append(toinsert);
General Comments 0
You need to be logged in to leave comments. Login now