Tiem Cong Nghe

Showing suggestions.

Opening the store's index…
↑↓ to move↵ to openesc to close
Tiem Cong Nghe search
Animationv1.0.0~21 KB gzipped

Dijkstra Animation

A glowing weighted graph where the shortest path spreads one settled node at a time: Dijkstra with a live priority queue, for lessons and slides

FreeFree
Format

.zip · HTML / CSS / JS · v1.0.0

Free — no account, no email. Always the newest version.

Live preview

Version
Preview width
Zoom

About

Dijkstra's algorithm is easiest to understand when you watch the shortest path spread. This animation runs the real dijkstra and shortestPath from the free algorithm page, step by step: the vertex the queue hands out locks in, its edges are tried one by one, and every edge that beats a distance flows, updates the number on its node and pushes a fresh entry into the queue. Old entries are not removed. They stay in the queue, struck through, until they come out and are skipped. The dist and prev arrays sit under the graph and change in step, the line of code that is running lights up beside it, and in the end the shortest-path tree glows and the path to your target lights up.

  • The listing's own logic: lazy deletion, the (distance, vertex) tie-break and a strict <, checked against the listing on seeded random graphs
  • A priority queue you can read: pop order, the entry just popped, stale entries marked
  • Four seeded graphs (a city map, a longer route that is cheaper, a tie-break and an unreachable island), or your own edges typed in
  • Pick any source and any target; counters for pops, relaxations and stale pops
  • A full player with a scrubber and 0.5×–4× speed, built to look good on a slide or in a recording
  • Every colour, radius, font and timing is a CSS custom property; light and dark follow your page
  • Nothing to install: one CSS file and one script, or one React component

Features · 12

  • Animates dijkstra and shortestPath exactly as the free algorithm page's JavaScript listing writes them: a lazy priority queue ordered by distance then vertex, the stale check on every pop, a strict < to relax
  • A node-link graph with weighted edges: the frontier glows amber, every relaxed edge flows and the tentative distance on its node changes, and a settled node locks in a colour that shows how far it is from the source
  • A live priority queue in pop order, with the entry just popped beside it, the newest entry glowing and stale entries struck through and dashed until they are skipped
  • A dist and prev table under the graph in step with every frame, and a prev tree that grows (dashed while a vertex is only reached, solid once it is final)
  • At the end the shortest-path tree lights up, then shortestPath walks back from the target one vertex at a time and the path glows gold with its cost; a target nothing leads to ends on an empty path
  • Counters for pops, relaxations and stale pops, and the listing's own variables (u and v) gliding over the nodes as chips
  • Four seeded graphs: a city map, a graph where the longer route is cheaper, a tie-break and an unreachable island, with a New button for fresh weights
  • Pick the source and the target, or type your own graph like 0-1:4; 1>2:3 (a dash for two-way edges, an arrow for one-way, up to 12 vertices and 24 edges)
  • The code panel shows dijkstra, then shortestPath, with the lines that are running lit
  • Player: play, pause, step back and forward, reset, scrub, 0.5×–4× speed, optional loop
  • Plain HTML/CSS/JS and React (Next.js ready) builds, light and dark
  • Zero dependencies, about 21 KB gzipped (script and CSS together)

How to use it

Link the stylesheet and the script once, then add an empty element with data-dijkstra-animation wherever you want a player:

HTML
<link rel="stylesheet" href="dijkstra-animation.css" />
<script src="dijkstra-animation.js" defer></script>

<div class="dijkstra-animation" data-dijkstra-animation></div>

<div
  class="dijkstra-animation"
  data-dijkstra-animation
  data-dijkstra-animation-scenario="shortcut"
  data-dijkstra-animation-seed="3"
></div>

<div
  class="dijkstra-animation"
  data-dijkstra-animation
  data-dijkstra-animation-edges="0-1:4; 0-2:1; 2-1:2; 1-3:1; 2-3:5; 3-4:3"
  data-dijkstra-animation-source="0"
  data-dijkstra-animation-target="4"
></div>

Options as data attributes, all starting with data-dijkstra-animation-:

Attribute Default What it does
-scenario city-map city-map, shortcut, tie-break or unreachable: the graph to run
-edges the preset's Your own graph: a-b:w for an edge that works both ways, a>b:w for a one-way edge, separated by ;, , or new lines (up to 24, weights 0–99, vertices 0–11; the weight defaults to 1)
-vertices as many as the edges name How many vertices your own graph has (2–12); the ones no edge names stay alone, at ∞
-source the preset's (0) Where the run starts
-target the preset's (the last vertex) Where the path ends
-seed 7 Which weights the preset builds: the same seed always gives the same graph
-speed 1 0.25 to 4
-autoplay true Plays on its own once loaded (never with reduced motion)
-loop false Starts again after a pause on the answer
-code true false hides the code panel
-inputs true false hides the rows of inputs (graph, source, target, edges)

Elements added after the page loads: DijkstraAnimation.init(container); it returns a function that undoes it. For full control, DijkstraAnimation.createDijkstraAnimation(element, options) returns a handle with setScenario, setEdges(text) (it returns false and says why on the page when the edges cannot be read), setVertices, setSource, setTarget, shuffle, player (play, pause, seek…), trace() and destroy.

Ask about this product

Not sure it fits your project? Ask — the answer comes from this page.

Answers are written by AI from this page and can be wrong. The page itself is what counts.

Changelog

  1. 1.0.0First releaseLatest

    Plain HTML/CSS/JS and React builds of a step-by-step Dijkstra animation: a weighted graph where the frontier glows, edges relax and settled nodes lock in, a live priority queue with its stale entries, a dist / prev table, the shortest-path tree and the path to a chosen target, four seeded graphs or your own edges, player controls, light and dark.

  2. Fixes and new features land behind the same download, which always serves the latest version.

Reviews

No reviews yet

Used it? Be the first to say how it went.

Write a review

How did it work for you? Reviews appear once we have read them.

Your rating
Never shown. Only used if we need to reach you about your review.
0 / 2000

Your name and review are shown on this page; your email is not. See the terms.

  • AnimationPathfinding

    Pathfinding Maze

    An editable neon maze where BFS, Dijkstra, A* and greedy search race to the goal, step by step

    Free