From 19a8db4a17ea690b50a8e45f869e63e330c67a10 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Tue, 30 Nov 2021 21:47:22 +0300 Subject: [PATCH] disallow adding custom labels to state group --- modules/ui/labels-editor.js | 28 ++++++++++++++++++++++++++-- modules/ui/tools.js | 7 ++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/modules/ui/labels-editor.js b/modules/ui/labels-editor.js index ba30fd55..3d7a3b7f 100644 --- a/modules/ui/labels-editor.js +++ b/modules/ui/labels-editor.js @@ -60,10 +60,18 @@ function editLabel() { function selectLabelGroup(text) { const group = text.parentNode.id; + + if (group === "states" || group === "burgLabels") { + document.getElementById("labelGroupShow").style.display = "none"; + return; + } + + hideGroupSection(); const select = document.getElementById("labelGroupSelect"); select.options.length = 0; // remove all options labels.selectAll(":scope > g").each(function () { + if (this.id === "states") return; if (this.id === "burgLabels") return; select.options.add(new Option(this.id, this.id, false, this.id === group)); }); @@ -89,7 +97,15 @@ function editLabel() { } function addControlPoint(point) { - debug.select("#controlPoints").append("circle").attr("cx", point.x).attr("cy", point.y).attr("r", 2.5).attr("stroke-width", 0.8).call(d3.drag().on("drag", dragControlPoint)).on("click", clickControlPoint); + debug + .select("#controlPoints") + .append("circle") + .attr("cx", point.x) + .attr("cy", point.y) + .attr("r", 2.5) + .attr("stroke-width", 0.8) + .call(d3.drag().on("drag", dragControlPoint)) + .on("click", clickControlPoint); } function dragControlPoint() { @@ -141,7 +157,15 @@ function editLabel() { } const before = ":nth-child(" + (index + 2) + ")"; - debug.select("#controlPoints").insert("circle", before).attr("cx", point[0]).attr("cy", point[1]).attr("r", 2.5).attr("stroke-width", 0.8).call(d3.drag().on("drag", dragControlPoint)).on("click", clickControlPoint); + debug + .select("#controlPoints") + .insert("circle", before) + .attr("cx", point[0]) + .attr("cy", point[1]) + .attr("r", 2.5) + .attr("stroke-width", 0.8) + .call(d3.drag().on("drag", dragControlPoint)) + .on("click", clickControlPoint); redrawLabelPath(); } diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 2fe930ac..f928c25c 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -470,9 +470,10 @@ function addLabelOnClick() { const id = getNextId("label"); // use most recently selected label group - let selected = labelGroupSelect.value; - const symbol = selected ? "#" + selected : "#addedLabels"; - let group = labels.select(symbol); + const lastSelected = labelGroupSelect.value; + const groupId = ["", "states", "burgLabels"].includes(lastSelected) ? "#addedLabels" : "#" + lastSelected; + + let group = labels.select(groupId); if (!group.size()) group = labels .append("g")