Skip to content
Snippets Groups Projects
Commit 3313bfd7 authored by Paul Nitzke's avatar Paul Nitzke
Browse files

Cache hue color offset

* This should theoretically improve performance as we only calculate it
  once instead of once for every colored node
parent e7f94809
No related branches found
No related tags found
1 merge request!39Fix: Cache ColorsUsed for huge performance boost
......@@ -10,6 +10,7 @@ namespace SparseTransform.Convert
{
private bool _textcolor;
private int _colorsUsed;
private int _hueFactor;
/// <summary>
/// Constructor constructing a color-dictionary for coloring purpose.
......@@ -19,6 +20,8 @@ namespace SparseTransform.Convert
{
this._colorsUsed = graph.ColorsUsed;
this._textcolor = textColor;
// This is the offset for coloring. Less colors = more distance between. Cached for NodeLabel.
this._hueFactor = 255 / this._colorsUsed;
}
/// <summary>
......@@ -29,10 +32,8 @@ namespace SparseTransform.Convert
/// <returns></returns>
public override String NodeLabel(GraphNode node, String prefix)
{
// This is the offset. Less colors = more distance between
int hueFactor = 255 / this._colorsUsed;
// Calculate the hue. We modulo with 255 to not exceed spectrum. Then convert to float for DOT
double hue = Math.Round((double)((node.Color * hueFactor) % 255) / 255, 3);
double hue = Math.Round((double)((node.Color * _hueFactor) % 255) / 255, 3);
StringBuilder label = new StringBuilder();
// Append label name and general layout info
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment