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

Flip tooltip position when its rendered beyond screen plot #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sergeylukin
Copy link

@sergeylukin sergeylukin commented Jun 18, 2021

Description

Render tooltip from the opposite side of mouse (using same offset but in opposite direction) when mouse is positioned so close to screen edge that tooltip is rendered beyond the plot hiding it's content.

Before (mouse cursor does not appear on screenshot):

Screen Shot 2021-06-18 at 3 33 06

After:

Screen Shot 2021-06-18 at 3 30 28

@sergeylukin sergeylukin force-pushed the flip-on-screen-overflow branch from 48ce3af to 2ab16cd Compare June 18, 2021 00:43
@sergeylukin sergeylukin force-pushed the flip-on-screen-overflow branch from 2ab16cd to 7c4c149 Compare June 18, 2021 01:14
Copy link
Owner

@marlo22 marlo22 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! 🎉 It looks (and works) awesome! I've added some code-style comments, could you take care of that? 🙏 😉

Before merge, I'd like to add tests (I'm currently working on it) to be sure that everything works fine. The package is used in many projects and we must be sure that nothing will break. 😉

constructor(props) {
super(props);
this.containerRef = React.createRef();
}
Copy link
Owner

@marlo22 marlo22 Jun 20, 2021

Choose a reason for hiding this comment

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

We can avoid declaring a constructor by assigning containerRef as a class property (see the state property). 😉 This approach is consistent with the current code style (IMO it's clearer and more convinient). Can you change it? 😄

Comment on lines +38 to +39
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;
Copy link
Owner

Choose a reason for hiding this comment

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

Can you destructure these properties?

Suggested change
const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;
const { innerWidth: screenWidth, innerHeight: screenHeight } = window;

Comment on lines +40 to +41
const containerWidth = this.containerRef.current.clientWidth;
const containerHeight = this.containerRef.current.clientHeight;
Copy link
Owner

Choose a reason for hiding this comment

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

These too, please? 😉

Suggested change
const containerWidth = this.containerRef.current.clientWidth;
const containerHeight = this.containerRef.current.clientHeight;
const { clientWidth: containerWidth, clientHeight: containerHeight } = this.containerRef.current;

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.

2 participants