File size: 1,175 Bytes
11edfba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""This file contains color information"""
from typing import List, Dict
from colors import COLOR_MAPPING_, COLOR_MAPPING_CATEGORY_, ade_palette


def convert_hex_to_rgba(hex_code: str) -> str:
    """Convert hex code to rgba.
    Args:
        hex_code (str): hex string
    Returns:
        str: rgba string
    """
    hex_code = hex_code.lstrip('#')
    return "rgba(" + str(int(hex_code[0:2], 16)) + ", " + str(int(hex_code[2:4], 16)) + ", " + str(int(hex_code[4:6], 16)) + ", 1.0)"


def convert_dict_to_rgba(color_dict: Dict) -> Dict:
    """Convert hex code to rgba for all elements in a dictionary.
    Args:
        color_dict (Dict): color dictionary
    Returns:
        Dict: color dictionary with rgba values
    """
    updated_dict = {}
    for k, v in color_dict.items():
        updated_dict[convert_hex_to_rgba(k)] = v
    return updated_dict


def convert_nested_dict_to_rgba(nested_dict):
    updated_dict = {}
    for k, v in nested_dict.items():
        updated_dict[k] = convert_dict_to_rgba(v)
    return updated_dict


COLOR_MAPPING = convert_dict_to_rgba(COLOR_MAPPING_)
COLOR_MAPPING_CATEGORY = convert_nested_dict_to_rgba(COLOR_MAPPING_CATEGORY_)