Browse Source

Fix tooltip randomly switching when have equal values (#2311)

pull/2323/head
Anthony Pessy 7 years ago committed by Yoshiya Hinosawa
parent
commit
9904867183
  1. 11
      src/arc.js
  2. 7
      src/data.js

11
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 () {

7
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;
};

Loading…
Cancel
Save