changeset 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 930f8182a884
children 728fbb693183
files pylons_app/controllers/files.py pylons_app/lib/app_globals.py pylons_app/lib/helpers.py
diffstat 3 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/files.py	Sun Aug 29 00:11:28 2010 +0200
+++ b/pylons_app/controllers/files.py	Sun Aug 29 21:56:56 2010 +0200
@@ -27,7 +27,7 @@
 from pylons.controllers.util import redirect
 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 from pylons_app.lib.base import BaseController, render
-from pylons_app.lib.utils import EmptyChangeset, get_repo_slug
+from pylons_app.lib.utils import EmptyChangeset
 from pylons_app.model.hg_model import HgModel
 from vcs.exceptions import RepositoryError, ChangesetError
 from vcs.nodes import FileNode
--- a/pylons_app/lib/app_globals.py	Sun Aug 29 00:11:28 2010 +0200
+++ b/pylons_app/lib/app_globals.py	Sun Aug 29 21:56:56 2010 +0200
@@ -17,9 +17,7 @@
 
         """
         self.cache = CacheManager(**parse_cache_config_options(config))
-        self.changeset_annotation_colors = {}
         self.available_permissions = None   # propagated after init_model
-        self.app_title = None               # propagated after init_model
         self.baseui = None                  # propagated after init_model        
         
     @LazyProperty
--- a/pylons_app/lib/helpers.py	Sun Aug 29 00:11:28 2010 +0200
+++ b/pylons_app/lib/helpers.py	Sun Aug 29 21:56:56 2010 +0200
@@ -24,7 +24,6 @@
     convert_misc_entities, lchop, plural, rchop, remove_formatting, \
     replace_whitespace, urlify, truncate, wrap_paragraphs
 
-
 #Custom helpers here :)
 class _Link(object):
     '''
@@ -229,17 +228,31 @@
     @param filenode:
     """
     
-    color_dict = g.changeset_annotation_colors
+    color_dict = {}
     def gen_color():
-        import random
-        return [str(random.randrange(10, 235)) for _ in xrange(3)]
+        """generator for getting 10k of evenly distibuted colors using hsv color
+        and golden ratio.
+        """        
+        import colorsys
+        n = 10000
+        golden_ratio = 0.618033988749895
+        h = 0.22717784590367374
+        #generate 10k nice web friendly colors in the same order
+        for c in xrange(n):
+            h +=golden_ratio
+            h %= 1
+            HSV_tuple = [h, 0.95, 0.95]
+            RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple)
+            yield map(lambda x:str(int(x*256)),RGB_tuple)           
+
+    cgenerator = gen_color()
+        
     def get_color_string(cs):
         if color_dict.has_key(cs):
             col = color_dict[cs]
         else:
-            color_dict[cs] = gen_color()
-            col = color_dict[cs]
-        return "color: rgb(%s) ! important;" % (', '.join(col))
+            col = color_dict[cs] = cgenerator.next()
+        return "color: rgb(%s)! important;" % (', '.join(col))
         
     def url_func(changeset):
         tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>"+\
@@ -248,7 +261,7 @@
         tooltip_html = tooltip_html % (changeset.author,
                                                changeset.date,
                                                tooltip(changeset.message))
-        lnk_format = 'r%s:%s' % (changeset.revision,
+        lnk_format = 'r%-5s:%s' % (changeset.revision,
                                  changeset.raw_id)
         uri = link_to(
                 lnk_format,