From 6a54fdbf5831b482bc2d9fc2bb13d61a5bad7faa Mon Sep 17 00:00:00 2001 From: GermainBergeron Date: Mon, 21 Mar 2016 09:27:43 -0400 Subject: [PATCH] Add option to configure pie label ratio Keep default behaviour when no option is set Works with a number or a function Fixes #1628 --- src/arc.js | 9 ++++++--- src/config.js | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/arc.js b/src/arc.js index 748291e..fa31784 100644 --- a/src/arc.js +++ b/src/arc.js @@ -87,15 +87,18 @@ c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { c3_chart_internal_fn.transformForArcLabel = function (d) { - var $$ = this, + var $$ = this, config = $$.config, updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; if (updated && !$$.hasType('gauge')) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; h = Math.sqrt(x * x + y * y); - // TODO: ratio should be an option? - ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0; + if (config.pie_label_ratio) { + 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) + ")"; } return translate; diff --git a/src/config.js b/src/config.js index 6b65e1f..1e3f19b 100644 --- a/src/config.js +++ b/src/config.js @@ -172,6 +172,7 @@ c3_chart_internal_fn.getDefaultConfig = function () { pie_label_show: true, pie_label_format: undefined, pie_label_threshold: 0.05, + pie_label_ratio: undefined, pie_expand: {}, pie_expand_duration: 50, // gauge