From 0b8653b138455f9f10663b028b5ee9fffb4ce43a Mon Sep 17 00:00:00 2001 From: TeunHuijben Date: Wed, 4 Dec 2024 17:00:45 -0800 Subject: [PATCH 1/2] fixed bug where pointSize was wrong when changing from dataset with provided size to dataset without --- src/components/App.tsx | 3 +++ src/hooks/usePointCanvas.ts | 9 +++++++++ src/lib/PointCanvas.ts | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/components/App.tsx b/src/components/App.tsx index 46d82a9..43837bd 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -207,6 +207,9 @@ export default function App() { type: ActionType.CHECK_CAMERA_LOCK, ndim: trackManager.ndim, }); + dispatchCanvas({ + type: ActionType.RESET_POINT_SIZE, + }); }, [dispatchCanvas, trackManager]); // update the points when the array or timepoint changes diff --git a/src/hooks/usePointCanvas.ts b/src/hooks/usePointCanvas.ts index 38d2a1c..3944e84 100644 --- a/src/hooks/usePointCanvas.ts +++ b/src/hooks/usePointCanvas.ts @@ -9,6 +9,7 @@ enum ActionType { CUR_TIME = "CUR_TIME", CHECK_CAMERA_LOCK = "CHECK_CAMERA_LOCK", RESET_CAMERA = "RESET_CAMERA", + RESET_POINT_SIZE = "RESET_POINT_SIZE", INIT_POINTS_GEOMETRY = "INIT_POINTS_GEOMETRY", TRACK_WIDTH = "TRACK_WIDTH", POINT_BRIGHTNESS = "POINT_BRIGHTNESS", @@ -50,6 +51,10 @@ interface ResetCamera { type: ActionType.RESET_CAMERA; } +interface ResetPointSize { + type: ActionType.RESET_POINT_SIZE; +} + interface InitPointsGeometry { type: ActionType.INIT_POINTS_GEOMETRY; maxPointsPerTimepoint: number; @@ -153,6 +158,7 @@ type PointCanvasAction = | CurTime | CheckCameraLock | ResetCamera + | ResetPointSize | InitPointsGeometry | TrackWidth | PointBrightness @@ -186,6 +192,9 @@ function reducer(canvas: PointCanvas, action: PointCanvasAction): PointCanvas { case ActionType.RESET_CAMERA: newCanvas.resetCamera(); break; + case ActionType.RESET_POINT_SIZE: + newCanvas.resetPointSize(); + break; case ActionType.CUR_TIME: { // if curTime is a function, call it with the current time if (typeof action.curTime === "function") { diff --git a/src/lib/PointCanvas.ts b/src/lib/PointCanvas.ts index 9b74b99..283f8f3 100644 --- a/src/lib/PointCanvas.ts +++ b/src/lib/PointCanvas.ts @@ -248,6 +248,12 @@ export class PointCanvas { this.camera.position.set(cameraPosition[0], cameraPosition[1], cameraPosition[2]); this.controls.target.set(cameraTarget[0], cameraTarget[1], cameraTarget[2]); this.curTime = 0; + console.debug("Camera resetted"); + } + + resetPointSize() { + this.pointSize = initialPointSize; + console.debug("point size resetted to: ", this.pointSize); } updateSelectedPointIndices() { From f78b4af79d450ec634c742738b6db8e8ca2237fb Mon Sep 17 00:00:00 2001 From: TeunHuijben Date: Thu, 5 Dec 2024 18:17:54 -0800 Subject: [PATCH 2/2] only reset pointSize to initial value if new dataURL is provided, not when application is opened from a URL --- src/components/App.tsx | 9 +++------ src/components/DataControls.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 43837bd..4373032 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -133,8 +133,9 @@ export default function App() { const removeTracksUponNewData = () => { dispatchCanvas({ type: ActionType.REMOVE_ALL_TRACKS }); }; - const resetCamera = () => { + const actionsUponNewData = () => { dispatchCanvas({ type: ActionType.RESET_CAMERA }); + dispatchCanvas({ type: ActionType.RESET_POINT_SIZE }); }; // this function fetches the entire lineage for each track @@ -180,7 +181,6 @@ export default function App() { // update the array when the dataUrl changes useEffect(() => { - console.log("load data from %s", dataUrl); const trackManager = loadTrackManager(dataUrl); // TODO: add clean-up by returning another closure trackManager.then((tm: TrackManager | null) => { @@ -207,9 +207,6 @@ export default function App() { type: ActionType.CHECK_CAMERA_LOCK, ndim: trackManager.ndim, }); - dispatchCanvas({ - type: ActionType.RESET_POINT_SIZE, - }); }, [dispatchCanvas, trackManager]); // update the points when the array or timepoint changes @@ -471,7 +468,7 @@ export default function App() { initialDataUrl={initialViewerState.dataUrl} setDataUrl={setDataUrl} removeTracksUponNewData={removeTracksUponNewData} - resetCamera={resetCamera} + actionsUponNewData={actionsUponNewData} copyShareableUrlToClipboard={copyShareableUrlToClipboard} refreshPage={refreshPage} trackManager={trackManager} diff --git a/src/components/DataControls.tsx b/src/components/DataControls.tsx index 7a6f167..1fc5d92 100644 --- a/src/components/DataControls.tsx +++ b/src/components/DataControls.tsx @@ -13,7 +13,7 @@ interface DataControlsProps { copyShareableUrlToClipboard: () => void; refreshPage: () => void; removeTracksUponNewData: () => void; - resetCamera: () => void; + actionsUponNewData: () => void; trackManager: TrackManager | null; } @@ -53,7 +53,7 @@ export default function DataControls(props: DataControlsProps) { const setDataUrl = props.setDataUrl; const removeTracksUponNewData = props.removeTracksUponNewData; - const resetCamera = props.resetCamera; + const actionsUponNewData = props.actionsUponNewData; const handleDataUrlSubmit = useCallback( (event: React.FormEvent) => { event.preventDefault(); @@ -61,13 +61,13 @@ export default function DataControls(props: DataControlsProps) { if (urlInput && urlInput.value) { setDataUrl(urlInput.value); removeTracksUponNewData(); - resetCamera(); + actionsUponNewData(); } else { // set to the initial URL if the input is empty or can't be found setDataUrl(props.initialDataUrl); } }, - [props.initialDataUrl, setDataUrl, removeTracksUponNewData, resetCamera], + [props.initialDataUrl, setDataUrl, removeTracksUponNewData, actionsUponNewData], ); // only close the popover if the URL gives a valid track manager