Skip to content

Commit

Permalink
chart selection when figure (#1787)
Browse files Browse the repository at this point in the history
* chart selection when figure
resolves #1786

* test figure explicitly

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Sep 13, 2024
1 parent 893568d commit 8209983
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions frontend/taipy-gui/src/components/Taipy/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 12 additions & 2 deletions taipy/gui/_renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<Empty>",
default_value: t.Optional[t.Any] = "<Empty>",
lib_name: str = "taipy",
):
from ..gui import Gui
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion taipy/gui/_renderers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class _Factory:
("max", PropertyType.number),
("value", PropertyType.dynamic_number),
("format",),
("orientation"),
("orientation",),
("width",),
("height",),
]
Expand Down
2 changes: 2 additions & 0 deletions taipy/gui/utils/chart_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8209983

Please sign in to comment.