Skip to content

Commit 4b73fc3

Browse files
authoredMay 5, 2021
Merge pull request #5622 from plotly/fix5585-log-text
Fixup texttemplate on log axes
2 parents 8cccacc + ca962bc commit 4b73fc3

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed
 

‎src/components/drawing/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ drawing.textPointStyle = function(s, trace, gd) {
943943
}
944944

945945
if(texttemplate) {
946-
var labels = trace._module.formatLabels ? trace._module.formatLabels(d, trace, fullLayout) : {};
946+
var fn = trace._module.formatLabels;
947+
var labels = fn ? fn(d, trace, fullLayout) : {};
947948
var pointValues = {};
948949
appendArrayPointValue(pointValues, trace, d.i);
949950
var meta = trace._meta || {};

‎src/traces/bar/plot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
647647
}
648648

649649
function formatLabel(u) {
650-
return tickText(pAxis, u, true).text;
650+
return tickText(pAxis, pAxis.c2l(u), true).text;
651651
}
652652

653653
function formatNumber(v) {
654-
return tickText(vAxis, +v, true).text;
654+
return tickText(vAxis, vAxis.c2l(v), true).text;
655655
}
656656

657657
var cdi = cd[index];

‎src/traces/scatter/format_labels.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = function formatLabels(cdi, trace, fullLayout) {
99
var xa = Axes.getFromTrace(mockGd, trace, 'x');
1010
var ya = Axes.getFromTrace(mockGd, trace, 'y');
1111

12-
labels.xLabel = Axes.tickText(xa, cdi.x, true).text;
13-
labels.yLabel = Axes.tickText(ya, cdi.y, true).text;
12+
labels.xLabel = Axes.tickText(xa, xa.c2l(cdi.x), true).text;
13+
labels.yLabel = Axes.tickText(ya, ya.c2l(cdi.y), true).text;
1414

1515
return labels;
1616
};

‎test/jasmine/tests/bar_test.js

+17
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,23 @@ describe('Text templates on bar traces:', function() {
27092709
['%{x}', ['Jan 1, 2019', 'Feb 1, 2019']]
27102710
]);
27112711

2712+
checkTextTemplate({
2713+
data: [{
2714+
type: 'bar',
2715+
textposition: 'outside',
2716+
x: [1, 2, 3],
2717+
y: [3, 2, 1],
2718+
hovertemplate: '%{x}-%{y}',
2719+
texttemplate: '%{x}-%{y}'
2720+
}],
2721+
layout: {
2722+
xaxis: {type: 'log'},
2723+
yaxis: {type: 'log'},
2724+
}
2725+
}, 'text.bartext', [
2726+
['%{x}-%{y}', ['1-3', '2-2', '3-1']]
2727+
]);
2728+
27122729
checkTextTemplate({
27132730
data: [{
27142731
type: 'bar',

‎test/jasmine/tests/scatter_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,22 @@ describe('Text templates on scatter traces:', function() {
12411241
[['%{y}', '%{x}-%{y}'], ['1', '1-5', '', '']]
12421242
]);
12431243

1244+
checkTextTemplate({
1245+
data: [{
1246+
type: 'scatter',
1247+
mode: 'text',
1248+
x: [1, 2, 3],
1249+
y: [3, 2, 1],
1250+
texttemplate: '%{x}-%{y}'
1251+
}],
1252+
layout: {
1253+
xaxis: {type: 'log'},
1254+
yaxis: {type: 'log'},
1255+
}
1256+
}, '.textpoint', [
1257+
['%{x}-%{y}', ['1-3', '2-2', '3-1']]
1258+
]);
1259+
12441260
checkTextTemplate({
12451261
data: [{
12461262
type: 'scatter',

0 commit comments

Comments
 (0)
Please sign in to comment.