From c4dc20eac09b00fe220ad2854f331717ab9a3adb Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 12 Oct 2017 14:50:48 +0800 Subject: [PATCH] tweak legend keeping aspect --- src/util/graphic.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/util/graphic.js b/src/util/graphic.js index 7c7420f51..aa13e2f49 100644 --- a/src/util/graphic.js +++ b/src/util/graphic.js @@ -88,14 +88,21 @@ define(function(require) { return path; }; + /** + * Create a image element from image url + * @param {string} imageUrl image url + * @param {Object} opts options + * @param {module:zrender/core/BoundingRect} rect constrain rect + * @param {string} [layout=cover] 'center' or 'cover' + */ graphic.makeImage = function (imageUrl, rect, layout) { var path = new graphic.Image({ style: { image: imageUrl, x: rect.x, y: rect.y, - width: rect.w, - height: rect.h + width: rect.width, + height: rect.height }, onload: function (img) { if (layout === 'center') { @@ -103,12 +110,7 @@ define(function(require) { width: img.width, height: img.height }; - - var r = centerGraphic(rect, boundingRect); - path.style.x = r.x; - path.style.y = r.y; - path.style.width = r.width; - path.style.height = r.height; + path.setStyle(centerGraphic(rect, boundingRect)); } } }); -- GitLab