Skip to content

Commit e0bde45

Browse files
committed
texttemplate: add customdata variable and 🔒 down with test
1 parent c3e9961 commit e0bde45

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

src/components/drawing/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ drawing.textPointStyle = function(s, trace, gd) {
700700
}
701701

702702
if(template) {
703-
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, d, trace._meta || {});
703+
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, d, trace._meta || {}, {customdata: d.data});
704704
}
705705

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

src/traces/bar/plot.js

+2
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
591591
obj.percenTotalLabel = Lib.formatPercent(cdi.sumR);
592592
}
593593

594+
var customdata = Lib.castOption(trace, cdi.i, 'customdata');
595+
if(customdata) obj.customdata = customdata;
594596
return Lib.texttemplateString(texttemplate, obj, fullLayout._d3locale, obj, trace._meta || {});
595597
}
596598

src/traces/pie/plot.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,8 @@ function formatSliceLabel(gd, pt, cd0) {
980980
percent: pt.v / cd0.vTotal,
981981
percentLabel: helpers.formatPiePercent(pt.v / cd0.vTotal, fullLayout.separators),
982982
color: pt.color,
983-
text: pt.text
983+
text: pt.text,
984+
customdata: Lib.castOption(trace, pt.i, 'customdata')
984985
};
985986
}
986987

src/traces/sunburst/plot.js

+1
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ function formatSliceLabel(pt, trace, fullLayout) {
762762
}
763763
var ptTx = Lib.castOption(trace, cdi.i, 'text');
764764
if(Lib.isValidTextValue(ptTx)) obj.text = ptTx;
765+
obj.customdata = Lib.castOption(trace, cdi.i, 'customdata');
765766
return Lib.texttemplateString(txt, obj, fullLayout._d3locale, obj, trace._meta || {});
766767
}
767768

test/jasmine/assets/check_texttemplate.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
1717
expect(gd._fullData[0].textinfo).toBe(undefined);
1818
});
1919

20+
// Generate customdata
21+
var N = tests[0][1].length;
22+
var customdata = [];
23+
for(var i = 0; i < N; i++) {
24+
customdata.push(Lib.randstr({}));
25+
}
26+
mock[0].customdata = customdata;
27+
tests.push(['%{customdata}', customdata]);
28+
2029
tests.forEach(function(test) {
21-
it('should support textemplate', function(done) {
30+
it('should support texttemplate', function(done) {
2231
var gd = createGraphDiv();
2332
var mockCopy = Lib.extendDeep(mock, {});
2433
mockCopy[0].texttemplate = test[0];

test/jasmine/tests/sunburst_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ describe('Test sunburst interactions edge cases', function() {
12391239
});
12401240
});
12411241

1242-
describe('Test texttemplate:', function() {
1242+
describe('Test sunburst texttemplate:', function() {
12431243
checkTextTemplate([{
12441244
type: 'sunburst',
12451245
labels: ['Eve', 'Cain', 'Seth', 'Enos', 'Esther'],

0 commit comments

Comments
 (0)