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

Fix: Cache used colors

* This greatly increases performance (Many orders of magnite faster)
* ColorsUsed is implemented so that every time it is queried the value
  is calculated on the fly
* When writing ColorsUsed I did not think this would be a problem since
  we only need it once: When calculating the color
* But the actual implementation used it at two points so that for x
  colored nodes the ColorsUsed were calculated twice.
* Ideally this would be fixed by changing the ColorsUsed implementation
  in the -Graph classes. This might be fixed later so consider this
  commit a hotfix
parent 69a8cde4
No related branches found
No related tags found
1 merge request!39Fix: Cache ColorsUsed for huge performance boost
......@@ -8,16 +8,16 @@ namespace SparseTransform.Convert
/// </summary>
public class ColoredDotWriter : DotWriter
{
private IGraph _coloredGraph;
private bool _textcolor;
private int _colorsUsed;
/// <summary>
/// Constructor constructing a color-dictionary for coloring purpose.
/// </summary>
/// <param name="textColor">decision whether the labels should be colored or labelled.</param>
public ColoredDotWriter(IGraph graph, bool textColor)
{
this._coloredGraph = graph;
this._colorsUsed = graph.ColorsUsed;
this._textcolor = textColor;
}
......@@ -30,7 +30,7 @@ namespace SparseTransform.Convert
public override String NodeLabel(GraphNode node, String prefix)
{
// This is the offset. Less colors = more distance between
int hueFactor = 255 / _coloredGraph.ColorsUsed;
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);
......@@ -41,7 +41,7 @@ namespace SparseTransform.Convert
// If current node is colored, apply either text label with color or set fill color
if (node.Colored)
{
if (_textcolor || _coloredGraph.ColorsUsed > 255)
if (_textcolor || this._colorsUsed > 255)
{
label.Append($", label=\"{prefix}{node.Index}\\n color:{node.Color}\"");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment