Skip to content

Commit

Permalink
Merge pull request #5622 from plotly/fix5585-log-text
Browse files Browse the repository at this point in the history
Fixup texttemplate on log axes
  • Loading branch information
archmoj authored May 5, 2021
2 parents 8cccacc + ca962bc commit 4b73fc3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ drawing.textPointStyle = function(s, trace, gd) {
}

if(texttemplate) {
var labels = trace._module.formatLabels ? trace._module.formatLabels(d, trace, fullLayout) : {};
var fn = trace._module.formatLabels;
var labels = fn ? fn(d, trace, fullLayout) : {};
var pointValues = {};
appendArrayPointValue(pointValues, trace, d.i);
var meta = trace._meta || {};
Expand Down
4 changes: 2 additions & 2 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
}

function formatLabel(u) {
return tickText(pAxis, u, true).text;
return tickText(pAxis, pAxis.c2l(u), true).text;
}

function formatNumber(v) {
return tickText(vAxis, +v, true).text;
return tickText(vAxis, vAxis.c2l(v), true).text;
}

var cdi = cd[index];
Expand Down
4 changes: 2 additions & 2 deletions src/traces/scatter/format_labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = function formatLabels(cdi, trace, fullLayout) {
var xa = Axes.getFromTrace(mockGd, trace, 'x');
var ya = Axes.getFromTrace(mockGd, trace, 'y');

labels.xLabel = Axes.tickText(xa, cdi.x, true).text;
labels.yLabel = Axes.tickText(ya, cdi.y, true).text;
labels.xLabel = Axes.tickText(xa, xa.c2l(cdi.x), true).text;
labels.yLabel = Axes.tickText(ya, ya.c2l(cdi.y), true).text;

return labels;
};
17 changes: 17 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2709,6 +2709,23 @@ describe('Text templates on bar traces:', function() {
['%{x}', ['Jan 1, 2019', 'Feb 1, 2019']]
]);

checkTextTemplate({
data: [{
type: 'bar',
textposition: 'outside',
x: [1, 2, 3],
y: [3, 2, 1],
hovertemplate: '%{x}-%{y}',
texttemplate: '%{x}-%{y}'
}],
layout: {
xaxis: {type: 'log'},
yaxis: {type: 'log'},
}
}, 'text.bartext', [
['%{x}-%{y}', ['1-3', '2-2', '3-1']]
]);

checkTextTemplate({
data: [{
type: 'bar',
Expand Down
16 changes: 16 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,22 @@ describe('Text templates on scatter traces:', function() {
[['%{y}', '%{x}-%{y}'], ['1', '1-5', '', '']]
]);

checkTextTemplate({
data: [{
type: 'scatter',
mode: 'text',
x: [1, 2, 3],
y: [3, 2, 1],
texttemplate: '%{x}-%{y}'
}],
layout: {
xaxis: {type: 'log'},
yaxis: {type: 'log'},
}
}, '.textpoint', [
['%{x}-%{y}', ['1-3', '2-2', '3-1']]
]);

checkTextTemplate({
data: [{
type: 'scatter',
Expand Down

0 comments on commit 4b73fc3

Please sign in to comment.