-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Color-code SQL query "Timeline" stripes according to stacktrace #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The canonical pattern for duplicating a list is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've seen this one debated. Not a big deal, as you say. I think [:] is a bit more cryptic. |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is a one-liner and is called exactly once, why don't you inline it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have it named, since otherwise it's too cryptic for my taste. Mind if I leave this as is?