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 element snapping and alignment #80407

Merged
merged 15 commits into from
Jan 30, 2024
Merged

Canvas: Add element snapping and alignment #80407

merged 15 commits into from
Jan 30, 2024

Conversation

nmarrs
Copy link
Contributor

@nmarrs nmarrs commented Jan 12, 2024

There are a few potentially low hanging fruit that we should take advantage of with improving canvas.

One of these is the snappable feature built into the moveable library. This PR pushes canvas further into a more matured product experience / helps smooth over its rougher edges.

Screen.Recording.2024-01-11.at.8.51.19.PM.mov

TODO

  • Experiment more with available options / API for snappable
  • Fix drag group functionality (i.e. remove elements in current selection to avoid glitchy UX with snappable (remove on groupDragStart and re-add selected elements back on groupDragEnd))
  • Fix similar functionality for resize (we should remove current element from being considered in snappable)
  • Testing ... lots of testing
    • Noticed that there are some scaling issues with pan / zoom (@drew08t any help with this would be 🙏)
  • Clean up
  • Docs
    • Initial draft, not sure it makes sense to include unless we allow the user to turn this functionality off (i.e. just have what's new entry vs docs update) -> question: does it make sense to make this another canvas option to toggle on / off vs just defaulting to always being on?
  • What's new entry? (may be an easy win for 10.4, can be lumped with other canvas low hanging fruit updates)

@nmarrs nmarrs added add to changelog area/panel/canvas Issues related to canvas panel no-backport Skip backport of PR add to what's new labels Jan 12, 2024
@nmarrs nmarrs added this to the 10.4.x milestone Jan 12, 2024
@nmarrs nmarrs self-assigned this Jan 12, 2024
@grafana-delivery-bot grafana-delivery-bot bot modified the milestones: 10.4.x, 10.3.x Jan 12, 2024
@nmarrs nmarrs modified the milestones: 10.3.x, 10.4.x Jan 29, 2024
@nmarrs nmarrs marked this pull request as ready for review January 29, 2024 04:50
@nmarrs nmarrs requested a review from a team as a code owner January 29, 2024 04:50
@nmarrs nmarrs requested review from leeoniya and adela-almasan and removed request for a team January 29, 2024 04:50
@nmarrs nmarrs changed the title [POC / WIP] Canvas: Improve element positioning with snappable feature Canvas: Add element snapping and alignment Jan 29, 2024
Copy link
Collaborator

@imatwawana imatwawana left a comment

Choose a reason for hiding this comment

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

Small edit

@@ -426,9 +436,25 @@ export class Scene {
.on('dragStart', (event) => {
this.ignoreDataUpdate = true;
this.setNonTargetPointerEvents(event.target, true);

if (this.moveable && this.moveable.elementGuidelines) {
const targetIndex = this.moveable.elementGuidelines.indexOf(event.target);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: may not be worth it, but there's some duped code a few time here that we could maybe abstract out? Either way, this is awesome!

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 yes that is a good point, a lot of repeated code here, thanks for pointing this out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on closer review breaking out this logic I think is not really in scope of these changes (honestly the scene.tsx file has been needing a cleaning up for a while now (ideally breaking out moveable / selecto config to their own file where we can better group helper functions specific to setting up config (and also cleaning up scene.tsx a ton)

For now I've included some comments to help with future readability / maintainability 🤞

@drew08t
Copy link
Contributor

drew08t commented Jan 29, 2024

I will take a look at the pan / zoom issues you were experiencing this week.

@drew08t
Copy link
Contributor

drew08t commented Jan 29, 2024

Tested it locally and works great; however, as you mentioned, I am experiencing a couple issues during zoom, which I documented here: #81528

Because these appear to be caused by moveable itself, we will disable snappable during zoom for now until we can follow-up on this.

Copy link
Contributor

@drew08t drew08t left a comment

Choose a reason for hiding this comment

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

Behaving nicely, with follow-up tasks documented with regards to zoom / multi-select.

@@ -426,9 +436,25 @@ export class Scene {
.on('dragStart', (event) => {
this.ignoreDataUpdate = true;
this.setNonTargetPointerEvents(event.target, true);

if (this.moveable && this.moveable.elementGuidelines) {
const targetIndex = this.moveable.elementGuidelines.indexOf(event.target);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

on closer review breaking out this logic I think is not really in scope of these changes (honestly the scene.tsx file has been needing a cleaning up for a while now (ideally breaking out moveable / selecto config to their own file where we can better group helper functions specific to setting up config (and also cleaning up scene.tsx a ton)

For now I've included some comments to help with future readability / maintainability 🤞

const scale = zoomPanPinchRef.state.scale;
scene.scale = scale;
updateMoveable(scale);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@drew08t i've done some minor cleanup to these changes, would appreciate a quick set of 👀 to make sure I'm not doing anything strange 😬

nmarrs and others added 2 commits January 30, 2024 07:11
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
@nmarrs nmarrs merged commit b0130ec into main Jan 30, 2024
15 checks passed
@nmarrs nmarrs deleted the canvas-snappable branch January 30, 2024 23:37
@Hipska
Copy link
Contributor

Hipska commented Feb 9, 2024

Does this also include option to select multiple items and align them Left/Center/Right/Top/Middle/Bottom?

Ukochka pushed a commit that referenced this pull request Feb 14, 2024
Co-authored-by: drew08t <drew08@gmail.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
@aangelisc aangelisc modified the milestones: 10.4.x, 10.4.0 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants