Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom canvas #85

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### 📚 Documentation and demo website changes

- Reformatted demo website to horizontal layout.
- Added zoom functionality to output canvas.

### 🔧 Internal changes

Expand Down
30 changes: 23 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,31 @@ 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}
/>
<div style={{ height: 500, justifyContent: "center" }}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally convinced you need a div here, but if you want to keep it you should make its width style 100% to ensure it fills its parent

<TransformWrapper
minScale={0.2}
wheel={{ step: 0.2, smoothStep: 0.01 }}
>
<TransformComponent>
<canvas
style={{
height: 500,
}}
data-testid="memory-models-canvas"
ref={canvasRef}
width={canvasWidth}
height={canvasHeight}
/>
</TransformComponent>
</TransformWrapper>
</div>
</Paper>
);
}
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
},
"dependencies": {
yoonieaj marked this conversation as resolved.
Show resolved Hide resolved
"react-zoom-pan-pinch": "^3.6.1"
}
}
Loading