Skip to content

Commit

Permalink
texttemplate: add customdata variable and 🔒 down with test
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Jul 23, 2019
1 parent c3e9961 commit e0bde45
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ drawing.textPointStyle = function(s, trace, gd) {
}

if(template) {
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, d, trace._meta || {});
text = Lib.texttemplateString(text, {}, gd._fullLayout._d3locale, d, trace._meta || {}, {customdata: d.data});
}

var pos = d.tp || trace.textposition;
Expand Down
2 changes: 2 additions & 0 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
obj.percenTotalLabel = Lib.formatPercent(cdi.sumR);
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ function formatSliceLabel(gd, pt, cd0) {
percent: pt.v / cd0.vTotal,
percentLabel: helpers.formatPiePercent(pt.v / cd0.vTotal, fullLayout.separators),
color: pt.color,
text: pt.text
text: pt.text,
customdata: Lib.castOption(trace, pt.i, 'customdata')
};
}

Expand Down
1 change: 1 addition & 0 deletions src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ function formatSliceLabel(pt, trace, fullLayout) {
}
var ptTx = Lib.castOption(trace, cdi.i, 'text');
if(Lib.isValidTextValue(ptTx)) obj.text = ptTx;
obj.customdata = Lib.castOption(trace, cdi.i, 'customdata');
return Lib.texttemplateString(txt, obj, fullLayout._d3locale, obj, trace._meta || {});
}

Expand Down
11 changes: 10 additions & 1 deletion test/jasmine/assets/check_texttemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ module.exports = function checkTextTemplate(mock, selector, tests) {
expect(gd._fullData[0].textinfo).toBe(undefined);
});

// Generate customdata
var N = tests[0][1].length;
var customdata = [];
for(var i = 0; i < N; i++) {
customdata.push(Lib.randstr({}));
}
mock[0].customdata = customdata;
tests.push(['%{customdata}', customdata]);

tests.forEach(function(test) {
it('should support textemplate', function(done) {
it('should support texttemplate', function(done) {
var gd = createGraphDiv();
var mockCopy = Lib.extendDeep(mock, {});
mockCopy[0].texttemplate = test[0];
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/sunburst_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ describe('Test sunburst interactions edge cases', function() {
});
});

describe('Test texttemplate:', function() {
describe('Test sunburst texttemplate:', function() {
checkTextTemplate([{
type: 'sunburst',
labels: ['Eve', 'Cain', 'Seth', 'Enos', 'Esther'],
Expand Down

0 comments on commit e0bde45

Please sign in to comment.