refactor(MapNode, StatisticsToggle): streamline text rendering in MapNode and replace switches with buttons in StatisticsToggle for improved UI

This commit is contained in:
2025-09-15 17:39:07 +02:00
parent 0c5d0616e5
commit 7f4ca796aa
2 changed files with 102 additions and 77 deletions

View File

@@ -208,9 +208,19 @@ export const MapNode: React.FC<MapNodeProps> = ({
<tspan fill={getSecurityColor(security)}>{security.toFixed(1)}</tspan> <tspan fill={getSecurityColor(security)}>{security.toFixed(1)}</tspan>
)} )}
</text> </text>
{/* Dynamic text positioning based on what's shown */}
{(() => {
let currentY = textOffset + 15;
const textElements = [];
// Add signatures if present
if (signatures !== undefined && signatures > 0) {
textElements.push(
<text <text
key="signatures"
x="0" x="0"
y={textOffset + 15} y={currentY}
textAnchor="middle" textAnchor="middle"
fill="#a3a3a3" fill="#a3a3a3"
fontSize="12" fontSize="12"
@@ -222,14 +232,19 @@ export const MapNode: React.FC<MapNodeProps> = ({
transform={`scale(${1 / (1200 / viewBoxWidth)})`} transform={`scale(${1 / (1200 / viewBoxWidth)})`}
transformOrigin="0 0" transformOrigin="0 0"
> >
{signatures !== undefined && signatures > 0 && `📡 ${signatures}`} 📡 {signatures}
</text> </text>
);
currentY += 15;
}
{/* Statistics display - fixed visual size regardless of zoom */} // Add jumps if enabled and present
{showJumps && jumps !== undefined && ( if (showJumps && jumps !== undefined) {
textElements.push(
<text <text
key="jumps"
x="0" x="0"
y={textOffset + 30} y={currentY}
textAnchor="middle" textAnchor="middle"
fill="#60a5fa" fill="#60a5fa"
fontSize="10" fontSize="10"
@@ -243,12 +258,17 @@ export const MapNode: React.FC<MapNodeProps> = ({
> >
🚀 {jumps} 🚀 {jumps}
</text> </text>
)} );
currentY += 15;
}
{showKills && kills !== undefined && ( // Add kills if enabled and present
if (showKills && kills !== undefined) {
textElements.push(
<text <text
key="kills"
x="0" x="0"
y={textOffset + 45} y={currentY}
textAnchor="middle" textAnchor="middle"
fill="#f87171" fill="#f87171"
fontSize="10" fontSize="10"
@@ -262,7 +282,11 @@ export const MapNode: React.FC<MapNodeProps> = ({
> >
{kills} {kills}
</text> </text>
)} );
}
return textElements;
})()}
</g> </g>
); );
} }

View File

@@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import { Switch } from '@/components/ui/switch';
interface StatisticsToggleProps { interface StatisticsToggleProps {
jumpsEnabled: boolean; jumpsEnabled: boolean;
@@ -15,28 +14,30 @@ export const StatisticsToggle: React.FC<StatisticsToggleProps> = ({
onKillsToggle, onKillsToggle,
}) => { }) => {
return ( return (
<div className="absolute top-2 left-2 bg-slate-800/90 backdrop-blur-sm rounded-lg p-3 shadow-lg border border-slate-700"> <div className="absolute top-2 right-2 bg-slate-800/90 backdrop-blur-sm rounded-lg p-2 shadow-lg border border-slate-700">
<div className="flex flex-col gap-3"> <div className="flex gap-2">
<div className="flex items-center gap-3"> <button
<Switch onClick={() => onJumpsToggle(!jumpsEnabled)}
id="jumps-toggle" className={`p-2 rounded transition-colors ${
checked={jumpsEnabled} jumpsEnabled
onCheckedChange={onJumpsToggle} ? 'bg-blue-600/20 text-blue-400 hover:bg-blue-600/30'
/> : 'bg-gray-600/20 text-gray-400 hover:bg-gray-600/30'
<label htmlFor="jumps-toggle" className="text-sm font-medium text-white"> }`}
🚀 Show Jumps title={jumpsEnabled ? 'Hide Jumps' : 'Show Jumps'}
</label> >
</div> 🚀
<div className="flex items-center gap-3"> </button>
<Switch <button
id="kills-toggle" onClick={() => onKillsToggle(!killsEnabled)}
checked={killsEnabled} className={`p-2 rounded transition-colors ${
onCheckedChange={onKillsToggle} killsEnabled
/> ? 'bg-red-600/20 text-red-400 hover:bg-red-600/30'
<label htmlFor="kills-toggle" className="text-sm font-medium text-white"> : 'bg-gray-600/20 text-gray-400 hover:bg-gray-600/30'
Show Kills }`}
</label> title={killsEnabled ? 'Hide Kills' : 'Show Kills'}
</div> >
</button>
</div> </div>
</div> </div>
); );