Skip to content

Commit

Permalink
fix: set proper default scale for zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaCholak committed Jul 20, 2024
1 parent 562492a commit fcc1152
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/WhiteBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type WhiteBoardProps = {
// setScale: (scale: number) => void;
}

const DEFAULT_SCALE = 0.6;

export const scaleValues = new Map<string, number>();


Expand All @@ -20,7 +22,7 @@ function WhiteBoard(props: WhiteBoardProps) {
height: 0,
});

const [scale, setScale] = useState(scaleValues.get(props.view_id) || 0.6);
const [scale, setScale] = useState(scaleValues.get(props.view_id) || DEFAULT_SCALE);

// const [selectedElement, setSelectedElement] = useState<string | null>(null);
const [stagePosition, setStagePosition] = useState({
Expand Down Expand Up @@ -85,7 +87,7 @@ function WhiteBoard(props: WhiteBoardProps) {
const minScale = 0.05;
const maxScale = 3;
evt.cancelBubble = true;
const newScale = Math.min(Math.max((scale || 1) - evt.evt.deltaY / 500 * scale, minScale), maxScale);
const newScale = Math.min(Math.max((scale || DEFAULT_SCALE) - evt.evt.deltaY / 500 * scale, minScale), maxScale);
setScale(newScale);
scaleValues.set(props.view_id, newScale);

Expand Down

0 comments on commit fcc1152

Please sign in to comment.