Replies: 1 comment
-
Rubber ducky programming. I think I figured it out styling at least after going back and reviewing the FormatVertex code and a couple other examples; public void RenderGraph(string fileName)
{
var graph = new AdjacencyGraph<string, Edge<string>>();
foreach (var (genomeMoniker, creature) in creatureDict)
{
if (creature.Name != "Unknown" || showEggs)
{
if (!graph.ContainsVertex(genomeMoniker))
{
graph.AddVertex(genomeMoniker);
}
foreach (var (parentGenome, parent) in creature.Parents)
{
if (!graph.ContainsVertex(parentGenome))
{
graph.AddVertex(parentGenome);
}
graph.AddEdge(new Edge<string>(source: parentGenome, target: genomeMoniker));
}
}
}
var graphviz = new GraphvizAlgorithm<string, Edge<string>>(graph);
graphviz.FormatVertex += (sender, args) =>
{
if (creatureDict.ContainsKey(args.Vertex)){
var nodeStyle = new GraphvizVertex();
SetCreatureNodeStyle(args.Vertex,creatureDict[args.Vertex], ref nodeStyle);
args.VertexFormat.Label = creatureDict[args.Vertex].Name;
args.VertexFormat.Shape = nodeStyle.Shape;
args.VertexFormat.Style = nodeStyle.Style;
args.VertexFormat.FillColor = nodeStyle.FillColor;
args.VertexFormat.FontColor = nodeStyle.FontColor;
args.VertexFormat.StrokeColor = nodeStyle.StrokeColor;
}
};
graphviz.FormatEdge += (_, args) =>
{
if (creatureDict.ContainsKey(args.Edge.Target)){
var creature = creatureDict[args.Edge.Target];
var parent = creature.Parents[args.Edge.Source];
args.EdgeFormat.StrokeColor = GetEdgeColor(parent.Sex);
}
};
graphviz.Generate(new FileDotEngine(), fileName);
} Still not sure how to set the ID of the node, as the dot output is still listing the original index. Also would like to use some currently non-listed shapes in the GraphvizVertexShape like CDS if this is possible. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi QuikGraph,
I have a python POC for a (video game) genealogy map, that I think QuikGraph might be a good use-case for. The core of the project reads in an ancestry list, creates & styles nodes and edges, and outputs an SVG file for display (understand that at the moment QuikGraph can't create the SVG, but a .dot file is plenty fine for the next stage of the project). One of the goals is to allow some level of interaction, like being able to click on a node/vertex and have the ancestors high-lighted.
To start, though, I've hit a roadblock building the dot structure to use the creature ID as the primary ID, and doing the initial styling of each element.
Original python (live project can be seen here):
Attempted C#:
Aside from the label issue, the overall output aligns correctly.
I'm guessing the way I'm going about things is a bit backwards/not directly translatable in the same way. The example provided in the other discussion on IDs appears to only function for styling everything. I'm guessing I need to somehow extend the TVertex class to be able to use the custom rendering, but I'm not sure how to go about this.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions