瀏覽代碼

chart selection when figure (#1787)

* chart selection when figure
resolves #1786

* test figure explicitly

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 8 月之前
父節點
當前提交
8209983894

+ 8 - 2
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) => {

+ 12 - 2
taipy/gui/_renderers/builder.py

@@ -79,7 +79,7 @@ class _Builder:
         element_name: str,
         attributes: t.Optional[t.Dict[str, t.Any]],
         hash_names: t.Optional[t.Dict[str, str]] = None,
-        default_value="<Empty>",
+        default_value: t.Optional[t.Any] = "<Empty>",
         lib_name: str = "taipy",
     ):
         from ..gui import Gui
@@ -599,7 +599,7 @@ class _Builder:
         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 @@ class _Builder:
         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)

+ 1 - 1
taipy/gui/_renderers/factory.py

@@ -278,7 +278,7 @@ class _Factory:
                 ("max", PropertyType.number),
                 ("value", PropertyType.dynamic_number),
                 ("format",),
-                ("orientation"),
+                ("orientation",),
                 ("width",),
                 ("height",),
             ]

+ 2 - 0
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)