diff --git a/src/arc.js b/src/arc.js index 58eb5ee5b..b20600dce 100644 --- a/src/arc.js +++ b/src/arc.js @@ -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 () { diff --git a/src/data.js b/src/data.js index e7009b66e..dd217d44d 100644 --- a/src/data.js +++ b/src/data.js @@ -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; @@ -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; };