From 564fa79c32bf0b654b44fac04afc4e73b5d28955 Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 16 Apr 2019 21:40:44 -0400 Subject: [PATCH] expose pie insert text info function --- src/traces/pie/calc.js | 48 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/traces/pie/calc.js b/src/traces/pie/calc.js index f918f51ba30..2544a289c95 100644 --- a/src/traces/pie/calc.js +++ b/src/traces/pie/calc.js @@ -85,27 +85,36 @@ function calc(gd, trace) { // include the sum of all values in the first point if(cd[0]) cd[0].vTotal = vTotal; - // now insert text if(trace.textinfo && trace.textinfo !== 'none') { - var hasLabel = trace.textinfo.indexOf('label') !== -1; - var hasText = trace.textinfo.indexOf('text') !== -1; - var hasValue = trace.textinfo.indexOf('value') !== -1; - var hasPercent = trace.textinfo.indexOf('percent') !== -1; - var separators = fullLayout.separators; - - var thisText; - - for(i = 0; i < cd.length; i++) { - pt = cd[i]; - thisText = hasLabel ? [pt.label] : []; - if(hasText) { - var texti = helpers.getFirstFilled(trace.text, pt.pts); - if(texti) thisText.push(texti); - } - if(hasValue) thisText.push(helpers.formatPieValue(pt.v, separators)); - if(hasPercent) thisText.push(helpers.formatPiePercent(pt.v / vTotal, separators)); - pt.text = thisText.join('
'); + // now insert text + cd = insertText(gd, trace, cd, vTotal); + } + + return cd; +} + +function insertText(gd, trace, cd, vTotal) { + var fullLayout = gd._fullLayout; + var i, pt; + + var hasLabel = trace.textinfo.indexOf('label') !== -1; + var hasText = trace.textinfo.indexOf('text') !== -1; + var hasValue = trace.textinfo.indexOf('value') !== -1; + var hasPercent = trace.textinfo.indexOf('percent') !== -1; + var separators = fullLayout.separators; + + var thisText; + + for(i = 0; i < cd.length; i++) { + pt = cd[i]; + thisText = hasLabel ? [pt.label] : []; + if(hasText) { + var texti = helpers.getFirstFilled(trace.text, pt.pts); + if(texti) thisText.push(texti); } + if(hasValue) thisText.push(helpers.formatPieValue(pt.v, separators)); + if(hasPercent) thisText.push(helpers.formatPiePercent(pt.v / vTotal, separators)); + pt.text = thisText.join('
'); } return cd; @@ -189,6 +198,7 @@ function generateExtendedColors(colorList, extendedColorWays) { module.exports = { calc: calc, crossTraceCalc: crossTraceCalc, + insertText: insertText, makePullColorFn: makePullColorFn, generateExtendedColors: generateExtendedColors