Skip to content

Commit

Permalink
demo: Implement canvas zooming (#85)
Browse files Browse the repository at this point in the history
Uses react-pinch-pan-zoom library.
---------

Co-authored-by: David Liu <[email protected]>
  • Loading branch information
yoonieaj and david-yz-liu authored Sep 13, 2024
1 parent 1255dcd commit 5d594ee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Reformatted demo website to horizontal layout.
- Added more documentation for the `--output` flag.
- Added zoom functionality to output canvas.

### 🔧 Internal changes

Expand Down
3 changes: 2 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"memory-viz": "*",
"react": "^18.3.1",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12"
"react-error-boundary": "^4.0.12",
"react-zoom-pan-pinch": "^3.6.1"
}
}
29 changes: 22 additions & 7 deletions demo/src/SvgDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useRef, useEffect } from "react";
import mem from "memory-viz";
import { Paper } from "@mui/material";
import { configDataPropTypes } from "./MemoryModelsUserInput";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";

type SvgDisplayPropTypes = {
jsonResult: object | null;
Expand Down Expand Up @@ -33,16 +34,30 @@ export default function SvgDisplay(props: SvgDisplayPropTypes) {
<Paper
sx={{
height: 500,
overflow: "auto",
overflow: "hidden",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
variant="outlined"
>
<canvas
data-testid="memory-models-canvas"
ref={canvasRef}
width={canvasWidth}
height={canvasHeight}
/>
<TransformWrapper
minScale={0.2}
wheel={{ step: 0.2, smoothStep: 0.01 }}
>
<TransformComponent>
<canvas
style={{
height: "100%",
width: "100%",
}}
data-testid="memory-models-canvas"
ref={canvasRef}
width={canvasWidth}
height={canvasHeight}
/>
</TransformComponent>
</TransformWrapper>
</Paper>
);
}
Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d594ee

Please sign in to comment.