DAA was using getEdgeLabelX() and getEdgeLabelY() methods that added extra offsets, causing weight boxes to be misaligned.
<!-- Background rect -->
<rect
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2 - 18"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 23"
width="36"
height="26"
rx="6"
/>
<!-- Weight label -->
<text
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 5"
>
{{ weight }}
</text><!-- Background rect -->
<rect
[attr.x]="getEdgeLabelX(e) - 18" ← getEdgeLabelX returns (x1+x2)/2
[attr.y]="getEdgeLabelY(e) - 23" ← getEdgeLabelY returns (y1+y2)/2 - 5
/>
<!-- Weight label -->
<text
[attr.x]="getEdgeLabelX(e)" ← (x1+x2)/2 ✓
[attr.y]="getEdgeLabelY(e)" ← (y1+y2)/2 - 5 ✓
>Result:
- Text Y position:
(y1+y2)/2 - 5✅ - Rect Y position:
((y1+y2)/2 - 5) - 23=(y1+y2)/2 - 28❌ 5px too high!
<!-- Background rect -->
<rect
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2 - 18"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 23"
width="36"
height="26"
rx="6"
/>
<!-- Weight label -->
<text
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 5"
>
{{e.w}}
</text>Result:
- Text Y position:
(y1+y2)/2 - 5✅ - Rect Y position:
(y1+y2)/2 - 23✅ - Perfect alignment like DSA!
<svg viewBox="0 0 800 500">
<defs>
<marker id="arrow">...</marker>
</defs>
<!-- Draw edges -->
<g class="edges">
<g *ngFor="let edge of edges">
<line />
<rect class="weight-bg" />
<text class="edge-weight" />
</g>
</g>
<!-- Draw nodes -->
<g class="nodes">
<g *ngFor="let node of nodes">
<circle class="exploring-ring" />
<circle class="node-circle" />
<text class="node-label" />
<text class="distance-label" />
</g>
</g>
</svg><svg viewBox="0 0 800 500">
<defs>
<marker id="arrow">...</marker>
</defs>
<!-- Draw edges - EXACT DSA STRUCTURE -->
<g class="edges">
<g *ngFor="let e of edges">
<line />
<rect class="weight-bg" />
<text class="edge-weight" />
</g>
</g>
<!-- Draw nodes - EXACT DSA STRUCTURE -->
<g class="nodes">
<g *ngFor="let idx of displayOrder">
<circle class="exploring-ring" />
<circle class="node-circle" />
<text class="node-label" />
<text class="distance-label" />
</g>
</g>
</svg><g *ngFor="let edge of edges">
<!-- Edge line -->
<line
[attr.x1]="getNode(edge.from).x"
[attr.y1]="getNode(edge.from).y"
[attr.x2]="getNode(edge.to).x"
[attr.y2]="getNode(edge.to).y"
[attr.class]="getEdgeLineClass(edge)"
/>
<!-- Weight box -->
<rect
[attr.x]="(getNode(edge.from).x + getNode(edge.to).x) / 2 - 18"
[attr.y]="(getNode(edge.from).y + getNode(edge.to).y) / 2 - 23"
width="36"
height="26"
rx="6"
[ngClass]="{'weight-bg': true, 'weight-bg-active': isEdgeActive(edge)}"
/>
<!-- Weight text -->
<text
[attr.x]="(getNode(edge.from).x + getNode(edge.to).x) / 2"
[attr.y]="(getNode(edge.from).y + getNode(edge.to).y) / 2 - 5"
[attr.class]="isEdgeActive(edge) ? 'edge-weight active' : 'edge-weight'"
>
{{ edge.weight }}
</text>
</g><g *ngFor="let e of edges">
<!-- Edge line -->
<line
[attr.x1]="nodes[e.from].x"
[attr.y1]="nodes[e.from].y"
[attr.x2]="nodes[e.to].x"
[attr.y2]="nodes[e.to].y"
[ngClass]="{
'edge-tree': prev[e.to] === e.from,
'edge-active': activeEdge && activeEdge.from === e.from && activeEdge.to === e.to
}"
/>
<!-- Weight box - EXACT DSA positioning -->
<rect
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2 - 18"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 23"
width="36"
height="26"
rx="6"
[ngClass]="{
'weight-bg': true,
'weight-bg-active': activeEdge && activeEdge.from === e.from && activeEdge.to === e.to
}"
/>
<!-- Weight text - EXACT DSA positioning -->
<text
[attr.x]="(nodes[e.from].x + nodes[e.to].x) / 2"
[attr.y]="(nodes[e.from].y + nodes[e.to].y) / 2 - 5"
[attr.class]="(activeEdge && activeEdge.from === e.from && activeEdge.to === e.to) ? 'edge-weight active' : 'edge-weight'"
>
{{e.w}}
</text>
</g>Key Match:
- ✅ Same inline calculation for X and Y
- ✅ Same offsets (-18 for X, -23 for Y on rect)
- ✅ Same text positioning (midpoint X, midpoint - 5 for Y)
- ✅ Same conditional classes
<g *ngFor="let node of nodes">
<!-- Exploring ring -->
<circle
*ngIf="node.id === currentNode"
[attr.cx]="node.x"
[attr.cy]="node.y"
[attr.r]="38"
class="exploring-ring"
/>
<!-- Node circle -->
<circle
[attr.cx]="node.x"
[attr.cy]="node.y"
[attr.r]="node.id === currentNode ? 30 : 25"
[attr.class]="getNodeCircleClass(node)"
/>
<!-- Node label (inside) -->
<text
[attr.x]="node.x"
[attr.y]="node.y + 5"
class="node-label"
>
{{ node.id }}
</text>
<!-- Distance (outside, below) -->
<text
[attr.x]="node.x"
[attr.y]="node.y + (node.id === currentNode ? 30 : 25) + 18"
class="distance-label"
>
{{ node.distance === Infinity ? '∞' : node.distance }}
</text>
</g><g *ngFor="let idx of displayOrder">
<!-- Exploring ring -->
<circle
*ngIf="activeNode === idx"
[attr.cx]="nodes[idx].x"
[attr.cy]="nodes[idx].y"
[attr.r]="38"
class="exploring-ring"
/>
<!-- Node circle -->
<circle
[attr.cx]="nodes[idx].x"
[attr.cy]="nodes[idx].y"
[attr.r]="activeNode === idx ? 30 : 25"
[attr.class]="getNodeCircleClass(idx)"
/>
<!-- Node label (inside) -->
<text
[attr.x]="nodes[idx].x"
[attr.y]="nodes[idx].y + 5"
class="node-label">
{{displayIndex[idx]}}
</text>
<!-- Distance (outside, below) -->
<text
[attr.x]="nodes[idx].x"
[attr.y]="nodes[idx].y + (activeNode === idx ? 30 : 25) + 18"
class="distance-label"
>
{{dist[idx] === INF ? '∞' : dist[idx]}}
</text>
</g>Key Match:
- ✅ Same structure (ring, circle, label, distance)
- ✅ Same conditional logic (activeNode vs currentNode)
- ✅ Same sizing (radius 38 ring, 30/25 circle)
- ✅ Same text positioning (+5 inside, +radius+18 outside)
/* Base line style */
.graph-svg line {
stroke: #4a5568;
stroke-width: 2;
}
/* Active edge (being checked) */
line.edge-active {
stroke: #fbbf24;
stroke-width: 4;
animation: edgePulse 0.8s ease-in-out infinite;
}
/* Tree edge (in shortest path) */
line.edge-tree {
stroke: #10b981;
stroke-width: 3;
}
/* Weight box */
.weight-bg {
fill: rgba(15, 23, 42, 0.95);
stroke: #475569;
stroke-width: 1.5;
}
/* Active weight box */
.weight-bg-active {
fill: rgba(251, 191, 36, 0.3);
stroke: #fbbf24;
stroke-width: 2.5;
filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.6));
animation: weightPulse 1s ease-in-out infinite;
}/* Base node */
.node-circle {
stroke-width: 3;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Unvisited */
.node-circle.unvisited {
fill: #041014;
stroke: #4a5568;
}
/* In queue (source) - NO PULSE */
.node-circle.in-queue {
fill: #1e40af;
stroke: #3b82f6;
filter: drop-shadow(0 0 8px rgba(59,130,246,0.7));
}
/* Exploring (active) */
.node-circle.exploring {
fill: #fbbf24;
stroke: #f59e0b;
stroke-width: 4;
filter: drop-shadow(0 0 18px #fbbf24);
animation: softGlow 0.7s ease-in-out infinite alternate;
}
/* Visited */
.node-circle.visited {
fill: #10b981;
stroke: #059669;
filter: drop-shadow(0 0 10px #10b981);
}
/* Exploring ring */
.exploring-ring {
fill: none;
stroke: #fbbf24;
stroke-width: 2;
stroke-dasharray: 10 5;
animation: ringPulse 2s linear infinite;
}[Graph centered]
Nodes: Blue (source) → Yellow (exploring) → Green (visited)
Edges: Gray → Yellow (active) → Green (tree)
Weights: Dark boxes → Yellow glowing boxes
Distance: Below nodes, adapts to size
[Graph left, Table right]
Nodes: Blue (source, static) → Yellow (exploring) → Green (visited)
Edges: Gray → Yellow (active) → Green (tree)
Weights: Dark boxes → Yellow glowing boxes ✅ FIXED!
Distance: Below nodes, adapts to size ✅
e:\Algorithm visualizer\algorithm-visualizer\frontend\src\app\pages\daa\dijkstra.component.ts
-
Edge rendering (Lines ~45-75):
- ❌ OLD: Used
getEdgeLabelX(e)andgetEdgeLabelY(e)methods - ✅ NEW: Uses inline
(nodes[e.from].x + nodes[e.to].x) / 2calculation - Result: Weight boxes now perfectly centered like DSA
- ❌ OLD: Used
-
Node rendering (Lines ~77-110):
- ✅ Added
<g class="nodes">wrapper for consistency - ✅ Changed node label Y from
+4to+5(matches DSA) - Result: Better vertical alignment
- ✅ Added
-
CSS (Line ~218):
- ❌ OLD:
.node-circle.in-queuehadanimation: softPulse - ✅ NEW:
.node-circle.in-queuehas staticfilter: drop-shadow - Result: Source node doesn't pulse
- ❌ OLD:
- Hard refresh:
Ctrl + Shift + R - Check weight labels (7, 3, 4, etc.)
- Should be centered in dark rounded boxes
- Numbers should be vertically centered in boxes
- Boxes should not be offset up/down
- Node A starts blue (static, no pulse)
- Click Play
- Node A turns yellow with ring
- Distance "0" stays below node
- Node A turns green when done
- Edges start gray
- Active edge turns yellow with pulse
- Weight box glows yellow
- Tree edges turn green
- Weight boxes return to dark
- Graph on left (800x500 viewport)
- Table on right (320px wide)
- Controls at bottom
- Everything properly aligned
Perfect DSA-quality animations with proper weight box positioning!
Initial State:
┌─────────────────────────────┬──────────────┐
│ 🔵 A (0) │ Node | Dist │
│ / | \ │ ─────┼───── │
│ [7] [3] [4] │ A │ 0 │
│ / | \ │ B │ ∞ │
│ 🔴 B 🔴 C 🔴 D │ C │ ∞ │
│ (∞) (∞) (∞) │ ... │
└─────────────────────────────┴──────────────┘
After Play (Processing A):
┌─────────────────────────────┬──────────────┐
│ 🟡 A (0)⭕ │ Node | Dist │
│ / ⚡ | ⚡ \ │ ─────┼───── │
│ [7] [3] [4] ← Glowing │ A │ 0 │
│ / | \ │ B │ 4 │
│ 🔴 B 🔴 C 🔴 D │ C │ 2 │
│ (4) (2) (9) │ ... │
└─────────────────────────────┴──────────────┘
Final State:
┌─────────────────────────────┬──────────────┐
│ 🟢 A (0) │ Node | Dist │
│ / | \ │ ─────┼───── │
│ [7] [3] [4] │ A │ 0 │
│ / | \ │ B │ 4 │
│ 🟢 B 🟢 C 🟢 D │ C │ 2 │
│ (4) (2) (9) │ D │ 9 │
└─────────────────────────────┴──────────────┘
All weight boxes properly aligned, no offset issues! 🎉