Skip to content

Commit 87420bf

Browse files
authored
Merge pull request #6051 from destiny-wu/pie-chart-negative-sum-drop
Discard negative values from pie chart post-aggregation instead of during summation
2 parents 285b923 + 1331ad8 commit 87420bf

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

draftlogs/6051_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Discard negative values from pie chart post-aggregation instead of during summation [[#6051](https://github.com/plotly/plotly.js/pull/6051)]

src/traces/pie/calc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function calc(gd, trace) {
3939
v = vals[i];
4040
if(!isNumeric(v)) continue;
4141
v = +v;
42-
if(v < 0) continue;
4342
} else v = 1;
4443

4544
label = labels[i];
@@ -76,6 +75,9 @@ function calc(gd, trace) {
7675
}
7776
}
7877

78+
// Drop aggregate sums of value 0 or less
79+
cd = cd.filter(function(elem) { return elem.v >= 0; });
80+
7981
var shouldSort = (trace.type === 'funnelarea') ? isAggregated : trace.sort;
8082
if(shouldSort) cd.sort(function(a, b) { return b.v - a.v; });
8183

21.6 KB
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"data": [
3+
{
4+
"labels": [
5+
"Apples",
6+
"Apples",
7+
"Bananas",
8+
"Oranges",
9+
"Pears",
10+
"Pears",
11+
"Apples",
12+
"Pears"
13+
],
14+
"type": "pie",
15+
"domain": {"x": [0, 0.4]}
16+
},
17+
{
18+
"labels": [
19+
"Apples",
20+
"Apples",
21+
"Bananas",
22+
"Oranges",
23+
"Pears",
24+
"Pears",
25+
"Apples",
26+
"Pears"
27+
],
28+
"values": [
29+
10, -20, 20, 40, 10, -20, 70, 5
30+
],
31+
"marker": {"colors": ["", "", "#ccc"]},
32+
"type": "pie",
33+
"domain": {"x": [0.5, 1]},
34+
"textinfo": "label+value+percent"
35+
}
36+
],
37+
"layout": {
38+
"height": 300,
39+
"width": 500
40+
}
41+
}

0 commit comments

Comments
 (0)