Spaces:
Running
Running
Download algospaced-ui/src/components/map/CurvyPathAndNodes.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/map/CurvyPathAndNodes.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/map/CurvyPathAndNodes.tsx
-
curl -L -o CurvyPathAndNodes.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/map/CurvyPathAndNodes.tsx
15.3 kB
| import React from 'react'; | |
| import type { MapNode, MapTheme } from '../../types/mapTypes'; | |
| import { buildPathString, buildSubPathString } from '../../data/mapData'; | |
| interface CurvyPathAndNodesProps { | |
| nodes: MapNode[]; | |
| activeNodeIndex: number; | |
| completions: Set<number>; | |
| theme: MapTheme; | |
| showNodeNumbers: boolean; | |
| onNodeClick: (index: number) => void; | |
| hoveredNodeIndex: number | null; | |
| setHoveredNodeIndex: (index: number | null) => void; | |
| } | |
| export const CurvyPathAndNodes: React.FC<CurvyPathAndNodesProps> = ({ | |
| nodes, | |
| activeNodeIndex, | |
| completions, | |
| theme, | |
| showNodeNumbers, | |
| onNodeClick, | |
| hoveredNodeIndex, | |
| setHoveredNodeIndex, | |
| }) => { | |
| const isDark = theme.id !== 'parchment'; | |
| // Find highest completed index in sequence to light the continuous trail | |
| const highestCompletedIdx = nodes.reduce((maxIdx, node, idx) => { | |
| return completions.has(node.id) ? Math.max(maxIdx, idx) : maxIdx; | |
| }, -1); | |
| const litIndex = Math.max(activeNodeIndex, highestCompletedIdx); | |
| const fullPathD = buildPathString(nodes); | |
| const litPathD = buildSubPathString(nodes, litIndex); | |
| const activeNode = | |
| activeNodeIndex >= 0 && activeNodeIndex < nodes.length ? nodes[activeNodeIndex] : null; | |
| // Render hand-drawn mini-landmarks at milestone waypoints (every 25th node) | |
| const renderMilestoneLandmark = (idx: number, isLit: boolean, isCompleted: boolean) => { | |
| // Do not draw a mini-landmark on the final node since the Huge Stone Tower is already there | |
| if (idx === nodes.length - 1) return null; | |
| const stroke = theme.pencilColor; | |
| const fillTone = isCompleted | |
| ? '#b91c1c' | |
| : isLit | |
| ? '#d97706' | |
| : isDark | |
| ? '#2c241b' | |
| : '#dfd1b4'; | |
| if (idx === 0) { | |
| // Waypoint 1: Explorer's Basecamp Tent | |
| return ( | |
| <g transform="translate(0, -10)" pointerEvents="none"> | |
| <path | |
| d="M -11,4 L 0,-11 L 11,4 Z" | |
| fill={fillTone} | |
| stroke={stroke} | |
| strokeWidth="1.5" | |
| strokeLinejoin="round" | |
| /> | |
| <path d="M -3,4 L 0,-3 L 3,4 Z" fill={stroke} /> | |
| <line x1="0" y1="-11" x2="0" y2="-17" stroke={stroke} strokeWidth="1.3" /> | |
| <polygon points="0,-17 7,-14 0,-11" fill={isCompleted ? '#991b1b' : '#d97706'} /> | |
| </g> | |
| ); | |
| } | |
| const milestoneTier = Math.round((idx + 1) / 25) % 3; | |
| if (milestoneTier === 1) { | |
| // Node 25, 100...: Wayfarer's Campfire | |
| return ( | |
| <g transform="translate(0, -9)" pointerEvents="none"> | |
| <line x1="-8" y1="3" x2="8" y2="-1" stroke={stroke} strokeWidth="2" strokeLinecap="round" /> | |
| <line x1="-8" y1="-1" x2="8" y2="3" stroke={stroke} strokeWidth="2" strokeLinecap="round" /> | |
| <path | |
| d="M -5,0 C -6,-7 -1,-9 0,-14 C 2,-9 6,-7 5,0 Z" | |
| fill={isLit || isCompleted ? '#ea580c' : fillTone} | |
| stroke={stroke} | |
| strokeWidth="1.2" | |
| /> | |
| </g> | |
| ); | |
| } else if (milestoneTier === 2) { | |
| // Node 50, 125...: Stone Watchtower | |
| return ( | |
| <g transform="translate(0, -9)" pointerEvents="none"> | |
| <path | |
| d="M -7,3 L -5,-12 L 5,-12 L 7,3 Z" | |
| fill={fillTone} | |
| stroke={stroke} | |
| strokeWidth="1.5" | |
| /> | |
| <path | |
| d="M -7,-12 L -7,-16 L -3,-16 L -3,-12 L 3,-12 L 3,-16 L 7,-16 L 7,-12 Z" | |
| fill={fillTone} | |
| stroke={stroke} | |
| strokeWidth="1.3" | |
| /> | |
| </g> | |
| ); | |
| } else { | |
| // Node 75, 150...: Mountain Arch Gatehouse | |
| return ( | |
| <g transform="translate(0, -9)" pointerEvents="none"> | |
| <path | |
| d="M -9,3 L -9,-12 L 9,-12 L 9,3 L 4,3 L 4,-5 C 4,-9 -4,-9 -4,-5 L -4,3 Z" | |
| fill={fillTone} | |
| stroke={stroke} | |
| strokeWidth="1.5" | |
| strokeLinejoin="round" | |
| /> | |
| </g> | |
| ); | |
| } | |
| }; | |
| return ( | |
| <g id="curvy-path-nodes-layer"> | |
| {/* 1. Base Unlit Surveyor's Trail (Double-Inked Cartographic Footpath) */} | |
| <g id="unlit-path" filter="url(#quillInk)"> | |
| <path | |
| d={fullPathD} | |
| fill="none" | |
| stroke={theme.pencilShade} | |
| strokeWidth="4.2" | |
| strokeDasharray="2 8" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| opacity={0.45} | |
| /> | |
| <path | |
| d={fullPathD} | |
| fill="none" | |
| stroke={theme.pencilColor} | |
| strokeWidth="2.2" | |
| strokeDasharray="7 6" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| opacity={0.85} | |
| /> | |
| </g> | |
| {/* 2. Illuminated Lit-Up Path (Sepia-Cased Alchemical Gold Leaf Trail) */} | |
| {litIndex > 0 && litPathD && ( | |
| <g id="lit-path"> | |
| {/* Warm Alchemical Aura */} | |
| <path | |
| d={litPathD} | |
| fill="none" | |
| stroke="#d97706" | |
| strokeWidth="10" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| opacity={0.28} | |
| filter="url(#goldenGlow)" | |
| /> | |
| {/* Dark Sepia Ink Casing so the gold leaf pops on light parchment */} | |
| <path | |
| d={litPathD} | |
| fill="none" | |
| stroke={theme.pencilColor} | |
| strokeWidth="6.8" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| opacity={0.85} | |
| /> | |
| {/* Burnished Gold Leaf Core */} | |
| <path | |
| d={litPathD} | |
| fill="none" | |
| stroke="url(#goldPathGradient)" | |
| strokeWidth="4.2" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| /> | |
| {/* Fine Center Ink Highlight */} | |
| <path | |
| d={litPathD} | |
| fill="none" | |
| stroke="#fef3c7" | |
| strokeWidth="1.3" | |
| strokeDasharray="12 6" | |
| strokeLinecap="round" | |
| strokeLinejoin="round" | |
| opacity={0.8} | |
| /> | |
| </g> | |
| )} | |
| {/* 3. The Map Nodes */} | |
| <g id="nodes-collection"> | |
| {nodes.map((node, idx) => { | |
| const isCompleted = completions.has(node.id); | |
| const isLit = idx <= litIndex || isCompleted; | |
| const isActive = idx === activeNodeIndex; | |
| const isHovered = hoveredNodeIndex === idx; | |
| const isMilestone = | |
| (idx + 1) % 25 === 0 || idx === 0 || idx === nodes.length - 1; | |
| return ( | |
| <g | |
| key={node.id} | |
| id={`node-${node.id}`} | |
| transform={`translate(${node.x}, ${node.y})`} | |
| className="cursor-pointer transition-transform duration-200" | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| onNodeClick(idx); | |
| }} | |
| onMouseEnter={() => setHoveredNodeIndex(idx)} | |
| onMouseLeave={() => setHoveredNodeIndex(null)} | |
| > | |
| {/* Invisible larger hit target */} | |
| <circle cx="0" cy="0" r="18" fill="transparent" /> | |
| {/* Milestone Mini-Landmark Illustration */} | |
| {isMilestone && renderMilestoneLandmark(idx, isLit, isCompleted)} | |
| {/* UNLIT NODE STATE (Hand-Inked Cartographic Ring / X-Mark) */} | |
| {!isLit && !isCompleted && ( | |
| <g> | |
| <circle | |
| cx="0.8" | |
| cy="1.2" | |
| r={isMilestone ? 7.5 : 4.5} | |
| fill={theme.pencilShade} | |
| opacity={0.35} | |
| /> | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r={isMilestone ? 7 : 4.2} | |
| fill={isDark ? '#28221b' : '#efe3c9'} | |
| stroke={theme.pencilColor} | |
| strokeWidth={isMilestone ? 2 : 1.5} | |
| /> | |
| {isMilestone ? ( | |
| /* Cartographic X-Mark inside Milestone Ring */ | |
| <path | |
| d="M -3,-3 L 3,3 M -3,3 L 3,-3" | |
| stroke={theme.pencilColor} | |
| strokeWidth="1.6" | |
| strokeLinecap="round" | |
| /> | |
| ) : ( | |
| <circle cx="0" cy="0" r="1.3" fill={theme.pencilColor} /> | |
| )} | |
| </g> | |
| )} | |
| {/* LIT / COMPLETED NODE STATE (Crimson Wax Seal or Brass Astrolabe) */} | |
| {isLit && !isActive && ( | |
| <g filter="url(#nodeGlow)"> | |
| {/* Outer Stamped Rim */} | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r={isMilestone ? 9 : 6} | |
| fill={isCompleted ? 'url(#waxSealGradient)' : 'url(#brassNodeGradient)'} | |
| stroke={theme.pencilColor} | |
| strokeWidth="1.5" | |
| /> | |
| {/* Inner Embossed Wax Ring */} | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r={isMilestone ? 6.2 : 3.8} | |
| fill="none" | |
| stroke="#fef3c7" | |
| strokeWidth="0.9" | |
| opacity={0.75} | |
| /> | |
| {/* Center Stamped Emblem */} | |
| {isMilestone ? ( | |
| <polygon | |
| points="0,-4.5 1.3,-1.3 4.5,0 1.3,1.3 0,4.5 -1.3,1.3 -4.5,0 -1.3,-1.3" | |
| fill="#fef3c7" | |
| /> | |
| ) : ( | |
| <circle cx="0" cy="0" r="1.6" fill="#fef3c7" /> | |
| )} | |
| </g> | |
| )} | |
| {/* ACTIVE CURRENT NODE STATE (Surveyor's Compass Beacon & Pennant) */} | |
| {isActive && ( | |
| <g id="active-node-beacon"> | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r="13" | |
| fill="none" | |
| stroke="#b45309" | |
| strokeWidth="2" | |
| className="beacon-wave" | |
| /> | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r="13" | |
| fill="none" | |
| stroke="#d97706" | |
| strokeWidth="1.5" | |
| className="beacon-wave-delayed" | |
| /> | |
| <circle cx="0" cy="0" r="22" fill="url(#beaconGlow)" /> | |
| {/* Outer Compass Ring */} | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r="9.5" | |
| fill={isCompleted ? 'url(#waxSealGradient)' : 'url(#brassNodeGradient)'} | |
| stroke={theme.pencilColor} | |
| strokeWidth="2.2" | |
| filter="url(#nodeGlow)" | |
| /> | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r="6.5" | |
| fill="none" | |
| stroke="#fef3c7" | |
| strokeWidth="1" | |
| /> | |
| <polygon | |
| points="0,-4.5 1.4,-1.4 4.5,0 1.4,1.4 0,4.5 -1.4,1.4 -4.5,0 -1.4,-1.4" | |
| fill="#fef3c7" | |
| /> | |
| {/* Explorer's Heraldic Pennant Flag */} | |
| <g transform="translate(0, -19)" filter="url(#nodeGlow)"> | |
| <line | |
| x1="0" | |
| y1="-12" | |
| x2="0" | |
| y2="11" | |
| stroke={theme.pencilColor} | |
| strokeWidth="2.2" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d="M 0,-12 L 15,-7 L 11,-3 L 15,1 L 0,-2 Z" | |
| fill={isCompleted ? '#991b1b' : '#b45309'} | |
| stroke="#fef3c7" | |
| strokeWidth="1.2" | |
| strokeLinejoin="round" | |
| /> | |
| <circle cx="0" cy="-13" r="2" fill="#fbbf24" stroke={theme.pencilColor} strokeWidth="0.9" /> | |
| </g> | |
| </g> | |
| )} | |
| {/* Hover Ink Caliper Ring */} | |
| {isHovered && !isActive && ( | |
| <circle | |
| cx="0" | |
| cy="0" | |
| r="13" | |
| fill="none" | |
| stroke={isCompleted ? '#991b1b' : '#b45309'} | |
| strokeWidth="1.8" | |
| strokeDasharray="4 3" | |
| /> | |
| )} | |
| {/* Node Number Label */} | |
| {(showNodeNumbers || isMilestone || isHovered) && ( | |
| <text | |
| x="0" | |
| y={isMilestone ? 19 : -10} | |
| textAnchor="middle" | |
| fill={ | |
| isCompleted | |
| ? isDark | |
| ? '#fca5a5' | |
| : '#7f1d1d' | |
| : isLit | |
| ? isDark | |
| ? '#fcd34d' | |
| : '#92400e' | |
| : theme.pencilColor | |
| } | |
| className={`font-pencil font-bold select-none ${isMilestone ? 'text-[12px]' : 'text-[10px]' | |
| }`} | |
| opacity={isLit ? 1 : 0.78} | |
| > | |
| {node.id < 0 ? `P${idx + 1}` : node.id} | |
| </text> | |
| )} | |
| </g> | |
| ); | |
| })} | |
| </g> | |
| {/* 4. Active Node Tattered Scroll Tooltip Banner on Canvas */} | |
| {activeNode && ( | |
| <g | |
| transform={`translate(${activeNode.x}, ${activeNode.y - 46})`} | |
| className="pointer-events-none select-none transition-all duration-300" | |
| filter="url(#nodeGlow)" | |
| > | |
| {/* Notched Parchment Scroll Body */} | |
| <path | |
| d="M -88,-24 | |
| Q 0,-28 88,-24 | |
| L 81,-7 | |
| L 88,10 | |
| Q 0,14 -88,10 | |
| L -81,-7 Z" | |
| fill={isDark ? '#221b14' : '#f4e8cf'} | |
| stroke={theme.pencilColor} | |
| strokeWidth="1.8" | |
| strokeLinejoin="round" | |
| /> | |
| {/* Inner Scroll Rule */} | |
| <path | |
| d="M -78,-20 Q 0,-24 78,-20 M -78,6 Q 0,10 78,6" | |
| fill="none" | |
| stroke={theme.pencilShade} | |
| strokeWidth="0.8" | |
| /> | |
| {/* Pointer Tail */} | |
| <polygon | |
| points="-6,10 6,10 0,17" | |
| fill={isDark ? '#221b14' : '#f4e8cf'} | |
| stroke={theme.pencilColor} | |
| strokeWidth="1.6" | |
| /> | |
| <text | |
| x="0" | |
| y="-9" | |
| textAnchor="middle" | |
| fill={isDark ? '#fbbf24' : '#7c2d12'} | |
| className="font-cinzel font-bold text-[11px] tracking-wider" | |
| > | |
| WAYPOINT {activeNode.sequenceIndex + 1} OF {nodes.length} | |
| </text> | |
| <text | |
| x="0" | |
| y="4" | |
| textAnchor="middle" | |
| fill={isDark ? '#f4ebd9' : '#2c1d11'} | |
| className="font-garamond italic font-bold text-[12px]" | |
| > | |
| {activeNode.name.length > 22 | |
| ? activeNode.name.substring(0, 20) + '…' | |
| : activeNode.name} | |
| </text> | |
| </g> | |
| )} | |
| </g> | |
| ); | |
| }; |