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

[Feature]: Add zoom in/out controls to Plexus graphs #2072

Merged
merged 15 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
3 changes: 2 additions & 1 deletion packages/plexus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0",
"memoize-one": "6.0.0",
"viz.js": "1.8.1"
"viz.js": "1.8.1",
"react-icons": "^4.10.1"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
},
"scripts": {
"_tasks/build/lib/js": "node_modules/.bin/babel src --extensions '.tsx,.js' --out-dir lib",
Expand Down
14 changes: 11 additions & 3 deletions packages/plexus/src/zoom/MiniMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

import * as React from 'react';

import resetZoomIcon from './resetZoomIcon';

import { FaMagnifyingGlassPlus, FaMagnifyingGlassMinus } from 'react-icons/fa6';
import { HiMiniArrowsPointingOut } from 'react-icons/hi2';
Wise-Wizard marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable react/no-unused-prop-types */
type TProps = {
classNamePrefix?: string | void;
className?: string | void;
contentHeight: number;
contentWidth: number;
viewAll: () => void;
zoomIn: () => void;
zoomOut: () => void;
viewportHeight: number;
viewportWidth: number;
k?: number;
Expand Down Expand Up @@ -88,8 +90,14 @@ export function MiniMap(props: TProps) {
<div className={`${css.item} ${css.map}`} style={mapSize}>
<div className={css.mapActive} style={{ ...activeXform, ...mapSize }} />
</div>
<div className={`${css.item} ${css.button}`} onClick={props.zoomIn} role="button">
<FaMagnifyingGlassPlus />
</div>
<div className={`${css.item} ${css.button}`} onClick={props.zoomOut} role="button">
<FaMagnifyingGlassMinus />
</div>
<div className={`${css.item} ${css.button}`} onClick={props.viewAll} role="button">
{resetZoomIcon}
<HiMiniArrowsPointingOut />
</div>
</div>
);
Expand Down
22 changes: 22 additions & 0 deletions packages/plexus/src/zoom/ZoomManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type TZoomProps = {
contentHeight: number;
contentWidth: number;
viewAll: () => void;
zoomIn: () => void;
zoomOut: () => void;
viewportHeight: number;
viewportWidth: number;
};
Expand Down Expand Up @@ -96,6 +98,24 @@ export default class ZoomManager {
this.resetZoom();
}

public zoomIn = () => {
const selection = this.selection;
if (!selection) {
this.updateCallback(zoomIdentity);
return;
}
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
this.zoom.scaleBy(selection, 1.2);
};

public zoomOut = () => {
const selection = this.selection;
if (!selection) {
this.updateCallback(zoomIdentity);
return;
}
this.zoom.scaleBy(selection, 0.8);
};

public resetZoom = () => {
const elem = this.elem;
const selection = this.selection;
Expand Down Expand Up @@ -123,6 +143,8 @@ export default class ZoomManager {
x,
y,
viewAll: this.resetZoom,
zoomIn: this.zoomIn,
zoomOut: this.zoomOut,
};
}

Expand Down
27 changes: 0 additions & 27 deletions packages/plexus/src/zoom/resetZoomIcon.tsx

This file was deleted.