An easy to use Interactive Graph Path visualizer with batteries included to implement your own Algorithm Visualization.
Try (use Safari or Chorme or Firefox): Here
- Interactive with Touch/Pen Input supported
- Fully optimized for low-end Mobiles and Tablet devices.
- Responsive Design
- All the Basic and Advance Path Finding algorithms
- Easy to extend API to check your own pathfinding algorithm
- Fast, Medium, Slow and Step Wise execution for better understanding of Algorithm.
- Customizable Grid system (Colors, Execution Speed, Pause, Resume, Stop)
- Some of Maze Generation Algorithms included (more coming soon)
Use Latest Chrome/ Chromium Browsers/ Safari (mobile/ Tablets/ Desktop)
- Depth First Search
- Breadth First Search
- Bi-Directional Search
- Dijkstra's Algorithm
- A* Search Algorithm
- Best First Search (Next Update)
- Random Maze Generator
PathViz's all the algorithms are based on Runner class it's a simple class with three main methods
Note Runner work as a delayed loop (why? to animate the progress and have more control over the process)
Also, it helps in Step mode execution (step by step execution)
-
constructor- declare all the needed variables here
-
firstFrame()- initialize all your variabled (like first step in any recursive function call)
-
perFrame()- code for every next iteration
- if a certain condition met just call
this.done() this.done()will stop the execution andthis.fixedFramewill be called next
-
fixedFrame()- this function run for limited number(upto
this.count) of count afterthis.done()is called - run any other pre-processing test after
this.done(like tracing a path in a list) and updatingthis.countvalue
- this function run for limited number(upto
After you done with your runner's implementation just add it to Runners List in states consent and add it to "Algorithm" list in index.html
<a class="nav-link dropdown-toggle"
href="#"
id="algo-choice"
role="button"
data-toggle="dropdown"
title="Change Algorithm"
aria-haspopup="true"
aria-expanded="false"
>
<i class="fa fa-filter"></i> Algorithm
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li>
<a class="dropdown-item algo-selection" data-algo="runner_identifier_as_defined_in_states">
Your Algorithm Name <------
</a>
</li>
<li>
<a class="dropdown-item algo-selection" data-algo="dfs"
>Depth First Search (DFS)
</a>
</li>
... other runners ...
</a>- Implementation of DFS
// Depth First Search
class DfsRunner extends NodeSetter {
constructor() {
super("Depth First Search");
this.stack = null;
this.path = null;
this.visitedNodes = null;
this.parent = null;
}
mapPath() {
this.path = [];
let node = this.endNode;
while (node.id != this.startNode.id) {
this.path.push(node);
node = this.parent.get(node.id);
}
this.endNode.changeText(this.path.length);
this.count = this.path.length;
}
firstFrame() {
this.stack = new Stack();
this.parent = new Map();
this.visitedNodes = new Set();
this.stack.push(this.startNode);
}
perFrame() {
if (this.stack.size > 0) {
let node = this.stack.pop();
while (node && this.visitedNodes.has(node)) {
node = this.stack.pop();
}
if (node == this.endNode) {
this.done();
this.mapPath();
return;
}
node != this.startNode ? node.setAsTraversed() : null;
this.visitedNodes.add(node);
node.adjacents.forEach(r => {
if (!this.visitedNodes.has(r)) {
this.parent.set(r.id, node);
this.stack.push(r);
}
});
} else {
this.done();
this.mapPath();
return;
}
}
fixedFrames() {
const n = this.path.pop();
n.setAsPath();
}
}-
Runner -
runner.js- abstract class to implement runner
-
NodeSetter -
runner.js- It Extends Runner
- utility class that enables assignment of
this.startNodeandthis.endNode - every runner should extends
NodeSetterclass (see above example)
-
GraphNode -
graph.jsBase Node class for graphNodes- extends this to add more informations (eg. Box class extends GraphNode)
- property
idholds unique id of this node (default: uuid4) - property
valueholds location of the node in grid - property
adjacentsholds adjacents nodes inSet()
-
GraphMatrix -
graph.jsGraph Class that creates Grid Structure using GraphNode class -
Box -
grid.jsExtends GraphNode i.e used by GraphMatrix to build Grid system- Methods
changeText(text): used to add text to center of boxresetText(): used to remove text from the boxsetAsStart(): will set this box as start node (this is called by Grid class for handling states)removeAsStart(): will remove this box as start node (called by Grid class)setAsEnd(): will set this box as end node (this is called by Grid class for handling states)removeAsEnd(): will remove this box as end node (called by Grid class)setAsBlock(): create a wall and remove adjacent node connectionssetAsClear(): rejoins the adjacent nodessetAsTraversed(): mark box as traversedsetAsPath(): mark box as pathresetTraversed(): change traversed/path to clear box
- Methods
-
Grid -
grid.jsThis class is the main class that join all the bits and bytes in PathViz-
handles events (click, drag, touch, etc.)
-
handles boxes in good manners
-
Methods
setAsBlock(row_index, col_index): create block/ wall in gridsetAsClear(row_index, col_index): join adjacents nodesresetTraversal(): reset traversed boxesclearGrid(): clear every box in grid (i.e re joins all the node connections)setRunnerNodes(): re-assign startNode and endNodes to the connected runner( how? the event calls assign startNode and endNode in Grid and callingsetRunnerNodewill assign these node to runner)setRunner(runnerCode, extra): assign runner to gridrunnerCode: the key you used for Runner instates.RunnersMapextra: if your Runners Implementation hasextra parameter(ie. Map for extra information needed) [check A* Runner]
setRunnerSpeed(speed): speed enum is defined instatesobject. this method will asign execution speed (i.eperFrame()method frequency)getBox(row_index,col_index): returns live box from gridboxes: getter to access boxes matrix (2d array)runner: getter to access currently assigned runner to gridstartNodeandendNode: getters to access StartBox and EndBox respectivelyvisualize(): will initiate runner
-
utility classes and methods are defined in utility.js
- Queue
- Stack
- LNode : Doubly LinkedList node used in
QueueandStack - uuidv4()
processGrid(rowCount, columnCount, width, height, boxSize): will re-paint every thing within confined constraints
- preset grid`: resets grid (removes box with traversed/path mark and text on boxes)
init(): reinitialize whole page (events, colours, grid, states, etc.)
statesObject: -states.jsholds states of the app constants, enum, context, elementRef, etc.- Context
- ActiveGrid : currently active grid object
- Context
.png)