ソースを参照

GUI: Fix decimator zoom by single axis (#712) (#941)

Dinh Long Nguyen 1 年間 前
コミット
56760e7d5f
2 ファイル変更43 行追加39 行削除
  1. 28 31
      frontend/taipy-gui/src/components/Taipy/Chart.tsx
  2. 15 8
      taipy/gui/data/utils.py

+ 28 - 31
frontend/taipy-gui/src/components/Taipy/Chart.tsx

@@ -512,38 +512,35 @@ const Chart = (props: ChartProp) => {
 
     const onRelayout = useCallback(
         (eventData: PlotRelayoutEvent) => {
-            if (Object.keys(eventData).some((k) => k.startsWith("xaxis."))) {
-                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)
-                        .map(([k, v]) => `${k}=${v}`)
-                        .join("-");
-                    const dtKey =
-                        backCols.join("-") +
-                        (config.decimators ? `--${config.decimators.join("")}` : "") +
-                        "--" +
-                        eventDataKey;
-                    setDataKey(dtKey);
-                    dispatch(
-                        createRequestChartUpdateAction(
-                            updateVarName,
-                            id,
-                            module,
-                            backCols,
-                            dtKey,
-                            getDecimatorsPayload(
-                                config.decimators,
-                                plotRef.current,
-                                config.modes,
-                                config.columns,
-                                config.traces,
-                                eventData
-                            )
+            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)
+                    .map(([k, v]) => `${k}=${v}`)
+                    .join("-");
+                const dtKey =
+                    backCols.join("-") +
+                    (config.decimators ? `--${config.decimators.join("")}` : "") +
+                    "--" +
+                    eventDataKey;
+                setDataKey(dtKey);
+                dispatch(
+                    createRequestChartUpdateAction(
+                        updateVarName,
+                        id,
+                        module,
+                        backCols,
+                        dtKey,
+                        getDecimatorsPayload(
+                            config.decimators,
+                            plotRef.current,
+                            config.modes,
+                            config.columns,
+                            config.traces,
+                            eventData
                         )
-                    );
-                }
+                    )
+                );
             }
         },
         [

+ 15 - 8
taipy/gui/data/utils.py

@@ -118,7 +118,7 @@ def _df_relayout(
     if chart_mode not in ["lines+markers", "markers"]:
         return dataframe, is_copied
     # if chart data is invalid
-    if x0 is None or x1 is None or y0 is None or y1 is None:
+    if x0 is None and x1 is None and y0 is None and y1 is None:
         return dataframe, is_copied
     df = dataframe.copy() if not is_copied else dataframe
     is_copied = True
@@ -132,13 +132,20 @@ def _df_relayout(
         df[x_column] = df.index
         has_x_col = False
 
-    # if chart_mode is empty
-    if chart_mode == "lines+markers":
-        # only filter by x column
-        df = df.loc[(df[x_column] > x0) & (df[x_column] < x1)]
-    else:
-        # filter by both x and y columns
-        df = df.loc[(df[x_column] > x0) & (df[x_column] < x1) & (df[y_column] > y0) & (df[y_column] < y1)]  # noqa
+    df_filter_conditions = []
+    # filter by x column by default
+    if x0 is not None:
+        df_filter_conditions.append(df[x_column] > x0)
+    if x1 is not None:
+        df_filter_conditions.append(df[x_column] < x1)
+    # y column will be filtered only if chart_mode is not lines+markers (eg. markers)
+    if chart_mode != "lines+markers":
+        if y0 is not None:
+            df_filter_conditions.append(df[y_column] > y0)
+        if y1 is not None:
+            df_filter_conditions.append(df[y_column] < y1)
+    if df_filter_conditions:
+            df = df.loc[np.bitwise_and.reduce(df_filter_conditions)]
     if not has_x_col:
         df.drop(x_column, axis=1, inplace=True)
     return df, is_copied