Skip to content

Commit 4a56f5c

Browse files
committed
Support to sort series in legend alphabetically
1 parent ad43b10 commit 4a56f5c

8 files changed

Lines changed: 44 additions & 15 deletions

File tree

CHANGELOG_ION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# plotly.js ION changelog
22

3+
## [1.33.1-ion38] -- 2020-06-03
4+
5+
### Support to sort series in legend alphabetically.
6+
7+
38
## [1.33.1-ion37] -- 2020-05-18
49

510
### Reverted file committed wrongly.

dist_ion/plotly-ion.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24748,7 +24748,7 @@ module.exports = {
2474824748
},
2474924749
traceorder: {
2475024750
valType: 'flaglist',
24751-
flags: ['reversed', 'grouped'],
24751+
flags: ['reversed', 'grouped', 'alphabetical'],
2475224752
extras: ['normal'],
2475324753

2475424754
editType: 'legend',
@@ -25680,13 +25680,11 @@ function expandHorizontalMargin(gd) {
2568025680
* LICENSE file in the root directory of this source tree.
2568125681
*/
2568225682

25683-
2568425683
'use strict';
2568525684

2568625685
var Registry = require('../../registry');
2568725686
var helpers = require('./helpers');
2568825687

25689-
2569025688
module.exports = function getLegendData(calcdata, opts) {
2569125689
var lgroupToTraces = {},
2569225690
lgroups = [],
@@ -25721,7 +25719,7 @@ module.exports = function getLegendData(calcdata, opts) {
2572125719
lgroup = trace.legendgroup;
2572225720

2572325721
if(!helpers.legendGetsTrace(trace) || !trace.showlegend) continue;
25724-
25722+
2572525723
if(Registry.traceIs(trace, 'pie')) {
2572625724
if(!slicesShown[lgroup]) slicesShown[lgroup] = {};
2572725725

@@ -25773,6 +25771,20 @@ module.exports = function getLegendData(calcdata, opts) {
2577325771

2577425772
// needed in repositionLegend
2577525773
opts._lgroupsLength = lgroupsLength;
25774+
25775+
if (opts.traceorder === "alphabetical") {
25776+
legendData[0].sort((a, b) => {
25777+
if (a[0] && a[0].label) {
25778+
return a[0].label.localeCompare(b[0].label);
25779+
} else {
25780+
if (a[0] && a[0].trace && a[0].trace.name) {
25781+
return a[0].trace.name.localeCompare(b[0].trace.name);
25782+
}
25783+
}
25784+
});
25785+
}
25786+
25787+
2577625788
return legendData;
2577725789
};
2577825790

@@ -32811,7 +32823,7 @@ exports.svgAttrs = {
3281132823
var Plotly = require('./plotly');
3281232824

3281332825
// package version injected by `npm run preprocess`
32814-
exports.version = '1.33.1-ion37';
32826+
exports.version = '1.33.1-ion38';
3281532827

3281632828
// inject promise polyfill
3281732829
require('es6-promise').polyfill();
@@ -33104,7 +33116,7 @@ exports.valObjectMeta = {
3310433116
},
3310533117
colorlist: {
3310633118

33107-
requiredOpts: [],
33119+
3310833120

3310933121
coerceFunction: function(v, propOut, dflt) {
3311033122
function isColor(color) {
@@ -54825,7 +54837,7 @@ module.exports = overrideAll({
5482554837
showcountries: {
5482654838
valType: 'boolean',
5482754839

54828-
description: 'Sets whether or not country boundaries are drawn.'
54840+
5482954841
},
5483054842
countrycolor: {
5483154843
valType: 'color',

dist_ion/plotly-ion.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plotly.js",
3-
"version": "1.33.1-ion37",
3+
"version": "1.33.1-ion38",
44
"description": "The open source javascript graphing library that powers plotly",
55
"license": "MIT",
66
"main": "./lib/index.js",

src/assets/geo_assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ var saneTopojson = require('sane-topojson');
1212

1313

1414
// package version injected by `npm run preprocess`
15-
exports.version = '1.33.1-ion37';exports.topojson = saneTopojson;
15+
exports.version = '1.33.1-ion38';exports.topojson = saneTopojson;

src/components/legend/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
},
4949
traceorder: {
5050
valType: 'flaglist',
51-
flags: ['reversed', 'grouped'],
51+
flags: ['reversed', 'grouped', 'alphabetical'],
5252
extras: ['normal'],
5353
role: 'style',
5454
editType: 'legend',

src/components/legend/get_legend_data.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Registry = require('../../registry');
1312
var helpers = require('./helpers');
1413

15-
1614
module.exports = function getLegendData(calcdata, opts) {
1715
var lgroupToTraces = {},
1816
lgroups = [],
@@ -47,7 +45,7 @@ module.exports = function getLegendData(calcdata, opts) {
4745
lgroup = trace.legendgroup;
4846

4947
if(!helpers.legendGetsTrace(trace) || !trace.showlegend) continue;
50-
48+
5149
if(Registry.traceIs(trace, 'pie')) {
5250
if(!slicesShown[lgroup]) slicesShown[lgroup] = {};
5351

@@ -99,5 +97,19 @@ module.exports = function getLegendData(calcdata, opts) {
9997

10098
// needed in repositionLegend
10199
opts._lgroupsLength = lgroupsLength;
100+
101+
if (opts.traceorder === "alphabetical") {
102+
legendData[0].sort((a, b) => {
103+
if (a[0] && a[0].label) {
104+
return a[0].label.localeCompare(b[0].label);
105+
} else {
106+
if (a[0] && a[0].trace && a[0].trace.name) {
107+
return a[0].trace.name.localeCompare(b[0].trace.name);
108+
}
109+
}
110+
});
111+
}
112+
113+
102114
return legendData;
103115
};

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
var Plotly = require('./plotly');
1616

1717
// package version injected by `npm run preprocess`
18-
exports.version = '1.33.1-ion37';
18+
exports.version = '1.33.1-ion38';
1919

2020
// inject promise polyfill
2121
require('es6-promise').polyfill();

0 commit comments

Comments
 (0)