Skip to content

Commit c703c11

Browse files
committed
simplify dfltYanchor implementation
1 parent d113bcf commit c703c11

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/components/shapes/defaults.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
1616
};
1717

1818
function dfltLabelYanchor(isLine, labelTextPosition) {
19-
var dfltYanchor;
20-
if(isLine) {
21-
dfltYanchor = 'bottom';
22-
} else {
23-
if(labelTextPosition.indexOf('top') !== -1) {
24-
dfltYanchor = 'top';
25-
} else if(labelTextPosition.indexOf('bottom') !== -1) {
26-
dfltYanchor = 'bottom';
27-
} else {
28-
dfltYanchor = 'middle';
29-
}
30-
}
31-
return dfltYanchor;
19+
// If shape is a line, default y-anchor is 'bottom' (so that text is above line by default)
20+
// Otherwise, default y-anchor is equal to y-component of `textposition`
21+
// (so that text is positioned inside shape bounding box by default)
22+
return isLine ? 'bottom' :
23+
labelTextPosition.indexOf('top') !== -1 ? 'top' :
24+
labelTextPosition.indexOf('bottom') !== -1 ? 'bottom' : 'middle';
3225
}
3326

3427
function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {

src/components/shapes/draw_newshape/defaults.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ var Lib = require('../../../lib');
55

66

77
function dfltLabelYanchor(isLine, labelTextPosition) {
8-
var dfltYanchor;
9-
if(isLine) {
10-
dfltYanchor = 'bottom';
11-
} else {
12-
if(labelTextPosition.indexOf('top') !== -1) {
13-
dfltYanchor = 'top';
14-
} else if(labelTextPosition.indexOf('bottom') !== -1) {
15-
dfltYanchor = 'bottom';
16-
} else {
17-
dfltYanchor = 'middle';
18-
}
19-
}
20-
return dfltYanchor;
8+
// If shape is a line, default y-anchor is 'bottom' (so that text is above line by default)
9+
// Otherwise, default y-anchor is equal to y-component of `textposition`
10+
// (so that text is positioned inside shape bounding box by default)
11+
return isLine ? 'bottom' :
12+
labelTextPosition.indexOf('top') !== -1 ? 'top' :
13+
labelTextPosition.indexOf('bottom') !== -1 ? 'bottom' : 'middle';
2114
}
2215

2316
module.exports = function supplyDrawNewShapeDefaults(layoutIn, layoutOut, coerce) {

0 commit comments

Comments
 (0)