refactor: state labels - fix edit

This commit is contained in:
Azgaar 2022-09-17 00:57:54 +03:00
parent 392325eb53
commit b6acd8ffff

View file

@ -14,6 +14,8 @@ export function open({el}) {
closeDialogs(); closeDialogs();
if (!layerIsOn("toggleLabels")) toggleLayer("toggleLabels"); if (!layerIsOn("toggleLabels")) toggleLayer("toggleLabels");
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
const textPath = el.parentNode; const textPath = el.parentNode;
const text = textPath.parentNode; const text = textPath.parentNode;
elSelected = d3.select(text).call(d3.drag().on("start", dragLabel)).classed("draggable", true); elSelected = d3.select(text).call(d3.drag().on("start", dragLabel)).classed("draggable", true);
@ -123,8 +125,6 @@ export function open({el}) {
redrawLabelPath(); redrawLabelPath();
} }
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
function redrawLabelPath() { function redrawLabelPath() {
const path = byId("textPath_" + elSelected.attr("id")); const path = byId("textPath_" + elSelected.attr("id"));
const points = []; const points = [];
@ -308,26 +308,12 @@ export function open({el}) {
function changeText() { function changeText() {
const input = byId("labelText").value; const input = byId("labelText").value;
const el = elSelected.select("textPath").node(); const el = elSelected.select("textPath").node();
const example = d3
.select(elSelected.node().parentNode)
.append("text")
.attr("x", 0)
.attr("x", 0)
.attr("font-size", el.getAttribute("font-size"))
.node();
const lines = input.split("|"); const lines = input.split("|");
const top = (lines.length - 1) / -2; // y offset const top = (lines.length - 1) / -2; // y offset
const inner = lines const inner = lines.map((l, d) => `<tspan x="0" dy="${d ? 1 : top}em">${l}</tspan>`).join("");
.map((l, d) => {
example.innerHTML = l;
const left = example.getBBox().width / -2; // x offset
return `<tspan x="${left}px" dy="${d ? 1 : top}em">${l}</tspan>`;
})
.join("");
el.innerHTML = inner; el.innerHTML = inner;
example.remove();
if (elSelected.attr("id").slice(0, 10) === "stateLabel") if (elSelected.attr("id").slice(0, 10) === "stateLabel")
tip("Use States Editor to change an actual state name, not just a label", false, "warning"); tip("Use States Editor to change an actual state name, not just a label", false, "warning");