Skip to content

Commit a9625b6

Browse files
committed
drop funnelarea sort - auto sort when funnelarea is aggregated - fixup funnelarea tests without using sort
1 parent 4711c5c commit a9625b6

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

src/traces/funnelarea/attributes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,5 @@ module.exports = {
102102
description: [
103103
'Sets the ratio between bottom length and maximum top length.'
104104
].join(' ')
105-
},
106-
107-
sort: extendFlat({}, pieAttrs.sort, { dflt: false })
105+
}
108106
};

src/traces/funnelarea/defaults.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7070
Lib.coerceFont(coerce, 'title.font', layout.font);
7171
}
7272

73-
coerce('sort');
7473
coerce('aspectratio');
7574
coerce('baseratio');
7675
};

src/traces/pie/calc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function calc(gd, trace) {
4242
var pullColor = makePullColorFn(fullLayout['_' + trace.type + 'colormap']);
4343
var seriesLen = (hasVals ? vals : labels).length;
4444
var vTotal = 0;
45+
var isAggregated = false;
4546

4647
for(i = 0; i < seriesLen; i++) {
4748
var v, label, hidden;
@@ -73,6 +74,8 @@ function calc(gd, trace) {
7374
hidden: hidden
7475
});
7576
} else {
77+
isAggregated = true;
78+
7679
pt = cd[thisLabelIndex];
7780
pt.v += v;
7881
pt.pts.push(i);
@@ -84,7 +87,8 @@ function calc(gd, trace) {
8487
}
8588
}
8689

87-
if(trace.sort) cd.sort(function(a, b) { return b.v - a.v; });
90+
var shouldSort = (trace.type === 'funnelarea') ? isAggregated : trace.sort;
91+
if(shouldSort) cd.sort(function(a, b) { return b.v - a.v; });
8892

8993
// include the sum of all values in the first point
9094
if(cd[0]) cd[0].vTotal = vTotal;
34 Bytes
Loading

