Skip to content

[Canvas] Snap to page - #36102

Merged
monfera merged 3 commits into
masterfrom
snap-to-page
May 8, 2019
Merged

monfera merged 3 commits into
masterfrom
snap-to-page

Conversation

@monfera

@monfera monfera commented May 6, 2019 •

Copy link
Copy Markdown
Contributor

Summary

Snap to page borders and centerline - closes #23160

Implementation note: it's achieved by simply adding a "virtual element", a rectangle with the dimensions of the page itself, to the list of snap guide shapes. This virtual element doesn't exist in any other sense of the word, only for the sole purpose of page border snap. It was enough to define a single rectangle, it's as if we were snapping elements onto the inside of a very large rectangle (assuming the element to be snapped is inside, but of course it can be outside the page too). The centerline is done automatically, as not only the borders but the center of a rectangle also acts as a snap constraint:
snap

As seen, the centerlines of the dragged shape are also snapped to the page borders or page centerlines, in addition to the sides of the dragged shape, so it's easy to put elements in the x/y (or both) center of the page.

The Option resize modifier key goes well with the center snap, letting the user first snap to the desired centerline, then resize while not changing the horizontal, vertical or either center:
center resize

Resize snap works too, whether orthogonal or rotated:
resizesnap

Grouped elements work too:
group480

It'd be possible to solve grid snapping in a similar way:

  1. Add a virtual element for every intersection in the diagonal - ie. if a 9 x 9 grid is present, then it's enough to add 9 virtual elements
  2. Each virtual element has the coordinates of the grid line intersection of the diagonal, but their size (a, b) is zero

It'd be straightforward this way, but it's also possible to do it using the third of the elements, with rectangles where a, b correspond to the grid pitch, considering that snapping isn't only done to the rectangle borders, but also to its midpoint (which is why one rectangle was enough for this PR). But it's most likely needless optimization.

@monfera monfera added review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// labels May 6, 2019
@monfera
monfera requested a review from a team as a code owner May 6, 2019 08:32
@monfera monfera self-assigned this May 6, 2019
@elasticmachine

Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-canvas

@monfera monfera changed the title Snap to page [Canvas] Snap to page May 6, 2019
@elasticmachine

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@ryankeairns ryankeairns left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@monfera The functionality works as described, this is going to be really helpful as it was surprisingly difficult to set elements along the edge without going over :)

There is a small issue that @cqliu1 and I noticed late last week where, due to some position rounding, a white 1px line can appear along the edge when in full screen mode. This feature emphasizes the issue as you would expect the alignment to go flush to edge.

Here are some screenshots:
Screenshot 2019-05-06 08 03 28

Screenshot 2019-05-06 08 03 40

Changing to -199px seems to resolve it

Screenshot 2019-05-06 08 03 09

@monfera

monfera commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

@ryankeairns thanks, indeed @cqliu1 and you're right about this rasterization issue. Also, the snapping makes the issue pronounced in that to work around, the user has to use the Command key to relax the snap (basically, undoing the snapping).

I experimented with it a little bit in the past (not because of this edge-gap thing) and ended up not rounding the size/position pixels for some reasons encountered then. In this specific case, the rounding wouldn't always result in the elimination of the gap; in 50% of the cases, it would reify a 1px gap, because rounding can fall either way.

I tried Math.ceil for the size too, which solves this issue, but this results in imperfect grouping boundaries, on this closeup one box slightly intrudes into the other, despite their creation done with snapping too:

image

Maybe there are more, but I see these alternative solutions:

  1. Do the Math.ceil thing as it eliminates the gap at the page edges; don't worry about imperfect grouping boundaries because few people will make groups out of fixed solid colored rectangles
  2. Make the element positioning component (canvas/public/components/positionable/positionable.js) aware of the page size, and only do the rounding up for those edges in the vicinity of the page border
  3. In presentation mode, show a page that's 1px smaller at each edge (ie. the width and height of the panel would be smaller by 2px) therefore not showing the contested territory of the last pixel at the edge

The last option would be the simplest, any idea for how to do this best with CSS/HTML? Also, is it going to cause a problem elsewhere?

In short, rasterization is a minute problem on the surface but it can get tricky, and HTML is doing a less proper job with it than SVG (which has decent support).

I'm not sure about timing/priorities wrt. the upcoming feature, who can decide if we shall try to solve it even if it risks the cutoff, or if it should be a subsequent discussion and PR?

@monfera

monfera commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

Ah there's a 4th option: what if we made the snap guides 1px out from the actual page bounds? A 0..1px protrusion is OK... I'll try it and push if it works out

@monfera

monfera commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

@ryankeairns @cqliu1 I just pushed option 4, the 1px enlargement is unnoticeable while editing, and it appears to fix the issue

@alexfrancoeur
alexfrancoeur requested a review from shaunmcgough May 6, 2019 17:11
@alexfrancoeur

Copy link
Copy Markdown

I should be able to take this for a spin within the next day or so. @shaunmcgough, I added you as a reviewer as well. Any chance you'll be able to provide some feedback?

@ryankeairns

Copy link
Copy Markdown
Contributor

@monfera that's a great and simple solution. I agree it that this rasterization issue seems simple on the surface, but probably ends up as an intricate fix. The change you implemented allows us to punt on this for a while, thanks!

@elasticmachine

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@shaunmcgough shaunmcgough left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, great work, and works as expected.

@cqliu1 cqliu1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@monfera
monfera merged commit 235264c into master May 8, 2019
@monfera
monfera deleted the snap-to-page branch May 8, 2019 17:16
monfera added a commit to monfera/kibana that referenced this pull request May 8, 2019
* Typo

* Snap to page borders and center lines

* Feedback: avoid a potential 1px background-colored gap at the edge in presentation mode
monfera added a commit that referenced this pull request May 8, 2019
* Typo

* Snap to page borders and center lines

* Feedback: avoid a potential 1px background-colored gap at the edge in presentation mode
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
* Typo

* Snap to page borders and center lines

* Feedback: avoid a potential 1px background-colored gap at the edge in presentation mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// v7.2.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Layout Engine] Snap to page borders

7 participants