MCPcopy Index your code
hub / github.com/plotly/plotly.js / formatSliceLabel

Function formatSliceLabel

src/traces/pie/plot.js:1222–1283  ·  view source on GitHub ↗
(gd, pt, cd0)

Source from the content-addressed store, hash-verified

1220}
1221
1222function formatSliceLabel(gd, pt, cd0) {
1223 var fullLayout = gd._fullLayout;
1224 var trace = cd0.trace;
1225 // look for textemplate
1226 var texttemplate = trace.texttemplate;
1227
1228 // now insert text
1229 var textinfo = trace.textinfo;
1230 if (!texttemplate && textinfo && textinfo !== 'none') {
1231 var parts = textinfo.split('+');
1232 var hasFlag = function (flag) {
1233 return parts.indexOf(flag) !== -1;
1234 };
1235 var hasLabel = hasFlag('label');
1236 var hasText = hasFlag('text');
1237 var hasValue = hasFlag('value');
1238 var hasPercent = hasFlag('percent');
1239
1240 var separators = fullLayout.separators;
1241 var text;
1242
1243 text = hasLabel ? [pt.label] : [];
1244 if (hasText) {
1245 var tx = helpers.getFirstFilled(trace.text, pt.pts);
1246 if (isValidTextValue(tx)) text.push(tx);
1247 }
1248 if (hasValue) text.push(helpers.formatPieValue(pt.v, separators));
1249 if (hasPercent) text.push(helpers.formatPiePercent(pt.v / cd0.vTotal, separators));
1250 pt.text = text.join('<br>');
1251 }
1252
1253 function makeTemplateVariables(pt) {
1254 return {
1255 label: pt.label,
1256 value: pt.v,
1257 valueLabel: helpers.formatPieValue(pt.v, fullLayout.separators),
1258 percent: pt.v / cd0.vTotal,
1259 percentLabel: helpers.formatPiePercent(pt.v / cd0.vTotal, fullLayout.separators),
1260 color: pt.color,
1261 text: pt.text,
1262 customdata: Lib.castOption(trace, pt.i, 'customdata')
1263 };
1264 }
1265
1266 if (texttemplate) {
1267 var txt = Lib.castOption(trace, pt.i, 'texttemplate');
1268 if (!txt) {
1269 pt.text = '';
1270 } else {
1271 var obj = makeTemplateVariables(pt);
1272 var ptTx = helpers.getFirstFilled(trace.text, pt.pts);
1273 if (isValidTextValue(ptTx) || ptTx === '') obj.text = ptTx;
1274 pt.text = Lib.texttemplateString({
1275 data: [obj, trace._meta],
1276 fallback: trace.texttemplatefallback,
1277 labels: obj,
1278 locale: gd._fullLayout._d3locale,
1279 template: txt

Callers 4

plot.jsFile · 0.85
plotFunction · 0.85

Calls 2

makeTemplateVariablesFunction · 0.85
hasFlagFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…