Skip to content

Commit 564fa79

Browse files
committed
expose pie insert text info function
1 parent d996136 commit 564fa79

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/traces/pie/calc.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,36 @@ function calc(gd, trace) {
8585
// include the sum of all values in the first point
8686
if(cd[0]) cd[0].vTotal = vTotal;
8787

88-
// now insert text
8988
if(trace.textinfo && trace.textinfo !== 'none') {
90-
var hasLabel = trace.textinfo.indexOf('label') !== -1;
91-
var hasText = trace.textinfo.indexOf('text') !== -1;
92-
var hasValue = trace.textinfo.indexOf('value') !== -1;
93-
var hasPercent = trace.textinfo.indexOf('percent') !== -1;
94-
var separators = fullLayout.separators;
95-
96-
var thisText;
97-
98-
for(i = 0; i < cd.length; i++) {
99-
pt = cd[i];
100-
thisText = hasLabel ? [pt.label] : [];
101-
if(hasText) {
102-
var texti = helpers.getFirstFilled(trace.text, pt.pts);
103-
if(texti) thisText.push(texti);
104-
}
105-
if(hasValue) thisText.push(helpers.formatPieValue(pt.v, separators));
106-
if(hasPercent) thisText.push(helpers.formatPiePercent(pt.v / vTotal, separators));
107-
pt.text = thisText.join('<br>');
89+
// now insert text
90+
cd = insertText(gd, trace, cd, vTotal);
91+
}
92+
93+
return cd;
94+
}
95+
96+
function insertText(gd, trace, cd, vTotal) {
97+
var fullLayout = gd._fullLayout;
98+
var i, pt;
99+
100+
var hasLabel = trace.textinfo.indexOf('label') !== -1;
101+
var hasText = trace.textinfo.indexOf('text') !== -1;
102+
var hasValue = trace.textinfo.indexOf('value') !== -1;
103+
var hasPercent = trace.textinfo.indexOf('percent') !== -1;
104+
var separators = fullLayout.separators;
105+
106+
var thisText;
107+
108+
for(i = 0; i < cd.length; i++) {
109+
pt = cd[i];
110+
thisText = hasLabel ? [pt.label] : [];
111+
if(hasText) {
112+
var texti = helpers.getFirstFilled(trace.text, pt.pts);
113+
if(texti) thisText.push(texti);
108114
}
115+
if(hasValue) thisText.push(helpers.formatPieValue(pt.v, separators));
116+
if(hasPercent) thisText.push(helpers.formatPiePercent(pt.v / vTotal, separators));
117+
pt.text = thisText.join('<br>');
109118
}
110119

111120
return cd;
@@ -189,6 +198,7 @@ function generateExtendedColors(colorList, extendedColorWays) {
189198
module.exports = {
190199
calc: calc,
191200
crossTraceCalc: crossTraceCalc,
201+
insertText: insertText,
192202

193203
makePullColorFn: makePullColorFn,
194204
generateExtendedColors: generateExtendedColors

0 commit comments

Comments
 (0)