Skip to content

Commit

Permalink
Fix tooltip randomly switching when have equal values (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
panthony authored and kt3k committed Mar 24, 2018
1 parent 818f8b9 commit 9904867
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ c3_chart_internal_fn.initPie = function () {
$$.pie = d3.pie().value(function (d) {
return d.values.reduce(function (a, b) { return a + b.value; }, 0);
});
$$.pie.sort($$.getOrderFunction() || null);

let orderFct = $$.getOrderFunction();

// we need to reverse the returned order if asc or desc to have the slice in expected order.
if (orderFct && ($$.isOrderAsc() || $$.isOrderDesc())) {
let defaultSort = orderFct;
orderFct = (t1, t2) => defaultSort(t1, t2) * -1;
}

$$.pie.sort(orderFct || null);
};

c3_chart_internal_fn.updateRadius = function () {
Expand Down
7 changes: 2 additions & 5 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ c3_chart_internal_fn.isOrderAsc = function () {
c3_chart_internal_fn.getOrderFunction = function() {
var $$ = this, config = $$.config, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc();
if (orderAsc || orderDesc) {
var reducer = function (p, c) { return p + Math.abs(c.value); };
return function (t1, t2) {
var reducer = function (p, c) { return p + Math.abs(c.value); };
var t1Sum = t1.values.reduce(reducer, 0),
t2Sum = t2.values.reduce(reducer, 0);
return orderDesc ? t2Sum - t1Sum : t1Sum - t2Sum;
return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum;
};
} else if (isFunction(config.data_order)) {
return config.data_order;
Expand All @@ -209,9 +209,6 @@ c3_chart_internal_fn.orderTargets = function (targets) {
var fct = this.getOrderFunction();
if (fct) {
targets.sort(fct);
if (this.isOrderAsc() || this.isOrderDesc()) {
targets.reverse();
}
}
return targets;
};
Expand Down

0 comments on commit 9904867

Please sign in to comment.