aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql/utils.py
diff options
context:
space:
mode:
authorDavid Wolfe2014-02-11 19:16:10 -0400
committerDavid Wolfe2014-02-11 19:16:10 -0400
commit8d68d307af04166e7aa4fde915b95a41560b8f19 (patch)
tree8791cb98f566f6045913b2ed11d8c94facbdc6c7 /debug_toolbar/panels/sql/utils.py
parenteb7793807863a088cf7c67c34df7f31ad03cbc29 (diff)
downloaddjango-debug-toolbar-8d68d307af04166e7aa4fde915b95a41560b8f19.tar.bz2
Color-code SQL: code review changes; fallback to black after 2**24 colors
Diffstat (limited to 'debug_toolbar/panels/sql/utils.py')
-rw-r--r--debug_toolbar/panels/sql/utils.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py
index d6f0173..65d26bd 100644
--- a/debug_toolbar/panels/sql/utils.py
+++ b/debug_toolbar/panels/sql/utils.py
@@ -40,20 +40,22 @@ def swap_fields(sql):
def contrasting_color_generator():
"""
Generate constrasting colors by varying most significant bit of RGB first,
- and then vary subsebequent bits systematically.
+ 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 = 128
+ n = 1 << 7
so_far = [[0, 0, 0]]
- while (1):
+ 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 = n / 2
+ n >>= 1