Skip to content

Commit b352779

Browse files
committed
optimization and cleanup
1 parent b87ba71 commit b352779

1 file changed

Lines changed: 11 additions & 47 deletions

File tree

index.html

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
z-index: 1000;
223223
display: none;
224224
box-shadow: 0 0 10px rgba(255, 107, 53, 0.5);
225+
top: 0;
226+
left: 0;
227+
will-change: transform;
225228
}
226229

227230
/* Right Sidebar */
@@ -1520,8 +1523,9 @@ <h2 class="modal-title">Export Flow Map</h2>
15201523

15211524
if (clientX !== undefined && clientY !== undefined) {
15221525
const cursorRadius = size / 2;
1523-
this.brushCursor.style.left = `${(clientX - rect.left) - cursorRadius}px`;
1524-
this.brushCursor.style.top = `${(clientY - rect.top) - cursorRadius}px`;
1526+
const x = (clientX - rect.left) - cursorRadius;
1527+
const y = (clientY - rect.top) - cursorRadius;
1528+
this.brushCursor.style.transform = `translate3d(${x}px, ${y}px, 0)`;
15251529
}
15261530

15271531
// Update cursor appearance based on tool
@@ -1545,8 +1549,9 @@ <h2 class="modal-title">Export Flow Map</h2>
15451549
const visualSize = (this.brushSize * brushScale * 2) / scale;
15461550
const cursorRadius = visualSize / 2;
15471551

1548-
this.brushCursor.style.left = `${(e.clientX - rect.left) - cursorRadius}px`;
1549-
this.brushCursor.style.top = `${(e.clientY - rect.top) - cursorRadius}px`;
1552+
const x = (e.clientX - rect.left) - cursorRadius;
1553+
const y = (e.clientY - rect.top) - cursorRadius;
1554+
this.brushCursor.style.transform = `translate3d(${x}px, ${y}px, 0)`;
15501555

15511556
// Calculate mouse velocity and direction
15521557
this.mouseVelocityX = this.mouseX - this.lastMouseX;
@@ -1807,6 +1812,7 @@ <h2 class="modal-title">Export Flow Map</h2>
18071812
this.ctx.globalAlpha = 0.5;
18081813
this.ctx.strokeStyle = '#ffffff';
18091814
this.ctx.lineWidth = Math.max(1, 2 * scale);
1815+
this.ctx.beginPath();
18101816

18111817
const imageData = this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
18121818
const data = imageData.data;
@@ -1824,14 +1830,11 @@ <h2 class="modal-title">Export Flow Map</h2>
18241830
const magnitude = Math.sqrt(flowX * flowX + flowY * flowY);
18251831

18261832
if (magnitude > 0.1 && data[index + 3] > 10) {
1827-
this.ctx.beginPath();
18281833
this.ctx.moveTo(x, y);
18291834
this.ctx.lineTo(x + flowX * arrowSize, y + flowY * arrowSize);
1830-
this.ctx.stroke();
18311835

18321836
// Arrow head
18331837
const angle = Math.atan2(flowY, flowX);
1834-
this.ctx.beginPath();
18351838
this.ctx.moveTo(x + flowX * arrowSize, y + flowY * arrowSize);
18361839
this.ctx.lineTo(
18371840
x + flowX * arrowSize - headSize * Math.cos(angle - Math.PI / 6),
@@ -1842,11 +1845,10 @@ <h2 class="modal-title">Export Flow Map</h2>
18421845
x + flowX * arrowSize - headSize * Math.cos(angle + Math.PI / 6),
18431846
y + flowY * arrowSize - headSize * Math.sin(angle + Math.PI / 6)
18441847
);
1845-
this.ctx.stroke();
18461848
}
18471849
}
18481850
}
1849-
1851+
this.ctx.stroke();
18501852
this.ctx.restore();
18511853
}
18521854

@@ -2488,44 +2490,6 @@ <h2 class="modal-title">Export Flow Map</h2>
24882490

24892491
requestAnimationFrame(() => this.animate());
24902492
}
2491-
2492-
// Utility functions
2493-
hexToRgb(hex) {
2494-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
2495-
return result ? {
2496-
r: parseInt(result[1], 16),
2497-
g: parseInt(result[2], 16),
2498-
b: parseInt(result[3], 16)
2499-
} : null;
2500-
}
2501-
2502-
rgbToHex(r, g, b) {
2503-
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
2504-
}
2505-
2506-
hsvToRgb(h, s, v) {
2507-
let r, g, b;
2508-
const i = Math.floor(h * 6);
2509-
const f = h * 6 - i;
2510-
const p = v * (1 - s);
2511-
const q = v * (1 - f * s);
2512-
const t = v * (1 - (1 - f) * s);
2513-
2514-
switch (i % 6) {
2515-
case 0: r = v, g = t, b = p; break;
2516-
case 1: r = q, g = v, b = p; break;
2517-
case 2: r = p, g = v, b = t; break;
2518-
case 3: r = p, g = q, b = v; break;
2519-
case 4: r = t, g = p, b = v; break;
2520-
case 5: r = v, g = p, b = q; break;
2521-
}
2522-
2523-
return {
2524-
r: Math.round(r * 255),
2525-
g: Math.round(g * 255),
2526-
b: Math.round(b * 255)
2527-
};
2528-
}
25292493
}
25302494

25312495
// Initialize the application

0 commit comments

Comments
 (0)