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

Border radius #3203

Merged
merged 22 commits into from
Jan 24, 2024
Merged

Border radius #3203

merged 22 commits into from
Jan 24, 2024

Conversation

EliotRagueneau
Copy link
Contributor

Associated issues:

Checklist

Author:

  • The proper base branch has been selected. New features go on unstable. Bug-fix patches can go on either unstable or master.
  • Automated tests have been included in this pull request, if possible, for the new feature(s) or bug fix. Check this box if tests are not pragmatically possible (e.g. rendering features could include screenshots or videos instead of automated tests).
  • The associated GitHub issues are included (above).
  • Notes have been included (above).

Reviewers:

  • All automated checks are passing (green check next to latest commit).
  • At least one reviewer has signed off on the pull request.
  • For bug fixes: Just after this pull request is merged, it should be applied to both the master branch and the unstable branch. Normally, this just requires cherry-picking the corresponding merge commit from master to unstable -- or vice versa.

@EliotRagueneau
Copy link
Contributor Author

EliotRagueneau commented Dec 16, 2023

I'm going in hollidays until the 08/01/2024, so I posted this pull request though not yet fullly complete.

TODO

  • Store corner data rather than recalculating it for the draw, intersectLine and checkPoint functions in node-shapes.js generateRoundPolygon().
    • I've prepared what to be stored with round.js getRoundCorner(), but I wasn't sure where to store it.
    • The previous way of pre calculating points and unit vectors was at the node shape generator level, therefore prior to any access to radius data. Need to find a place to store. them and reuse them wherever needed
  • Add support for padding with border radius as discussed in border-radius property for node shapes with rounded corners #3198
  • Generate documenation for the new properties
  • Generate demo for the new edge types
  • Do further testing to make sure that there are never problems

Of course, feel free to complete some of those tasks while I'm away, and to give me feedback on some aspects.
This is a much bigger PR than all the previous ones I've made, so help would be really appreciated

@maxkfranz maxkfranz added the pinned A long-lived issue, such as a discussion label Dec 18, 2023
@maxkfranz
Copy link
Member

Pinned

@EliotRagueneau
Copy link
Contributor Author

Hi @maxkfranz , I hope you had nice holidays.

Could you please give me some advice on where to store pre-calculated results for rounded node shapes ?

Store corner data rather than recalculating it for the draw, intersectLine and checkPoint functions in node-shapes.js generateRoundPolygon().

I've prepared what to be stored with round.js getRoundCorner(), but I wasn't sure where to store it.
The previous way of pre calculating points and unit vectors was at the node shape generator level, therefore prior to any access to radius data. Need to find a place to store. them and reuse them wherever needed

@maxkfranz
Copy link
Member

Happy new year.

Caching the values is a bit more complicated than the decision of where to store the points. They need to be invalidated in the same cycle as the other cached values.

I'll get back to you with details in the next day or so.

For edges, caching is probably worthwhile, but for nodes it probably doesn't make much difference.

@EliotRagueneau
Copy link
Contributor Author

EliotRagueneau commented Jan 10, 2024

Reminder:

  • Check if the new roundness types are well supporting underlay
  • Check if the new roundness types are well supporting overlay

@maxkfranz
Copy link
Member

Some initial notes:

  1. Cached points can be stored in ele._private.rstyle.
  2. The caching of the points is initiated here: https://github.com/cytoscape/cytoscape.js/blob/unstable/src/extensions/renderer/base/coord-ele-math/edge-control-points.js#L928-L932
  3. allpts is also used for calculations and it may need to be updated, especially for a large radius on an edge.

@EliotRagueneau
Copy link
Contributor Author

EliotRagueneau commented Jan 11, 2024

For the edges, I've managed to cache what is need I believe.
allpts has been edited as well to handle middle edge arrows. I've even included a new midVector to simplify the drawing of the arrows afterwards, for their orientation

@EliotRagueneau
Copy link
Contributor Author

As you can see bellow, I've just tweaked a bit the outline formula to adjust the roundness of the outline, so that it looks neat.

Also I've checked for overlay and underlay, and both are working great for the new edge curvatures
Screenshot 2024-01-11 at 11 36 17

Copy link
Member

@maxkfranz maxkfranz left a comment

Choose a reason for hiding this comment

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

Just a point to consider re. naming before we merge this in:

src/style/properties.js Show resolved Hide resolved
@maxkfranz
Copy link
Member

Looks reasonable. There are some minor linter errors to resolve.

Are there any other tests or points of consideration before merging this in?

@EliotRagueneau
Copy link
Contributor Author

The thing that worries me the most really is the rounded node shapes which are now less optimised than before because we are not caching the unit vectors, I was hoping to be able to cache the rounded corners themselves within the nodes.

You said it was okay, but I'm a bit suprised because we are calculating them in 3 different functions for each round shapes, and potentially, if the user moves a node, we need to recalculate the roundness again and again to calculate the arrow head position using the intersection function. But if you say that's alright, I'm fine with it.

@maxkfranz
Copy link
Member

maxkfranz commented Jan 15, 2024 via email

@EliotRagueneau
Copy link
Contributor Author

Well no, with the current code, the new way to calculate corners is applied to all the rounded polygons, not just those for which the user specified the border radius. I did this to avoid having yet other shapes like "customisable-round-rectangle", and because the current implementation of the rounded shapes is failing when the width and the height are dissimilar.
Therefore the lack of node caching would is harmful anytime a user use a "round-xxx" shape

@EliotRagueneau
Copy link
Contributor Author

I've implemented the node caching, it's a bit more dirty than the previous caching since it is at the node level instead of the abstract shape definition, but the cache is well being used whenever we can, and updated whenever we need.
I think this covers all the concerns I had.

@maxkfranz
Copy link
Member

Looks great. Merged.

If you'd like to add anything else to this feature, or you notice any issues, just let me know.

@maxkfranz maxkfranz merged commit 3892b9b into cytoscape:unstable Jan 24, 2024
1 check passed
@EliotRagueneau
Copy link
Contributor Author

I noticed while testing it that for round-segments, it tends to create loops if a point is collinear to the previous and the following point, e.g. if A, B and C are on a single line, then B will have a loop on top of it.

Screenshot 2024-01-29 at 18 41 12

In theory, users shouldn't put unnecessary control points, and these are unnecessary since they do not make the edge move in any way, but it can be confusing. Do you think I should prevent this issue from happening? Like by ignoring collinear points? Is it too late to fix it for next release?

@maxkfranz
Copy link
Member

There are all sorts of cases where people can create invalid beziers.

We print some warnings in the console for the worst cases that get detected with no additional computational cost (e.g. the bezier can't be drawn at all).

If you think there can be an inexpensive check to detect this case, then we can either automatically correct the points or we can print a warning in the console. Someone might create collinear points when creating control points interactively. Consider the case where you have a few points and it's easier to just drag one point to be collinear rather than to delete it. That example demonstrates that autocorrection would generally be preferable.

Is it too late to fix it for next release?

We don't need to be too strict about the release date of 3.29.0. Let's consider 2024-02-12. Would that be enough time to add your proposed fix?

@EliotRagueneau
Copy link
Contributor Author

yes that's probably more than enough, thanks a lot!
Will fix that ASAP :D

@maxkfranz
Copy link
Member

Look forward to it

@EliotRagueneau
Copy link
Contributor Author

It seems my new commits are not showing in this PR, so I'll create a new PR

@EliotRagueneau EliotRagueneau mentioned this pull request Feb 1, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned A long-lived issue, such as a discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New edge type: smooth-segments border-radius property for node shapes with rounded corners
3 participants