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

Switch zoom controls to MUI #407

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions src/components/GraphViewport.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Stack from '@mui/material/Stack';
import { Component, createRef } from 'react';

import { renderSvg } from '../graph/svg-renderer';
import { TypeGraph } from '../graph/type-graph';
import { Viewport } from '../graph/viewport';
import ZoomInIcon from './icons/zoom-in.svg';
import ZoomOutIcon from './icons/zoom-out.svg';
import ZoomResetIcon from './icons/zoom-reset.svg';
import LoadingAnimation from './utils/LoadingAnimation';

interface GraphViewportProps {
Expand Down Expand Up @@ -119,6 +124,7 @@ export default class GraphViewport extends Component<

render() {
const isLoading = this.state.svgViewport == null;
const { svgViewport } = this.state;
return (
<Box
sx={(theme) => ({
Expand All @@ -145,6 +151,41 @@ export default class GraphViewport extends Component<
},
}}
/>
{!isLoading && (
<Stack
alignItems="center"
spacing={0.8}
padding={1}
position="absolute"
bottom={0}
right={0}
>
<IconButton
aria-label="Zoom in"
color="secondary"
sx={{ width: 18 }}
onClick={() => svgViewport?.zoomIn()}
>
<ZoomInIcon />
</IconButton>
<IconButton
aria-label="Reset zoom"
color="secondary"
sx={{ width: 55 }}
onClick={() => svgViewport?.reset()}
>
<ZoomResetIcon />
</IconButton>
<IconButton
aria-label="Zoom out"
color="secondary"
sx={{ width: 18 }}
onClick={() => svgViewport?.zoomOut()}
>
<ZoomOutIcon />
</IconButton>
</Stack>
)}
{isLoading && <LoadingAnimation />}
</Box>
);
Expand Down
11 changes: 11 additions & 0 deletions src/components/icons/zoom-in.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/components/icons/zoom-out.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/components/icons/zoom-reset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions src/components/viewport.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ g.graph > polygon {
fill: transparent;
}

#svg-pan-zoom-controls {
& path {
fill-opacity: 0.75;
fill: var(--field-name-color);
}
}

/* Nodes Styling */
.node {
pointer-events: bounding-box;
Expand Down
16 changes: 15 additions & 1 deletion src/graph/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ interface Point {
interface Instance {
resize(): Instance;
zoom(scale: number): void;
zoomIn(): void;
zoomOut(): void;
reset(): void;
getPan(): Point;
getZoom(): number;
pan(point: Point): Instance;
Expand Down Expand Up @@ -73,7 +76,6 @@ export class Viewport {
zoomScaleSensitivity: 0.25,
minZoom: 0.95,
maxZoom: this.maxZoom,
controlIconsEnabled: true,
});
this.zoomer.zoom(0.95);
}
Expand Down Expand Up @@ -220,6 +222,18 @@ export class Viewport {
});
}

zoomIn() {
this.zoomer.zoomIn();
}

zoomOut() {
this.zoomer.zoomOut();
}

reset() {
this.zoomer.reset();
}

destroy() {
this.resizeObserver.disconnect();
try {
Expand Down
Binary file modified tests/demo.spec.ts-snapshots/choose-github-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/choose-star-wars-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/choose-yelp-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/demo-after-resize-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/demo-before-resize-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/display-introspection-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/display-schema-from-url-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/display-sdl-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/fill-introspection-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/fill-sdl-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/loaded-demo-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/open-dialog-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/show-github-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/show-star-wars-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/show-yelp-preset-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/switch-to-presets-tab-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/demo.spec.ts-snapshots/switch-to-sdl-tab-Demo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading