Skip to content

Commit c5fdc36

Browse files
authoredMar 15, 2024··
Merge pull request #6924 from plotly/fix6919-heatmap-text-color-on-missing-data
Fix `heatmap` text color and `texttemplate` on cells with missing data
2 parents 49efb52 + 1b66e9e commit c5fdc36

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed
 

‎draftlogs/6924_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix heatmap text color and `texttemplate` on cells with missing data [[#6924](https://github.com/plotly/plotly.js/pull/6924)]

‎src/lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,9 @@ function templateFormatString(string, labels, d3locale) {
12191219
var fmt;
12201220
if(format[0] === ':') {
12211221
fmt = d3locale ? d3locale.numberFormat : lib.numberFormat;
1222-
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
1222+
if(value !== '') { // e.g. skip missing data on heatmap
1223+
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
1224+
}
12231225
}
12241226

12251227
if(format[0] === '|') {

‎src/traces/heatmap/plot.js

+1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
535535
var fontColor = font.color;
536536
if(!fontColor || fontColor === 'auto') {
537537
fontColor = Color.contrast(
538+
d.z === undefined ? gd._fullLayout.plot_bgcolor :
538539
'rgba(' +
539540
sclFunc(d.z).join() +
540541
')'
-291 Bytes
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"data": [
3+
{
4+
"colorscale": "Reds",
5+
"text": [
6+
[
7+
"One",
8+
"Two",
9+
"Three"
10+
],
11+
[
12+
"Four",
13+
"Five",
14+
"Six"
15+
],
16+
[
17+
"Seven",
18+
"Eight",
19+
"Nine"
20+
]
21+
],
22+
"texttemplate": "%{text}",
23+
"x": [
24+
0,
25+
1,
26+
2
27+
],
28+
"y": [
29+
0,
30+
1,
31+
2
32+
],
33+
"z": [
34+
[
35+
null,
36+
2,
37+
3
38+
],
39+
[
40+
4,
41+
null,
42+
6
43+
],
44+
[
45+
7,
46+
8,
47+
null
48+
]
49+
],
50+
"type": "heatmap"
51+
}
52+
],
53+
"layout": {
54+
"title": {
55+
"text": "Heatmap text color should contrast with<br>background on cells with missing data"
56+
},
57+
"width": 400,
58+
"height": 400
59+
}
60+
}

0 commit comments

Comments
 (0)
Please sign in to comment.