aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql/utils.py
diff options
context:
space:
mode:
authorDavid Wolfe2014-02-08 18:37:43 -0400
committerDavid Wolfe2014-02-08 19:39:30 -0400
commit6041b0da8317b3c8df2d1551f8282a9e59c336c3 (patch)
tree99405ed7bd34ed08a0efe87f1287e4f28d649751 /debug_toolbar/panels/sql/utils.py
parent1449c014ed449c7c139e2912b0ebb063b1134c83 (diff)
downloaddjango-debug-toolbar-6041b0da8317b3c8df2d1551f8282a9e59c336c3.tar.bz2
Color-code SQL query "Timeline" stripes according to stacktrace
Diffstat (limited to 'debug_toolbar/panels/sql/utils.py')
-rw-r--r--debug_toolbar/panels/sql/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py
index 3943168..d6f0173 100644
--- a/debug_toolbar/panels/sql/utils.py
+++ b/debug_toolbar/panels/sql/utils.py
@@ -35,3 +35,25 @@ def swap_fields(sql):
r'<a class="djDebugCollapsed djDebugToggle" href="#">\1</a> '
r'<strong>FROM')
return re.sub(expr, subs, sql)
+
+
+def contrasting_color_generator():
+ """
+ Generate constrasting colors by varying most significant bit of RGB first,
+ and then vary subsebequent bits systematically.
+ """
+ def rgb_to_hex(rgb):
+ return '#%02x%02x%02x' % tuple(rgb)
+
+ triples = [(1, 0, 0), (0, 1, 0), (0, 0, 1),
+ (1, 1, 0), (0, 1, 1), (1, 0, 1), (1, 1, 1)]
+ n = 128
+ so_far = [[0, 0, 0]]
+ while (1):
+ copy_so_far = list(so_far)
+ for triple in triples:
+ for previous in copy_so_far:
+ rgb = [n * triple[i] + previous[i] for i in range(3)]
+ so_far.append(rgb)
+ yield rgb_to_hex(rgb)
+ n = n / 2