aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug_toolbar/panels/sql/utils.py')
-rw-r--r--debug_toolbar/panels/sql/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py
index 3943168..65d26bd 100644
--- a/debug_toolbar/panels/sql/utils.py
+++ b/debug_toolbar/panels/sql/utils.py
@@ -35,3 +35,27 @@ 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 subsequent 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 = 1 << 7
+ so_far = [[0, 0, 0]]
+ while True:
+ if n == 0: # This happens after 2**24 colours; presumably, never
+ yield "#000000" # black
+ 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 >>= 1