Browse Source

Add option to configure pie label ratio

Keep default behaviour when no option is set
Works with a number or a function
Fixes  #1628
pull/1675/head
GermainBergeron 9 years ago committed by Ændrew Rininsland
parent
commit
6a54fdbf58
  1. 9
      src/arc.js
  2. 1
      src/config.js

9
src/arc.js

@ -87,15 +87,18 @@ c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) {
c3_chart_internal_fn.transformForArcLabel = function (d) { c3_chart_internal_fn.transformForArcLabel = function (d) {
var $$ = this, var $$ = this, config = $$.config,
updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; updated = $$.updateAngle(d), c, x, y, h, ratio, translate = "";
if (updated && !$$.hasType('gauge')) { if (updated && !$$.hasType('gauge')) {
c = this.svgArc.centroid(updated); c = this.svgArc.centroid(updated);
x = isNaN(c[0]) ? 0 : c[0]; x = isNaN(c[0]) ? 0 : c[0];
y = isNaN(c[1]) ? 0 : c[1]; y = isNaN(c[1]) ? 0 : c[1];
h = Math.sqrt(x * x + y * y); h = Math.sqrt(x * x + y * y);
// TODO: ratio should be an option? if (config.pie_label_ratio) {
ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0; ratio = isFunction(config.pie_label_ratio) ? config.pie_label_ratio(d, $$.radius, h) : config.pie_label_ratio;
} else {
ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0;
}
translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")"; translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")";
} }
return translate; return translate;

1
src/config.js

@ -172,6 +172,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
pie_label_show: true, pie_label_show: true,
pie_label_format: undefined, pie_label_format: undefined,
pie_label_threshold: 0.05, pie_label_threshold: 0.05,
pie_label_ratio: undefined,
pie_expand: {}, pie_expand: {},
pie_expand_duration: 50, pie_expand_duration: 50,
// gauge // gauge

Loading…
Cancel
Save