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

Lines directly on the lower or upper bound of a Y-axis with custom domain and allowDataOverflow gets partially clipped out of view #4458

Open
1 task done
tannerdolby opened this issue Apr 27, 2024 · 4 comments
Labels
enhancement Enhancement to a current API

Comments

@tannerdolby
Copy link

tannerdolby commented Apr 27, 2024

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Within a LineChart, define YAxis with a specified domain and allowDataOverflow <YAxis data={...} domain={[0, 100]} allowDataOverflow />
  2. Provide data points to the chart so lines will be created directly on the lower/upper bound of the y-axis
  3. See that lines on the lower and upper bound of the YAxis domain are clipped and appear thinner due to the <clipPath> clipping away part of the lines stroke width which is outside the cartesian grid
  4. Set allowDataOverflow={false}
  5. See that lines on the lower/upper bound are not clipped anymore and don't appear thinner in stroke width
  6. Set allowDataOverflow back to true

YAxis with custom domain and allowDataOverflow={true}
Screen Shot 2024-04-28 at 8 45 20 PM

YAxis with custom domain and allowDataOverflow={false}
Screen Shot 2024-04-28 at 8 43 41 PM

What is expected?

Lines that are directly on the lower or upper bound of a custom domain should have the normal stroke-width as the other lines and not appear halved or "thinner" in stroke width. Essentially, it would be nice if lines on the lower/upper bound could look the same visually when allowDataOverflow is true or false.

What is actually happening?

The <clipPath> that gets added from allowDataOverflow on the YAxis clips away everything outside of the cartesian coordinate area as expected, but this cuts lines almost in half when the line is directly on the lower or upper bound. Visually its not super noticeable but when you turn allowDataOverflow={false} you will see how the other half of the line appears again for lines directly on the lower/upper bound.

I tinkered around locally in Line.tsx with the demo LineChart but couldn't really find a good way to keep the lines on the lower/upper bound fully visible since it would require changing the position of the clipPath that clips outside the cartesian grid from allowDataOverflow on the YAxis. Altering the position of the to give the lines on the lower/upper bound extra breathing room so the full stroke width is visible works but it allows lines with data points that do overflow the domains upper bound to overflow the cartesian grid by a few pixels which doesn't seem like an option.

I also thought about approaching it in segments where if a sequence of contiguous points are all on the lower or upper bound, do something specifically for these line segments to prevent the <clipPath> on the cartesian grid from hiding the full line width.

Environment Info
Recharts v2.12.6
React 17.0.1
System MacOS
Browser Chrome Version 123.0.6312.87

@ckifer
Copy link
Member

ckifer commented Apr 30, 2024

I guess to me this is expected? There is a clip path and that clip path is at the edge of the chart - if there is a line exactly at that edge it will clip half of the line.

We will have a conundrum if some people want things clipped and some do not.

This might be a start of a larger conversation around what allowDataOverflow actually does and how things are affected based on other settings. I don't really have any great answers or quick fixes at the moment though

@ckifer ckifer added the enhancement Enhancement to a current API label Apr 30, 2024
@tannerdolby
Copy link
Author

@ckifer Yeah, I agree this is expected behavior since we don't want any lines past the edges of the chart when using allowDataOverflow.

I think this was mainly a "want to have" because I'm mostly using line charts with allowDataOverflow on the YAxis (due to variance of some data) and customers mention the lines "looking thinner / halved" on the edges of the chart. No worries on fixes or actions at the moment, just wanted to start the conversation around this in case others were wanting something similar.

@ckifer
Copy link
Member

ckifer commented Apr 30, 2024

Cool, thanks for the context.

It might be reasonable to say "if there is an line that will be clipped horizontally in half, expand the domain slightly but cut off everything after that"

but if you had a larger strokeWidth (say 10 or something), one might not want the graph domain expanded by 5 units to accommodate the entire item. Especially if the domain starts at something like 0. Or if you had another shape/line that expanded further down under the domain minimum

@tannerdolby
Copy link
Author

tannerdolby commented Apr 30, 2024

No problem, thank you for taking a look.

It might be reasonable to say "if there is an line that will be clipped horizontally in half, expand the domain slightly but cut off everything after that"

Exactly this. Lines on the edges should be fully visible (no longer clipped in half) from the slightly expanded domain and lines that actually cross the edges due to data points going out the top or bottom of the graph should still be clipped/hidden because they will potentially be "behind" the lines strokeWidth directly on the edges and then cut off everything after that.

Ya, that's a good point about larger strokeWidths. Definitely agree there should be a limit or rules where this domain expanding doesn't always happen if the strokeWidth is greater than some value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to a current API
Projects
None yet
Development

No branches or pull requests

2 participants