Commit da22b130 authored by Louis's avatar Louis
Browse files

Each package has its proper color

parent 0b7766cb
- badges: à partir de GET, avec defaut
- if no pkg nor user: random 10 packages
- Set chart colors
import http.server
from urllib.parse import urlparse, parse_qs
import colorsys
import functools
import os
import http.server
import jinja2
import operator
import os
import pkg_resources
import jinja2
import random
from pipstats import PackageList
......@@ -19,6 +21,13 @@ class Counter:
def as_id(string):
return "".join(list(filter(str.isalnum, string)))
def random_color(seed):
old_seed = random.random()
random.seed(seed)
rgb = colorsys.hsv_to_rgb(random.random(), 1, 1)
random.seed(old_seed)
return ("#%02x%02x%02x" % tuple([int(value * 256) for value in rgb]))[:7]
def _get_environment():
TEMPLATEDIR = os.path.join(
pkg_resources.resource_filename(__name__, 'data'),
......@@ -30,6 +39,7 @@ def _get_environment():
env.filters['PackageList'] = PackageList
env.filters['datetime'] = operator.methodcaller('strftime', "%Y-%m-%d %H:%M:%S")
env.filters['as_id'] = as_id
env.filters['color'] = random_color
return env
class HttpHandler(http.server.BaseHTTPRequestHandler):
......
......@@ -24,6 +24,10 @@
labels: [{% for key in packagelist.iter_ykeys(name) -%}
"{{ key }}"
{%- if not loop.last %}, {% endif -%}
{% endfor %}],
lineColors: [{% for key in packagelist.iter_ykeys(name) -%}
"{{ key |color }}"
{%- if not loop.last %}, {% endif -%}
{% endfor %}]
});
</script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment