Skip to content

Commit 93b05d3

Browse files
committed
Refactor to move attributes to top level
Fix variable references Fix formatting
1 parent 21f71e6 commit 93b05d3

File tree

6 files changed

+47
-46
lines changed

6 files changed

+47
-46
lines changed

src/plots/layout_attributes.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ module.exports = {
189189
'Sets the plot\'s height (in px).'
190190
].join(' ')
191191
},
192+
minreducedwidth: {
193+
valType: 'number',
194+
min: 2,
195+
dflt: 64,
196+
editType: 'plot',
197+
description: 'Minimum width of the plot with margin.automargin applied (in px)'
198+
},
199+
minreducedheight: {
200+
valType: 'number',
201+
min: 2,
202+
dflt: 64,
203+
editType: 'plot',
204+
description: 'Minimum height of the plot with margin.automargin applied (in px)'
205+
},
192206
margin: {
193207
l: {
194208
valType: 'number',
@@ -228,20 +242,6 @@ module.exports = {
228242
'between the plotting area and the axis lines'
229243
].join(' ')
230244
},
231-
minreducedwidth: {
232-
valType: 'number',
233-
min: 2,
234-
dflt: 64,
235-
editType: 'plot',
236-
description: 'Minimum width of the plot with automargin applied (in px)'
237-
},
238-
minreducedheight: {
239-
valType: 'number',
240-
min: 2,
241-
dflt: 64,
242-
editType: 'plot',
243-
description: 'Minimum height of the plot with automargin applied (in px)'
244-
},
245245
autoexpand: {
246246
valType: 'boolean',
247247
dflt: true,

src/plots/plots.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1506,14 +1506,15 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
15061506

15071507
coerce('width');
15081508
coerce('height');
1509+
coerce('minreducedwidth');
1510+
coerce('minreducedheight');
1511+
15091512
coerce('margin.l');
15101513
coerce('margin.r');
15111514
coerce('margin.t');
15121515
coerce('margin.b');
15131516
coerce('margin.pad');
15141517
coerce('margin.autoexpand');
1515-
coerce('margin.minreducedwidth');
1516-
coerce('margin.minreducedheight');
15171518

15181519
if(layoutIn.width && layoutIn.height) plots.sanitizeMargins(layoutOut);
15191520

@@ -1883,17 +1884,19 @@ plots.autoMargin = function(gd, id, o) {
18831884
var width = fullLayout.width;
18841885
var height = fullLayout.height;
18851886
var margin = fullLayout.margin;
1887+
var minreducedwidth = fullLayout.minreducedwidth;
1888+
var minreducedheight = fullLayout.minreducedheight;
18861889

18871890
var minFinalWidth = Lib.constrain(
18881891
width - margin.l - margin.r,
18891892
MIN_SPECIFIED_WIDTH,
1890-
margin.minreducedwidth
1893+
minreducedwidth
18911894
);
18921895

18931896
var minFinalHeight = Lib.constrain(
18941897
height - margin.t - margin.b,
18951898
MIN_SPECIFIED_HEIGHT,
1896-
margin.minreducedheight
1899+
minreducedheight
18971900
);
18981901

18991902
var maxSpaceW = Math.max(0, width - minFinalWidth);
@@ -1972,6 +1975,8 @@ plots.doAutoMargin = function(gd) {
19721975
var mb = margin.b;
19731976
var pushMargin = fullLayout._pushmargin;
19741977
var pushMarginIds = fullLayout._pushmarginIds;
1978+
var minreducedwidth = fullLayout.minreducedwidth;
1979+
var minreducedheight = fullLayout.minreducedheight;
19751980

19761981
if(fullLayout.margin.autoexpand !== false) {
19771982
for(var k in pushMargin) {
@@ -2030,13 +2035,13 @@ plots.doAutoMargin = function(gd) {
20302035
var minFinalWidth = Lib.constrain(
20312036
width - margin.l - margin.r,
20322037
MIN_SPECIFIED_WIDTH,
2033-
margin.minreducedwidth
2038+
minreducedwidth
20342039
);
20352040

20362041
var minFinalHeight = Lib.constrain(
20372042
height - margin.t - margin.b,
20382043
MIN_SPECIFIED_HEIGHT,
2039-
margin.minreducedheight
2044+
minreducedheight
20402045
);
20412046

20422047
var maxSpaceW = Math.max(0, width - minFinalWidth);

test/image/mocks/z-automargin-minreducedheight.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
},
3838
"width": 240,
3939
"height": 300,
40+
"minreducedheight": 55,
4041
"margin": {
4142
"t": 80,
4243
"b": 20,
4344
"l": 20,
44-
"r": 20,
45-
"minreducedheight": 55
45+
"r": 20
4646
},
4747
"yaxis": {
4848
"type": "date",

test/image/mocks/z-automargin-minreducedwidth.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
},
3939
"width": 240,
4040
"height": 200,
41+
"minreducedwidth": 55,
4142
"margin": {
4243
"t": 80,
4344
"b": 20,
4445
"l": 20,
45-
"r": 20,
46-
"minreducedwidth": 55
46+
"r": 20
4747
},
4848
"xaxis": {
4949
"type": "date",

test/jasmine/tests/plots_test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ describe('Test Plots', function() {
237237
t: 100,
238238
b: 80,
239239
pad: 0,
240-
autoexpand: true,
241-
minreducedwidth: 64,
242-
minreducedheight: 64
240+
autoexpand: true
243241
};
244242

245243
supplyLayoutDefaults(layoutIn, layoutOut);
@@ -263,9 +261,7 @@ describe('Test Plots', function() {
263261
t: 187,
264262
b: 311,
265263
pad: 0,
266-
autoexpand: true,
267-
minreducedwidth: 64,
268-
minreducedheight: 64
264+
autoexpand: true
269265
};
270266

271267
supplyLayoutDefaults(layoutIn, layoutOut);
@@ -1358,13 +1354,13 @@ describe('Test Plots with automargin and minreducedwidth/height', function() {
13581354
assertClose('height', '55');
13591355
})
13601356
.then(function() {
1361-
return Plotly.relayout(gd, 'margin.minreducedheight', 100);
1357+
return Plotly.relayout(gd, 'minreducedheight', 100);
13621358
})
13631359
.then(function() {
13641360
assert('height', '100');
13651361
})
13661362
.then(function() {
1367-
return Plotly.relayout(gd, 'margin.minreducedwidth', 100);
1363+
return Plotly.relayout(gd, 'minreducedwidth', 100);
13681364
})
13691365
.then(function() {
13701366
assert('width', '100');

test/plot-schema.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -3352,20 +3352,6 @@
33523352
"min": 0,
33533353
"valType": "number"
33543354
},
3355-
"minreducedheight": {
3356-
"description": "Minimum height of the plot with automargin applied (in px)",
3357-
"dflt": 64,
3358-
"editType": "plot",
3359-
"min": 2,
3360-
"valType": "number"
3361-
},
3362-
"minreducedwidth": {
3363-
"description": "Minimum width of the plot with automargin applied (in px)",
3364-
"dflt": 64,
3365-
"editType": "plot",
3366-
"min": 2,
3367-
"valType": "number"
3368-
},
33693355
"pad": {
33703356
"description": "Sets the amount of padding (in px) between the plotting area and the axis lines",
33713357
"dflt": 0,
@@ -3400,6 +3386,20 @@
34003386
"editType": "none",
34013387
"valType": "string"
34023388
},
3389+
"minreducedheight": {
3390+
"description": "Minimum height of the plot with margin.automargin applied (in px)",
3391+
"dflt": 64,
3392+
"editType": "plot",
3393+
"min": 2,
3394+
"valType": "number"
3395+
},
3396+
"minreducedwidth": {
3397+
"description": "Minimum width of the plot with margin.automargin applied (in px)",
3398+
"dflt": 64,
3399+
"editType": "plot",
3400+
"min": 2,
3401+
"valType": "number"
3402+
},
34033403
"modebar": {
34043404
"activecolor": {
34053405
"description": "Sets the color of the active or hovered on icons in the modebar.",

0 commit comments

Comments
 (0)