Skip to content

Commit b3da4e7

Browse files
committed
🔪 itemIsNotPlainObject from handleArrayContainerDefaults
1 parent 5cca8d3 commit b3da4e7

File tree

15 files changed

+52
-62
lines changed

15 files changed

+52
-62
lines changed

src/components/annotations/defaults.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
2424
});
2525
};
2626

27-
function handleAnnotationDefaults(annIn, annOut, fullLayout, opts, itemOpts) {
27+
function handleAnnotationDefaults(annIn, annOut, fullLayout) {
2828
function coerce(attr, dflt) {
2929
return Lib.coerce(annIn, annOut, attributes, attr, dflt);
3030
}
3131

32-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
32+
var visible = coerce('visible');
3333
var clickToShow = coerce('clicktoshow');
3434

35-
if(!(visible || clickToShow)) return annOut;
35+
if(!(visible || clickToShow)) return;
3636

3737
handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce);
3838

@@ -96,6 +96,4 @@ function handleAnnotationDefaults(annIn, annOut, fullLayout, opts, itemOpts) {
9696
annOut.y :
9797
Axes.cleanPosition(yClick, gdMock, annOut.yref);
9898
}
99-
100-
return annOut;
10199
}

src/components/annotations3d/defaults.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function handleDefaults(sceneLayoutIn, sceneLayoutOut, opts) {
2222
});
2323
};
2424

25-
function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts, itemOpts) {
25+
function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts) {
2626
function coerce(attr, dflt) {
2727
return Lib.coerce(annIn, annOut, attributes, attr, dflt);
2828
}
@@ -38,8 +38,8 @@ function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts, itemOpts) {
3838
}
3939

4040

41-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
42-
if(!visible) return annOut;
41+
var visible = coerce('visible');
42+
if(!visible) return;
4343

4444
handleAnnotationCommonDefaults(annIn, annOut, opts.fullLayout, coerce);
4545

@@ -71,6 +71,4 @@ function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts, itemOpts) {
7171
// if you have one part of arrow length you should have both
7272
Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
7373
}
74-
75-
return annOut;
7674
}

src/components/rangeselector/button_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
visible: {
1414
valType: 'boolean',
1515
role: 'info',
16+
dflt: true,
1617
editType: 'plot',
1718
description: 'Determines whether or not this button is visible.'
1819
},

src/components/rangeselector/defaults.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ module.exports = function handleDefaults(containerIn, containerOut, layout, coun
3333
});
3434

3535
var visible = coerce('visible', buttons.length > 0);
36-
if(!visible) return;
37-
38-
var posDflt = getPosDflt(containerOut, layout, counterAxes);
39-
coerce('x', posDflt[0]);
40-
coerce('y', posDflt[1]);
41-
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
36+
if(visible) {
37+
var posDflt = getPosDflt(containerOut, layout, counterAxes);
38+
coerce('x', posDflt[0]);
39+
coerce('y', posDflt[1]);
40+
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
4241

43-
coerce('xanchor');
44-
coerce('yanchor');
42+
coerce('xanchor');
43+
coerce('yanchor');
4544

46-
Lib.coerceFont(coerce, 'font', layout.font);
45+
Lib.coerceFont(coerce, 'font', layout.font);
4746

48-
var bgColor = coerce('bgcolor');
49-
coerce('activecolor', Color.contrast(bgColor, constants.lightAmount, constants.darkAmount));
50-
coerce('bordercolor');
51-
coerce('borderwidth');
47+
var bgColor = coerce('bgcolor');
48+
coerce('activecolor', Color.contrast(bgColor, constants.lightAmount, constants.darkAmount));
49+
coerce('bordercolor');
50+
coerce('borderwidth');
51+
}
5252
};
5353

54-
function buttonDefaults(buttonIn, buttonOut, selectorOut, opts, itemOpts) {
54+
function buttonDefaults(buttonIn, buttonOut, selectorOut, opts) {
5555
var calendar = opts.calendar;
5656

5757
function coerce(attr, dflt) {
5858
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
5959
}
6060

61-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
61+
var visible = coerce('visible');
6262

6363
if(visible) {
6464
var step = coerce('step');

src/components/shapes/defaults.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
2424
});
2525
};
2626

27-
function handleShapeDefaults(shapeIn, shapeOut, fullLayout, opts, itemOpts) {
27+
function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
2828
function coerce(attr, dflt) {
2929
return Lib.coerce(shapeIn, shapeOut, attributes, attr, dflt);
3030
}
3131

32-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
32+
var visible = coerce('visible');
3333

34-
if(!visible) return shapeOut;
34+
if(!visible) return;
3535

3636
coerce('layer');
3737
coerce('opacity');
@@ -119,6 +119,4 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout, opts, itemOpts) {
119119
else {
120120
Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
121121
}
122-
123-
return shapeOut;
124122
}

src/components/sliders/defaults.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ function stepDefaults(valueIn, valueOut, sliderOut, opts, itemOpts) {
100100
}
101101

102102
var visible;
103-
if(itemOpts.itemIsNotPlainObject || (valueIn.method !== 'skip' && !Array.isArray(valueIn.args))) {
103+
if(valueIn.method !== 'skip' && !Array.isArray(valueIn.args)) {
104104
visible = valueOut.visible = false;
105105
}
106106
else visible = coerce('visible');
107-
if(!visible) return;
108107

109-
coerce('method');
110-
coerce('args');
111-
var label = coerce('label', 'step-' + itemOpts.index);
112-
coerce('value', label);
113-
coerce('execute');
108+
if(visible) {
109+
coerce('method');
110+
coerce('args');
111+
var label = coerce('label', 'step-' + itemOpts.index);
112+
coerce('value', label);
113+
coerce('execute');
114+
}
114115
}

