diff --git a/frontend/taipy-gui/src/components/Taipy/Chart.tsx b/frontend/taipy-gui/src/components/Taipy/Chart.tsx index 1a38a2bb56..9abc731a46 100644 --- a/frontend/taipy-gui/src/components/Taipy/Chart.tsx +++ b/frontend/taipy-gui/src/components/Taipy/Chart.tsx @@ -656,10 +656,16 @@ const Chart = (props: ChartProp) => { tr[pt.curveNumber].push(getRealIndex(getPlotIndex(pt))); return tr; }, [] as number[][]); + if (config.traces.length === 0) { // figure + const theVar = getUpdateVar(updateVars, "selected"); + theVar && dispatch(createSendUpdateAction(theVar, traces, module, props.onChange, propagate)); + return; + } if (traces.length) { const upvars = traces.map((_, idx) => getUpdateVar(updateVars, `selected${idx}`)); - if (traces.length > 1 && new Set(upvars).size === 1) { - dispatch(createSendUpdateAction(upvars[0], traces, module, props.onChange, propagate)); + const setVars = new Set(upvars.filter((v) => v)); + if (traces.length > 1 && setVars.size === 1) { + dispatch(createSendUpdateAction(setVars.values().next().value, traces, module, props.onChange, propagate)); return; } traces.forEach((tr, idx) => { diff --git a/taipy/gui/_renderers/builder.py b/taipy/gui/_renderers/builder.py index 2fe4ae499b..db56b9f78d 100644 --- a/taipy/gui/_renderers/builder.py +++ b/taipy/gui/_renderers/builder.py @@ -79,7 +79,7 @@ def __init__( element_name: str, attributes: t.Optional[t.Dict[str, t.Any]], hash_names: t.Optional[t.Dict[str, str]] = None, - default_value="", + default_value: t.Optional[t.Any] = "", lib_name: str = "taipy", ): from ..gui import Gui @@ -599,7 +599,7 @@ def _get_chart_config(self, default_type: str, default_mode: str): config = _build_chart_config(self.__gui, self.__attributes, col_types) self.__set_json_attribute("defaultConfig", config) - self._set_chart_selected(max=len(config.get("traces", ""))) + self._set_chart_selected(max=len(config.get("traces", []))) self.__set_refresh_on_update() return self @@ -641,6 +641,16 @@ def _set_chart_selected(self, max=0): default_sel = self.__attributes.get(name) if not isinstance(default_sel, list) and name in self.__attributes: default_sel = [] + if max == 0: + self.__update_vars.extend( + self.__set_list_attribute( + name, + self.__hashes.get(name), + default_sel, + int, + ) + ) + return idx = 1 name_idx = f"{name}[{idx}]" sel = self.__attributes.get(name_idx) diff --git a/taipy/gui/_renderers/factory.py b/taipy/gui/_renderers/factory.py index 98702758fa..60ded38ca7 100644 --- a/taipy/gui/_renderers/factory.py +++ b/taipy/gui/_renderers/factory.py @@ -278,7 +278,7 @@ class _Factory: ("max", PropertyType.number), ("value", PropertyType.dynamic_number), ("format",), - ("orientation"), + ("orientation",), ("width",), ("height",), ] diff --git a/taipy/gui/utils/chart_config_builder.py b/taipy/gui/utils/chart_config_builder.py index 10ca0db0b7..8d871137e8 100644 --- a/taipy/gui/utils/chart_config_builder.py +++ b/taipy/gui/utils/chart_config_builder.py @@ -113,6 +113,8 @@ def __get_col_from_indexed(col_name: str, idx: int) -> t.Optional[str]: def _build_chart_config(gui: "Gui", attributes: t.Dict[str, t.Any], col_types: t.Dict[str, str]): # noqa: C901 + if "data" not in attributes and "figure" in attributes: + return {"traces": []} default_type = attributes.get("_default_type", "scatter") default_mode = attributes.get("_default_mode", "lines+markers") trace = __get_multiple_indexed_attributes(attributes, _CHART_NAMES)