Skip to content

Commit

Permalink
fixed bug where pointSize was wrong (#151)
Browse files Browse the repository at this point in the history
* fixed bug where pointSize was wrong when changing from dataset with provided size to dataset without

* only reset pointSize to initial value if new dataURL is provided, not when application is opened from a URL
  • Loading branch information
TeunHuijben authored Dec 6, 2024
1 parent 568e21b commit 0d7df4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -468,7 +468,7 @@ export default function App() {
initialDataUrl={initialViewerState.dataUrl}
setDataUrl={setDataUrl}
removeTracksUponNewData={removeTracksUponNewData}
resetCamera={resetCamera}
actionsUponNewData={actionsUponNewData}
copyShareableUrlToClipboard={copyShareableUrlToClipboard}
refreshPage={refreshPage}
trackManager={trackManager}
Expand Down
8 changes: 4 additions & 4 deletions src/components/DataControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface DataControlsProps {
copyShareableUrlToClipboard: () => void;
refreshPage: () => void;
removeTracksUponNewData: () => void;
resetCamera: () => void;
actionsUponNewData: () => void;
trackManager: TrackManager | null;
}

Expand Down Expand Up @@ -53,21 +53,21 @@ 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<HTMLFormElement>) => {
event.preventDefault();
const urlInput = document.getElementById("data-url-input") as HTMLInputElement;
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
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/usePointCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -153,6 +158,7 @@ type PointCanvasAction =
| CurTime
| CheckCameraLock
| ResetCamera
| ResetPointSize
| InitPointsGeometry
| TrackWidth
| PointBrightness
Expand Down Expand Up @@ -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") {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/PointCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0d7df4e

Please sign in to comment.