From db84364aa5288240fe86b1b40accc95fb657e5b4 Mon Sep 17 00:00:00 2001 From: Evolvedexperiment Date: Sat, 29 Jan 2022 14:21:04 +0000 Subject: [PATCH] Removed haching completely from map svg --- index.html | 2 -- main.js | 6 ------ modules/export.js | 4 +++- modules/load.js | 12 +++++------- modules/save.js | 1 - modules/ui/editors.js | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 4d71f944..c0f73e2f 100644 --- a/index.html +++ b/index.html @@ -148,8 +148,6 @@ - - diff --git a/main.js b/main.js index d58be361..4de5b137 100644 --- a/main.js +++ b/main.js @@ -656,7 +656,6 @@ function generate() { Military.generate(); Markers.generate(); - copyHatching(); addZones(); Names.getMapName(); @@ -1484,11 +1483,6 @@ function rankCells() { TIME && console.timeEnd("rankCells"); } -// copy the hatching (patterns) -function copyHatching() { - document.getElementById("hatching").innerHTML = document.getElementById("defs-hatching").innerHTML; -} - // regenerate some zones function addZones(number = 1) { TIME && console.time("addZones"); diff --git a/modules/export.js b/modules/export.js index 7b88a7e6..b8f74785 100644 --- a/modules/export.js +++ b/modules/export.js @@ -262,7 +262,9 @@ async function getMapURL(type, options = {}) { if (pattern) cloneDefs.appendChild(pattern.cloneNode(true)); } - if (!cloneEl.getElementById("hatching").children.length) cloneEl.getElementById("hatching")?.remove(); // remove unused hatching group + const hatching = svgDefs.getElementById("defs-hatching"); + if (hatching) cloneDefs.appendChild(hatching.cloneNode(true)); + if (!cloneEl.getElementById("fogging-cont")) cloneEl.getElementById("fog")?.remove(); // remove unused fog if (!cloneEl.getElementById("regions")) cloneEl.getElementById("statePaths")?.remove(); // removed unused statePaths if (!cloneEl.getElementById("labels")) cloneEl.getElementById("textPaths")?.remove(); // removed unused textPaths diff --git a/modules/load.js b/modules/load.js index 86aa79a1..d0d51714 100644 --- a/modules/load.js +++ b/modules/load.js @@ -472,11 +472,6 @@ function parseLoadedData(data) { if (!layerIsOn("toggleBorders")) $("#borders").fadeOut(); if (!layerIsOn("toggleStates")) regions.attr("display", "none").selectAll("path").remove(); - // 1.0 adds hatching - const gHatching = document.createElementNS("http://www.w3.org/2000/svg", "g"); - gHatching.setAttribute("id", "hatching"); - document.getElementsByTagName("defs")[0].appendChild(gHatching); - // 1.0 adds zones layer zones = viewbox.insert("g", "#borders").attr("id", "zones").attr("display", "none"); zones.attr("opacity", 0.6).attr("stroke", null).attr("stroke-width", 0).attr("stroke-dasharray", null).attr("stroke-linecap", "butt"); @@ -931,8 +926,11 @@ function parseLoadedData(data) { } } - copyHatching(); - + if (version < 1.72) { + // 1.72 moves the hatching patterns out of the SVG + document.getElementById("hatching")?.remove(); + } + })(); void (function checkDataIntegrity() { diff --git a/modules/save.js b/modules/save.js index fe9b64da..04f3e665 100644 --- a/modules/save.js +++ b/modules/save.js @@ -51,7 +51,6 @@ function getMapData() { cloneEl.querySelector("#viewbox").removeAttribute("transform"); cloneEl.querySelector("#ruler").innerHTML = ""; // always remove rulers - cloneEl.querySelector("#hatching").innerHTML = ""; // remove hatching patterns const serializedSVG = new XMLSerializer().serializeToString(cloneEl); diff --git a/modules/ui/editors.js b/modules/ui/editors.js index 0b647f78..aed40e01 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -482,7 +482,7 @@ function createPicker() { const colors = picker.append("g").attr("id", "pickerColors").attr("stroke", "#333333"); const hatches = picker.append("g").attr("id", "pickerHatches").attr("stroke", "#333333"); - const hatching = d3.selectAll("g#hatching > pattern"); + const hatching = d3.selectAll("g#defs-hatching > pattern"); const number = hatching.size(); const clr = d3.range(number).map(i => d3.hsl((i / number) * 360, 0.7, 0.7).hex());