Optimize renderTrails to build SVG point strings directly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
982bdb77e2
commit
6f121e2a90
1 changed files with 18 additions and 19 deletions
|
|
@ -1778,19 +1778,18 @@ function render(players) {
|
|||
/* ---------- rendering trails ------------------------------- */
|
||||
function renderTrails(trailData) {
|
||||
trailsContainer.innerHTML = '';
|
||||
const byChar = trailData.reduce((acc, pt) => {
|
||||
(acc[pt.character_name] = acc[pt.character_name] || []).push(pt);
|
||||
return acc;
|
||||
}, {});
|
||||
for (const [name, pts] of Object.entries(byChar)) {
|
||||
if (pts.length < 2) continue;
|
||||
const points = pts.map(pt => {
|
||||
// Build point strings directly - avoid intermediate arrays
|
||||
const byChar = {};
|
||||
for (const pt of trailData) {
|
||||
const { x, y } = worldToPx(pt.ew, pt.ns);
|
||||
return `${x},${y}`;
|
||||
}).join(' ');
|
||||
const key = pt.character_name;
|
||||
if (!byChar[key]) byChar[key] = { points: `${x},${y}`, count: 1 };
|
||||
else { byChar[key].points += ` ${x},${y}`; byChar[key].count++; }
|
||||
}
|
||||
for (const name in byChar) {
|
||||
if (byChar[name].count < 2) continue;
|
||||
const poly = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
|
||||
poly.setAttribute('points', points);
|
||||
// Use the same color as the player dot for consistency
|
||||
poly.setAttribute('points', byChar[name].points);
|
||||
poly.setAttribute('stroke', getColorFor(name));
|
||||
poly.setAttribute('fill', 'none');
|
||||
poly.setAttribute('class', 'trail-path');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue