Skip to content

Commit cf26237

Browse files
refactor of the push filtering function
1 parent 9dfdb91 commit cf26237

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

draftlogs/6193_add.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Add new options ('width', 'height', 'left', 'right', 'top', 'bottom') for the automargin property [[#6193](https://github.com/plotly/plotly.js/pull/6193)].
1+
- Add flaglist options including "left", "right", "top", "bottom", "width" and "height" to control the direction of `automargin` on cartesian axes [[#6193](https://github.com/plotly/plotly.js/pull/6193)]

src/plots/cartesian/axes.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ var GRID_PATH = { K: 'gridline', L: 'path' };
3939
var MINORGRID_PATH = { K: 'minor-gridline', L: 'path' };
4040
var TICK_PATH = { K: 'tick', L: 'path' };
4141
var TICK_TEXT = { K: 'tick', L: 'text' };
42+
var MARGIN_MAPPING = {
43+
width: ['x', 'r', 'l', 'xl', 'xr'],
44+
height: ['y', 't', 'b', 'yt', 'yb'],
45+
right: ['r', 'xr'],
46+
left: ['l', 'xl'],
47+
top: ['t', 'yt'],
48+
bottom: ['b', 'yb']
49+
};
4250

4351
var alignmentConstants = require('../../constants/alignment');
4452
var MID_SHIFT = alignmentConstants.MID_SHIFT;
@@ -2622,7 +2630,9 @@ axes.drawOne = function(gd, ax, opts) {
26222630
rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax);
26232631
}
26242632

2625-
keepSelectedAutoMargin(ax.automargin, push);
2633+
if(typeof ax.automargin === 'string') {
2634+
filterPush(push, ax.automargin);
2635+
}
26262636

26272637
Plots.autoMargin(gd, axAutoMarginID(ax), push);
26282638
Plots.autoMargin(gd, axMirrorAutoMarginID(ax), mirrorPush);
@@ -2638,22 +2648,12 @@ axes.drawOne = function(gd, ax, opts) {
26382648
return Lib.syncOrAsync(seq);
26392649
};
26402650

2641-
function keepSelectedAutoMargin(automargin, push) {
2642-
if(typeof automargin === 'boolean') return push;
2643-
2651+
function filterPush(push, automargin) {
26442652
var keepMargin = [];
2645-
var mapping = {
2646-
width: ['x', 'r', 'l', 'xl', 'xr'],
2647-
height: ['y', 't', 'b', 'yt', 'yb'],
2648-
right: ['r', 'xr'],
2649-
left: ['l', 'xl'],
2650-
top: ['t', 'yt'],
2651-
bottom: ['b', 'yb']
2652-
};
26532653

2654-
Object.keys(mapping).forEach(function(key) {
2654+
Object.keys(MARGIN_MAPPING).forEach(function(key) {
26552655
if(automargin.indexOf(key) !== -1) {
2656-
mapping[key].forEach(function(item) {
2656+
MARGIN_MAPPING[key].forEach(function(item) {
26572657
keepMargin.push(item);
26582658
});
26592659
}

0 commit comments

Comments
 (0)