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
diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html
index f927e5d..4d95a80 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/sql.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html
@@ -34,7 +34,7 @@
 						
 					
 					| -						
+ | {{ query.duration|floatformat:"2" }}
-- 
cgit v1.2.3
From eb7793807863a088cf7c67c34df7f31ad03cbc29 Mon Sep 17 00:00:00 2001
From: David Wolfe
Date: Mon, 10 Feb 2014 09:36:40 -0400
Subject: Color-code SQL: minor code style changes
---
 debug_toolbar/panels/sql/panel.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(limited to 'debug_toolbar')
diff --git a/debug_toolbar/panels/sql/panel.py b/debug_toolbar/panels/sql/panel.py
index cae5214..b7a9e4c 100644
--- a/debug_toolbar/panels/sql/panel.py
+++ b/debug_toolbar/panels/sql/panel.py
@@ -198,9 +198,8 @@ class SQLPanel(Panel):
                 query['stacktrace'] = render_stacktrace(query['stacktrace'])
                 i += 1
 
-                if not trace_colors.get(query['stacktrace']):
-                    c = colors.next()
-                    trace_colors[query['stacktrace']] = c
+                if query['stacktrace'] not in trace_colors:
+                    trace_colors[query['stacktrace']] = colors.next()
                 query['trace_color'] = trace_colors[query['stacktrace']]
 
             if trans_id:
-- 
cgit v1.2.3
From 8d68d307af04166e7aa4fde915b95a41560b8f19 Mon Sep 17 00:00:00 2001
From: David Wolfe
Date: Tue, 11 Feb 2014 19:16:10 -0400
Subject: Color-code SQL: code review changes; fallback to black after 2**24
 colors
---
 debug_toolbar/panels/sql/panel.py |  5 ++---
 debug_toolbar/panels/sql/utils.py | 10 ++++++----
 2 files changed, 8 insertions(+), 7 deletions(-)
(limited to 'debug_toolbar')
diff --git a/debug_toolbar/panels/sql/panel.py b/debug_toolbar/panels/sql/panel.py
index b7a9e4c..f6ce954 100644
--- a/debug_toolbar/panels/sql/panel.py
+++ b/debug_toolbar/panels/sql/panel.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
 
 import uuid
 from copy import copy
+from collections import defaultdict
 
 from django.conf.urls import patterns, url
 from django.db import connections
@@ -137,7 +138,7 @@ class SQLPanel(Panel):
 
     def process_response(self, request, response):
         colors = contrasting_color_generator()
-        trace_colors = {}
+        trace_colors = defaultdict(lambda: next(colors))
         if self._queries:
             width_ratio_tally = 0
             factor = int(256.0 / (len(self._databases) * 2.5))
@@ -198,8 +199,6 @@ class SQLPanel(Panel):
                 query['stacktrace'] = render_stacktrace(query['stacktrace'])
                 i += 1
 
-                if query['stacktrace'] not in trace_colors:
-                    trace_colors[query['stacktrace']] = colors.next()
                 query['trace_color'] = trace_colors[query['stacktrace']]
 
             if trans_id:
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
-- 
cgit v1.2.3 |