DagLib 1.0.0
See the version list below for details.
dotnet add package DagLib --version 1.0.0
NuGet\Install-Package DagLib -Version 1.0.0
<PackageReference Include="DagLib" Version="1.0.0" />
<PackageVersion Include="DagLib" Version="1.0.0" />
<PackageReference Include="DagLib" />
paket add DagLib --version 1.0.0
#r "nuget: DagLib, 1.0.0"
#:package DagLib@1.0.0
#addin nuget:?package=DagLib&version=1.0.0
#tool nuget:?package=DagLib&version=1.0.0
DagLib
A generic DAG (directed acyclic graph) library for .NET, built around Guid-based node identity with cycle detection, topological sorting, and ancestor/descendant traversal baked in. It's designed to sit behind immediate-mode node editor UIs like ImNodes, but has no dependency on any UI library itself.
Why
Node editors need a graph model that's easy to mutate interactively — add a node here, drag a link there — while never letting the underlying structure become invalid. DagLib rejects edges that would create a cycle at the moment you try to add them, so the UI layer never has to deal with an inconsistent graph in the first place. A full-graph cycle scan is also available for the one case interactive checks can't cover: data coming in from an external source, like a save file.
Features
- Typed payloads —
Node<T>andDagGraph<T>let each node carry any data type: a label, a record with position and color, a delegate, whatever the application needs. - Two layers of cycle safety — a cheap, single-edge check (
WouldCreateCycle) for interactive use, and a full-graph sweep (HasCycle) for validating data loaded from elsewhere. - Topological sort via Kahn's algorithm.
- Traversal helpers —
GetAncestorsandGetDescendantsfor impact analysis ("what does this feed into?" / "what feeds into this?"). - ID bridging —
NodeIdMappermaps each node's persistentGuidto a throwawayintfor int-keyed APIs like ImNodes, without ever discarding the original identity. - ImNodes-facing helper —
ImNodesGraphView<T>combines aDagGraph<T>and aNodeIdMapperinto a single facade for wiring up ImNodes events by int ID, so glue code isn't duplicated at every call site. - JSON persistence —
DagLib.Serialization.GraphSerializersaves and loads graphs as JSON, encoding edges as array indices rather than repeated Guids to keep files small, with an optional GZip-compressed format for larger graphs.
Install
dotnet add package DagLib
Usage
using DagLib;
var graph = new DagGraph<string>();
var a = graph.AddNode("A");
var b = graph.AddNode("B");
var c = graph.AddNode("C");
graph.AddEdge(a, b);
graph.AddEdge(a, c);
var order = graph.TopologicalSort();
Saving and loading JSON
using DagLib.Serialization;
GraphSerializer.Save(graph, "graph.json");
GraphSerializer.Save(graph, "graph.json.gz", compress: true);
var loaded = GraphSerializer.Load<string>("graph.json");
Working with ImNodes
using DagLib;
var mapper = new NodeIdMapper();
int imNodesId = mapper.GetOrCreateImNodesId(a.Id);
// pass imNodesId into the native API, e.g. ImNodes.BeginNode(imNodesId);
For a tighter integration, ImNodesGraphView<T> wraps a DagGraph<T> and a NodeIdMapper together, so ImNodes event handlers can work directly with int IDs instead of manually translating back and forth:
using DagLib;
var view = new ImNodesGraphView<string>(graph, mapper);
// Handling an IsLinkCreated event
view.AddEdge(fromImNodesId, toImNodesId);
// Handling a node deletion — removes it from both the graph and the ID mapping
view.RemoveNode(imNodesId);
// Driving a render loop
foreach (var (node, id) in view.GetRenderableNodes())
{
ImNodes.BeginNode(id);
// ... build UI from node.Data ...
ImNodes.EndNode();
}
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.