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

fix: Rendering the cursor before the shapes #4200

Closed
wants to merge 4 commits into from

Conversation

HHongSeungWoo
Copy link
Member

Description

Added rendering priority and adjusted the rendering order.

Related Issue

#3990

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or extended an existing story to show my changes
  • All new and existing tests passed.

Copy link
Contributor

@nikolasrieble nikolasrieble left a comment

Choose a reason for hiding this comment

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

I think we can simplify this further. Would love to hear other opinions as well though.

@@ -417,27 +417,38 @@ export const isSingleChildEqual = (nextChild: React.ReactElement, prevChild: Rea
return false;
};

type Priority = number;
type Index = number;
export const orderByPriorityAndIndex = <T>(items: [Priority, Index, T][]): [Priority, Index, T][] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer an implementation that uses a object, to benefit from named keys.

This would both make the code more readable as well as safer to use, i.e. one could not accidentally pass index and priority in the wrong order without noticing (both are number after all.)

PolarGrid: { handler: this.renderPolarGrid, once: true, priority: 0 },
PolarAngleAxis: { handler: this.renderPolarAxis, priority: 0 },
PolarRadiusAxis: { handler: this.renderPolarAxis, priority: 0 },
Customized: { handler: this.renderCustomized, priority: 1 },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we want to extend this with a number field, if really it can only be 0 or 1?
It seems to me that what instead care for is: Foreground vs Background.

I would always prefer types to be a simple as possible, and here number is needlessly open to extension. Soon, we might have someone add a new value, i.e. priority 2, or -1.

What do you think? Could we implement this with only a boolean flag? Something like isBackground: boolean?

@PavelVanecek
Copy link
Collaborator

We're trying to get rid of the renderMap, and element cloning. Can you think of a solution that uses a different approach?

@PavelVanecek
Copy link
Collaborator

Also can we please have tests on the e2e expected behaviour? Why this change exists is to eventually sort elements in DOM, right? Let's test that.

@ckifer
Copy link
Member

ckifer commented Feb 18, 2024

The point of the change is to render elements in the correct order because z index is not supported in SVGs. We'll have to do this somewhere, at some point, and currently there are a few bugs surrounding it (this one with the cursor rendering in front of bars for example). Since we can't prevent the user from putting things in random order, we will have to order things. Imo there could be more priority than just a Boolean value could hold. Not sure what the best approach is to do this but maybe it's best revisited after we refactor away the whole render map. Appreciate the effort @HHongSeungWoo! Might be something we need to think through more

@PavelVanecek
Copy link
Collaborator

Is this something we have to solve for users? Is it acceptable solution to document that "what you render last will be on top"?

If this is only for Cursor, can we move renderCursor call to be before children render?

@ckifer
Copy link
Member

ckifer commented Feb 18, 2024

I would say we should ensure the things that should be in the back are in the back if we possibly can. There are a lot of issues relating to z axis stuff. Grid and Cursor being the two that I would say we should solve for if we can, other things maybe aren't such a big deal.

@ckifer
Copy link
Member

ckifer commented Feb 19, 2024

^ Labels should also be readable

@HHongSeungWoo
Copy link
Member Author

If we choose the option to adjust the rendering order rather than documenting it, we can temporarily adopt this method until we refactor.

However, this change could also be a breaking change for someone.

@PavelVanecek
Copy link
Collaborator

I think this is now done with portals. On the 3.x branch only.

@ckifer ckifer closed this May 1, 2024
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.

None yet

4 participants