Skip to content

Sort object key values in schema #5813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 17, 2021
1 change: 1 addition & 0 deletions draftlogs/5813_change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Sort object key values in schema [[#5813](https://github.com/plotly/plotly.js/pull/5813)]
2 changes: 1 addition & 1 deletion src/components/calendars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var ONEDAY = constants.ONEDAY;

var attributes = {
valType: 'enumerated',
values: Object.keys(calendars.calendars),
values: Lib.sortObjectKeys(calendars.calendars),
editType: 'calc',
dflt: 'gregorian'
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/colorscale/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

var colorbarAttrs = require('../colorbar/attributes');
var counterRegex = require('../../lib/regex').counter;
var sortObjectKeys = require('../../lib/sort_object_keys');

var palettes = require('./scales.js').scales;
var paletteStr = Object.keys(palettes);
var paletteStr = sortObjectKeys(palettes);

function code(s) {
return '`' + s + '`';
Expand Down
2 changes: 2 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ lib.roundUp = searchModule.roundUp;
lib.sort = searchModule.sort;
lib.findIndexOfMin = searchModule.findIndexOfMin;

lib.sortObjectKeys = require('./sort_object_keys');

var statsModule = require('./stats');
lib.aggNums = statsModule.aggNums;
lib.len = statsModule.len;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/sort_object_keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function sortObjectKeys(obj) {
return Object.keys(obj).sort();
};
5 changes: 3 additions & 2 deletions src/plots/geo/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var colorAttrs = require('../../components/color/attributes');
var domainAttrs = require('../domain').attributes;
var constants = require('./constants');
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var sortObjectKeys = require('../../lib/sort_object_keys');

var geoAxesAttrs = {
range: {
Expand Down Expand Up @@ -100,14 +101,14 @@ var attrs = module.exports = overrideAll({
},
scope: {
valType: 'enumerated',
values: Object.keys(constants.scopeDefaults),
values: sortObjectKeys(constants.scopeDefaults),
dflt: 'world',
description: 'Set the scope of the map.'
},
projection: {
type: {
valType: 'enumerated',
values: Object.keys(constants.projNames),
values: sortObjectKeys(constants.projNames),
description: 'Sets the projection type.'
},
rotation: {
Expand Down
4 changes: 3 additions & 1 deletion src/plots/mapbox/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var sortObjectKeys = require('../../lib/sort_object_keys');

var requiredVersion = '1.10.1';

var OSM = '© <a target="_blank" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
Expand Down Expand Up @@ -156,7 +158,7 @@ var stylesNonMapbox = {
}
};

var styleValuesNonMapbox = Object.keys(stylesNonMapbox);
var styleValuesNonMapbox = sortObjectKeys(stylesNonMapbox);

module.exports = {
requiredVersion: requiredVersion,
Expand Down
5 changes: 3 additions & 2 deletions src/traces/scatter3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var DASHES = require('../../constants/gl3d_dashes');
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');
var extendFlat = require('../../lib/extend').extendFlat;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var sortObjectKeys = require('../../lib/sort_object_keys');

var scatterLineAttrs = scatterAttrs.line;
var scatterMarkerAttrs = scatterAttrs.marker;
Expand All @@ -20,7 +21,7 @@ var lineAttrs = extendFlat({
width: scatterLineAttrs.width,
dash: {
valType: 'enumerated',
values: Object.keys(DASHES),
values: sortObjectKeys(DASHES),
dflt: 'solid',
description: 'Sets the dash style of the lines.'
}
Expand Down Expand Up @@ -122,7 +123,7 @@ var attrs = module.exports = overrideAll({
marker: extendFlat({ // Parity with scatter.js?
symbol: {
valType: 'enumerated',
values: Object.keys(MARKER_SYMBOLS),
values: sortObjectKeys(MARKER_SYMBOLS),
dflt: 'circle',
arrayOk: true,
description: 'Sets the marker symbol type.'
Expand Down
3 changes: 2 additions & 1 deletion src/traces/scattergl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var scatterAttrs = require('../scatter/attributes');
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
var colorScaleAttrs = require('../../components/colorscale/attributes');

var sortObjectKeys = require('../../lib/sort_object_keys');
var extendFlat = require('../../lib/extend').extendFlat;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var DASHES = require('./constants').DASHES;
Expand Down Expand Up @@ -59,7 +60,7 @@ var attrs = module.exports = overrideAll({
},
dash: {
valType: 'enumerated',
values: Object.keys(DASHES),
values: sortObjectKeys(DASHES),
dflt: 'solid',
description: 'Sets the style of the lines.'
}
Expand Down
Loading