Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d943619

Browse files
committed
mv get(X|Y)anchor to Lib
1 parent 43c4e0d commit d943619

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

src/components/legend/draw.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ module.exports = function draw(gd) {
102102
var gs = fullLayout._size;
103103
var bw = opts.borderwidth;
104104

105-
var lx = gs.l + gs.w * opts.x - FROM_TL[getXanchor(opts)] * opts._width;
106-
var ly = gs.t + gs.h * (1 - opts.y) - FROM_TL[getYanchor(opts)] * opts._effHeight;
105+
var lx = gs.l + gs.w * opts.x - FROM_TL[Lib.getXanchor(opts)] * opts._width;
106+
var ly = gs.t + gs.h * (1 - opts.y) - FROM_TL[Lib.getYanchor(opts)] * opts._effHeight;
107107

108108
if(fullLayout.margin.autoexpand) {
109109
var lx0 = lx;
@@ -486,7 +486,7 @@ function computeLegendDimensions(gd, groups, traces) {
486486
var itemGap = constants.itemGap;
487487
var endPad = 2 * (bw + itemGap);
488488

489-
var yanchor = getYanchor(opts);
489+
var yanchor = Lib.getYanchor(opts);
490490
var isBelowPlotArea = opts.y < 0 || (opts.y === 0 && yanchor === 'top');
491491
var isAbovePlotArea = opts.y > 1 || (opts.y === 1 && yanchor === 'bottom');
492492

@@ -520,7 +520,7 @@ function computeLegendDimensions(gd, groups, traces) {
520520
opts._height += (opts._lgroupsLength - 1) * opts.tracegroupgap;
521521
}
522522
} else {
523-
var xanchor = getXanchor(opts);
523+
var xanchor = Lib.getXanchor(opts);
524524
var isLeftOfPlotArea = opts.x < 0 || (opts.x === 0 && xanchor === 'right');
525525
var isRightOfPlotArea = opts.x > 1 || (opts.x === 1 && xanchor === 'left');
526526
var isBeyondPlotAreaY = isAbovePlotArea || isBelowPlotArea;
@@ -633,8 +633,8 @@ function computeLegendDimensions(gd, groups, traces) {
633633
function expandMargin(gd) {
634634
var fullLayout = gd._fullLayout;
635635
var opts = fullLayout.legend;
636-
var xanchor = getXanchor(opts);
637-
var yanchor = getYanchor(opts);
636+
var xanchor = Lib.getXanchor(opts);
637+
var yanchor = Lib.getYanchor(opts);
638638

639639
return Plots.autoMargin(gd, 'legend', {
640640
x: opts.x,
@@ -645,15 +645,3 @@ function expandMargin(gd) {
645645
t: opts._effHeight * (FROM_TL[yanchor])
646646
});
647647
}
648-
649-
function getXanchor(opts) {
650-
return Lib.isRightAnchor(opts) ? 'right' :
651-
Lib.isCenterAnchor(opts) ? 'center' :
652-
'left';
653-
}
654-
655-
function getYanchor(opts) {
656-
return Lib.isBottomAnchor(opts) ? 'bottom' :
657-
Lib.isMiddleAnchor(opts) ? 'middle' :
658-
'top';
659-
}

src/lib/anchor_utils.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

12-
1311
/**
1412
* Determine the position anchor property of x/y xanchor/yanchor components.
1513
*
@@ -18,45 +16,67 @@
1816
* - values > 2/3 align the right at that fraction.
1917
*/
2018

21-
22-
exports.isLeftAnchor = function isLeftAnchor(opts) {
19+
function isLeftAnchor(opts) {
2320
return (
2421
opts.xanchor === 'left' ||
2522
(opts.xanchor === 'auto' && opts.x <= 1 / 3)
2623
);
27-
};
24+
}
2825

29-
exports.isCenterAnchor = function isCenterAnchor(opts) {
26+
function isCenterAnchor(opts) {
3027
return (
3128
opts.xanchor === 'center' ||
3229
(opts.xanchor === 'auto' && opts.x > 1 / 3 && opts.x < 2 / 3)
3330
);
34-
};
31+
}
3532

36-
exports.isRightAnchor = function isRightAnchor(opts) {
33+
function isRightAnchor(opts) {
3734
return (
3835
opts.xanchor === 'right' ||
3936
(opts.xanchor === 'auto' && opts.x >= 2 / 3)
4037
);
41-
};
38+
}
4239

43-
exports.isTopAnchor = function isTopAnchor(opts) {
40+
function isTopAnchor(opts) {
4441
return (
4542
opts.yanchor === 'top' ||
4643
(opts.yanchor === 'auto' && opts.y >= 2 / 3)
4744
);
48-
};
45+
}
4946

50-
exports.isMiddleAnchor = function isMiddleAnchor(opts) {
47+
function isMiddleAnchor(opts) {
5148
return (
5249
opts.yanchor === 'middle' ||
5350
(opts.yanchor === 'auto' && opts.y > 1 / 3 && opts.y < 2 / 3)
5451
);
55-
};
52+
}
5653

57-
exports.isBottomAnchor = function isBottomAnchor(opts) {
54+
function isBottomAnchor(opts) {
5855
return (
5956
opts.yanchor === 'bottom' ||
6057
(opts.yanchor === 'auto' && opts.y <= 1 / 3)
6158
);
59+
}
60+
61+
function getXanchor(opts) {
62+
return isRightAnchor(opts) ? 'right' :
63+
isCenterAnchor(opts) ? 'center' :
64+
'left';
65+
}
66+
67+
function getYanchor(opts) {
68+
return isBottomAnchor(opts) ? 'bottom' :
69+
isMiddleAnchor(opts) ? 'middle' :
70+
'top';
71+
}
72+
73+
module.exports = {
74+
isLeftAnchor: isLeftAnchor,
75+
isCenterAnchor: isCenterAnchor,
76+
isRightAnchor: isRightAnchor,
77+
getXanchor: getXanchor,
78+
isTopAnchor: isTopAnchor,
79+
isMiddleAnchor: isMiddleAnchor,
80+
isBottomAnchor: isBottomAnchor,
81+
getYanchor: getYanchor
6282
};

src/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ var anchorUtils = require('./anchor_utils');
106106
lib.isLeftAnchor = anchorUtils.isLeftAnchor;
107107
lib.isCenterAnchor = anchorUtils.isCenterAnchor;
108108
lib.isRightAnchor = anchorUtils.isRightAnchor;
109+
lib.getXanchor = anchorUtils.getXanchor;
109110
lib.isTopAnchor = anchorUtils.isTopAnchor;
110111
lib.isMiddleAnchor = anchorUtils.isMiddleAnchor;
111112
lib.isBottomAnchor = anchorUtils.isBottomAnchor;
113+
lib.getYanchor = anchorUtils.getYanchor;
112114

113115
var geom2dModule = require('./geometry2d');
114116
lib.segmentsIntersect = geom2dModule.segmentsIntersect;

0 commit comments

Comments
 (0)