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

Split Tooltip into TooltipBoundingBox #3951

Merged
merged 3 commits into from Nov 13, 2023

Conversation

PavelVanecek
Copy link
Collaborator

Description

I think this is an opportunity to have two clearly defined components with split responsibility. One doing the position (BoundingBox) and one doing the content (Tooltip).

Related Issue

Motivation and Context

How Has This Been Tested?

unit tests

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.

@@ -33,30 +37,25 @@ function renderContent<TValue extends ValueType, TName extends NameType>(
return <DefaultTooltipContent {...props} />;
}

export type TooltipProps<TValue extends ValueType, TName extends NameType> = DefaultProps<TValue, TName> & {
export type TooltipProps<TValue extends ValueType, TName extends NameType> = ToltipContentProps<TValue, TName> & {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changes to props:

  1. "Sort lines alphabetically"
  2. viewBox uses (identical) imported type instead of inline.

reverseDirection: { x: false, y: false },
offset: 10,
viewBox: { x: 0, y: 0, height: 0, width: 0 },
animationDuration: 400,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"Sort lines alphabetically"

Math.abs(box.width - this.lastBoundingBox.width) > EPS ||
Math.abs(box.height - this.lastBoundingBox.height) > EPS
) {
this.lastBoundingBox.width = box.width;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this instance assignment is a potential bug but I copy pasted it without a change.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you think this is a bug, please do elaborate, and create a follow up issue. We can tackle this independently. I appreciate this you only copied it in this PR.

Copy link
Member

@ckifer ckifer Nov 12, 2023

Choose a reason for hiding this comment

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

I think @HHongSeungWoo recently modified this section?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@HHongSeungWoo confirmed in another thread that this is intentional: #3852 (comment)

I do not have any evidence that this is a bug. It's only an antipattern that can lead to bugs - this thing here is why useState and useRef exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(Reading defaultProps and cloning elements are also antipatterns 😬 )

Copy link
Member

Choose a reason for hiding this comment

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

This should probably be a function component then no? 😅

Copy link
Member

Choose a reason for hiding this comment

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

While we have many anti-patterns, I think this one is similar to useMemo.
Due to getTooltipTranslate, this seems to be the best option for now.

@PavelVanecek
Copy link
Collaborator Author

This will also make my PoC branches easier - there's tons of conflicts.

dismissedAtCoordinate: Coordinate;
};

const EPS = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: If you know what EPS stands for, I would sure love to replace this with a proper name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"Epsilon"

denotes the smallest quantity like a term which is taken as the zero in some limit

Copy link
Member

Choose a reason for hiding this comment

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

This is no longer necessary. It seems to have been added due to the structure of obtaining the tooltip's viewbox, which could have caused an infinite loop

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.

Nice cleanup, I like it. It further simplifies the Tooltip and marginally increases test coverage.

Well done. ❤️ 🚀

@nikolasrieble nikolasrieble merged commit 9e473fe into recharts:master Nov 13, 2023
5 checks passed
@PavelVanecek PavelVanecek deleted the TooltipBoundingBox branch November 14, 2023 10:28
GMer78 pushed a commit to GMer78/recharts-1 that referenced this pull request Nov 24, 2023
## Description

I think this is an opportunity to have two clearly defined components
with split responsibility. One doing the position (BoundingBox) and one
doing the content (Tooltip).

## Related Issue

## Motivation and Context

## How Has This Been Tested?

unit tests

## 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:

- [X] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [X] I have added tests to cover my changes.
- [ ] I have added a storybook story or extended an existing story to
show my changes
- [X] All new and existing tests passed.
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