Mercurial > kallithea
comparison pylons_app/lib/helpers.py @ 438:0d4fceb91c9c
fixes #24, added generator that generates equally distrybuted colors. Thus skipping creating one large coloring history.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 29 Aug 2010 21:56:56 +0200 |
parents | dee0e7eb0370 |
children | e5157e2a530e |
comparison
equal
deleted
inserted
replaced
437:930f8182a884 | 438:0d4fceb91c9c |
---|---|
21 from webhelpers.pylonslib import Flash as _Flash | 21 from webhelpers.pylonslib import Flash as _Flash |
22 from webhelpers.pylonslib.secure_form import secure_form | 22 from webhelpers.pylonslib.secure_form import secure_form |
23 from webhelpers.text import chop_at, collapse, convert_accented_entities, \ | 23 from webhelpers.text import chop_at, collapse, convert_accented_entities, \ |
24 convert_misc_entities, lchop, plural, rchop, remove_formatting, \ | 24 convert_misc_entities, lchop, plural, rchop, remove_formatting, \ |
25 replace_whitespace, urlify, truncate, wrap_paragraphs | 25 replace_whitespace, urlify, truncate, wrap_paragraphs |
26 | |
27 | 26 |
28 #Custom helpers here :) | 27 #Custom helpers here :) |
29 class _Link(object): | 28 class _Link(object): |
30 ''' | 29 ''' |
31 Make a url based on label and url with help of url_for | 30 Make a url based on label and url with help of url_for |
227 """ | 226 """ |
228 pygmentize function for annotation | 227 pygmentize function for annotation |
229 @param filenode: | 228 @param filenode: |
230 """ | 229 """ |
231 | 230 |
232 color_dict = g.changeset_annotation_colors | 231 color_dict = {} |
233 def gen_color(): | 232 def gen_color(): |
234 import random | 233 """generator for getting 10k of evenly distibuted colors using hsv color |
235 return [str(random.randrange(10, 235)) for _ in xrange(3)] | 234 and golden ratio. |
235 """ | |
236 import colorsys | |
237 n = 10000 | |
238 golden_ratio = 0.618033988749895 | |
239 h = 0.22717784590367374 | |
240 #generate 10k nice web friendly colors in the same order | |
241 for c in xrange(n): | |
242 h +=golden_ratio | |
243 h %= 1 | |
244 HSV_tuple = [h, 0.95, 0.95] | |
245 RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple) | |
246 yield map(lambda x:str(int(x*256)),RGB_tuple) | |
247 | |
248 cgenerator = gen_color() | |
249 | |
236 def get_color_string(cs): | 250 def get_color_string(cs): |
237 if color_dict.has_key(cs): | 251 if color_dict.has_key(cs): |
238 col = color_dict[cs] | 252 col = color_dict[cs] |
239 else: | 253 else: |
240 color_dict[cs] = gen_color() | 254 col = color_dict[cs] = cgenerator.next() |
241 col = color_dict[cs] | 255 return "color: rgb(%s)! important;" % (', '.join(col)) |
242 return "color: rgb(%s) ! important;" % (', '.join(col)) | |
243 | 256 |
244 def url_func(changeset): | 257 def url_func(changeset): |
245 tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>"+\ | 258 tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>"+\ |
246 " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" | 259 " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" |
247 | 260 |
248 tooltip_html = tooltip_html % (changeset.author, | 261 tooltip_html = tooltip_html % (changeset.author, |
249 changeset.date, | 262 changeset.date, |
250 tooltip(changeset.message)) | 263 tooltip(changeset.message)) |
251 lnk_format = 'r%s:%s' % (changeset.revision, | 264 lnk_format = 'r%-5s:%s' % (changeset.revision, |
252 changeset.raw_id) | 265 changeset.raw_id) |
253 uri = link_to( | 266 uri = link_to( |
254 lnk_format, | 267 lnk_format, |
255 url('changeset_home', repo_name=changeset.repository.name, | 268 url('changeset_home', repo_name=changeset.repository.name, |
256 revision=changeset.raw_id), | 269 revision=changeset.raw_id), |