1. Peter Suter
  2. Trac-workflow-macro

Commits

Peter Suter  committed 36839de

More saturated, deterministic colors.

  • Participants
  • Parent commits 2a15c72
  • Branches ticket-10270-workflow-macro

Comments (0)

Files changed (1)

File trac/htdocs/js/workflow_graph.js

View file
     ctx.fillText(edge.label, -measured.width / 2, margin);
     ctx.setTransform(1, 0, 0, 1, 0, 0);
   };
-  
-  function mixRandomColor(r, g, b) {
+
+  function hexColor(r, g, b) {
     return '#' + 
-      Math.floor((r + Math.random() * 255) / 2).toString(16) +
-      Math.floor((g + Math.random() * 255) / 2).toString(16) +
-      Math.floor((b + Math.random() * 255) / 2).toString(16);
+      Math.floor(r).toString(16) +
+      Math.floor(g).toString(16) +
+      Math.floor(b).toString(16);
   }
-  
-  var colors  = ["Black", "Blue", "Red", "Green", "Fuchsia"];
+
+  function saturatedColor(r, g, b) {
+    var avg = (r + g + b) / 3;
+    if (r < avg) r /= 2;
+    if (g < avg) g /= 2;
+    if (b < avg) b /= 2;
+    return hexColor(r, g, b);
+  }
+
+  var colors = ["Black", "Blue", "Red", "Green", "Fuchsia"];
 
   function getActionColor(i) {
     if (i < colors.length)
       return colors[i];
-    return mixRandomColor(127, 127, 127);
+    return saturatedColor(
+      ((i+70) * 30269) % 256, ((i+71) * 30307) % 256, ((i+72) * 30323) % 256);
   }
   
   function layout(graph) {