Skip to content

Commit 8a242b1

Browse files
committed
Do not override outside when base is set
When bars are in stack or relative mode, 'outside' position should not be overriden when a base is set.
1 parent 3f95f04 commit 8a242b1

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/traces/bar/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
199199
textHeight;
200200

201201
if(textPosition === 'outside') {
202-
if(!isOutmostBar) textPosition = 'inside';
202+
if(!isOutmostBar && !calcBar.hasB) textPosition = 'inside';
203203
}
204204

205205
if(textPosition === 'auto') {

test/jasmine/tests/bar_test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,68 @@ describe('A bar plot', function() {
901901
.then(done);
902902
});
903903

904+
it('Pushes outside text relative bars inside when not outmost', function(done) {
905+
var data = [{
906+
x: [1, 1, 2, 2],
907+
y: [10, 20, 20, 10],
908+
type: 'bar',
909+
text: ['a', 'b', 'c', 'd'],
910+
textposition: ['outside', 'inside', 'outside', 'inside'],
911+
}];
912+
var layout = {barmode: 'relative'};
913+
914+
Plotly.plot(gd, data, layout).then(function() {
915+
var traceNodes = getAllTraceNodes(gd),
916+
barNodes = getAllBarNodes(traceNodes[0]),
917+
foundTextNodes;
918+
919+
for(var i = 0; i < barNodes.length; i++) {
920+
var barNode = barNodes[i],
921+
pathNode = barNode.querySelector('path'),
922+
textNode = barNode.querySelector('text');
923+
if(textNode) {
924+
foundTextNodes = true;
925+
assertTextIsInsidePath(textNode, pathNode);
926+
}
927+
}
928+
929+
expect(foundTextNodes).toBe(true);
930+
})
931+
.catch(failTest)
932+
.then(done);
933+
});
934+
935+
it('does not push text inside when base is set', function(done) {
936+
var data = [{
937+
x: [1, 1, 2, 2],
938+
y: [10, 20, 20, 10],
939+
base: [1, 2, 3, 4],
940+
type: 'bar',
941+
text: ['a', 'b', 'c', 'd'],
942+
textposition: ['outside', 'outside', 'outside', 'outside'],
943+
}];
944+
var layout = {barmode: 'relative'};
945+
946+
Plotly.plot(gd, data, layout).then(function() {
947+
var traceNodes = getAllTraceNodes(gd),
948+
barNodes = getAllBarNodes(traceNodes[0]),
949+
foundTextNodes;
950+
951+
for(var i = 0; i < barNodes.length; i++) {
952+
var barNode = barNodes[i],
953+
pathNode = barNode.querySelector('path'),
954+
textNode = barNode.querySelector('text');
955+
if(textNode) {
956+
foundTextNodes = true;
957+
assertTextIsAbovePath(textNode, pathNode);
958+
}
959+
}
960+
961+
expect(foundTextNodes).toBe(true);
962+
})
963+
.catch(failTest)
964+
.then(done);
965+
});
904966
it('should show bar texts (outside case)', function(done) {
905967
var data = [{
906968
y: [10, -20, 30],

0 commit comments

Comments
 (0)