Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 04503ea

Browse filesBrowse files
committed
fix texttemplate formatting for scatter{polar,geo,ternary,carpet}
... by calling `_module.formatLabels` during Drawing.textPointStyle. This way, prefixes and suffixes render correctly in texttemplate text and minus signs now show up correctly.
1 parent 76d8a11 commit 04503ea
Copy full SHA for 04503ea

File tree

6 files changed

+73
-10
lines changed
Filter options

6 files changed

+73
-10
lines changed

‎src/components/drawing/index.js

Copy file name to clipboardExpand all lines: src/components/drawing/index.js
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;
2626

2727
var subTypes = require('../../traces/scatter/subtypes');
2828
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
29+
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
2930

3031
var drawing = module.exports = {};
31-
var appendArrayPointValue = require('../fx/helpers').appendArrayPointValue;
3232

3333
// -----------------------------------------------------
3434
// styling functions for plot elements
@@ -684,27 +684,32 @@ drawing.textPointStyle = function(s, trace, gd) {
684684
if(!s.size()) return;
685685

686686
var selectedTextColorFn;
687-
688687
if(trace.selectedpoints) {
689688
var fns = drawing.makeSelectedTextStyleFns(trace);
690689
selectedTextColorFn = fns.selectedTextColorFn;
691690
}
692691

693-
var template = trace.texttemplate;
692+
var texttemplate = trace.texttemplate;
693+
var fullLayout = gd._fullLayout;
694694

695695
s.each(function(d) {
696696
var p = d3.select(this);
697-
var text = Lib.extractOption(d, trace, template ? 'txt' : 'tx', template ? 'texttemplate' : 'text');
697+
698+
var text = texttemplate ?
699+
Lib.extractOption(d, trace, 'txt', 'texttemplate') :
700+
Lib.extractOption(d, trace, 'tx', 'text');
698701

699702
if(!text && text !== 0) {
700703
p.remove();
701704
return;
702705
}
703706

704-
if(template) {
705-
var pt = {};
706-
appendArrayPointValue(pt, trace, d.i);
707-
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, pt, d, trace._meta || {});
707+
if(texttemplate) {
708+
var labels = trace._module.formatLabels ? trace._module.formatLabels(d, trace, fullLayout) : {};
709+
var pointValues = {};
710+
appendArrayPointValue(pointValues, trace, d.i);
711+
var meta = trace._meta || {};
712+
text = Lib.texttemplateString(text, labels, fullLayout._d3locale, pointValues, d, meta);
708713
}
709714

710715
var pos = d.tp || trace.textposition;

‎test/jasmine/tests/carpet_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/carpet_test.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ describe('scattercarpet texttemplates', function() {
730730
'b': [1, 2, 3],
731731
'y': [[1, 2.2, 3], [1.5, 2.7, 3.5], [1.7, 2.9, 3.7]]
732732
}], 'g.textpoint', [
733-
['%{text}: %{a:0.1f}, %{b:0.1f}', ['A: 0.1, 1.5', 'B: 0.1, 1.5', 'C: 0.3, 1.5']]
733+
['%{text}: %{a:0.1f}, %{b:0.1f}', ['A: 0.1, 1.5', 'B: 0.1, 1.5', 'C: 0.3, 1.5']],
734+
['%{y}', ['1.000', '1.000', '2.200']]
734735
]);
735736
});
736737
describe('contourcarpet plotting & editing', function() {

‎test/jasmine/tests/scatter_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scatter_test.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,9 @@ describe('end-to-end scatter tests', function() {
12391239
.catch(failTest)
12401240
.then(done);
12411241
});
1242+
});
12421243

