diff --git a/test/util/test_cmaps.py b/test/util/test_cmaps.py index 500a4cfea..164718621 100644 --- a/test/util/test_cmaps.py +++ b/test/util/test_cmaps.py @@ -402,8 +402,11 @@ def test_create_colormap_from_config_color_entry_object(self): { "name": "my_cmap", "type": "continuous", - "colors": [[0.0, "red"], [12.0, "#0000FF"], [24.0, [0, 1, 0, 0.3]]], - "labels": ["low", "medium", "high"], + "colors": [ + [0.0, "red", "low"], + [12.0, "#0000FF", "medium"], + [24.0, [0, 1, 0, 0.3], "high"], + ], }, config_parse, ) @@ -431,8 +434,11 @@ def test_create_colormap_from_config_color_entry_tuple(self): { "name": "my_cmap", "type": "categorical", - "colors": [[0.0, "red"], [1.0, "#0000FF"], [2.0, [0, 1, 0]]], - "labels": ["low", "", "high"], + "colors": [ + [0.0, "red", "low"], + [1.0, "#0000FF"], + [2.0, [0, 1, 0], "high"], + ], }, config_parse, ) diff --git a/xcube/util/cmaps.py b/xcube/util/cmaps.py index fa701290f..e73bd9808 100644 --- a/xcube/util/cmaps.py +++ b/xcube/util/cmaps.py @@ -491,6 +491,7 @@ def parse_cm_code(cm_code: str) -> tuple[str, Optional[Colormap]]: user_color_map: dict[str, Any] = json.loads(cm_code) cm_name = user_color_map["name"] cm_items = user_color_map["colors"] + cm_items = [item[:2] for item in cm_items] cm_type = user_color_map.get("type", "continuous") cm_base_name, _, _ = parse_cm_name(cm_name) n = len(cm_items) @@ -635,22 +636,17 @@ def get_cmap_png_base64(cmap: matplotlib.colors.Colormap) -> str: def create_colormap_from_config(cmap_config: dict) -> Colormap: registry = ColormapRegistry() colors = [] - labels = [] for color in cmap_config["Colors"]: if isinstance(color, list): - colors.append(color[:2]) - if len(color) == 3: - labels.append(color[2]) - else: - labels.append("") + colors.append(color) else: - colors.append([color["Value"], color["Color"]]) if "Label" in color: - labels.append(color["Label"]) + colors.append([color["Value"], color["Color"], color["Label"]]) else: - labels.append("") + colors.append([color["Value"], color["Color"]]) - for i, [_, color] in enumerate(colors): + for i, item in enumerate(colors): + color = item[1] if isinstance(color, list): if any([val > 1 for val in color]): colors[i][1] = list(np.array(color) / 255) @@ -658,7 +654,6 @@ def create_colormap_from_config(cmap_config: dict) -> Colormap: name=cmap_config["Identifier"], type=cmap_config["Type"], colors=colors, - labels=labels, ) _, cmap = registry.get_cmap(json.dumps(config_parse)) return cmap, config_parse