Skip to content

Commit 0b516f7

Browse files
committed
texttemplate: use result of appendArrayPointValue as available variables
1 parent 902d2d3 commit 0b516f7

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

src/components/drawing/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var subTypes = require('../../traces/scatter/subtypes');
2828
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
2929

3030
var drawing = module.exports = {};
31+
var appendArrayPointValue = require('../fx/helpers').appendArrayPointValue;
3132

3233
// -----------------------------------------------------
3334
// styling functions for plot elements
@@ -700,10 +701,9 @@ drawing.textPointStyle = function(s, trace, gd) {
700701
}
701702

702703
if(template) {
703-
var extra = {};
704-
if(d.tx) extra.text = d.tx;
705-
if(d.data) extra.customdata = d.data;
706-
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, d, trace._meta || {}, extra);
704+
var pt = {};
705+
appendArrayPointValue(pt, trace, d.i);
706+
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, pt, d, trace._meta || {});
707707
}
708708

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

src/traces/bar/plot.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var attributes = require('./attributes');
2626
var attributeText = attributes.text;
2727
var attributeTextPosition = attributes.textposition;
2828

29+
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
30+
2931
// padding in pixels around text
3032
var TEXTPAD = 3;
3133

@@ -567,8 +569,8 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
567569
obj.value = cdi.s;
568570
obj.valueLabel = formatNumber(cdi.s);
569571

570-
obj.x = cdi.x;
571-
obj.y = cdi.y;
572+
var pt = {};
573+
appendArrayPointValue(pt, trace, cdi.i);
572574

573575
if(isWaterfall) {
574576
obj.delta = +cdi.rawS || cdi.s;
@@ -593,7 +595,7 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
593595

594596
var customdata = Lib.castOption(trace, cdi.i, 'customdata');
595597
if(customdata) obj.customdata = customdata;
596-
return Lib.texttemplateString(texttemplate, obj, fullLayout._d3locale, obj, trace._meta || {});
598+
return Lib.texttemplateString(texttemplate, obj, fullLayout._d3locale, pt, obj, trace._meta || {});
597599
}
598600

599601
// TODO: calcTextinfo should build a texttemplate pass it to calcTexttemplate()

test/jasmine/tests/bar_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,17 @@ describe('A bar plot', function() {
11081108
[['%{y}', '%{value}', '%{text}'], ['1', '5', 'C']]
11091109
]);
11101110

1111+
checkTextTemplate([{
1112+
type: 'bar',
1113+
textposition: 'outside',
1114+
x: ['2019-01-01', '2019-02-01'],
1115+
y: [1, 2],
1116+
hovertemplate: '%{x}',
1117+
texttemplate: '%{x}'
1118+
}], 'text.bartext', [
1119+
['%{x}', ['2019-01-01', '2019-02-01']]
1120+
]);
1121+
11111122
it('should show bar texts (inside case)', function(done) {
11121123
var data = [{
11131124
y: [10, 20, 30],

test/jasmine/tests/scatterpolar_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('Test scatterpolar texttemplate:', function() {
209209
'r': [1, 0.5, 1],
210210
'theta': [0, 90, 180],
211211
}], 'g.textpoint', [
212-
['%{text}: (%{r:0.2f}, %{theta:0.2f})', ['A: (1.00, 0.00)', 'B: (0.50, 1.57)', 'C: (1.00, 3.14)']],
213-
[['', '', '%{theta:0.2f}'], ['', '', '3.14']]
212+
['%{text}: (%{r:0.2f}, %{theta:0.1f})', ['A: (1.00, 0.0)', 'B: (0.50, 90.0)', 'C: (1.00, 180.0)']],
213+
[['', 'b%{theta:0.2f}', '%{theta:0.2f}'], ['', 'b90.00', '180.00']]
214214
]);
215215
});

test/jasmine/tests/scatterternary_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,6 @@ describe('Test scattergeo texttemplate:', function() {
565565
'mode': 'markers+text',
566566
'text': ['A', 'B', 'C']
567567
}], 'g.textpoint', [
568-
['%{text} (%{a:.2f}, %{b:.2f}, %{c:.2f})', ['A (0.30, 0.20, 0.50)', 'B (0.22, 0.56, 0.22)', 'C (0.56, 0.22, 0.22)']]
568+
['%{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
]);
570570
});

0 commit comments

Comments
 (0)