From bba555be10666bfb5f8a2d99e9c00ac2fd86074b Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 25 Sep 2023 12:44:47 +0200 Subject: [PATCH] =?UTF-8?q?Replace=20SVG=E2=80=99s=20foreign=20attribute?= =?UTF-8?q?=20with=20a=20specific=20prefix=20for=20IDs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I decided to use a custom attribute for the campsite label in the SVG because i was a bit wary of reusing ‘id’ for that, specially given that most labels are number only and XML can not have IDs starting with a number. In fact, at least Inkscape and Affinity solve the problem by having an additional foreign attribute to keep the “group label” in without that restriction (‘inkscape:label’ and ‘serif:id’, respectively), thus i thought of doing the same, but with a namespace that i control and be independent of the design program. However, it seems that Affinity does not have a way of editing the XML attributes like Inkscape does[0], thus there is no way of adding or editing that value from there; i can not ask Oriol to edit the SVG file in a text editor each time. We have agreed to reuse the ‘id’ attribute to contain the campsite’s label by using a specific prefix, that we checked is editable without issue in Affinity’s UI. [0]: https://forum.affinity.serif.com/index.php?/topic/24318-xml-data/&do=findComment&comment=115609 --- web/static/camper.js | 5 +- web/templates/campground_map.svg | 182 +++++++++++++++---------------- 2 files changed, 94 insertions(+), 93 deletions(-) diff --git a/web/static/camper.js b/web/static/camper.js index 90f1c35..621030f 100644 --- a/web/static/camper.js +++ b/web/static/camper.js @@ -139,8 +139,9 @@ export function setupCampgroundMap(map) { if (!map) { return; } - for (const campsite of Array.from(map.querySelectorAll('.lodge'))) { - const label = campsite.getAttribute('camper:lodge'); + const prefix = "cp_"; + for (const campsite of Array.from(map.querySelectorAll(`[id^="${prefix}"]`))) { + const label = campsite.id.substring(prefix.length); if (!label) { continue; } diff --git a/web/templates/campground_map.svg b/web/templates/campground_map.svg index 1785a78..bef71cb 100644 --- a/web/templates/campground_map.svg +++ b/web/templates/campground_map.svg @@ -1,4 +1,4 @@ - + @@ -19,35 +19,35 @@ - + 30 - + 31 - + 32 - + 33 - + 34 - + 35 - + 36 - + B1 @@ -55,152 +55,152 @@ - + D1 - + D2 - + D3 - + D4 - + 38 - + 39 - + 40 - + 41 - + 42 - + 43 - + 44 - + 45 - + 46 - + 47 - + 48 - + 50 - + 51 - + 52 - + 53 - + 54 - + 55 - + 79 - + 80 - + 89 - + 98 - + 97 - + 96 - + 90 - + 91 - + 92 - + 93 - + 94 - + 95 - + 81 - + 82 - + 83 @@ -210,187 +210,187 @@ - + 77 - + 76 - + 75 - + 74 - + 73 - + 72 - + 71 - + 70 - + 69 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + 9 - + 10 - + 11 - + 12 - + 64 - + 65 - + 62 - + 63 - + 56 - + 57 - + 58 - + 59 - + 60 - + 61 - + 29 - + 28 - + 27 - + 26 - + 25 - + 24 - + 23 - + 22 - + 21 - + 20 - + 19 - + 18 - + 17 - + 16 - + 15 - + 14