Skip to content

Don't override outside when base is set #3156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ module.exports = {
'*inside* positions `text` inside, next to the bar end',
'(rotated and scaled if needed).',
'*outside* positions `text` outside, next to the bar end',
'(scaled if needed).',
'*auto* positions `text` inside or outside',
'so that `text` size is maximized.'
'(scaled if needed), unless there is another bar stacked on',
'this one, then the text gets pushed inside.',
'*auto* tries to position `text` inside the bar, but if',
'the bar is too small and no bar is stacked on this one',
'the text is moved outside.'
].join(' ')
},

Expand Down
2 changes: 1 addition & 1 deletion src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
textHeight;

if(textPosition === 'outside') {
if(!isOutmostBar) textPosition = 'inside';
if(!isOutmostBar && !calcBar.hasB) textPosition = 'inside';
}

if(textPosition === 'auto') {
Expand Down
72 changes: 72 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,78 @@ describe('A bar plot', function() {
.then(done);
});

it('Pushes outside text relative bars inside when not outmost', function(done) {
var data = [{
x: [1, 2],
y: [20, 10],
type: 'bar',
text: ['a', 'b'],
textposition: 'outside',
}, {
x: [1, 2],
y: [20, 10],
type: 'bar',
text: ['c', 'd']
}];
var layout = {barmode: 'relative'};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
barNodes = getAllBarNodes(traceNodes[0]),
foundTextNodes;

for(var i = 0; i < barNodes.length; i++) {
var barNode = barNodes[i],
pathNode = barNode.querySelector('path'),
textNode = barNode.querySelector('text');
if(textNode) {
foundTextNodes = true;
assertTextIsInsidePath(textNode, pathNode);
}
}

expect(foundTextNodes).toBe(true);
})
.catch(failTest)
.then(done);
});

it('does not push text inside when base is set', function(done) {
var data = [{
x: [1, 2],
y: [20, 10],
base: [1, 2],
type: 'bar',
text: ['a', 'b'],
textposition: 'outside',
}, {
x: [3, 4],
y: [30, 40],
type: 'bar',
text: ['c', 'd']
}];
var layout = {barmode: 'relative'};

Plotly.plot(gd, data, layout).then(function() {
var traceNodes = getAllTraceNodes(gd),
barNodes = getAllBarNodes(traceNodes[0]),
foundTextNodes;

for(var i = 0; i < barNodes.length; i++) {
var barNode = barNodes[i],
pathNode = barNode.querySelector('path'),
textNode = barNode.querySelector('text');
if(textNode) {
foundTextNodes = true;
assertTextIsAbovePath(textNode, pathNode);
}
}

expect(foundTextNodes).toBe(true);
})
.catch(failTest)
.then(done);
});
it('should show bar texts (outside case)', function(done) {
var data = [{
y: [10, -20, 30],
Expand Down