test/image/mocks/funnelarea_simple.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"data": [
33
{
44
"values": [
5-
1,
6-
2,
7-
3,
5+
5,
86
4,
9-
5
7+
3,
8+
2,
9+
1
1010
],
11-
"type": "funnelarea", "sort": true
11+
"type": "funnelarea"
1212
}
1313
],
1414
"layout": {

test/jasmine/tests/funnelarea_test.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ describe('Funnelarea traces', function() {
105105
Plotly.newPlot(gd, [{
106106
values: [1, 2, 3, 4, 5],
107107
type: 'funnelarea',
108-
sort: false,
109108
marker: {
110109
line: {width: 3, color: 'rgba(100,100,100,0.7)'},
111110
colors: [
@@ -206,17 +205,17 @@ describe('Funnelarea traces', function() {
206205

207206
it('propagate explicit colors to the same labels in earlier OR later traces', function(done) {
208207
var data1 = [
209-
{type: 'funnelarea', sort: true, values: [3, 2], marker: {colors: ['red', 'black']}, domain: {x: [0.5, 1]}},
210-
{type: 'funnelarea', sort: true, values: [2, 5], domain: {x: [0, 0.5]}}
208+
{type: 'funnelarea', values: [3, 2], marker: {colors: ['red', 'black']}, domain: {x: [0.5, 1]}},
209+
{type: 'funnelarea', values: [2, 5], domain: {x: [0, 0.5]}}
211210
];
212211
var data2 = Lib.extendDeep([], [data1[1], data1[0]]);
213212

214213
Plotly.newPlot(gd, data1)
215-
.then(_checkSliceColors(['255,0,0', '0,0,0', '0,0,0', '255,0,0']))
214+
.then(_checkSliceColors(['255,0,0', '0,0,0', '255,0,0', '0,0,0']))
216215
.then(function() {
217216
return Plotly.newPlot(gd, data2);
218217
})
219-
.then(_checkSliceColors(['0,0,0', '255,0,0', '255,0,0', '0,0,0']))
218+
.then(_checkSliceColors(['255,0,0', '0,0,0', '255,0,0', '0,0,0']))
220219
.catch(failTest)
221220
.then(done);
222221
});
@@ -724,8 +723,8 @@ describe('funnelarea hovering', function() {
724723
unhoverData = data;
725724
});
726725

727-
mouseEvent('mouseover', width / 2 - 7, height / 2 - 7);
728-
mouseEvent('mouseout', width / 2 - 7, height / 2 - 7);
726+
mouseEvent('mouseover', width / 2 - 7, height / 2 + 50);
727+
mouseEvent('mouseout', width / 2 - 7, height / 2 + 50);
729728

730729
expect(hoverData.points.length).toEqual(1);
731730
expect(unhoverData.points.length).toEqual(1);
@@ -822,29 +821,29 @@ describe('funnelarea hovering', function() {
822821
.then(_hover)
823822
.then(function() {
824823
assertLabel(
825-
['4', '5', '33.3%'].join('\n'),
824+
['0', '5', '33.3%'].join('\n'),
826825
['rgb(31, 119, 180)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)'],
827826
'initial'
828827
);
829828

830-
return Plotly.restyle(gd, 'text', [['A', 'B', 'C', 'D', 'E']]);
829+
return Plotly.restyle(gd, 'text', [['E', 'D', 'C', 'B', 'A']]);
831830
})
832831
.then(_hover)
833832
.then(function() {
834833
assertLabel(
835-
['4', 'E', '5', '33.3%'].join('\n'),
834+
['0', 'E', '5', '33.3%'].join('\n'),
836835
null,
837836
'added text'
838837
);
839838

840839
return Plotly.restyle(gd, 'hovertext', [[
841-
'Apple', 'Banana', 'Clementine', 'Dragon Fruit', 'Eggplant'
840+
'Eggplant', 'Dragon Fruit', 'Clementine', 'Banana', 'Apple'
842841
]]);
843842
})
844843
.then(_hover)
845844
.then(function() {
846845
assertLabel(
847-
['4', 'Eggplant', '5', '33.3%'].join('\n'),
846+
['0', 'Eggplant', '5', '33.3%'].join('\n'),
848847
null,
849848
'added hovertext'
850849
);
@@ -854,7 +853,7 @@ describe('funnelarea hovering', function() {
854853
.then(_hover)
855854
.then(function() {
856855
assertLabel(
857-
['4', 'SUP', '5', '33.3%'].join('\n'),
856+
['0', 'SUP', '5', '33.3%'].join('\n'),
858857
null,
859858
'constant hovertext'
860859
);
@@ -870,23 +869,23 @@ describe('funnelarea hovering', function() {
870869
.then(_hover)
871870
.then(function() {
872871
assertLabel(
873-
['4', 'SUP', '5', '33.3%'].join('\n'),
872+
['0', 'SUP', '5', '33.3%'].join('\n'),
874873
['rgb(255, 0, 0)', 'rgb(255, 255, 0)', 15, 'Roboto', 'rgb(0, 0, 255)'],
875874
'new styles'
876875
);
877876

878-
return Plotly.restyle(gd, 'hoverinfo', [[null, null, null, null, 'label+percent']]);
877+
return Plotly.restyle(gd, 'hoverinfo', [['label+percent', null, null, null, null]]);
879878
})
880879
.then(_hover)
881880
.then(function() {
882-
assertLabel(['4', '33.3%'].join('\n'), null, 'new hoverinfo');
881+
assertLabel(['0', '33.3%'].join('\n'), null, 'new hoverinfo');
883882

884-
return Plotly.restyle(gd, 'hoverinfo', [[null, null, null, null, 'dont+know+what+im-doing']]);
883+
return Plotly.restyle(gd, 'hoverinfo', [['dont+know+what+im-doing', null, null, null, null]]);
885884
})
886885
.then(_hover)
887886
.then(function() {
888887
assertLabel(
889-
['4', 'SUP', '5', '33.3%'].join('\n'),
888+
['0', 'SUP', '5', '33.3%'].join('\n'),
890889
null,
891890
'garbage hoverinfo'
892891
);
@@ -935,7 +934,7 @@ describe('funnelarea hovering', function() {
935934
.then(_hover)
936935
.then(function() {
937936
assertLabel(
938-
['4', '5', '33.3%'].join('\n'),
937+
['0', '5', '33.3%'].join('\n'),
939938
['rgb(31, 119, 180)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)'],
940939
'initial'
941940
);
@@ -951,7 +950,7 @@ describe('funnelarea hovering', function() {
951950
);
952951

953952
return Plotly.restyle(gd, {
954-
'text': [['A', 'B', 'C', 'D', 'E']],
953+
'text': [['E', 'D', 'C', 'B', 'A']],
955954
'hovertemplate': '%{text}<extra></extra>'
956955
});
957956
})
@@ -978,12 +977,12 @@ describe('funnelarea hovering', function() {
978977
.then(_hover)
979978
.then(function() {
980979
assertLabel(
981-
['4'].join('\n'),
980+
['0'].join('\n'),
982981
null,
983982
'hovertemplate %{label}'
984983
);
985984
})
986-
.then(function() { return Plotly.restyle(gd, 'hovertemplate', [['', '', '', '', 'ht 5 %{percent:0.2%}<extra></extra>']]); })
985+
.then(function() { return Plotly.restyle(gd, 'hovertemplate', [['ht 5 %{percent:0.2%}<extra></extra>', '', '', '', '']]); })
987986
.then(_hover)
988987
.then(function() {
989988
assertLabel(
@@ -1003,12 +1002,12 @@ describe('funnelarea hovering', function() {
10031002
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
10041003
.then(_hover)
10051004
.then(function() {
1006-
assertHoverLabelContent({nums: '4\n5\n33.3%', name: 'looooooooooo...'}, 'base');
1005+
assertHoverLabelContent({nums: '0\n5\n33.3%', name: 'looooooooooo...'}, 'base');
10071006
})
10081007
.then(function() { return Plotly.restyle(gd, 'hoverlabel.namelength', 2); })
10091008
.then(_hover)
10101009
.then(function() {
1011-
assertHoverLabelContent({nums: '4\n5\n33.3%', name: 'lo'}, 'base');
1010+
assertHoverLabelContent({nums: '0\n5\n33.3%', name: 'lo'}, 'base');
10121011
})
10131012
.catch(failTest)
10141013
.then(done);
@@ -1050,15 +1049,15 @@ describe('Test event data of interactions on a funnelarea plot:', function() {
10501049
var point = data.points[0];
10511050

10521051
expect(point.curveNumber).toBe(0);
1053-
expect(point.pointNumber).toBe(4);
1054-
expect(point.pointNumbers).toEqual([4]);
1052+
expect(point.pointNumber).toBe(0);
1053+
expect(point.pointNumbers).toEqual([0]);
10551054
expect(point.data).toBe(gd.data[0]);
10561055
expect(point.fullData).toBe(gd._fullData[0]);
1057-
expect(point.label).toBe('4');
1056+
expect(point.label).toBe('0');
10581057
expect(point.value).toBe(5);
10591058
expect(point.color).toBe('#1f77b4');
1060-
expect(point.id).toEqual(['maggie']);
1061-
expect(point.customdata).toEqual([{9: 10}]);
1059+
expect(point.id).toEqual(['marge']);
1060+
expect(point.customdata).toEqual([{1: 2}]);
10621061

10631062
// no need for backward compat i/v
10641063
expect('i' in point).toBe(false);
@@ -1106,7 +1105,7 @@ describe('Test event data of interactions on a funnelarea plot:', function() {
11061105

11071106
expect(futureData.points[0].pointNumber).toBeUndefined();
11081107
expect(futureData.points[0].i).toBeUndefined();
1109-
expect(futureData.points[0].pointNumbers).toEqual([4, 9]);
1108+
expect(futureData.points[0].pointNumbers).toEqual([0, 5]);
11101109
});
11111110
});
11121111

0 commit comments

Comments
 (0)