From 9f7ca73e8cbedbd6c02d1651115eeb4afeca9d77 Mon Sep 17 00:00:00 2001 From: sverweij Date: Sun, 26 Nov 2023 13:52:06 +0100 Subject: [PATCH] refactor: makes the hack look less gross --- src/cli/tools/svg-in-html-snippets/script.js | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cli/tools/svg-in-html-snippets/script.js b/src/cli/tools/svg-in-html-snippets/script.js index 6ec9cce21..93c02ed2c 100644 --- a/src/cli/tools/svg-in-html-snippets/script.js +++ b/src/cli/tools/svg-in-html-snippets/script.js @@ -263,13 +263,20 @@ document.querySelector("svg").insertAdjacentHTML( // chrome) do not render the gradient, but instead make the line transparent // (or the color of the background, I haven't looked into it that deeply, // but for the hack it doesn't matter which). -function skewLineABit(pElement) { - var d = pElement.attributes.d.value; - var lastValue = d.match(/(\d+\.?\d*)$/)[0]; - var newValue = parseFloat(lastValue) + 0.001; - - pElement.attributes.d.value = d.replace(lastValue, newValue); +// @side-effect: changes the path element passed in. +function skewLineABit(lDrawingInstructions) { + var lLastValue = lDrawingInstructions.match(/(\d+\.?\d*)$/)[0]; + // Smaller values than .001 _should_ work as well, but don't in all + // cases. Even this value is so small that it is not visible to the + // human eye (tested with the two I have at my disposal). + var lNewLastValue = parseFloat(lLastValue) + 0.001; + + return lDrawingInstructions.replace(lLastValue, lNewLastValue); } + nodeListToArray(document.querySelectorAll("path")) .filter((pElement) => pElement.parentElement.classList.contains("edge")) - .forEach((pElement) => skewLineABit(pElement)); + .forEach( + (pElement) => + (pElement.attributes.d.value = skewLineABit(pElement.attributes.d.value)), + );