Skip to content

Commit

Permalink
hide out of border first and last tick lables having more than 2
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Dec 10, 2021
1 parent 134c01d commit 07cd536
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,19 @@ function drawColorBar(g, opts, gd) {
)
)) {
// for horizontal colorbars when there is a border line or having different background color
// adjust x positioning for the first/last tick labels if they go outside the border
// hide/adjust x positioning for the first/last tick labels if they go outside the border
var tickLabels = axLayer.selectAll('text');
var numTicks = tickLabels[0].length;

var border = g.select('.' + cn.cbbg).node();
var oBb = Drawing.bBox(border);
var oTr = Drawing.getTranslate(g);

var TEXTPAD = 2;

var tickLabels = axLayer.selectAll('text');
tickLabels.each(function(d, i) {
var first = 0;
var last = tickLabels[0].length - 1;
var last = numTicks - 1;
if(i === first || i === last) {
var iBb = Drawing.bBox(this);
var iTr = Drawing.getTranslate(this);
Expand All @@ -727,9 +729,7 @@ function drawColorBar(g, opts, gd) {

deltaX = oRight - iRight;
if(deltaX > 0) deltaX = 0;
}

if(i === first) {
} else if(i === first) {
var iLeft = iBb.left + iTr.x;
var oLeft = oBb.left + oTr.x + vPx + borderwidth + TEXTPAD;

Expand All @@ -738,10 +738,14 @@ function drawColorBar(g, opts, gd) {
}

if(deltaX) {
this.setAttribute('transform',
'translate(' + deltaX + ',0) ' +
this.getAttribute('transform')
);
if(numTicks < 3) { // adjust position
this.setAttribute('transform',
'translate(' + deltaX + ',0) ' +
this.getAttribute('transform')
);
} else { // hide
this.setAttribute('visibility', 'hidden');
}
}
}
});
Expand Down
Binary file modified test/image/baselines/h-colorbar01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/h-colorbar12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 07cd536

Please sign in to comment.