Skip to content

Commit

Permalink
Merge pull request #6910 from plotly/insiderange-categories
Browse files Browse the repository at this point in the history
Fix insiderange with category axes
  • Loading branch information
archmoj authored Mar 1, 2024
2 parents 9069e34 + 6f05ee4 commit 55b5338
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions draftlogs/6910_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix `insiderange` with category axes [[#6910](https://github.com/plotly/plotly.js/pull/6910)]
12 changes: 6 additions & 6 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3907,13 +3907,13 @@ axes.drawLabels = function(gd, ax, opts) {

var anchorAxRange = anchorAx.range;

var p0 = anchorAx.d2p(anchorAxRange[index]);
var p1 = anchorAx.d2p(anchorAxRange[otherIndex]);
var p0 = anchorAx.r2p(anchorAxRange[index]);
var p1 = anchorAx.r2p(anchorAxRange[otherIndex]);

var _tempNewRange = fullLayout._insideTickLabelsUpdaterange[anchorAx._name + '.range'];
if(_tempNewRange) { // case of having multiple anchored axes having insideticklabel
var q0 = anchorAx.d2p(_tempNewRange[index]);
var q1 = anchorAx.d2p(_tempNewRange[otherIndex]);
var q0 = anchorAx.r2p(_tempNewRange[index]);
var q1 = anchorAx.r2p(_tempNewRange[otherIndex]);

var dir = sgn * (ax._id.charAt(0) === 'y' ? 1 : -1);

Expand All @@ -3938,8 +3938,8 @@ axes.drawLabels = function(gd, ax, opts) {

if(ax._id.charAt(0) !== 'y') move = -move;

newRange[index] = anchorAx.p2d(
anchorAx.d2p(anchorAxRange[index]) +
newRange[index] = anchorAx.p2r(
anchorAx.r2p(anchorAxRange[index]) +
sgn * move
);

Expand Down
Binary file added test/image/baselines/zz-insiderange-category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/image/mocks/zz-insiderange-category.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"data": [
{
"name": "bar",
"x": [
"A",
"B",
"C",
"D"
],
"y": [
50,
70,
90,
35
],
"type": "bar"
}
],
"layout": {
"xaxis": {
"type": "category",
"insiderange": [
1,
2
]
},
"yaxis": {
"side": "right",
"ticklabelposition": "inside top"
},
"width": 400
}
}

0 comments on commit 55b5338

Please sign in to comment.