Skip to content

Commit

Permalink
Merge pull request #1140 from dondi/maika-1093
Browse files Browse the repository at this point in the history
Addition fix to previous fix for #1093
  • Loading branch information
dondi authored Nov 13, 2024
2 parents 4f0adaf + 061ad53 commit 770e4d1
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions web-client/public/js/setup-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ export const setupHandlers = grnState => {
window.document.body.appendChild(emptySvg);
var emptySvgDeclarationComputed = getComputedStyle(emptySvg);

const traverse = svg => {
var tree = [];
tree.push(svg);
// implement DFS
const visit = (node) => {
if (node && node.hasChildNodes()) {
var child = node.firstChild;
const traverse = (node) => {
const tree = [];
const visit = (currentNode) => {
if (currentNode && currentNode.hasChildNodes()) {
let child = currentNode.firstChild;
while (child) {
if (child.nodeType === 1 && child.nodeName !== "SCRIPT") {
tree.push(child);
Expand All @@ -110,38 +108,39 @@ export const setupHandlers = grnState => {
}
}
};
visit(svg);
visit(node);
return tree;
};

const explicitlySetStyle = element => {
const cSSStyleDeclarationComputed = window.getComputedStyle(element);
let i;
let len;
let key;
let value;
let computedStyleStr = "";

for (i = 0, len = cSSStyleDeclarationComputed.length; i < len; i++) {
key = cSSStyleDeclarationComputed[i];
value = cSSStyleDeclarationComputed.getPropertyValue(key);
const cssStyleDeclarationComputed = window.getComputedStyle(element);
const computedStyleObj = {};


for (let i = 0; i < cssStyleDeclarationComputed.length; i++) {
const key = cssStyleDeclarationComputed[i];
const value = cssStyleDeclarationComputed.getPropertyValue(key);
if (value !== emptySvgDeclarationComputed.getPropertyValue(key)) {
// Don't set computed style of width and height. Makes SVG elmements disappear.
if ((key !== "height") && (key !== "width")) {
computedStyleStr += key + ":" + value + ";";
computedStyleObj[key] = value;
}

}
}
element.setAttribute("style", computedStyleStr);

if (element.classList.contains("weight")) {
computedStyleObj["visibility"] = "hidden";
}

if (computedStyleObj) {
Object.assign(element.style, computedStyleObj)
}
};

// hardcode computed css styles inside svg
var allElements = traverse(svg);
var i = allElements.length;
while (i--) {
explicitlySetStyle(allElements[i]);
}
allElements.forEach(explicitlySetStyle);
};

const sourceAttributeSetter = (svg) => {
Expand Down

0 comments on commit 770e4d1

Please sign in to comment.