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

Canvas: Add snapping to vertex edit #84417

Merged
merged 28 commits into from
Mar 21, 2024
Merged

Conversation

drew08t
Copy link
Contributor

@drew08t drew08t commented Mar 13, 2024

Add snapping to vertex edit of connections in canvas.

  • Horizontal snapping during edit
  • Vertical snapping during edit
  • Snapping to delete vertex (straight line)
  • horizontal snapping during creation
  • vertical snapping during creation
  • escape snapping hot key (control key)

Disable snapping using control key:
Mar-15-2024 15-20-04

Snapping during vertex creation:
Mar-15-2024 15-19-31

Horizontal and vertical snap during vertex edit:
Mar-13-2024 22-14-16

Deleting a vertex:
Mar-13-2024 15-16-06

Closes #83269

@drew08t drew08t added the area/panel/canvas Issues related to canvas panel label Mar 13, 2024
@drew08t drew08t added this to the 11.0.x milestone Mar 13, 2024
@drew08t drew08t self-assigned this Mar 13, 2024
@drew08t drew08t changed the title Canvas: Add snapping to vertex edit [WIP] Canvas: Add snapping to vertex edit Mar 13, 2024
Base automatically changed from drew08t/canvas-midpoint-control to main March 15, 2024 16:35
@drew08t drew08t added add to changelog no-backport Skip backport of PR labels Mar 15, 2024
@drew08t drew08t changed the title [WIP] Canvas: Add snapping to vertex edit Canvas: Add snapping to vertex edit Mar 15, 2024
@drew08t drew08t marked this pull request as ready for review March 15, 2024 22:26
@drew08t drew08t requested a review from a team as a code owner March 15, 2024 22:26
@drew08t drew08t requested review from nmarrs, baldm0mma and Develer and removed request for a team March 15, 2024 22:26
Copy link
Contributor

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

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

Overall LGTM! Great job on the vertex work!! It is super fun to play around with :)

const angleOverall = calculateAngle(vx1, vy1, vx2, vy2);
const angleBefore = calculateAngle(vx1, vy1, x, y);
deleteVertex = Math.abs(angleBefore - angleOverall) < CONNECTION_VERTEX_SNAP_TOLERANCE;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit but this logic might be good to clean up and put into a separate func

@@ -275,6 +281,8 @@ export class Connections {

// Handles mousemove and mouseup events when dragging an existing vertex
vertexListener = (event: MouseEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be done later after G11 cutoff but we might want to consider breaking out vertex logic into separate file maybe 🤔


if (deleteVertex) {
// Display temporary vertex removal
this.scene.selecto!.rootContainer!.style.cursor = 'not-allowed';
Copy link
Contributor

@nmarrs nmarrs Mar 19, 2024

Choose a reason for hiding this comment

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

is the cursor style change there to indicate that the vertexes are being removed? I'm not sure this is necessary (i.e. end user probably doesn't care if vertexes are being removed and just care about ending line) / might be confusing to end user as it seems like they are doing an action that isn't allowed or something 🤔

Screen.Recording.2024-03-18.at.9.02.12.PM.mov

Copy link
Collaborator

Choose a reason for hiding this comment

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

I want to agree here, feels like this cursor doesn't quite match up with the outcome expected. Maybe would be better to have a treatment for the line or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, appreciate having more eyes on this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's subtle, but by simply hiding the vertex during "deletion snap", I think is good enough for now.

Mar-20-2024 23-29-20

Copy link
Contributor

Choose a reason for hiding this comment

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

:shipit:

@lukasztyrala
Copy link
Member

LGTM, great that we have snapping. 👍

Copy link
Collaborator

@codeincarnate codeincarnate left a comment

Choose a reason for hiding this comment

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

Looks pretty good! See my comment regaring deletion 😄

@@ -18,6 +19,11 @@ import {
import { CONNECTION_ANCHOR_ALT, ConnectionAnchors, CONNECTION_ANCHOR_HIGHLIGHT_OFFSET } from './ConnectionAnchors';
import { ConnectionSVG } from './ConnectionSVG';

export const CONNECTION_VERTEX_ID = 'vertex';
export const CONNECTION_VERTEX_ADD_ID = 'vertexAdd';
const CONNECTION_VERTEX_ORTHO_TOLERANCE = 0.05; // Cartesian ratio against vertical or horizontal tolerance
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lovely use of constants ❤️


if (deleteVertex) {
// Display temporary vertex removal
this.scene.selecto!.rootContainer!.style.cursor = 'not-allowed';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I want to agree here, feels like this cursor doesn't quite match up with the outcome expected. Maybe would be better to have a treatment for the line or something like that?

@drew08t drew08t merged commit 3877d97 into main Mar 21, 2024
14 checks passed
@drew08t drew08t deleted the drew08t/canvas-vertex-snapping branch March 21, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend area/panel/canvas Issues related to canvas panel no-backport Skip backport of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canvas: Angle snapping when editing mid point
5 participants