Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fdcdd22

Browse filesBrowse files
authored
Merge pull request #3156 from eivindjahren/outside_inside_not_when_hasb
Don't override outside when base is set
2 parents c3a0118 + 706465b commit fdcdd22
Copy full SHA for fdcdd22

File tree

Expand file treeCollapse file tree

3 files changed

+78
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+78
-4
lines changed

‎src/traces/bar/attributes.js

Copy file name to clipboardExpand all lines: src/traces/bar/attributes.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ module.exports = {
7272
'*inside* positions `text` inside, next to the bar end',
7373
'(rotated and scaled if needed).',
7474
'*outside* positions `text` outside, next to the bar end',
75-
'(scaled if needed).',
76-
'*auto* positions `text` inside or outside',
77-
'so that `text` size is maximized.'
75+
'(scaled if needed), unless there is another bar stacked on',
76+
'this one, then the text gets pushed inside.',
77+
'*auto* tries to position `text` inside the bar, but if',
78+
'the bar is too small and no bar is stacked on this one',
79+
'the text is moved outside.'
7880
].join(' ')
7981
},
8082

‎src/traces/bar/plot.js

Copy file name to clipboardExpand all lines: src/traces/bar/plot.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
198198
textHeight;
199199

200200
if(textPosition === 'outside') {
201-
if(!isOutmostBar) textPosition = 'inside';
201+
if(!isOutmostBar && !calcBar.hasB) textPosition = 'inside';
202202
}
203203

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

‎test/jasmine/tests/bar_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/bar_test.js
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,78 @@ describe('A bar plot', function() {
971971
.then(done);
972972
});
973973

974+
it('Pushes outside text relative bars inside when not outmost', function(done) {
975+
var data = [{
976+
x: [1, 2],
977+
y: [20, 10],
978+
type: 'bar',
979+
text: ['a', 'b'],
980+
textposition: 'outside',
981+
}, {
982+
x: [1, 2],
983+
y: [20, 10],
984+
type: 'bar',
985+
text: ['c', 'd']
986+
}];
987+
var layout = {barmode: 'relative'};
988+
989+
Plotly.plot(gd, data, layout).then(function() {
990+
var traceNodes = getAllTraceNodes(gd),
991+
barNodes = getAllBarNodes(traceNodes[0]),
992+
foundTextNodes;
993+
994+
for(var i = 0; i < barNodes.length; i++) {
995+
var barNode = barNodes[i],
996+
pathNode = barNode.querySelector('path'),
997+
textNode = barNode.querySelector('text');
998+
if(textNode) {
999+
foundTextNodes = true;
1000+
assertTextIsInsidePath(textNode, pathNode);
1001+
}
1002+
}
1003+
1004+
expect(foundTextNodes).toBe(true);
1005+
})
1006+
.catch(failTest)
1007+
.then(done);
1008+
});
1009+
1010+
it('does not push text inside when base is set', function(done) {
1011+
var data = [{
1012+
x: [1, 2],
1013+
y: [20, 10],
1014+
base: [1, 2],
1015+
type: 'bar',
1016+
text: ['a', 'b'],
1017+
textposition: 'outside',
1018+
}, {
1019+
x: [3, 4],
1020+
y: [30, 40],
1021+
type: 'bar',
1022+
text: ['c', 'd']
1023+
}];
1024+
var layout = {barmode: 'relative'};
1025+
1026+
Plotly.plot(gd, data, layout).then(function() {
1027+
var traceNodes = getAllTraceNodes(gd),
1028+
barNodes = getAllBarNodes(traceNodes[0]),
1029+
foundTextNodes;
1030+
1031+
for(var i = 0; i < barNodes.length; i++) {
1032+
var barNode = barNodes[i],
1033+
pathNode = barNode.querySelector('path'),
1034+
textNode = barNode.querySelector('text');
1035+
if(textNode) {
1036+
foundTextNodes = true;
1037+
assertTextIsAbovePath(textNode, pathNode);
1038+
}
1039+
}
1040+
1041+
expect(foundTextNodes).toBe(true);
1042+
})
1043+
.catch(failTest)
1044+
.then(done);
1045+
});
9741046
it('should show bar texts (outside case)', function(done) {
9751047
var data = [{
9761048
y: [10, -20, 30],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.