GraphWorld, GraphNode, GraphEdge#
GraphWorld visualizes an undirected graph.
Nodes are placed at explicit pixel positions; edges are drawn as lines between them.
The world is well-suited for BFS, DFS, Dijkstra and other graph traversal tasks.
Building the graph#
from miniworlds_data import GraphWorld
world = GraphWorld(width=700, height=500)
a = world.add_node("A", position=(100, 100))
b = world.add_node("B", position=(300, 100))
c = world.add_node("C", position=(200, 300))
world.connect(a, b)
world.connect(a, c)
world.connect(b, c)
world.set_start(a)
world.set_target(c)
world.run()
GraphWorld operations#
Method |
Description |
|---|---|
|
Add a node with a unique name and optional display value and position; return the |
|
Return the node with the given name. |
|
Connect two nodes with an undirected edge; return the |
|
Return the list of neighboring |
|
Mark a node as the search origin (red). |
|
Mark a node as the search goal (blue). |
|
Highlight a node with a named state or explicit color. |
|
Highlight the edge between two nodes. |
|
Reset all nodes and edges to their default/start/target colors. |
|
Highlight the edges along a sequence of node names or instances as a path. |
|
List of all |
|
List of all |
Node states: default, visited, current, frontier, start, target, path.
Edge states: default, visited, path.
GraphNode attributes#
Attribute |
Description |
|---|---|
|
Unique identifier string. |
|
Displayed value. |
|
Current highlight state string. |
|
Change the highlight state. |
GraphEdge attributes#
Attribute |
Description |
|---|---|
|
Source |
|
Target |
|
Change the edge color. |
|
Recompute the line endpoints from the current node positions. |
API Reference#
- class miniworlds_data.graph_world.GraphWorld(*, width=600, height=400, node_radius=22, background=(250, 250, 250, 255))#
Visualizes an undirected graph. The table above lists the public graph operations intended for traversal and pathfinding examples.
- class miniworlds_data.graph_world.GraphNode#
Node actor used by
GraphWorld.
- class miniworlds_data.graph_world.GraphEdge#
Edge actor used by
GraphWorld.