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
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,10 @@ module.exports = function setConvert(ax, fullLayout) {

ax.isPtWithinRange = function(d, calendar) {
var coord = ax.c2l(d[axLetter], null, calendar);
var r0 = ax.r2l(ax.range[0]);
var r1 = ax.r2l(ax.range[1]);

return (
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.

};

ax.clearCalc = function() {
Expand Down
Binary file modified test/image/baselines/bar_cliponaxis-false.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions test/image/mocks/bar_cliponaxis-false.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
"cliponaxis": true,
"textfont": {"size": [20]},
"marker": {"opacity": 0.3}
},
{
"type": "bar",
"name": "should see text",
"x": ["banana"],
"y": [1],
"text": ["banana"],
"textposition": "outside",
"cliponaxis": false,
"textfont": {"size": [20]},
"xaxis": "x3",
"yaxis": "y3"
}
],
"layout": {
Expand All @@ -51,15 +63,23 @@
"showticklabels": false,
"mirror": true,
"layer": "below traces",
"domain": [0, 0.48]
"domain": [0, 0.38]
},
"xaxis2": {
"anchor": "y2",
"showline": true,
"showticklabels": false,
"mirror": true,
"layer": "below traces",
"domain": [0.52, 1]
"domain": [0.42, 0.80]
},
"xaxis3": {
"anchor": "y3",
"showline": true,
"showticklabels": false,
"mirror": true,
"layer": "below traces",
"domain": [0.84, 1]
},
"yaxis": {
"showline": true,
Expand All @@ -74,7 +94,14 @@
"layer": "below traces",
"range": [0, 2]
},
"width": 700,
"yaxis3": {
"anchor": "x3",
"showline": true,
"mirror": true,
"layer": "below traces",
"range": [2, 0]
},
"width": 800,
"height": 400,
"margin": {"t": 40},
"dragmode": "pan"
Expand Down