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

New defaults for colorbar.title.font and legend.title.font to depend on colorbar.tickfont and legend.font and increase their sizes #5611

Merged
merged 13 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions src/components/colorbar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {

handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');

var opts = {outerTicks: false, font: layout.font};
var font = layout.font;
var opts = {outerTicks: false, font: font};
if(ticklabelposition.indexOf('inside') !== -1) {
opts.bgColor = 'black'; // could we instead use the average of colors in the scale?
}
handleTickLabelDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);

coerce('title.text', layout._dfltTitle.colorbar);
Lib.coerceFont(coerce, 'title.font', layout.font);

var tickFont = colorbarOut.tickfont;
var dfltTitleFont = Lib.extendFlat({}, tickFont, {
color: font.color,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the colorbar.title.font.color depends on layout.font not tickfont so that with inside ticklabels getting white, it renders outside using #444.

size: Lib.bigFont(tickFont.size)
});
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
coerce('title.side');
};
3 changes: 2 additions & 1 deletion src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ module.exports = {
font: fontAttrs({
editType: 'legend',
description: [
'Sets this legend\'s title font.'
'Sets this legend\'s title font.',
'Defaults to `legend.font` with its size increased about 20%.'
].join(' '),
}),
side: {
Expand Down
13 changes: 9 additions & 4 deletions src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
coerce('borderwidth');
Lib.coerceFont(coerce, 'font', layoutOut.font);
var itemFont = Lib.coerceFont(coerce, 'font', layoutOut.font);

var orientation = coerce('orientation');
var isHorizontal = orientation === 'h';
var defaultX, defaultY, defaultYAnchor;

if(orientation === 'h') {
if(isHorizontal) {
defaultX = 0;

if(Registry.getComponentMethod('rangeslider', 'isVisible')(layoutIn.xaxis)) {
Expand Down Expand Up @@ -119,7 +120,11 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {

var titleText = coerce('title.text');
if(titleText) {
coerce('title.side', orientation === 'h' ? 'left' : 'top');
Lib.coerceFont(coerce, 'title.font', layoutOut.font);
coerce('title.side', isHorizontal ? 'left' : 'top');
var dfltTitleFont = Lib.extendFlat({}, itemFont, {
size: Lib.bigFont(itemFont.size)
});

Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
}
};
5 changes: 5 additions & 0 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ function computeTextDimensions(g, gd, legendObj, aTitle) {
// approximation to height offset to center the font
// to avoid getBoundingClientRect
if(aTitle === MAIN_TITLE) {
if(legendObj.title.side === 'left') {
// add extra space between legend title and itmes
width += constants.itemGap * 2;
}

svgTextUtils.positionText(textEl,
bw + constants.titlePad,
bw + lineHeight
Expand Down
4 changes: 4 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,3 +1263,7 @@ lib.join2 = function(arr, mainSeparator, lastSeparator) {
}
return arr.join(mainSeparator);
};

lib.bigFont = function(size) {
return Math.round(1.2 * size);
};
2 changes: 1 addition & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ axes.prepTicks = function(ax, opts) {

if(!nt) {
if(ax.type === 'category' || ax.type === 'multicategory') {
minPx = ax.tickfont ? (ax.tickfont.size || 12) * 1.2 : 15;
minPx = ax.tickfont ? Lib.bigFont(ax.tickfont.size || 12) : 15;
nt = ax._length / minPx;
} else {
minPx = ax._id.charAt(0) === 'y' ? 40 : 80;
Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
coerce('title.text', dfltTitle);
Lib.coerceFont(coerce, 'title.font', {
family: font.family,
size: Math.round(font.size * 1.2),
size: Lib.bigFont(font.size),
color: dfltFontColor
});

Expand Down
2 changes: 1 addition & 1 deletion src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
coerceAxis('title.text');
Lib.coerceFont(coerceAxis, 'title.font', {
family: opts.font.family,
size: Math.round(opts.font.size * 1.2),
size: Lib.bigFont(opts.font.size),
color: dfltFontColor
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/plots/ternary/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut

Lib.coerceFont(coerce, 'title.font', {
family: options.font.family,
size: Math.round(options.font.size * 1.2),
size: Lib.bigFont(options.font.size),
color: dfltFontColor
});

Expand Down
2 changes: 1 addition & 1 deletion src/traces/carpet/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
if(title) {
Lib.coerceFont(coerce, 'title.font', {
family: font.family,
size: Math.round(font.size * 1.2),
size: Lib.bigFont(font.size),
color: dfltFontColor
});
coerce('title.offset');
Expand Down
Binary file modified test/image/baselines/airfoil.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/bar-like_textangle45.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/bar-like_textangle60.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/bar-marker-line-colorscales.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/cmid-zmid.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/colorscale_constraint.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/contour-heatmap-coloring-set-contours.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/contour_heatmap_coloring_reversescale.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/geo_choropleth-legend.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/geo_choropleth-usa.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/geo_choropleth-usa_legend.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/geo_europe-bubbles.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/gl2d_marker_coloraxis.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/gl2d_parcoords_coloraxis.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/gl2d_scatter-colorscale-colorbar.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/gl3d_mesh3d_coloring.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/gl3d_reversescale.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/gl3d_scatter3d-colorscale-marker-and-line.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/gl3d_scatter3d-colorscale.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/gl3d_surface_contour_start-end-size.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/gl3d_surface_opacityscale_contour.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/gl3d_tetrahedra.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/gl3d_volume_multiple-traces.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/gl3d_volume_multiple-traces_one-cube.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/heatmap_legend.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/layout_metatext.png
Binary file modified test/image/baselines/multicategory_histograms.png
Binary file modified test/image/baselines/pie_inside-text-orientation.png
Binary file modified test/image/baselines/scatter-colorscale-colorbar.png
Binary file modified test/image/baselines/sunburst_values_colorscale.png
Binary file modified test/image/baselines/ticklabelposition-4.png
Binary file modified test/image/baselines/titles-avoid-labels.png
Binary file modified test/image/baselines/trace_metatext.png
Binary file modified test/image/baselines/treemap_values_colorscale.png
Binary file modified test/image/baselines/uniformtext_bar-like_10_auto.png
Binary file modified test/image/baselines/uniformtext_bar-like_8_horizontal.png
Binary file modified test/image/baselines/uniformtext_bar-like_8_textangle.png
Binary file modified test/image/baselines/uniformtext_bar-like_8_textangle45.png
Binary file modified test/image/baselines/uniformtext_pie_16_auto.png
Binary file modified test/image/baselines/uniformtext_pie_8_horizontal.png
Binary file modified test/image/baselines/uniformtext_pie_8_horizontal_center.png
Binary file modified test/image/baselines/uniformtext_pie_8_radial.png
Binary file modified test/image/baselines/uniformtext_pie_8_tangential.png
Binary file modified test/image/baselines/uniformtext_pie_inside-text-orientation.png
Binary file modified test/image/baselines/uniformtext_pie_pull.png
2 changes: 1 addition & 1 deletion test/image/mocks/bar-like_textangle45.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall</b><br>textangle:-45"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of removing all the <b> tags in titles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.
To make it easier to see what the default look like.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - we have other examples of styled text, so this is fine.

"text": "bar, funnel & waterfall<br>textangle:-45"
}
},
"barmode": "stack",
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/bar-like_textangle60.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall</b><br>textangle:-60"
"text": "bar, funnel & waterfall<br>textangle:-60"
}
},
"barmode": "stack",
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/gl3d_mesh3d_coloring.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"bgcolor": "#eee",
"orientation": "h",
"title": {
"text": "<b>mesh3d with different coloring:</b>",
"text": "mesh3d with different coloring:",
"side": "top left"
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/heatmap_legend.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"orientation": "h",
"title": {
"side": "top left",
"text": "<b><i>heatmap and contour legends<i></b>"
"text": "<i>heatmap and contour legends<i>"
}
},
"height": 800,
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/pie_inside-text-orientation.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
},
"legend": {
"title": {
"text": "<b>inside text orientation</b>"
"text": "inside text orientation"
}
},
"font": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_bar-like_10_auto.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall uniform text</b><br>with <i>auto</i> orientation<br>minsize=8"
"text": "bar, funnel & waterfall uniform text<br>with <i>auto</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_bar-like_8_horizontal.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall uniform text</b><br>with <i>horizontal</i> orientation<br>minsize=8"
"text": "bar, funnel & waterfall uniform text<br>with <i>horizontal</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_bar-like_8_textangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall uniform text</b><br>with vertical orientation<br>textangle:-90 | minsize=8"
"text": "bar, funnel & waterfall uniform text<br>with vertical orientation<br>textangle:-90 | minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_bar-like_8_textangle45.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>bar, funnel & waterfall uniform text</b><br>textangle:-45 | minsize=8"
"text": "bar, funnel & waterfall uniform text<br>textangle:-45 | minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_16_auto.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>pie uniform text</b><br>with <i>auto</i> orientation<br>minsize=16"
"text": "pie uniform text<br>with <i>auto</i> orientation<br>minsize=16"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_8_horizontal.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>pie uniform text</b><br>with <i>horizontal</i> orientation<br>minsize=8"
"text": "pie uniform text<br>with <i>horizontal</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_8_horizontal_center.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>pie uniform text</b><br>with <i>horizontal</i> orientation<br>minsize=8"
"text": "pie uniform text<br>with <i>horizontal</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_8_radial.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>pie uniform text</b><br>with <i>radial</i> orientation<br>minsize=8"
"text": "pie uniform text<br>with <i>radial</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_8_tangential.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"legend": {
"orientation": "h",
"title": {
"text": "<b>pie uniform text</b><br>with <i>tangential</i> orientation<br>minsize=8"
"text": "pie uniform text<br>with <i>tangential</i> orientation<br>minsize=8"
}
},
"uniformtext": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
},
"legend": {
"title": {
"text": "<b>inside text orientation</b>"
"text": "inside text orientation"
}
},
"font": {
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/uniformtext_pie_pull.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
},
"legend": {
"title": {
"text": "<b>pie uniform text</b><br>with <i>horizontal</i> orientation<br>minsize=20"
"text": "pie uniform text<br>with <i>horizontal</i> orientation<br>minsize=20"
}
},
"uniformtext": {
Expand Down
1 change: 1 addition & 0 deletions test/jasmine/tests/histogram2d_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Test histogram2d', function() {

function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
layout._dfltTitle = {colorbar: 'cb'};
layout.font = {color: '#444'};

return supplyDefaultsRaw(traceIn, traceOut, defaultColor, layout);
}
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/mesh3d_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Test mesh3d', function() {

describe('supplyDefaults', function() {
var defaultColor = '#444';
var layout = {_dfltTitle: {colorbar: 'cb'}};
var layout = {_dfltTitle: {colorbar: 'cb'}, font: {color: '#444'}};

var traceIn, traceOut;

Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/surface_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Test surface', function() {

describe('supplyDefaults', function() {
var defaultColor = '#444';
var layout = {_dfltTitle: {colorbar: 'cb'}};
var layout = {_dfltTitle: {colorbar: 'cb'}, font: {color: '#444'}};

var traceIn, traceOut;

Expand Down