This commit is contained in:
Azgaar 2024-03-04 19:51:49 +01:00
parent 5aa1d65a1b
commit bf817ee8ed
3 changed files with 21 additions and 8 deletions

View file

@ -8041,7 +8041,7 @@
<script src="modules/biomes.js"></script> <script src="modules/biomes.js"></script>
<script src="modules/names-generator.js?v=1.87.14"></script> <script src="modules/names-generator.js?v=1.87.14"></script>
<script src="modules/cultures-generator.js?v=1.96.00"></script> <script src="modules/cultures-generator.js?v=1.96.00"></script>
<script src="modules/renderers/state-labels.js"></script> <script src="modules/renderers/state-labels.js?v=1.96.04"></script>
<script src="modules/burgs-and-states.js?v=1.92.00"></script> <script src="modules/burgs-and-states.js?v=1.92.00"></script>
<script src="modules/routes-generator.js"></script> <script src="modules/routes-generator.js"></script>
<script src="modules/religions-generator.js?v=1.93.08"></script> <script src="modules/religions-generator.js?v=1.93.08"></script>

View file

@ -4,6 +4,10 @@
function drawStateLabels(list) { function drawStateLabels(list) {
console.time("drawStateLabels"); console.time("drawStateLabels");
// temporary make the labels visible
const layerDisplay = labels.style("display");
labels.style("display", null);
const {cells, states, features} = pack; const {cells, states, features} = pack;
const stateIds = cells.state; const stateIds = cells.state;
@ -17,7 +21,11 @@ function drawStateLabels(list) {
const MAX_ITERATIONS = 100; const MAX_ITERATIONS = 100;
const labelPaths = getLabelPaths(); const labelPaths = getLabelPaths();
drawLabelPath(); const letterLength = checkExampleLetterLength();
drawLabelPath(letterLength);
// restore labels visibility
labels.style("display", layerDisplay);
function getLabelPaths() { function getLabelPaths() {
const labelPaths = []; 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 mode = options.stateLabelsMode || "auto";
const lineGen = d3.line().curve(d3.curveBundle.beta(1)); const lineGen = d3.line().curve(d3.curveBundle.beta(1));
const textGroup = d3.select("g#labels > g#states"); const textGroup = d3.select("g#labels > g#states");
const pathGroup = d3.select("defs > g#deftemp > g#textPaths"); 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) { for (const [stateId, pathPoints] of labelPaths) {
const state = states[stateId]; const state = states[stateId];
if (!state.i || state.removed) throw new Error("State must not be neutral or removed"); if (!state.i || state.removed) throw new Error("State must not be neutral or removed");

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
// version and caching control // 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; document.title += " v" + version;