react-mesh-router
v1.0.2
Published
A simple and visual mesh router library using Dijkstra's algorithm. Create nodes and edges, calculate the shortest path, and visualize it easily in React.
Readme
🚦 react-mesh-router
A simple and visual mesh router library using Dijkstra's algorithm. Create nodes and edges, calculate the shortest path, and visualize it easily in React.
📌 Features
- Add and manage graph nodes with weighted edges
- Compute shortest path using Dijkstra's algorithm
- Visualize nodes, edges, and the active path
- Easy to integrate with any React app
📦 Installation
npm install react-mesh-router
# or
yarn add react-mesh-router
🛠️ Usage
1. Import the library
import { MeshRouter, MeshVisualizer } from "react-mesh-router";
2. Create the mesh and add nodes
const mesh = new MeshRouter();
mesh.addNode("A", [{ id: "B", weight: 1 }, { id: "C", weight: 4 }]);
mesh.addNode("B", [{ id: "A", weight: 1 }, { id: "C", weight: 2 }]);
mesh.addNode("C", [{ id: "A", weight: 4 }, { id: "B", weight: 2 }]);
3. Find the shortest path
const path = mesh.findShortestPath("A", "C"); // ➝ ["A", "B", "C"]
4. Visualize it in React
<MeshVisualizer
nodes={["A", "B", "C"]}
edges={[
{ from: "A", to: "B", weight: 1 },
{ from: "A", to: "C", weight: 4 },
{ from: "B", to: "C", weight: 2 },
]}
highlightEdges={[
{ from: "A", to: "B", weight: 1 },
{ from: "B", to: "C", weight: 2 },
]}
/>