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
Prev Previous commit
also set cliponaxis to false when textposition is auto
  • Loading branch information
emilykl committed Sep 16, 2025
commit 9519d75861782ecd0c331a0fc008e221f99f44bc
2 changes: 1 addition & 1 deletion draftlogs/7558_fix.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Set `cliponaxis: false` by default for bar traces with `text` and `textposition: 'outside'`, to prevent text clipping [#7558](https://github.com/plotly/plotly.js/pull/7558)
- 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)
11 changes: 6 additions & 5 deletions src/traces/bar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ function handleText(traceIn, traceOut, layout, coerce, textposition, opts) {
if(moduleHasUnselected) coerce('unselected.textfont.color');
if(moduleHasConstrain) coerce('constraintext');
if(moduleHasCliponaxis) {
if(traceOut.text && textposition === 'outside') {
// When `textposition` is `'outside'`, bar labels 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`.
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');
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ module.exports = {
'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 *outside*',
'Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside*',
'in which case the default is *false*.'
].join(' ')
},
Expand Down
19 changes: 19 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ describe('Bar.supplyDefaults', function() {
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],
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*. Defaults to *true*, except for bar traces with `textposition` set to *outside* in which case the default is *false*.",
"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*. Defaults to *true*, except for bar traces with `textposition` set to *outside* in which case the default is *false*.",
"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*. Defaults to *true*, except for bar traces with `textposition` set to *outside* in which case the default is *false*.",
"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*. Defaults to *true*, except for bar traces with `textposition` set to *outside* in which case the default is *false*.",
"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