Skip to content

Commit

Permalink
Chart refresh col but no data
Browse files Browse the repository at this point in the history
resolves #2302
fix selector y padding
relates to #2305
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Dec 10, 2024
1 parent 8936332 commit 2dc0051
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion frontend/taipy-gui/public/stylekit/controls/selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
**************************************************/

.taipy-selector {
margin: 4px 0;
margin: 0;
}


Expand Down
64 changes: 36 additions & 28 deletions frontend/taipy-gui/src/components/Taipy/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ const updateArrays = (sel: number[][], val: number[], idx: number) => {
return sel;
};

const getDataKey = (columns: Record<string, ColumnDesc>, decimators?: string[]): [string[], string] => {
const backCols = Object.values(columns).map((col) => col.dfid);
return [backCols, backCols.join("-") + (decimators ? `--${decimators.join("")}` : "")];
};

const Chart = (props: ChartProp) => {
const {
title = "",
Expand Down Expand Up @@ -348,24 +353,25 @@ const Chart = (props: ChartProp) => {
const config = useDynamicJsonProperty(props.config, props.defaultConfig, defaultConfig);

useEffect(() => {
if (updateVarName && (refresh || !data[dataKey])) {
const backCols = Object.values(config.columns).map((col) => col.dfid);
const dtKey = backCols.join("-") + (config.decimators ? `--${config.decimators.join("")}` : "");
if (updateVarName) {
const [backCols, dtKey] = getDataKey(config.columns, config.decimators);
setDataKey(dtKey);
if (refresh || !data[dtKey]) {
dispatch(
createRequestChartUpdateAction(
updateVarName,
id,
module,
backCols,
dtKey,
getDecimatorsPayload(
config.decimators,
plotRef.current,
config.modes,
config.columns,
config.traces
Promise.resolve().then(() =>
dispatch(
createRequestChartUpdateAction(
updateVarName,
id,
module,
backCols,
dtKey,
getDecimatorsPayload(
config.decimators,
plotRef.current,
config.modes,
config.columns,
config.traces
)
)
)
);
Expand Down Expand Up @@ -395,7 +401,10 @@ const Chart = (props: ChartProp) => {
layout.template = template;
}
if (props.figure) {
return merge({},props.figure[0].layout as Partial<Layout>, layout, {title: title || layout.title || (props.figure[0].layout as Partial<Layout>).title, clickmode: "event+select"});
return merge({}, props.figure[0].layout as Partial<Layout>, layout, {
title: title || layout.title || (props.figure[0].layout as Partial<Layout>).title,
clickmode: "event+select",
});
}
return {
...layout,
Expand Down Expand Up @@ -442,8 +451,12 @@ const Chart = (props: ChartProp) => {
if (props.figure) {
return lastDataPl.current;
}
if (data.__taipy_refresh !== undefined && lastDataPl.current) {
return lastDataPl.current;
if (data.__taipy_refresh !== undefined) {
return lastDataPl.current || [];
}
const dtKey = getDataKey(config.columns, config.decimators)[1];
if (!dataKey.startsWith(dtKey)) {
return lastDataPl.current || [];
}
const datum = data[dataKey];
lastDataPl.current = datum
Expand Down Expand Up @@ -525,7 +538,7 @@ const Chart = (props: ChartProp) => {
}
return ret as Data;
})
: [];
: lastDataPl.current || [];
return lastDataPl.current;
}, [props.figure, selected, data, config, dataKey]);

Expand Down Expand Up @@ -556,15 +569,10 @@ const Chart = (props: ChartProp) => {
(eventData: PlotRelayoutEvent) => {
onRangeChange && dispatch(createSendActionNameAction(id, module, { action: onRangeChange, ...eventData }));
if (config.decimators && !config.types.includes("scatter3d")) {
const backCols = Object.values(config.columns).map((col) => col.dfid);
const eventDataKey = Object.entries(eventData)
const [backCols, dtKeyBase] = getDataKey(config.columns, config.decimators);
const dtKey = `${dtKeyBase}--${Object.entries(eventData)
.map(([k, v]) => `${k}=${v}`)
.join("-");
const dtKey =
backCols.join("-") +
(config.decimators ? `--${config.decimators.join("")}` : "") +
"--" +
eventDataKey;
.join("-")}`;
setDataKey(dtKey);
dispatch(
createRequestChartUpdateAction(
Expand Down

0 comments on commit 2dc0051

Please sign in to comment.