mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-23 15:47:24 +01:00
refactor: optimize label rendering by building HTML string for batch updates
This commit is contained in:
parent
6fa3f786dc
commit
e1740567c6
1 changed files with 11 additions and 10 deletions
|
|
@ -35,22 +35,23 @@ const burgLabelsRenderer = (): void => {
|
|||
const dx = dxAttr ? parseFloat(dxAttr) : 0;
|
||||
const dy = dyAttr ? parseFloat(dyAttr) : 0;
|
||||
|
||||
// Build HTML string for all labels in this group
|
||||
const labelsHTML: string[] = [];
|
||||
for (const labelData of labels) {
|
||||
// Update label data with SVG group offsets
|
||||
if (labelData.dx !== dx || labelData.dy !== dy) {
|
||||
Labels.updateLabel(labelData.i, { dx, dy });
|
||||
}
|
||||
|
||||
labelGroup
|
||||
.append("text")
|
||||
.attr("text-rendering", "optimizeSpeed")
|
||||
.attr("id", `burgLabel${labelData.burgId}`)
|
||||
.attr("data-id", labelData.burgId)
|
||||
.attr("x", labelData.x)
|
||||
.attr("y", labelData.y)
|
||||
.attr("dx", `${dx}em`)
|
||||
.attr("dy", `${dy}em`)
|
||||
.text(labelData.text);
|
||||
labelsHTML.push(
|
||||
`<text text-rendering="optimizeSpeed" id="burgLabel${labelData.burgId}" data-id="${labelData.burgId}" x="${labelData.x}" y="${labelData.y}" dx="${dx}em" dy="${dy}em">${labelData.text}</text>`
|
||||
);
|
||||
}
|
||||
|
||||
// Set all labels at once
|
||||
const groupNode = labelGroup.node();
|
||||
if (groupNode) {
|
||||
groupNode.innerHTML = labelsHTML.join("");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue