Skip to content

Commit 74d12ae

Browse files
committed
Manually define the color of an endpoint from the config file
1 parent 463cd98 commit 74d12ae

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

dashboard/colors.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from colorhash import ColorHash
2+
from dashboard import config
3+
4+
import ast
25

36

47
def get_color(hash):
@@ -7,7 +10,9 @@ def get_color(hash):
710
:param hash: the string that is translated into a color
811
:return: a color (as string)
912
"""
10-
c = ColorHash(hash)
11-
rgb = c.rgb
13+
if hash in config.colors:
14+
rgb = ast.literal_eval(config.colors[hash])
15+
else:
16+
rgb = ColorHash(hash).rgb
1217
return 'rgb({0}, {1}, {2})'.format(rgb[0], rgb[1], rgb[2])
1318

dashboard/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import configparser
22
import os
3+
import ast
34

45

56
class Config(object):
@@ -21,6 +22,7 @@ def __init__(self):
2122
self.guest_username = 'guest'
2223
self.guest_password = 'guest_password'
2324
self.outlier_detection_constant = 2.5
25+
self.colors = {}
2426

2527
# define a custom function to retrieve the session_id or username
2628
self.get_group_by = None
@@ -66,6 +68,10 @@ def from_file(self, config_file):
6668
if parser.has_option('dashboard', 'TEST_DIR'):
6769
self.test_dir = parser.get('dashboard', 'TEST_DIR')
6870

71+
# For manually defining colors of specific endpoints
72+
if parser.has_option('dashboard', 'COLORS'):
73+
self.colors = ast.literal_eval(parser.get('dashboard', 'COLORS'))
74+
6975
# When the option git is selected, it overrides the given version
7076
if parser.has_option('dashboard', 'GIT'):
7177
git = parser.get('dashboard', 'GIT')

0 commit comments

Comments
 (0)