Tiem Cong Nghe

Showing suggestions.

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

Topological Sort Animation

A glowing dependency graph that peels itself in order: Kahn's algorithm with live in-degree badges, a visible FIFO queue and the order filling up

5.0{count} review
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

Topological sort is easiest to understand when you watch the graph peel itself. This animation runs Kahn's algorithm from the free algorithm page, step by step: every task is a glowing vertex with a live in-degree badge, the vertices with nothing left to wait for fly into a visible FIFO queue, and taking one appends it to the order strip, crosses its outgoing edges out and ticks its neighbours' badges down. The line of code that is running lights up beside it, and when the graph has a cycle the queue runs dry early, the leftovers turn red and the caption explains why the order is short.

  • Kahn's algorithm exactly as the listing writes it, including the head index that makes the queue O(1)
  • Live in-degree badges, an inDegree[] array under the graph, and a queue and an order drawn as real arrays
  • Five ready-made graphs, course prerequisites, build steps, a diamond, a cycle and the page's two-source example, or your own edges typed in
  • Counters for pops, edges removed and queued vertices, and the +1s of counting against the −1s of crossing out
  • 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 · 11

  • Animates Kahn's algorithm exactly as the free algorithm page writes it: in-degree counting, a FIFO queue with a head index, and the order built one pop at a time
  • A layered directed graph with arrows, a live in-degree badge on every vertex that ticks up while counting and down as edges are crossed out, and a glow on every vertex that is ready
  • The queue shown as the real array: ready vertices fly into their slots, the head marker moves along, taken entries stay behind dimmed, and each pop slides into the order strip
  • Crossed-out edges fade as their neighbours' badges tick down; each placed vertex keeps a colour from its place in the order, so the sweep of colours shows the order
  • On a cycle the queue runs dry early: the leftover vertices and the edges never crossed out turn red, the empty order slots are marked, and the caption says why the order is short
  • inDegree[] under the graph in step with every frame, counters for pops, edges removed and queued vertices, and two bars that set the +1s of counting against the −1s of crossing out
  • Five ready-made graphs (the two-source example, course prerequisites, build steps, a diamond, a cycle), or type your own edges like 0>1; 0>2; 1>3 (up to 10 vertices and 20 edges, repeated edges and self-loops included)
  • The code panel shows the listing line for line, with the lines the frame is on lit, and the values of u, v and head above it
  • 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 19 KB gzipped (script and CSS together)

How to use it

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

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

<div class="topological-sort-animation" data-topological-sort-animation></div>

<div
  class="topological-sort-animation"
  data-topological-sort-animation
  data-topological-sort-animation-scenario="cycle"
></div>

<div
  class="topological-sort-animation"
  data-topological-sort-animation
  data-topological-sort-animation-edges="0>1; 0>2; 1>3; 2>3"
  data-topological-sort-animation-vertices="5"
></div>

Options as data attributes, all starting with data-topological-sort-animation-:

Attribute Default What it does
-scenario two-sources two-sources, courses, build, diamond or cycle: the graph to run
-edges the scenario's Your own graph: edges like 0>1, 0->1, 0→1 or 0 1, separated by ;, , or new lines (up to 20, vertices 0–9). Repeated edges and self-loops are fine
-vertices just enough How many vertices your edges live on (2–10); made bigger when your edges name more, and the extra ones start with nothing pointing at them
-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 summary
-code true false hides the code panel
-inputs true false hides the rows of inputs (graph buttons, edges, vertices)

Edges are written in the order the listing meets them: the vertices a vertex points to are visited in the order you type them, so 0>2; 0>1 queues 2 before 1.

Elements added after the page loads: TopologicalSortAnimation.init(container); it returns a function that undoes it. For full control, TopologicalSortAnimation.createTopologicalSortAnimation(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, 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 topological sort (Kahn's algorithm) animation: a layered directed graph with live in-degree badges, a visible FIFO queue with its head index, an order strip filling up as edges are crossed out, stuck vertices lighting up on a cycle, five ready-made graphs or your own edges, live code, counters, player controls, light and dark.

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

Reviews

5.0out of 5
{count} review
  • 5 stars: 1
  • 4 stars: 0
  • 3 stars: 0
  • 2 stars: 0
  • 1 stars: 0
  1. tu

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.

  • AnimationGraphs

    Kruskal Animation

    A glowing graph where the cheapest network builds itself: Kruskal's minimum spanning tree with a sorted edge list and union-find colours, for lessons and slides

    Free
  • AnimationGraphs

    Graph Traversal Animation

    Queue or stack, watch the search choose: BFS and DFS on a glowing graph, side by side, ready for your lessons, slides and posts

    Free