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

Introduce horizontal colorbars #6024

Merged
merged 27 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e6bf1d2
introduce orientation attribute for colorbars
archmoj Nov 16, 2021
ff17d3d
draw horizontal colorbars
archmoj Nov 16, 2021
fd043df
test horizontal colorbars
archmoj Nov 16, 2021
05d1fae
draft log for PR 6024
archmoj Nov 17, 2021
9e87c24
new test
archmoj Nov 17, 2021
3c11c1f
new mock capturing a top side bug
archmoj Nov 17, 2021
06def17
rename to hColorbarMoveTitle
archmoj Nov 17, 2021
5e13658
fixup top title positioning
archmoj Nov 17, 2021
00987c5
add new test
archmoj Nov 17, 2021
eab32b3
match horizontal colorbar.y with vertical
archmoj Nov 17, 2021
ef423fa
only adjust graph title position when yanchor is bottom
archmoj Nov 17, 2021
9119a04
fixup editable horizontal colorbar
archmoj Nov 22, 2021
fb9ca33
add horizontal colorbar test
archmoj Nov 23, 2021
926d584
add horizontal colorbar tests
archmoj Nov 23, 2021
3d7bb0b
rename horizontal colorbar mocks
archmoj Nov 23, 2021
1dfc512
Update src/components/colorbar/attributes.js
archmoj Dec 2, 2021
d8b9c08
Update src/components/colorbar/attributes.js
archmoj Dec 2, 2021
7bc4fb4
Update src/components/colorbar/attributes.js
archmoj Dec 2, 2021
b6d7a91
Update src/components/colorbar/attributes.js
archmoj Dec 2, 2021
6a21c57
Update src/components/colorbar/attributes.js
archmoj Dec 2, 2021
fb56f8e
update draft schema change
archmoj Dec 3, 2021
8a137e3
center title of horizontal colorbars on the right side
archmoj Dec 5, 2021
2f09b6e
adjust first and last tick labels for horizontal colorbars
archmoj Dec 9, 2021
3eba6f0
compare colorbar.bgcolor with paper_bgcolor
archmoj Dec 10, 2021
134c01d
improve test - need to show & adjust start and end ticks
archmoj Dec 10, 2021
07cd536
hide out of border first and last tick lables having more than 2
archmoj Dec 10, 2021
a0901bd
improve image test
archmoj Dec 10, 2021
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
52 changes: 51 additions & 1 deletion src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function drawColorBar(g, opts, gd) {
var thicknessmode = opts.thicknessmode;
var outlinewidth = opts.outlinewidth;
var borderwidth = opts.borderwidth;
var bgcolor = opts.bgcolor;
var xanchor = opts.xanchor;
var yanchor = opts.yanchor;
var xpad = opts.xpad;
Expand Down Expand Up @@ -672,7 +673,7 @@ function drawColorBar(g, opts, gd) {
.attr('y', (isVertical ? vPx : uPx) - (isVertical ? lenPx : ypad + moveY - hColorbarMoveTitle))
.attr(isVertical ? 'width' : 'height', Math.max(outerThickness - hColorbarMoveTitle, 2))
.attr(isVertical ? 'height' : 'width', Math.max(lenPx + extraW, 2))
.call(Color.fill, opts.bgcolor)
.call(Color.fill, bgcolor)
.call(Color.stroke, opts.bordercolor)
.style('stroke-width', borderwidth);

Expand All @@ -697,6 +698,55 @@ function drawColorBar(g, opts, gd) {
gs.t - (isVertical ? 0 : (1 - yRatio) * outerThickness - moveY)
));

if(!isVertical && (
borderwidth || (
tinycolor(bgcolor).getAlpha() &&
!tinycolor.equals(fullLayout.plot_bgcolor, bgcolor)
)
)) {
// 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
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;
if(i === first || i === last) {
var iBb = Drawing.bBox(this);
var iTr = Drawing.getTranslate(this);
var deltaX;

if(i === last) {
var iRight = iBb.right + iTr.x;
var oRight = oBb.right + oTr.x + vPx - borderwidth - TEXTPAD + optsX;

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

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

deltaX = oLeft - iLeft;
if(deltaX < 0) deltaX = 0;
}

if(deltaX) {
this.setAttribute('transform',
'translate(' + deltaX + ',0) ' +
this.getAttribute('transform')
);
}
}
});
}

// auto margin adjustment
var marginOpts = {};
var lFrac = FROM_TL[xanchor];
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.