Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,35 +1123,39 @@ function calcTextinfo(cd, index, xa, ya) {
var final = cdi.v;
var initial = final - delta;

if (hasFlag('initial')) text.push(formatNumber(initial));
if (hasFlag('delta')) text.push(formatNumber(delta));
if (hasFlag('final')) text.push(formatNumber(final));
for (var j = 0; j < parts.length; j++) {
Comment thread
Abineshabee marked this conversation as resolved.
Outdated
var wPart = parts[j].trim();
if (wPart === 'initial') text.push(formatNumber(initial));
else if (wPart === 'delta') text.push(formatNumber(delta));
else if (wPart === 'final') text.push(formatNumber(final));
}
}

if (isFunnel) {
if (hasFlag('value')) text.push(formatNumber(cdi.s));

var nPercent = 0;
if (hasFlag('percent initial')) nPercent++;
if (hasFlag('percent previous')) nPercent++;
if (hasFlag('percent total')) nPercent++;

var hasMultiplePercents = nPercent > 1;

if (hasFlag('percent initial')) {
tx = Lib.formatPercent(cdi.begR);
if (hasMultiplePercents) tx += ' of initial';
text.push(tx);
}
if (hasFlag('percent previous')) {
tx = Lib.formatPercent(cdi.difR);
if (hasMultiplePercents) tx += ' of previous';
text.push(tx);
}
if (hasFlag('percent total')) {
tx = Lib.formatPercent(cdi.sumR);
if (hasMultiplePercents) tx += ' of total';
text.push(tx);
for (var k = 0; k < parts.length; k++) {
var part = parts[k].trim();
if (part === 'value') {
text.push(formatNumber(cdi.s));
} else if (part === 'percent initial') {
tx = Lib.formatPercent(cdi.begR);
if (hasMultiplePercents) tx += ' of initial';
text.push(tx);
} else if (part === 'percent previous') {
tx = Lib.formatPercent(cdi.difR);
if (hasMultiplePercents) tx += ' of previous';
text.push(tx);
} else if (part === 'percent total') {
tx = Lib.formatPercent(cdi.sumR);
if (hasMultiplePercents) tx += ' of total';
text.push(tx);
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/jasmine/tests/funnel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1757,4 +1757,29 @@ describe('funnel uniformtext', function() {
}))
.then(done, done.fail);
});

it('should respect textinfo token order', function() {
var mock = {
data: [{
type: 'funnel',
y: ['Awareness', 'Interest', 'Action'],
x: [1000, 700, 400],
textinfo: 'percent initial+value'
}],
layout: {}
};

return Plotly.newPlot(createGraphDiv(), mock.data, mock.layout)
.then(function(gd) {
var texts = gd.calcdata[0].map(function(d) { return d.tx; });

// percent initial must come BEFORE value
// expected: "100%" before "1000", not "1000" before "100%"
expect(texts[0]).toMatch(/^[\d.]+%/); // starts with percent
expect(texts[1]).toMatch(/^[\d.]+%/);
expect(texts[2]).toMatch(/^[\d.]+%/);
})
.then(destroyGraphDiv);
});

});