Module: check_mk
Branch: master
Commit: 339c4ff53d6efea388f0f485d67a5ff8cdaedfb8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=339c4ff53d6efeā¦
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jan 28 14:43:20 2016 +0100
New function for random palette color
---
web/htdocs/metrics.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 585ce68..ec860db 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -34,7 +34,7 @@
# unit: The definition-dict of a unit like in unit_info
# graph_template: Template for a graph. Essentially a dict with the key
"metrics"
-import math, time, colorsys, shlex, operator
+import math, time, colorsys, shlex, operator, random
import config, defaults, pagetypes, table
from lib import *
from valuespec import *
@@ -200,6 +200,17 @@ def get_palette_color_by_index(i, shading='a'):
return "%s/%s" % (color_key, shading)
+def get_next_random_palette_color():
+ keys = cmk_color_palette.keys()
+ if html.is_cached("random_color_index"):
+ last_index = html.get_cached("random_color_index")
+ else:
+ last_index = random.randint(0, len(keys))
+ index = (last_index + 1) % len(keys)
+ html.set_cache("random_color_index", index)
+ return parse_color_into_hexrgb("%s/a" % keys[index])
+
+
# 23/c -> #ff8040
# #ff8040 -> #ff8040
def parse_color_into_hexrgb(color_string):