From bf817ee8ed03111ce3577355ce67b576303c0ff5 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Mon, 4 Mar 2024 19:51:49 +0100 Subject: [PATCH] fix: #1052 --- index.html | 2 +- modules/renderers/state-labels.js | 25 +++++++++++++++++++------ versioning.js | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 194e560b..16e69f49 100644 --- a/index.html +++ b/index.html @@ -8041,7 +8041,7 @@ - + diff --git a/modules/renderers/state-labels.js b/modules/renderers/state-labels.js index 0c82a4cd..b0cf3001 100644 --- a/modules/renderers/state-labels.js +++ b/modules/renderers/state-labels.js @@ -4,6 +4,10 @@ function drawStateLabels(list) { console.time("drawStateLabels"); + // temporary make the labels visible + const layerDisplay = labels.style("display"); + labels.style("display", null); + const {cells, states, features} = pack; const stateIds = cells.state; @@ -17,7 +21,11 @@ function drawStateLabels(list) { const MAX_ITERATIONS = 100; const labelPaths = getLabelPaths(); - drawLabelPath(); + const letterLength = checkExampleLetterLength(); + drawLabelPath(letterLength); + + // restore labels visibility + labels.style("display", layerDisplay); function getLabelPaths() { const labelPaths = []; @@ -110,17 +118,22 @@ function drawStateLabels(list) { } } - function drawLabelPath() { + function checkExampleLetterLength() { + const textGroup = d3.select("g#labels > g#states"); + const testLabel = textGroup.append("text").attr("x", 0).attr("y", 0).text("Example"); + const letterLength = testLabel.node().getComputedTextLength() / 7; // approximate length of 1 letter + testLabel.remove(); + + return letterLength; + } + + function drawLabelPath(letterLength) { const mode = options.stateLabelsMode || "auto"; const lineGen = d3.line().curve(d3.curveBundle.beta(1)); const textGroup = d3.select("g#labels > g#states"); const pathGroup = d3.select("defs > g#deftemp > g#textPaths"); - const testLabel = textGroup.append("text").attr("x", 0).attr("y", 0).text("Example"); - const letterLength = testLabel.node().getComputedTextLength() / 7; // approximate length of 1 letter - testLabel.remove(); - for (const [stateId, pathPoints] of labelPaths) { const state = states[stateId]; if (!state.i || state.removed) throw new Error("State must not be neutral or removed"); diff --git a/versioning.js b/versioning.js index 2bcedad9..2ea16dfe 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.96.03"; // generator version, update each time +const version = "1.96.04"; // generator version, update each time { document.title += " v" + version;