Skip to content

Commit 184d7e7

Browse files
committed
draw labels on contour plots only when colring is heatmap
- corect label positions for histograd2dcontours
1 parent ce90ced commit 184d7e7

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

src/traces/contour/defaults.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
coerce('hovertext');
3434
coerce('hoverongaps');
3535
coerce('hovertemplate');
36-
coerce('texttemplate');
37-
38-
var fontDflt = Lib.extendFlat({}, layout.font);
39-
fontDflt.color = undefined; // color contrast by default
40-
Lib.coerceFont(coerce, 'textfont', fontDflt);
4136

4237
var isConstraint = (coerce('contours.type') === 'constraint');
4338
coerce('connectgaps', Lib.isArray1D(traceOut.z));
@@ -48,4 +43,15 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4843
handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
4944
handleStyleDefaults(traceIn, traceOut, coerce, layout);
5045
}
46+
47+
if(
48+
traceOut.contours &&
49+
traceOut.contours.coloring === 'heatmap'
50+
) {
51+
coerce('texttemplate');
52+
53+
var fontDflt = Lib.extendFlat({}, layout.font);
54+
fontDflt.color = undefined; // color contrast by default
55+
Lib.coerceFont(coerce, 'textfont', fontDflt);
56+
}
5157
};

src/traces/heatmap/plot.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,15 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
366366
_numFormat: xa._numFormat
367367
};
368368

369+
var isHistogram2dContour = trace.type === 'histogram2dcontour';
370+
369371
var textData = [];
370372
for(i = 0; i < m; i++) {
371373
var yVal;
372-
if(cd0.yCenter) {
374+
if(isHistogram2dContour) {
375+
if(i === 0 || i === m - 1) continue;
376+
yVal = cd0.y[i];
377+
} else if(cd0.yCenter) {
373378
yVal = cd0.yCenter[i];
374379
} else {
375380
if(i + 1 === m && cd0.y[i + 1] === undefined) continue;
@@ -381,7 +386,10 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
381386

382387
for(j = 0; j < n; j++) {
383388
var xVal;
384-
if(cd0.xCenter) {
389+
if(isHistogram2dContour) {
390+
if(j === 0 || j === n - 1) continue;
391+
xVal = cd0.x[j];
392+
} else if(cd0.xCenter) {
385393
xVal = cd0.xCenter[j];
386394
} else {
387395
if(j + 1 === n && cd0.x[j + 1] === undefined) continue;

src/traces/histogram2dcontour/defaults.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2222

2323
handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
2424
handleStyleDefaults(traceIn, traceOut, coerce, layout);
25-
coerce('hovertemplate');
26-
coerce('texttemplate');
27-
28-
var fontDflt = Lib.extendFlat({}, layout.font);
29-
fontDflt.color = undefined; // color contrast by default
30-
Lib.coerceFont(coerce, 'textfont', fontDflt);
31-
3225
coerce('xhoverformat');
3326
coerce('yhoverformat');
27+
coerce('hovertemplate');
28+
if(
29+
traceOut.contours &&
30+
traceOut.contours.coloring === 'heatmap'
31+
) {
32+
coerce('texttemplate');
33+
34+
var fontDflt = Lib.extendFlat({}, layout.font);
35+
fontDflt.color = undefined; // color contrast by default
36+
Lib.coerceFont(coerce, 'textfont', fontDflt);
37+
}
3438
};
4.65 KB
Loading
39.4 KB
Loading

test/image/mocks/contour_legend-colorscale.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
}
5959
],
6060
"layout": {
61+
"template": {
62+
"data": {
63+
"contour": [{
64+
"texttemplate": "%{z:.2s}"
65+
}]
66+
}
67+
},
6168
"title": {"text": "<b>contour legends with heatmap coloring</b><br>red-blue should be equal to reversed blue-red.<br>i.e. display identical legends for identical graphs"},
6269
"margin": {
6370
"t": 125,

test/image/mocks/histogram2d_legend.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"showlegend": true,
9999
"showscale": false,
100100
"texttemplate": "%{z}",
101+
"contours": {"coloring": "heatmap"},
101102
"type": "histogram2dcontour",
102103
"name": "histogram2dcontour"
103104
},
@@ -133,6 +134,7 @@
133134
"showscale": false,
134135
"reversescale": true,
135136
"texttemplate": "%{z}",
137+
"contours": {"coloring": "heatmap"},
136138
"type": "histogram2dcontour",
137139
"name": "histogram2dcontour reversed scale"
138140
}

0 commit comments

Comments
 (0)