1244+
describe('Text templates on scatter traces:', function() {
12431245
checkTextTemplate([{
12441246
type: 'scatter',
12451247
mode: 'markers+lines+text',
@@ -1249,6 +1251,21 @@ describe('end-to-end scatter tests', function() {
12491251
['%{y}', ['1', '5', '3', '2']],
12501252
[['%{y}', '%{x}-%{y}'], ['1', '1-5', '', '']]
12511253
]);
1254+
1255+
checkTextTemplate({
1256+
data: [{
1257+
type: 'scatter',
1258+
mode: 'text',
1259+
x: ['a', 'b'],
1260+
y: ['1000', '1200']
1261+
}],
1262+
layout: {
1263+
xaxis: { tickprefix: '*', ticksuffix: '*' },
1264+
yaxis: { tickprefix: '$', ticksuffix: ' !', tickformat: '.2f'}
1265+
}
1266+
}, '.textpoint', [
1267+
['%{x} is %{y}', ['*a* is $1000.00 !', '*b* is $1200.00 !']]
1268+
]);
12521269
});
12531270

12541271
describe('stacked area', function() {

‎test/jasmine/tests/scattergeo_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scattergeo_test.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ describe('Test scattergeo texttemplate:', function() {
446446
'lat': [45.5, 43.4, 49.13],
447447
'text': ['Montreal', 'Toronto', 'Vancouver']
448448
}], '.scattergeo text', [
449-
['%{text}: %{lon}, %{lat}', ['Montreal: -73.57, 45.5', 'Toronto: -79.24, 43.4', 'Vancouver: -123.06, 49.13']]
449+
['%{text}: %{lon}, %{lat}', ['Montreal: 73.57, 45.5', 'Toronto: 79.24, 43.4', 'Vancouver: 123.06, 49.13']]
450450
]);
451451

452452
checkTextTemplate([{

‎test/jasmine/tests/scatterpolar_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scatterpolar_test.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,21 @@ describe('Test scatterpolar texttemplate:', function() {
212212
['%{text}: (%{r:0.2f}, %{theta:0.1f})', ['A: (1.00, 0.0)', 'B: (0.50, 90.0)', 'C: (1.00, 180.0)']],
213213
[['', 'b%{theta:0.2f}', '%{theta:0.2f}'], ['', 'b90.00', '180.00']]
214214
]);
215+
216+
checkTextTemplate({
217+
data: [{
218+
type: 'scatterpolar',
219+
mode: 'text',
220+
theta: ['a', 'b'],
221+
r: ['1000', '1200']
222+
}],
223+
layout: {
224+
polar: {
225+
radialaxis: { tickprefix: '$', ticksuffix: ' !', tickformat: '.2f'},
226+
angularaxis: { tickprefix: '*', ticksuffix: '*' }
227+
}
228+
}
229+
}, '.textpoint', [
230+
['%{theta} is %{r}', ['*a* is $1000.00 !', '*b* is $1200.00 !']]
231+
]);
215232
});

‎test/jasmine/tests/scatterternary_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scatterternary_test.js
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,27 @@ describe('Test scatterternary texttemplate:', function() {
567567
}], 'g.textpoint', [
568568
['%{text} (%{a:.1f}, %{b:.1f}, %{c:.1f})', ['A (3.0, 2.0, 5.0)', 'B (2.0, 5.0, 2.0)', 'C (5.0, 2.0, 2.0)']]
569569
]);
570+
571+
checkTextTemplate({
572+
data: [{
573+
type: 'scatterternary',
574+
mode: 'text',
575+
a: [3, 2, 5],
576+
b: [2, 5, 2],
577+
c: [5, 2, 2]
578+
}],
579+
layout: {
580+
ternary: {
581+
aaxis: { tickprefix: '*', ticksuffix: '*' },
582+
baxis: { tickprefix: '$', ticksuffix: ' !', tickformat: '.2f'},
583+
caxis: { tickprefix: '#', ticksuffix: '^'}
584+
}
585+
}
586+
}, '.textpoint', [
587+
['%{a} is %{b} is %{c}', [
588+
'*0.3* is $0.20 ! is #0.5^',
589+
'*0.2222222* is $0.56 ! is #0.2222222^',
590+
'*0.5555556* is $0.22 ! is #0.2222222^'
591+
]]
592+
]);
570593
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.