Skip to content

Fix containment check for reversed ranges #1

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

Closed
wants to merge 3 commits into from

Conversation

darabos
Copy link
Owner

@darabos darabos commented Apr 6, 2018

I committed the "before" baseline to demonstrate the issue. You can see the fix in the second commit's diff:
cliponaxis-before-after

This example is a bit unusual. Who uses upside-down bar charts?! In real life I hit this issue with a horizontal bar chart where I wanted the order of the groups in the chart to match the order in the legend:
horizontal-bar-chart

I set autorange: 'reverse' and the texts disappeared:
bars-reversed

If I remove cliponaxis: false, the texts are clipped:
bars-clipped

I'm open to suggestions, but this PR is aimed at fixing the version with the missing texts.

coord >= ax.r2l(ax.range[0]) &&
coord <= ax.r2l(ax.range[1])
);
return Math.min(r0, r1) <= coord && coord <= Math.max(r0, r1);
Copy link

Choose a reason for hiding this comment

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

Perhaps:

var r0 = ax.r2l(ax.range[0]);
var r1 = ax.r2l(ax.range[1]);

if(r0 < r1) {
  return coord >= r0 && coords <= r1;
} else {
  // reversed axis case
  return coord <= r0 && coords >= r1;
}

would perform (one comparison instead of Math.min + Math.max) and arguably more readable.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks, done. I will try to figure out how to recreate this pull request against the main repo.

@darabos darabos closed this Apr 6, 2018
darabos pushed a commit that referenced this pull request Oct 2, 2018
* treat zero as valid fixes plotly#2660

* PR suggestions: toBe instead of toEqual
darabos pushed a commit that referenced this pull request Oct 2, 2018
Fix for number 0 treated as invalid in hover (#1)
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