From d077ee7430e810a933f6eb4faf0a2b0799460bc8 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 4 May 2021 10:49:02 -0400 Subject: [PATCH 1/5] refactor function lookup --- src/components/drawing/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 3aa65a573d6..2faf5f637ea 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -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 || {}; From 73d5438052a74e7a8dd9d42864036db9aca29470 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 4 May 2021 11:08:24 -0400 Subject: [PATCH 2/5] fix issue 5585 for scatter and scattergl --- src/traces/scatter/format_labels.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/traces/scatter/format_labels.js b/src/traces/scatter/format_labels.js index a3604c7dd53..92c714f15a1 100644 --- a/src/traces/scatter/format_labels.js +++ b/src/traces/scatter/format_labels.js @@ -9,8 +9,14 @@ 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; + var x = cdi.x; + var y = cdi.y; + + if(xa.type === 'log') x = xa.c2r(x); + if(ya.type === 'log') y = ya.c2r(y); + + labels.xLabel = Axes.tickText(xa, x, true).text; + labels.yLabel = Axes.tickText(ya, y, true).text; return labels; }; From 2326b5b0693484ecf7d248ed6b338eb29fe0c970 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 4 May 2021 12:04:51 -0400 Subject: [PATCH 3/5] fix issue 5585 for bars --- src/traces/bar/plot.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index fdc047eafc0..718aa5b5eaf 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -647,10 +647,14 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) { } function formatLabel(u) { + if(pAxis.type === 'log') u = pAxis.c2r(u); + return tickText(pAxis, u, true).text; } function formatNumber(v) { + if(vAxis.type === 'log') v = vAxis.c2r(v); + return tickText(vAxis, +v, true).text; } From 33e178396ca78ae83a0c3592dbfb54b887ce1bbe Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 4 May 2021 12:33:18 -0400 Subject: [PATCH 4/5] add jasmine tests --- test/jasmine/tests/bar_test.js | 17 +++++++++++++++++ test/jasmine/tests/scatter_test.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index 1d852eb04f0..41d826f93c0 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -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', diff --git a/test/jasmine/tests/scatter_test.js b/test/jasmine/tests/scatter_test.js index 4006d0b640f..80c7ff97e53 100644 --- a/test/jasmine/tests/scatter_test.js +++ b/test/jasmine/tests/scatter_test.js @@ -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', From ca962bc0a6adb687416f332ecbf769d2f215ff9d Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 5 May 2021 14:29:07 -0400 Subject: [PATCH 5/5] use c2l instead of c2r --- src/traces/bar/plot.js | 8 ++------ src/traces/scatter/format_labels.js | 10 ++-------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index 718aa5b5eaf..8923665593d 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -647,15 +647,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) { } function formatLabel(u) { - if(pAxis.type === 'log') u = pAxis.c2r(u); - - return tickText(pAxis, u, true).text; + return tickText(pAxis, pAxis.c2l(u), true).text; } function formatNumber(v) { - if(vAxis.type === 'log') v = vAxis.c2r(v); - - return tickText(vAxis, +v, true).text; + return tickText(vAxis, vAxis.c2l(v), true).text; } var cdi = cd[index]; diff --git a/src/traces/scatter/format_labels.js b/src/traces/scatter/format_labels.js index 92c714f15a1..5908a425466 100644 --- a/src/traces/scatter/format_labels.js +++ b/src/traces/scatter/format_labels.js @@ -9,14 +9,8 @@ module.exports = function formatLabels(cdi, trace, fullLayout) { var xa = Axes.getFromTrace(mockGd, trace, 'x'); var ya = Axes.getFromTrace(mockGd, trace, 'y'); - var x = cdi.x; - var y = cdi.y; - - if(xa.type === 'log') x = xa.c2r(x); - if(ya.type === 'log') y = ya.c2r(y); - - labels.xLabel = Axes.tickText(xa, x, true).text; - labels.yLabel = Axes.tickText(ya, 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; };