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 23 commits
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
1 change: 1 addition & 0 deletions draftlogs/6024_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Introduce horizontal colorbars [[#6024](https://github.com/plotly/plotly.js/pull/6024)]
49 changes: 29 additions & 20 deletions src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ var overrideAll = require('../../plot_api/edit_types').overrideAll;


module.exports = overrideAll({
// TODO: only right is supported currently
// orient: {
// valType: 'enumerated',
// values: ['left', 'right', 'top', 'bottom'],
// dflt: 'right',
// description: [
// 'Determines which side are the labels on',
// '(so left and right make vertical bars, etc.)'
// ].join(' ')
// },
orientation: {
valType: 'enumerated',
values: ['h', 'v'],
dflt: 'v',
description: 'Sets the orientation of the colorbar.'
},
thicknessmode: {
valType: 'enumerated',
values: ['fraction', 'pixels'],
Expand Down Expand Up @@ -61,21 +57,23 @@ module.exports = overrideAll({
},
x: {
valType: 'number',
dflt: 1.02,
min: -2,
max: 3,
description: [
'Sets the x position of the color bar (in plot fraction).'
'Sets the x position of the color bar (in plot fraction).',
'Defaults to 1.02 when `orientation` is *v* and',
'0.5 when `orientation` is *h*.'
].join(' ')
},
xanchor: {
valType: 'enumerated',
values: ['left', 'center', 'right'],
dflt: 'left',
description: [
'Sets this color bar\'s horizontal position anchor.',
'This anchor binds the `x` position to the *left*, *center*',
'or *right* of the color bar.'
'or *right* of the color bar.',
'Defaults to *left* when `orientation` is *v* and',
'*center* when `orientation` is *h*.'
].join(' ')
},
xpad: {
Expand All @@ -86,21 +84,23 @@ module.exports = overrideAll({
},
y: {
valType: 'number',
dflt: 0.5,
min: -2,
max: 3,
description: [
'Sets the y position of the color bar (in plot fraction).'
'Sets the y position of the color bar (in plot fraction).',
'Defaults to 0.5 when `orientation` is *v* and',
'1.02 when `orientation` is *h*.'
].join(' ')
},
yanchor: {
valType: 'enumerated',
values: ['top', 'middle', 'bottom'],
dflt: 'middle',
description: [
'Sets this color bar\'s vertical position anchor',
'This anchor binds the `y` position to the *top*, *middle*',
'or *bottom* of the color bar.'
'or *bottom* of the color bar.',
'Defaults to *middle* when `orientation` is *v* and',
'*bottom* when `orientation` is *h*.'
].join(' ')
},
ypad: {
Expand Down Expand Up @@ -143,18 +143,26 @@ module.exports = overrideAll({
'In other cases the default is *hide past div*.'
].join(' ')
}),

// ticklabelposition: not used directly, as values depend on orientation
// left/right options are for x axes, and top/bottom options are for y axes
ticklabelposition: {
valType: 'enumerated',
values: [
'outside', 'inside',
'outside top', 'inside top',
'outside left', 'inside left',
'outside right', 'inside right',
'outside bottom', 'inside bottom'
],
dflt: 'outside',
description: [
'Determines where tick labels are drawn.'
'Determines where tick labels are drawn relative to the ticks.',
'Left and right options are used when `orientation` is *h*,',
'top and bottom when `orientation` is *v*.'
].join(' ')
},

ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
Expand Down Expand Up @@ -193,10 +201,11 @@ module.exports = overrideAll({
side: {
valType: 'enumerated',
values: ['right', 'top', 'bottom'],
dflt: 'top',
description: [
'Determines the location of color bar\'s title',
'with respect to the color bar.',
'Defaults to *top* when `orientation` if *v* and ',
'defaults to *right* when `orientation` if *h*.',
'Note that the title\'s location used to be set',
'by the now deprecated `titleside` attribute.'
].join(' ')
Expand Down
38 changes: 30 additions & 8 deletions src/components/colorbar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
return Lib.coerce(colorbarIn, colorbarOut, attributes, attr, dflt);
}

var margin = layout.margin || {t: 0, b: 0, l: 0, r: 0};
var w = layout.width - margin.l - margin.r;
var h = layout.height - margin.t - margin.b;

var orientation = coerce('orientation');
var isVertical = orientation === 'v';

var thicknessmode = coerce('thicknessmode');
coerce('thickness', (thicknessmode === 'fraction') ?
30 / (layout.width - layout.margin.l - layout.margin.r) :
30 / (isVertical ? w : h) :
30
);

var lenmode = coerce('lenmode');
coerce('len', (lenmode === 'fraction') ?
1 :
layout.height - layout.margin.t - layout.margin.b
isVertical ? h : w
);

coerce('x');
coerce('xanchor');
coerce('x', isVertical ? 1.02 : 0.5);
coerce('xanchor', isVertical ? 'left' : 'center');
coerce('xpad');
coerce('y');
coerce('yanchor');
coerce('y', isVertical ? 0.5 : 1.02);
coerce('yanchor', isVertical ? 'middle' : 'bottom');
coerce('ypad');
Lib.noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);

Expand All @@ -44,7 +51,22 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
coerce('borderwidth');
coerce('bgcolor');

var ticklabelposition = coerce('ticklabelposition');
var ticklabelposition = Lib.coerce(colorbarIn, colorbarOut, {
ticklabelposition: {
valType: 'enumerated',
dflt: 'outside',
values: isVertical ? [
'outside', 'inside',
'outside top', 'inside top',
'outside bottom', 'inside bottom'
] : [
'outside', 'inside',
'outside left', 'inside left',
'outside right', 'inside right'
]
}
}, 'ticklabelposition');

coerce('ticklabeloverflow', ticklabelposition.indexOf('inside') !== -1 ? 'hide past domain' : 'hide past div');

handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
Expand All @@ -66,5 +88,5 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
size: Lib.bigFont(tickFont.size)
});
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
coerce('title.side');
coerce('title.side', isVertical ? 'top' : 'right');
};
Loading