From 6ba6ce89ce0c43c43379ea00356edd11e3012e25 Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Tue, 27 May 2014 11:01:16 -0400 Subject: [PATCH] adding label threshold for pie/donut --- c3.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/c3.js b/c3.js index d2180b8..a3defcb 100644 --- a/c3.js +++ b/c3.js @@ -242,6 +242,7 @@ // pie var __pie_label_show = getConfig(['pie', 'label', 'show'], true), __pie_label_format = getConfig(['pie', 'label', 'format']), + __pie_label_threshold = getConfig(['pie', 'label', 'threshold'], 0.05), __pie_expand = getConfig(['pie', 'expand'], true), __pie_onclick = getConfig(['pie', 'onclick'], function () {}), __pie_onmouseover = getConfig(['pie', 'onmouseover'], function () {}), @@ -250,6 +251,7 @@ // donut var __donut_label_show = getConfig(['donut', 'label', 'show'], true), __donut_label_format = getConfig(['donut', 'label', 'format']), + __donut_label_threshold = getConfig(['donut', 'label', 'threshold'], 0.05), __donut_expand = getConfig(['donut', 'expand'], true), __donut_title = getConfig(['donut', 'title'], ""), __donut_onclick = getConfig(['donut', 'onclick'], function () {}), @@ -1016,6 +1018,7 @@ updated = updateAngle(d); value = updated ? updated.value : null; ratio = getArcRatio(updated); + if (! meetsArcLabelThreshold(ratio)) { return ""; } format = getArcLabelFormat(); return format ? format(value, ratio) : defaultArcValueFormat(value, ratio); } @@ -1050,6 +1053,10 @@ function shouldShowArcLabel() { return hasDonutType(c3.data.targets) ? __donut_label_show : __pie_label_show; } + function meetsArcLabelThreshold(ratio) { + var threshold = hasDonutType(c3.data.targets) ? __donut_label_threshold : __pie_label_threshold; + return ratio >= threshold; + } function getArcLabelFormat() { return hasDonutType(c3.data.targets) ? __donut_label_format : __pie_label_format; }