How to easily set node-specific font colors?
Closed this issue · 4 comments
Thank you for this excellent library! It's easy to use and pretty comprehensive for my needs.
I have one question: To change the font color for a specific node, do I have to use the HTML styling as the documentation says? Like this one
using GiGraph.Dot.Extensions;
graph.Nodes.Add("Foo", node =>
{
node.Shape = DotNodeShape.Rectangle;
node.Label = @"<font color=""royalblue"" point-size=""20""><b>• Foo <font color=""black"">Bar</font></b></font><br/><i><u>Baz</u></i>".AsHtml();
});
If so, that seems to force me to rewrite the Label
field. However, I only want to style the node.
Is there a field that I failed to find?
Figured it out myself:
node.Attributes.Collection.Set("fontcolor", myColor);
Glad you wrote! :) Your final solution is correct, but this way you omit the abstraction the library gives you, and provide Graphviz attribute names directly. You can simply do it this way:
node.Font.Color = Color.Red
As long as you only want to adjust the color of the whole label, this is fine. You can generally do the following with the label:
- set font color, font size and font name (for the complete text, not its parts),
- left- or right-justify individual lines of text, or center them.
See here.
When you want to have more granular control on pieces of text, you can use HTML (see here).
If you are more familiar with Graphviz attribute names, you can also see the mapping file in this repository. You can look for an attribute name to learn by which programmatic property it is exposed on specific graph elements. In your case this would be:
"fontcolor": [ "Font.Color: DotColor [Graph, Cluster, Node, Edge]" ]
Thanks a lot. How did I miss that? lol