Skip to content

Commit feb2f38

Browse files
committed
standardize default yanchor behavior between shape and draw_newshape
1 parent c20370a commit feb2f38

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/components/shapes/defaults.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
1515
});
1616
};
1717

18-
function dfltLabelYanchor(shapeType, labelTextPosition) {
18+
function dfltLabelYanchor(isLine, labelTextPosition) {
1919
var dfltYanchor;
20-
if(shapeType === 'line') {
20+
if(isLine) {
2121
dfltYanchor = 'bottom';
2222
} else {
2323
if(labelTextPosition.indexOf('top') !== -1) {
@@ -134,21 +134,13 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
134134
}
135135

136136
// Label options
137+
var isLine = shapeType === 'line';
137138
coerce('label.text');
138-
coerce('label.textangle', shapeType === 'line' ? 'auto' : 0);
139-
<<<<<<< HEAD
140-
var labelTextPosition = coerce(
141-
'label.textposition',
142-
shapeType === 'line' ? 'middle' : 'middle center'
143-
);
139+
coerce('label.textangle', isLine ? 'auto' : 0);
140+
var labelTextPosition = coerce('label.textposition', isLine ? 'middle' : 'middle center');
144141
coerce('label.xanchor');
145142
// Default yanchor value depends on shape type and label textposition
146-
coerce('label.yanchor', dfltLabelYanchor(shapeType, labelTextPosition));
147-
=======
148-
coerce('label.textposition', shapeType === 'line' ? 'middle' : 'middle center');
149-
coerce('label.xanchor');
150-
coerce('label.yanchor');
151-
>>>>>>> dfb608eb8a3a7a139b2f418edbc9e74c96782091
143+
coerce('label.yanchor', dfltLabelYanchor(isLine, labelTextPosition));
152144
coerce('label.padding');
153145
Lib.coerceFont(coerce, 'label.font', fullLayout.font);
154146
}

src/components/shapes/draw_newshape/defaults.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
var Color = require('../../color');
44
var Lib = require('../../../lib');
55

6+
7+
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;
21+
}
22+
623
module.exports = function supplyDrawNewShapeDefaults(layoutIn, layoutOut, coerce) {
724
coerce('newshape.drawdirection');
825
coerce('newshape.layer');
@@ -19,9 +36,9 @@ module.exports = function supplyDrawNewShapeDefaults(layoutIn, layoutOut, coerce
1936
var isLine = layoutIn.dragmode === 'drawline';
2037
coerce('newshape.label.text');
2138
coerce('newshape.label.textangle', isLine ? 'auto' : 0);
22-
coerce('newshape.label.textposition', isLine ? 'middle' : 'middle center');
39+
var labelTextPosition = coerce('newshape.label.textposition', isLine ? 'middle' : 'middle center');
2340
coerce('newshape.label.xanchor');
24-
coerce('newshape.label.yanchor');
41+
coerce('newshape.label.yanchor', dfltLabelYanchor(isLine, labelTextPosition));
2542
coerce('newshape.label.padding');
2643
Lib.coerceFont(coerce, 'newshape.label.font', layoutOut.font);
2744

0 commit comments

Comments
 (0)