@@ -777,10 +777,11 @@ def _set_color_source_vec(
777777 alpha : float = 1.0 ,
778778 table_name : str | None = None ,
779779 table_layer : str | None = None ,
780- render_type : Literal ["points" ] | None = None ,
780+ render_type : Literal ["points" , "labels" ] | None = None ,
781781) -> tuple [ArrayLike | pd .Series | None , ArrayLike , bool ]:
782782 if value_to_plot is None and element is not None :
783- color = np .full (len (element ), na_color .get_hex_with_alpha ())
783+ n_elements = len (element ) if render_type != "labels" else len (dask .array .unique (element .data ).compute ())
784+ color = np .full (n_elements , na_color .get_hex_with_alpha ())
784785 return color , color , False
785786
786787 # Figure out where to get the color from
@@ -1000,7 +1001,7 @@ def _get_categorical_color_mapping(
10001001 alpha : float = 1 ,
10011002 groups : list [str ] | str | None = None ,
10021003 palette : list [str ] | str | None = None ,
1003- render_type : Literal ["points" ] | None = None ,
1004+ render_type : Literal ["points" , "labels" ] | None = None ,
10041005) -> Mapping [str , str ]:
10051006 if not isinstance (color_source_vector , Categorical ):
10061007 raise TypeError (f"Expected `categories` to be a `Categorical`, but got { type (color_source_vector ).__name__ } " )
@@ -1648,15 +1649,15 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
16481649 }:
16491650 if not isinstance (color , str | tuple | list ):
16501651 raise TypeError ("Parameter 'color' must be a string or a tuple/list of floats." )
1651- if element_type in {"shapes" , "points" }:
1652+ if element_type in {"shapes" , "points" , "labels" }:
16521653 if _is_color_like (color ):
16531654 logger .info ("Value for parameter 'color' appears to be a color, using it as such." )
16541655 param_dict ["col_for_color" ] = None
16551656 param_dict ["color" ] = Color (color )
16561657 if param_dict ["color" ].alpha_is_user_defined ():
16571658 if element_type == "points" and param_dict .get ("alpha" ) is None :
16581659 param_dict ["alpha" ] = param_dict ["color" ].get_alpha_as_float ()
1659- elif element_type == "shapes" and param_dict .get ("fill_alpha" ) is None :
1660+ elif element_type in [ "shapes" , "labels" ] and param_dict .get ("fill_alpha" ) is None :
16601661 param_dict ["fill_alpha" ] = param_dict ["color" ].get_alpha_as_float ()
16611662 else :
16621663 logger .info (
@@ -1668,7 +1669,7 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
16681669 param_dict ["color" ] = None
16691670 else :
16701671 raise ValueError (f"{ color } is not a valid RGB(A) array and therefore can't be used as 'color' value." )
1671- elif "color" in param_dict and element_type != "labels " :
1672+ elif "color" in param_dict and element_type != "images " :
16721673 param_dict ["col_for_color" ] = None
16731674
16741675 if outline_width := param_dict .get ("outline_width" ):
@@ -1754,6 +1755,8 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
17541755 elif element_type == "shapes" :
17551756 # set default fill_alpha for shapes if not given by user explicitly or implicitly (as part of color)
17561757 param_dict ["fill_alpha" ] = 1.0
1758+ elif element_type == "lables" :
1759+ param_dict ["fill_alpha" ] = 0.4
17571760
17581761 if (cmap := param_dict .get ("cmap" )) is not None and (palette := param_dict .get ("palette" )) is not None :
17591762 raise ValueError ("Both `palette` and `cmap` are specified. Please specify only one of them." )
@@ -1894,7 +1897,7 @@ def _validate_label_render_params(
18941897 element : str | None ,
18951898 cmap : list [Colormap | str ] | Colormap | str | None ,
18961899 color : str | None ,
1897- fill_alpha : float | int ,
1900+ fill_alpha : float | int | None ,
18981901 contour_px : int | None ,
18991902 groups : list [str ] | str | None ,
19001903 palette : list [str ] | str | None ,
@@ -1939,12 +1942,23 @@ def _validate_label_render_params(
19391942 element_params [el ]["table_layer" ] = param_dict ["table_layer" ]
19401943
19411944 element_params [el ]["table_name" ] = None
1942- element_params [el ]["color" ] = None
1943- color = param_dict ["color" ]
1944- if color is not None :
1945- color , table_name = _validate_col_for_column_table (sdata , el , color , param_dict ["table_name" ], labels = True )
1945+
1946+ # element_params[el]["color"] = None # TODO: delete
1947+ # color = param_dict["color"]
1948+ # if color is not None:
1949+ # color, table_name = _validate_col_for_column_table(sdata, el, color, param_dict["table_name"],
1950+ # labels=True)
1951+ # element_params[el]["table_name"] = table_name
1952+ # element_params[el]["color"] = color
1953+ element_params [el ]["color" ] = param_dict ["color" ]
1954+
1955+ element_params [el ]["col_for_color" ] = None
1956+ if (col_for_color := param_dict ["col_for_color" ]) is not None :
1957+ col_for_color , table_name = _validate_col_for_column_table (
1958+ sdata , el , col_for_color , param_dict ["table_name" ], labels = True
1959+ )
19461960 element_params [el ]["table_name" ] = table_name
1947- element_params [el ]["color " ] = color
1961+ element_params [el ]["col_for_color " ] = col_for_color
19481962
19491963 element_params [el ]["palette" ] = param_dict ["palette" ] if element_params [el ]["table_name" ] is not None else None
19501964 element_params [el ]["groups" ] = param_dict ["groups" ] if element_params [el ]["table_name" ] is not None else None
0 commit comments