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

Add drag pan type #256

Merged
merged 5 commits into from
Jul 8, 2024
Merged

Add drag pan type #256

merged 5 commits into from
Jul 8, 2024

Conversation

ghsteff
Copy link
Contributor

@ghsteff ghsteff commented Jul 3, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The only way to pan the chart is with scrolling

What is the new behavior?

You can pan charts by dragging the screen with panType='drag'. This will also enable zooming with the mouse wheel

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Screen.Recording.2024-07-03.at.2.16.11.PM.mov

Copy link

vercel bot commented Jul 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
reaflow ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 8, 2024 2:54pm

Copy link

netlify bot commented Jul 3, 2024

Deploy Preview for reaflow ready!

Name Link
🔨 Latest commit 85ec43c
🔍 Latest deploy log https://app.netlify.com/sites/reaflow/deploys/668bfd605badc00008624cd6
😎 Deploy Preview https://deploy-preview-256--reaflow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/Canvas.tsx Outdated
@@ -244,11 +274,34 @@ const InternalCanvas: FC<CanvasProps & { ref?: Ref<CanvasRef> }> = forwardRef(({
}
}, [createDragNodeChildren, dragNodeData, layout?.children]);

useEffect(() => {
const zoomOnWheelScroll = (e: WheelEvent) => {
Copy link
Member

@amcdnl amcdnl Jul 8, 2024

Choose a reason for hiding this comment

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

We probably want to add pinch too. Use the pinch in react-use-gesture

Copy link
Member

Choose a reason for hiding this comment

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

I would also combine the gestures into 1 and use the wheel event they provide - https://use-gesture.netlify.app/docs/gestures/#handling-multiple-gestures-at-once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah nice that's cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the pinch zoom is already being applied here

useGesture(
{
onPinch: ({ offset: [d], event }) => {
event.preventDefault();
// TODO: Set X/Y on center of zoom
const next = limit(d / 100, minZoom, maxZoom);
setFactor(next);
onZoomChange(next + 1);
}
},
{
enabled: !disabled,
domTarget: svgRef,
eventOptions: { passive: false }
}
);

@@ -313,7 +302,6 @@ const InternalCanvas: FC<CanvasProps & { ref?: Ref<CanvasRef> }> = forwardRef(({
}}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
{...bind()}
Copy link
Member

Choose a reason for hiding this comment

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

You don't need this because u set the domTarget correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

@amcdnl amcdnl merged commit c4db788 into master Jul 8, 2024
7 checks passed
@amcdnl amcdnl deleted the feat/Add-drag-pan-type branch July 8, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants