Skip to content

Commit 40d3077

Browse files
committed
Simplify map trace colorbar edit types
1 parent b4dc27a commit 40d3077

7 files changed

Lines changed: 53 additions & 122 deletions

File tree

‎draftlogs/5616_fix.md‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎draftlogs/7864_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Preserve `colorbars` edit types for colorbar attributes on map traces [[#7864](https://github.com/plotly/plotly.js/pull/7864)]

‎src/traces/scattergeo/attributes.js‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,7 @@ const breakingChangeWarning = [
1919
'Country names in existing plots may not work in the new version.'
2020
].join(' ');
2121

22-
function restoreColorbarEditTypes(attrs) {
23-
function restoreEditTypes(obj) {
24-
for(var key in obj) {
25-
var val = obj[key];
26-
if(val && typeof val === 'object') {
27-
if(val.editType === 'calc') {
28-
val.editType = 'colorbars';
29-
}
30-
if(!val.valType) {
31-
restoreEditTypes(val);
32-
}
33-
if(Array.isArray(val.items)) {
34-
for(var i = 0; i < val.items.length; i++) {
35-
if(val.items[i] && typeof val.items[i] === 'object') {
36-
if(val.items[i].editType === 'calc') {
37-
val.items[i].editType = 'colorbars';
38-
}
39-
if(!val.items[i].valType) {
40-
restoreEditTypes(val.items[i]);
41-
}
42-
}
43-
}
44-
}
45-
}
46-
}
47-
}
48-
if(attrs && attrs.marker && attrs.marker.colorbar) {
49-
restoreEditTypes(attrs.marker.colorbar);
50-
}
51-
return attrs;
52-
}
53-
54-
module.exports = restoreColorbarEditTypes(overrideAll(
22+
var attrs = overrideAll(
5523
{
5624
lon: {
5725
valType: 'data_array',
@@ -207,4 +175,8 @@ module.exports = restoreColorbarEditTypes(overrideAll(
207175
},
208176
'calc',
209177
'nested'
210-
));
178+
);
179+
180+
attrs.marker.colorbar = require('../../components/colorbar/attributes');
181+
182+
module.exports = attrs;

‎src/traces/scattermap/attributes.js‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,7 @@ var mapLayoutAtributes = require('../../plots/map/layout_attributes');
1515
var lineAttrs = scatterGeoAttrs.line;
1616
var markerAttrs = scatterGeoAttrs.marker;
1717

18-
function restoreColorbarEditTypes(attrs) {
19-
function restoreEditTypes(obj) {
20-
for(var key in obj) {
21-
var val = obj[key];
22-
if(val && typeof val === 'object') {
23-
if(val.editType === 'calc') {
24-
val.editType = 'colorbars';
25-
}
26-
if(!val.valType) {
27-
restoreEditTypes(val);
28-
}
29-
if(Array.isArray(val.items)) {
30-
for(var i = 0; i < val.items.length; i++) {
31-
if(val.items[i] && typeof val.items[i] === 'object') {
32-
if(val.items[i].editType === 'calc') {
33-
val.items[i].editType = 'colorbars';
34-
}
35-
if(!val.items[i].valType) {
36-
restoreEditTypes(val.items[i]);
37-
}
38-
}
39-
}
40-
}
41-
}
42-
}
43-
}
44-
if(attrs && attrs.marker && attrs.marker.colorbar) {
45-
restoreEditTypes(attrs.marker.colorbar);
46-
}
47-
return attrs;
48-
}
49-
50-
module.exports = restoreColorbarEditTypes(overrideAll(
18+
var attrs = overrideAll(
5119
{
5220
lon: scatterGeoAttrs.lon,
5321
lat: scatterGeoAttrs.lat,
@@ -209,4 +177,8 @@ module.exports = restoreColorbarEditTypes(overrideAll(
209177
},
210178
'calc',
211179
'nested'
212-
));
180+
);
181+
182+
attrs.marker.colorbar = require('../../components/colorbar/attributes');
183+
184+
module.exports = attrs;

‎src/traces/scattermapbox/attributes.js‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,7 @@ var mapboxLayoutAtributes = require('../../plots/mapbox/layout_attributes');
1515
var lineAttrs = scatterGeoAttrs.line;
1616
var markerAttrs = scatterGeoAttrs.marker;
1717

18-
function restoreColorbarEditTypes(attrs) {
19-
function restoreEditTypes(obj) {
20-
for(var key in obj) {
21-
var val = obj[key];
22-
if(val && typeof val === 'object') {
23-
if(val.editType === 'calc') {
24-
val.editType = 'colorbars';
25-
}
26-
if(!val.valType) {
27-
restoreEditTypes(val);
28-
}
29-
if(Array.isArray(val.items)) {
30-
for(var i = 0; i < val.items.length; i++) {
31-
if(val.items[i] && typeof val.items[i] === 'object') {
32-
if(val.items[i].editType === 'calc') {
33-
val.items[i].editType = 'colorbars';
34-
}
35-
if(!val.items[i].valType) {
36-
restoreEditTypes(val.items[i]);
37-
}
38-
}
39-
}
40-
}
41-
}
42-
}
43-
}
44-
if(attrs && attrs.marker && attrs.marker.colorbar) {
45-
restoreEditTypes(attrs.marker.colorbar);
46-
}
47-
return attrs;
48-
}
49-
50-
module.exports = restoreColorbarEditTypes(overrideAll(
18+
var attrs = overrideAll(
5119
{
5220
lon: scatterGeoAttrs.lon,
5321
lat: scatterGeoAttrs.lat,
@@ -209,4 +177,8 @@ module.exports = restoreColorbarEditTypes(overrideAll(
209177
},
210178
'calc',
211179
'nested'
212-
));
180+
);
181+
182+
attrs.marker.colorbar = require('../../components/colorbar/attributes');
183+
184+
module.exports = attrs;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var traceAttrs = {
2+
scattergeo: require('../../../src/traces/scattergeo/attributes'),
3+
scattermap: require('../../../src/traces/scattermap/attributes'),
4+
scattermapbox: require('../../../src/traces/scattermapbox/attributes')
5+
};
6+
7+
describe('map trace colorbar edit types', function() {
8+
'use strict';
9+
10+
Object.keys(traceAttrs).forEach(function(name) {
11+
var attrs = traceAttrs[name];
12+
13+
it(name + ' should preserve colorbar edit types', function() {
14+
function assertColorbarEditTypes(obj, path) {
15+
Object.keys(obj).forEach(function(key) {
16+
var val = obj[key];
17+
var attrPath = path ? path + '.' + key : key;
18+
19+
if(val && typeof val === 'object') {
20+
if(val.editType) {
21+
expect(val.editType).withContext(attrPath).toBe('colorbars');
22+
}
23+
if(!val.valType) assertColorbarEditTypes(val, attrPath);
24+
}
25+
});
26+
}
27+
28+
assertColorbarEditTypes(attrs.marker.colorbar, 'marker.colorbar');
29+
});
30+
});
31+
});

‎test/plot-schema.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67535,7 +67535,7 @@
6753567535
},
6753667536
"valType": "any"
6753767537
},
67538-
"editType": "calc",
67538+
"editType": "colorbars",
6753967539
"exponentformat": {
6754067540
"description": "Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If *none*, it appears as 1,000,000,000. If *e*, 1e+9. If *E*, 1E+9. If *power*, 1x10^9 (with 9 in a super script). If *SI*, 1G. If *B*, 1B. *SI* uses prefixes from \"femto\" f (10^-15) to \"tera\" T (10^12). *SI extended* covers instead the full SI range from \"quecto\" q (10^-30) to \"quetta\" Q (10^30). If *SI* or *SI extended* is used and the exponent is beyond the above ranges, the formatting rule will automatically be switched to the power notation.",
6754167541
"dflt": "B",
@@ -72317,7 +72317,7 @@
7231772317
},
7231872318
"valType": "any"
7231972319
},
72320-
"editType": "calc",
72320+
"editType": "colorbars",
7232172321
"exponentformat": {
7232272322
"description": "Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If *none*, it appears as 1,000,000,000. If *e*, 1e+9. If *E*, 1E+9. If *power*, 1x10^9 (with 9 in a super script). If *SI*, 1G. If *B*, 1B. *SI* uses prefixes from \"femto\" f (10^-15) to \"tera\" T (10^12). *SI extended* covers instead the full SI range from \"quecto\" q (10^-30) to \"quetta\" Q (10^30). If *SI* or *SI extended* is used and the exponent is beyond the above ranges, the formatting rule will automatically be switched to the power notation.",
7232372323
"dflt": "B",
@@ -73873,7 +73873,7 @@
7387373873
},
7387473874
"valType": "any"
7387573875
},
73876-
"editType": "calc",
73876+
"editType": "colorbars",
7387773877
"exponentformat": {
7387873878
"description": "Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If *none*, it appears as 1,000,000,000. If *e*, 1e+9. If *E*, 1E+9. If *power*, 1x10^9 (with 9 in a super script). If *SI*, 1G. If *B*, 1B. *SI* uses prefixes from \"femto\" f (10^-15) to \"tera\" T (10^12). *SI extended* covers instead the full SI range from \"quecto\" q (10^-30) to \"quetta\" Q (10^30). If *SI* or *SI extended* is used and the exponent is beyond the above ranges, the formatting rule will automatically be switched to the power notation.",
7387973879
"dflt": "B",

0 commit comments

Comments
 (0)