Skip to content

Commit 9519d75

Browse files
committed
also set cliponaxis to false when textposition is auto
1 parent 180fecf commit 9519d75

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

draftlogs/7558_fix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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)
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)

src/traces/bar/defaults.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ function handleText(traceIn, traceOut, layout, coerce, textposition, opts) {
149149
if(moduleHasUnselected) coerce('unselected.textfont.color');
150150
if(moduleHasConstrain) coerce('constraintext');
151151
if(moduleHasCliponaxis) {
152-
if(traceOut.text && textposition === 'outside') {
153-
// When `textposition` is `'outside'`, bar labels are very frequently clipped
154-
// since text is not included in autorange calculations.
155-
// So we set `cliponaxis` to `false` by default in that case to prevent clipping;
156-
// otherwise we use the normal default for `cliponaxis`, which is `true`.
152+
if(traceOut.text && ['auto', 'outside'].includes(textposition)) {
153+
// When `textposition` is `'outside'` (or `auto`), bar labels outside
154+
// the bar are very frequently clipped since text is not included
155+
// in autorange calculations. So we set `cliponaxis` to `false` by default
156+
// in that case to prevent clipping; otherwise we use the normal default
157+
// for `cliponaxis`, which is `true`.
157158
coerce('cliponaxis', false);
158159
} else {
159160
coerce('cliponaxis');

src/traces/scatter/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ module.exports = {
363363
'are clipped about the subplot axes.',
364364
'To show markers and text nodes above axis lines and tick labels,',
365365
'make sure to set `xaxis.layer` and `yaxis.layer` to *below traces*.',
366-
'Defaults to *true*, except for bar traces with `textposition` set to *outside*',
366+
'Defaults to *true*, except for bar traces with `textposition` set to *auto* or *outside*',
367367
'in which case the default is *false*.'
368368
].join(' ')
369369
},

test/jasmine/tests/bar_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,25 @@ describe('Bar.supplyDefaults', function() {
227227
expect(traceOut.cliponaxis).toBe(false);
228228
});
229229

230+
it('should set cliponaxis to false when text has value and textposition is auto', function() {
231+
traceIn = {
232+
y: [1, 2, 3],
233+
text: ['A', 'B', 'C'],
234+
textposition: 'auto'
235+
};
236+
supplyDefaults(traceIn, traceOut, defaultColor, {});
237+
expect(traceOut.cliponaxis).toBe(false);
238+
});
239+
240+
it('should set cliponaxis to false when text has value and textposition is unspecified', function() {
241+
traceIn = {
242+
y: [1, 2, 3],
243+
text: ['A', 'B', 'C'],
244+
};
245+
supplyDefaults(traceIn, traceOut, defaultColor, {});
246+
expect(traceOut.cliponaxis).toBe(false);
247+
});
248+
230249
it('should set cliponaxis to default (true) when text is not provided', function() {
231250
traceIn = {
232251
y: [1, 2, 3],

test/plot-schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58647,7 +58647,7 @@
5864758647
"valType": "string"
5864858648
},
5864958649
"cliponaxis": {
58650-
"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*.",
58650+
"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*.",
5865158651
"dflt": true,
5865258652
"editType": "plot",
5865358653
"valType": "boolean"
@@ -74276,7 +74276,7 @@
7427674276
"animatable": false,
7427774277
"attributes": {
7427874278
"cliponaxis": {
74279-
"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*.",
74279+
"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*.",
7428074280
"dflt": false,
7428174281
"editType": "plot",
7428274282
"valType": "boolean"
@@ -78753,7 +78753,7 @@
7875378753
"animatable": false,
7875478754
"attributes": {
7875578755
"cliponaxis": {
78756-
"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*.",
78756+
"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*.",
7875778757
"dflt": false,
7875878758
"editType": "plot",
7875978759
"valType": "boolean"
@@ -81062,7 +81062,7 @@
8106281062
"valType": "data_array"
8106381063
},
8106481064
"cliponaxis": {
81065-
"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*.",
81065+
"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*.",
8106681066
"dflt": true,
8106781067
"editType": "plot",
8106881068
"valType": "boolean"

0 commit comments

Comments
 (0)