The ColorConfig
class uses JSON config files to define the default colors. Each color is defined by a color code:
- Hexadecimal:
"#FFFFFF"
- RGB(A):
[1, 1, 1]
or[255, 255, 255]
The JSON file must contain the following fields:
The default color is used for the features which don't have a color setted.
"default_color": [1, 1, 1]
The minimal color is minimal color of the heatmap. This color corresponds to the lower values of the heatmap.
"min_color": [0, 1, 0]
The maximal color is the maximal color of the heatmap. This color corresponds to the higher values of the heatmap.
"max_color": [1, 0, 0]
The number of colors is used to create the colors of the heatmap. It corresponds to the number of colors between the min_color and the max_color.
"nb_colors": 20
The color dictionary is used to match colors with attribute values. Each attribute value must be a key of the dictionary. A key default
should be present for features which don't have a value for the targeted attribute (or have a value not present in the dictionary).
"color_dict": {
"office": [1, 0, 0],
"store": [0, 1, 0],
"residential": [0, 0, 1],
"default": [0.5, 0.5, 0.5]
}
To create a ColorConfig
instance, use:
color_config = ColorConfig()
It will load the default_config.json. You can use another config file with:
color_config = ColorConfig("path/to/config.json")
Once the ColorConfig
is created, you can get colored materials:
mat = color_config.get_default_color()
key = "office"
mat = color_config.get_color_by_key(key)
factor = 0.7
mat = color_config.get_color_by_lerp(factor)