From 76c6aff40c9a9141f7c8b0c2651c0667c92ffd24 Mon Sep 17 00:00:00 2001 From: yusuf canbaz Date: Thu, 20 Feb 2020 14:29:39 +0300 Subject: [PATCH] cytoscape#41 don't change aspect ratio of image --- cytoscape-navigator.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cytoscape-navigator.js b/cytoscape-navigator.js index 7299f30..1bcdfe3 100644 --- a/cytoscape-navigator.js +++ b/cytoscape-navigator.js @@ -871,7 +871,9 @@ var png = that.cy.png({ full: true, - scale: zoom + scale: zoom, + maxHeight: h, + maxWidth: w }); if( png.indexOf('image/png') < 0 ){ img.removeAttribute( 'src' ); @@ -879,9 +881,14 @@ img.setAttribute( 'src', png ); } + var translate = { + x: (w - zoom*( bb.w ))/2, + y: (h - zoom*( bb.h ))/2 + }; + $img.style['position'] = 'absolute'; - $img.style['width'] = w + 'px'; - $img.style['height'] = h + 'px'; + $img.style['left'] = translate.x + 'px'; + $img.style['top'] = translate.y + 'px'; }