Browse Source

fix tooltip data order for stacked charts

pull/1337/head
Jan Teichmann 9 years ago
parent
commit
8dfe05ce23
  1. 23
      src/tooltip.js

23
src/tooltip.js

@ -29,15 +29,24 @@ c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaul
titleFormat = config.tooltip_format_title || defaultTitleFormat,
nameFormat = config.tooltip_format_name || function (name) { return name; },
valueFormat = config.tooltip_format_value || defaultValueFormat,
text, i, title, value, name, bgcolor;
if (config.data_order === 'desc') {
text, i, title, value, name, bgcolor,
orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc();
if (config.data_groups.length === 0) {
d.sort(function(a,b){
return b.value-a.value;
return orderAsc ? a.value - b.value : b.value - a.value;
});
} else if (config.data_order === 'asc') {
d.sort(function(a,b){
return a.value-b.value;
} else {
var targets = $$.orderTargets($$.data.targets);
var data_targets = targets.map(function (i) {
return i.id;
});
d.sort(function(a, b) {
if (a.value > 0 && b.value > 0) {
return orderAsc ? data_targets.indexOf(a.id) - data_targets.indexOf(b.id) : data_targets.indexOf(b.id) - data_targets.indexOf(a.id);
} else {
return orderAsc ? a.value - b.value : b.value - a.value;
}
});
}

Loading…
Cancel
Save