From e68f8cc20a5957d45c5a2dbbbeb784d8e3bf96bb Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Fri, 25 Jun 2021 10:06:58 -0500 Subject: [PATCH] better gradient previews --- src/js/PaintBox.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/js/PaintBox.js b/src/js/PaintBox.js index f47e3d8..e727403 100644 --- a/src/js/PaintBox.js +++ b/src/js/PaintBox.js @@ -82,19 +82,10 @@ MD.PaintBox = function(container, type){ var id = this.grad.id = 'gradbox_' + this.type; fillAttr = "url(#" + id + ')'; if (this.grad.getAttribute('gradientUnits') === "userSpaceOnUse") { - const box = $("#tool_" + this.type); - const width = box.width(); - const height = box.height(); - const selectedElement = svgCanvas.getSelectedElems().filter(Boolean)[0]; - if (!selectedElement) return; - const bbox = selectedElement.getBBox(); - const rRatio = this.grad.getAttribute("r") / (bbox.width/2); - const cxRatio = this.grad.getAttribute("cx") / (bbox.width); - const cyRatio = this.grad.getAttribute("cy") / (bbox.height); - this.grad.removeAttribute("gradientTransform"); - this.grad.setAttribute("r", width/2*rRatio); - this.grad.setAttribute("cx", cxRatio * width/2); - this.grad.setAttribute("cy", cyRatio * height/2); + const gradient = this.grad; + ["userSpaceOnUse", "gradientTransform", "gradientUnits", "cx", "cy", "fx", "fy", "r"].forEach(attr => { + gradient.removeAttribute(attr); + }); } } this.rect.setAttribute('fill', fillAttr);