Skip to content
Open
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
1 change: 1 addition & 0 deletions draftlogs/7558_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Set `cliponaxis: false` by default for bar traces with `text` and `textposition: 'auto'` or `'outside'`, to prevent text clipping [#7558](https://github.com/plotly/plotly.js/pull/7558)
13 changes: 12 additions & 1 deletion src/traces/bar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ function handleText(traceIn, traceOut, layout, coerce, textposition, opts) {
if(moduleHasSelected) coerce('selected.textfont.color');
if(moduleHasUnselected) coerce('unselected.textfont.color');
if(moduleHasConstrain) coerce('constraintext');
if(moduleHasCliponaxis) coerce('cliponaxis');
if(moduleHasCliponaxis) {
if(traceOut.text && ['auto', 'outside'].includes(textposition)) {
// When `textposition` is `'outside'` (or `auto`), bar labels outside
// the bar are very frequently clipped since text is not included
// in autorange calculations. So we set `cliponaxis` to `false` by default
// in that case to prevent clipping; otherwise we use the normal default
// for `cliponaxis`, which is `true`.
coerce('cliponaxis', false);
} else {
coerce('cliponaxis');
}
}
if(moduleHasTextangle) coerce('textangle');

coerce('texttemplate');
Expand Down
4 changes: 3 additions & 1 deletion src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ module.exports = {
'Determines whether or not markers and text nodes',
'are clipped about the subplot axes.',
'To show markers and text nodes above axis lines and tick labels,',
'make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.'
'make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.',
'Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside*',
'in which case the default is *false*.'
].join(' ')
},

Expand Down
Binary file modified test/image/baselines/zz-pattern_bars-path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,65 @@ describe('Bar.supplyDefaults', function() {
expect(traceOut.insidetextfont.size).toBe(20);
});

it('should set cliponaxis to false when text has value and textposition is outside', function() {
traceIn = {
y: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'outside'
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(false);
});

it('should set cliponaxis to false when text has value and textposition is auto', function() {
traceIn = {
y: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'auto'
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(false);
});

it('should set cliponaxis to false when text has value and textposition is unspecified', function() {
traceIn = {
y: [1, 2, 3],
text: ['A', 'B', 'C'],
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(false);
});

it('should set cliponaxis to default (true) when text is not provided', function() {
traceIn = {
y: [1, 2, 3],
textposition: 'outside'
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(true);
});

it('should set cliponaxis to default (true) when textposition is not outside', function() {
traceIn = {
y: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'inside'
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(true);
});

it('should respect explicit cliponaxis setting even with text and outside position', function() {
traceIn = {
y: [1, 2, 3],
text: ['A', 'B', 'C'],
textposition: 'outside',
cliponaxis: true
};
supplyDefaults(traceIn, traceOut, defaultColor, {});
expect(traceOut.cliponaxis).toBe(true);
});

it('should inherit layout.calendar', function() {
traceIn = {
x: [1, 2, 3],
Expand Down
8 changes: 4 additions & 4 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58647,7 +58647,7 @@
"valType": "string"
},
"cliponaxis": {
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.",
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*. Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside* in which case the default is *false*.",
"dflt": true,
"editType": "plot",
"valType": "boolean"
Expand Down Expand Up @@ -74276,7 +74276,7 @@
"animatable": false,
"attributes": {
"cliponaxis": {
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.",
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*. Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside* in which case the default is *false*.",
"dflt": false,
"editType": "plot",
"valType": "boolean"
Expand Down Expand Up @@ -78753,7 +78753,7 @@
"animatable": false,
"attributes": {
"cliponaxis": {
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.",
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*. Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside* in which case the default is *false*.",
"dflt": false,
"editType": "plot",
"valType": "boolean"
Expand Down Expand Up @@ -81062,7 +81062,7 @@
"valType": "data_array"
},
"cliponaxis": {
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.",
"description": "Determines whether or not markers and text nodes are clipped about the subplot axes. To show markers and text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*. Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside* in which case the default is *false*.",
"dflt": true,
"editType": "plot",
"valType": "boolean"
Expand Down
Loading