Skip to content

Commit

Permalink
Add baton and selections unconditionally to plot props
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterC-DLS committed Sep 30, 2024
1 parent 28ab893 commit c430eb4
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions client/component/src/ConnectedPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ function ConnectedPlot({
const [linePlotConfig, setLinePlotConfig] =
useState<PlotConfig>(defaultPlotConfig);
const [scatterData, setScatterData] = useState<ScatterData>();
const { selections, setSelections, isNewSelection, updateSelection } =
useSelections();
const {
selections,
setSelections,
isNewSelection,
updateSelection: hUpdateSelection,
} = useSelections();
const interactionTime = useRef<number>(0);

const mountState = useRef('');
Expand Down Expand Up @@ -397,12 +401,12 @@ function ConnectedPlot({
});
};

const cUpdateSelection = (
const updateSelection = (
selection: SelectionBase | null,
broadcast = true,
clear = false
) => {
const id = updateSelection(selection, clear);
const id = hUpdateSelection(selection, clear);
if (broadcast) {
if (clear) {
sendClientMessage('clear_selection_data', {
Expand Down Expand Up @@ -481,9 +485,6 @@ function ConnectedPlot({
xDomain,
yDomain,
plotConfig,
updateSelection: cUpdateSelection,
selections,
batonProps,
updateLineParams,
});
};
Expand Down Expand Up @@ -521,18 +522,12 @@ function ConnectedPlot({
setPlotProps({
...heatmapData,
plotConfig: imagePlotConfig,
updateSelection: cUpdateSelection,
selections,
batonProps,
});
} else {
console.log('%s: new image data', plotId, Object.keys(imageData));
setPlotProps({
...imageData,
plotConfig: imagePlotConfig,
updateSelection: cUpdateSelection,
selections,
batonProps,
});
}
};
Expand All @@ -545,10 +540,7 @@ function ConnectedPlot({
setPlotProps({
...scatterData,
plotConfig: scatterPlotConfig,
updateSelection: cUpdateSelection,
setPointSize: updateScatterParams,
selections,
batonProps,
});
};

Expand All @@ -559,9 +551,6 @@ function ConnectedPlot({
setPlotProps({
...surfaceData,
plotConfig: surfacePlotConfig,
updateSelection,
selections,
batonProps,
});
};

Expand All @@ -570,7 +559,6 @@ function ConnectedPlot({
console.log('%s: new table data', plotId, Object.keys(tableData));
setPlotProps({
...tableData,
batonProps,
});
};

Expand Down Expand Up @@ -601,7 +589,7 @@ function ConnectedPlot({
setSelections(() => []);
} else {
setSelections((prevSelections) => {
const ns = [];
const ns = [] as SelectionBase[];
for (const s of prevSelections) {
if (!ids.includes(s.id)) {
ns.push(s);
Expand Down Expand Up @@ -633,9 +621,6 @@ function ConnectedPlot({
});
};

const showSelections = useRef<boolean>(false);
const changeBaton = useRef<boolean>(false);

useEffect(() => {
if (!lastMessage) {
return;
Expand All @@ -652,21 +637,14 @@ function ConnectedPlot({
}
// eslint-disable-next-line
const decodedMessage = decode(data) as DecodedMessage;
console.log(
'%s: decodedMessage',
plotId,
Object.keys(decodedMessage),
typeof decodedMessage
);
console.log('%s: decodedMessage', plotId, Object.keys(decodedMessage));

const interaction = measureInteraction();
afterFrame(() => {
interactionTime.current = interaction.end();
});

let report = true;
showSelections.current = true;
changeBaton.current = false;
if ('mlData' in decodedMessage) {
plotMultilineData(decodedMessage);
} else if ('alData' in decodedMessage) {
Expand All @@ -676,10 +654,8 @@ function ConnectedPlot({
} else if ('scData' in decodedMessage) {
plotNewScatterData(decodedMessage);
} else if ('suData' in decodedMessage) {
showSelections.current = false;
plotNewSurfaceData(decodedMessage);
} else if ('taData' in decodedMessage) {
showSelections.current = false;
displayNewTableData(decodedMessage);
} else if ('updateSelections' in decodedMessage) {
updateSelections(decodedMessage);
Expand All @@ -688,7 +664,6 @@ function ConnectedPlot({
} else if ('setSelections' in decodedMessage) {
replaceSelections(decodedMessage);
} else if ('baton' in decodedMessage) {
changeBaton.current = true;
updateBaton(decodedMessage);
} else if ('requester' in decodedMessage) {
approveBatonRequest(decodedMessage);
Expand All @@ -705,11 +680,8 @@ function ConnectedPlot({
}, [lastMessage, plotId]);

let currentProps = plotProps;
if (currentProps && changeBaton.current) {
currentProps = { ...currentProps, batonProps };
}
if (currentProps && showSelections.current) {
currentProps = { ...currentProps, selections };
if (currentProps) {
currentProps = { ...currentProps, batonProps, updateSelection, selections };
}

if (currentProps) {
Expand All @@ -731,11 +703,11 @@ function ConnectedPlot({
return <h2>Plot server connection closed</h2>;
}

if (!plotProps) {
if (!currentProps) {
return <h2>Awaiting command from plot server</h2>;
}

return <AnyPlot {...(currentProps as AnyPlotProps)} />;
return <AnyPlot {...currentProps} />;
}

export default ConnectedPlot;
Expand Down

0 comments on commit c430eb4

Please sign in to comment.