Skip to content

Commit

Permalink
smart dflt for cluster.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Oct 14, 2022
1 parent 54aaa17 commit 477d2a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/traces/scattermapbox/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = overrideAll({
cluster: {
enabled: {
valType: 'boolean',
dflt: false,
description: 'Determines whether clustering is enabled or disabled.'
},
maxzoom: extendFlat({}, mapboxLayoutAtributes.layers.maxzoom, {
Expand Down
26 changes: 18 additions & 8 deletions src/traces/scattermapbox/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

function coerce2(attr, dflt) {
return Lib.coerce2(traceIn, traceOut, attributes, attr, dflt);
}

var len = handleLonLatDefaults(traceIn, traceOut, coerce);
if(!len) {
traceOut.visible = false;
Expand Down Expand Up @@ -46,14 +50,20 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}
}

var hasCluster = coerce('cluster.enabled');
if(hasCluster) {
coerce('cluster.maxzoom');
coerce('cluster.step');
coerce('cluster.color', traceOut.marker.color || defaultColor);
coerce('cluster.size');
coerce('cluster.opacity');
}
var clusterMaxzoom = coerce2('cluster.maxzoom');
var clusterStep = coerce2('cluster.step');
var clusterColor = coerce2('cluster.color', (traceOut.marker && traceOut.marker.color) || defaultColor);
var clusterSize = coerce2('cluster.size');
var clusterOpacity = coerce2('cluster.opacity');

var clusterEnabledDflt =
clusterMaxzoom !== false ||
clusterStep !== false ||
clusterColor !== false ||
clusterSize !== false ||
clusterOpacity !== false;

coerce('cluster.enabled', clusterEnabledDflt);

if(subTypes.hasText(traceOut)) {
handleTextDefaults(traceIn, traceOut, layout, coerce, {noSelect: true});
Expand Down
4 changes: 0 additions & 4 deletions test/image/mocks/mapbox_scattercluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"opacity": 0.5
},
"cluster": {
"enabled": true,
"size": 20,
"color": "yellow"
},
Expand Down Expand Up @@ -61,7 +60,6 @@
"size": 20
},
"cluster": {
"enabled": true,
"size": 10
},
"lon": [
Expand Down Expand Up @@ -110,7 +108,6 @@
"size": 10
},
"cluster": {
"enabled": true,
"size": 20
},
"lon": [
Expand Down Expand Up @@ -159,7 +156,6 @@
"size": 10
},
"cluster": {
"enabled": true,
"size": 10
},
"lon": [
Expand Down
1 change: 0 additions & 1 deletion test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53461,7 +53461,6 @@
"editType": "calc",
"enabled": {
"description": "Determines whether clustering is enabled or disabled.",
"dflt": false,
"editType": "calc",
"valType": "boolean"
},
Expand Down

0 comments on commit 477d2a0

Please sign in to comment.