Skip to content

Commit

Permalink
fix: better plotly deselect (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Sep 20, 2024
1 parent 1e5cc09 commit 0099ecd
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions frontend/src/plugins/impl/plotly/PlotlyPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Objects } from "@/utils/objects";
import { isEqual, set } from "lodash-es";
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
import { usePrevious } from "@uidotdev/usehooks";
import { Arrays } from "@/utils/arrays";

interface Data {
figure: Figure;
Expand Down Expand Up @@ -177,31 +178,17 @@ export const PlotlyComponent = memo(
setValue((prev) => ({ ...prev, ...obj }));
}
}}
onUpdate={(figure) => {
// If the user double-clicks, all selection will be cleared
// But this does not call onSelected, so we need to clear it here
const selections =
"selections" in figure.layout &&
Array.isArray(figure.layout.selections)
? figure.layout.selections
: [];
if (selections.length === 0) {
setValue((prev) => {
const prevSelections = prev?.selections ?? [];
if (prevSelections.length === 0) {
return prev;
}

return {
...prev,
selections: selections,
points: [],
indices: [],
range: undefined,
};
});
}
}}
onDeselect={useEvent(() => {
setValue((prev) => {
return {
...prev,
selections: Arrays.EMPTY,
points: Arrays.EMPTY,
indices: Arrays.EMPTY,
range: undefined,
};
});
})}
config={plotlyConfig}
onSelected={useEvent((evt: Readonly<Plotly.PlotSelectionEvent>) => {
if (!evt) {
Expand Down

0 comments on commit 0099ecd

Please sign in to comment.