src/components/updatemenus/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ function menuDefaults(menuIn, menuOut, layoutOut) {
6565
coerce('borderwidth');
6666
}
6767

68-
function buttonDefaults(buttonIn, buttonOut, selectorOut, opts, itemOpts) {
68+
function buttonDefaults(buttonIn, buttonOut) {
6969
function coerce(attr, dflt) {
7070
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
7171
}
7272

73-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject &&
73+
var visible = coerce('visible',
7474
(buttonIn.method === 'skip' || Array.isArray(buttonIn.args)));
7575
if(visible) {
7676
coerce('method');

src/plots/array_container_defaults.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var Template = require('../plot_api/plot_template');
3434
* - parentObj {object} (as in closure)
3535
* - opts {object} (as in closure)
3636
* - itemOpts {object}
37-
* - itemIsNotPlainObject {boolean}
3837
* - index {integer}
3938
* N.B.
4039
*
@@ -57,13 +56,15 @@ module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut
5756
var itemOpts = {};
5857

5958
if(!Lib.isPlainObject(itemIn)) {
60-
itemOpts.itemIsNotPlainObject = true;
61-
itemIn = {};
59+
itemOut = templater.newItem({});
60+
itemOut.visible = false;
6261
}
63-
itemOut = templater.newItem(itemIn);
62+
else {
63+
itemOut = templater.newItem(itemIn);
6464

65-
if(itemOut.visible !== false) {
66-
opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts, itemOpts);
65+
if(itemOut.visible !== false) {
66+
opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts, itemOpts);
67+
}
6768
}
6869

6970
itemOut._input = itemIn;

src/plots/cartesian/tick_label_defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ function getShowAttrDflt(containerIn) {
8484
}
8585
}
8686

87-
function tickformatstopDefaults(valueIn, valueOut, contOut, opts, itemOpts) {
87+
function tickformatstopDefaults(valueIn, valueOut) {
8888
function coerce(attr, dflt) {
8989
return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);
9090
}
9191

92-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
92+
var visible = coerce('visible');
9393
if(visible) {
9494
coerce('dtickrange');
9595
coerce('value');

src/plots/mapbox/layout_defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ function handleDefaults(containerIn, containerOut, coerce, opts) {
4444
containerOut._input = containerIn;
4545
}
4646

47-
function handleLayerDefaults(layerIn, layerOut, mapboxOut, opts, itemOpts) {
47+
function handleLayerDefaults(layerIn, layerOut) {
4848
function coerce(attr, dflt) {
4949
return Lib.coerce(layerIn, layerOut, layoutAttributes.layers, attr, dflt);
5050
}
5151

52-
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);
52+
var visible = coerce('visible');
5353
if(visible) {
5454
var sourceType = coerce('sourcetype');
5555
coerce('source');

src/traces/parcoords/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
3838
return Infinity;
3939
}
4040

41-
function dimensionDefaults(dimensionIn, dimensionOut, traceOut, opts, itemOpts) {
41+
function dimensionDefaults(dimensionIn, dimensionOut) {
4242
function coerce(attr, dflt) {
4343
return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);
4444
}
4545

4646
var values = coerce('values');
4747
var visible = coerce('visible');
48-
if(!(values && values.length && !itemOpts.itemIsNotPlainObject)) {
48+
if(!(values && values.length)) {
4949
visible = dimensionOut.visible = false;
5050
}
5151

src/traces/splom/defaults.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5151
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
5252
};
5353

54-
function dimensionDefaults(dimIn, dimOut, traceOut, opts, itemOpts) {
54+
function dimensionDefaults(dimIn, dimOut) {
5555
function coerce(attr, dflt) {
5656
return Lib.coerce(dimIn, dimOut, attributes.dimensions, attr, dflt);
5757
}
5858

5959
coerce('label');
60-
coerce('visible');
6160
var values = coerce('values');
6261

63-
if(!(values && values.length && !itemOpts.itemIsNotPlainObject)) {
64-
dimOut.visible = false;
65-
}
62+
if(!(values && values.length)) dimOut.visible = false;
63+
else coerce('visible');
6664
}
6765

6866
function handleAxisDefaults(traceIn, traceOut, layout, coerce) {

test/jasmine/tests/annotations_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ describe('Test annotations', function() {
5757
out.forEach(function(item, i) {
5858
expect(item).toEqual(jasmine.objectContaining({
5959
visible: false,
60-
_input: {},
61-
_index: i,
62-
clicktoshow: false
60+
_index: i
6361
}));
6462
});
6563
});

test/jasmine/tests/shapes_test.js

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ describe('Test shapes defaults:', function() {
7979
out.forEach(function(item, i) {
8080
expect(item).toEqual(jasmine.objectContaining({
8181
visible: false,
82-
_input: {},
8382
_index: i
8483
}));
8584
});

test/jasmine/tests/updatemenus_test.js

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ describe('update menus defaults', function() {
5151
layoutOut.updatemenus.forEach(function(item, i) {
5252
expect(item).toEqual(jasmine.objectContaining({
5353
visible: false,
54-
buttons: [],
55-
_input: {},
5654
_index: i
5755
}));
5856
});

0 commit comments

Comments
 (0)