Skip to content

Commit 445ada3

Browse files
committed
Drop negative values post-aggregation instead of during summation in pie chart generation
1 parent 285b923 commit 445ada3

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}
42+

0 commit comments

Comments
 (0)