Skip to content

Commit

Permalink
Switch zoom controls to MUI
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 15, 2024
1 parent fbb833e commit dbf200d
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 8 deletions.
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';

Check failure on line 9 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './icons/zoom-in.svg'

Check failure on line 9 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './icons/zoom-in.svg'
import ZoomOutIcon from './icons/zoom-out.svg';

Check failure on line 10 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './icons/zoom-out.svg'

Check failure on line 10 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './icons/zoom-out.svg'
import ZoomResetIcon from './icons/zoom-reset.svg';

Check failure on line 11 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './icons/zoom-reset.svg'

Check failure on line 11 in src/components/GraphViewport.tsx

View workflow job for this annotation

GitHub Actions / ci / Lint source files

Unable to resolve path to module './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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dbf200d

Please sign in to comment.