Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / scripts / generate_uiStateJSON.py
1 # Template for UIState (Currently supports only colors)
2 UI_STATE_BODY = {
3     "vis": {
4         "colors": None
5     }
6 }
7
8
9 def generate(dash_config, viz_config):
10
11     colors = {}
12
13     # Check for 'color' key in 'series' or 'seriesParams' in
14     # either viz_config and dash_config
15
16     # Note:- 'series' simplifies 'seriesParams' and 'aggs'
17     # and avoids duplication
18
19     try:
20         series = dash_config['y-axis']['series']
21         for _, value in series.items():
22             try:
23                 colors[value['label']] = value['color']
24             except KeyError:
25                 continue
26     except KeyError:
27         pass
28
29     try:
30         series = viz_config['series']
31         for _, value in series.items():
32             try:
33                 colors[value['label']] = value['color']
34             except KeyError:
35                 continue
36     except KeyError:
37         pass
38
39     try:
40         seriesParams = dash_config['y-axis']['seriesParams']
41         for _, value in seriesParams.items():
42             try:
43                 colors[value['label']] = value['color']
44             except KeyError:
45                 continue
46     except KeyError:
47         pass
48
49     try:
50         seriesParams = viz_config['seriesParams']
51         for _, value in seriesParams.items():
52             try:
53                 colors[value['label']] = value['color']
54             except KeyError:
55                 continue
56     except KeyError:
57         pass
58
59     UI_STATE_BODY['vis']['colors'] = colors
60
61     return UI_STATE_BODY