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

Fix heatmap text color and texttemplate on cells with missing data #6924

Merged
merged 6 commits into from
Mar 15, 2024
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
1 change: 1 addition & 0 deletions draftlogs/6924_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix heatmap text color and `texttemplate` on cells with missing data [[#6924](https://github.com/plotly/plotly.js/pull/6924)]
4 changes: 3 additions & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,9 @@ function templateFormatString(string, labels, d3locale) {
var fmt;
if(format[0] === ':') {
fmt = d3locale ? d3locale.numberFormat : lib.numberFormat;
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
if(value !== '') { // e.g. skip missing data on heatmap
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
}
}

if(format[0] === '|') {
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
var fontColor = font.color;
if(!fontColor || fontColor === 'auto') {
fontColor = Color.contrast(
d.z === undefined ? gd._fullLayout.plot_bgcolor :
'rgba(' +
sclFunc(d.z).join() +
')'
Expand Down
Binary file modified test/image/baselines/heatmap_xyz-gaps-on-sides.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions test/image/mocks/zz-heatmap-text-color-on-missing-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"data": [
{
"colorscale": "Reds",
"text": [
[
"One",
"Two",
"Three"
],
[
"Four",
"Five",
"Six"
],
[
"Seven",
"Eight",
"Nine"
]
],
"texttemplate": "%{text}",
"x": [
0,
1,
2
],
"y": [
0,
1,
2
],
"z": [
[
null,
2,
3
],
[
4,
null,
6
],
[
7,
8,
null
]
],
"type": "heatmap"
}
],
"layout": {
"title": {
"text": "Heatmap text color should contrast with<br>background on cells with missing data"
},
"width": 400,
"height": 400
}
}