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

Function calcTextinfo

src/traces/bar/plot.js:1085–1159  ·  view source on GitHub ↗
(cd, index, xa, ya)

Source from the content-addressed store, hash-verified

1083}
1084
1085function calcTextinfo(cd, index, xa, ya) {
1086 var trace = cd[0].trace;
1087 var isHorizontal = trace.orientation === 'h';
1088 var isWaterfall = trace.type === 'waterfall';
1089 var isFunnel = trace.type === 'funnel';
1090
1091 function formatLabel(u) {
1092 var pAxis = isHorizontal ? ya : xa;
1093 return tickText(pAxis, u, true).text;
1094 }
1095
1096 function formatNumber(v) {
1097 var sAxis = isHorizontal ? xa : ya;
1098 return tickText(sAxis, +v, true).text;
1099 }
1100
1101 var textinfo = trace.textinfo;
1102 var cdi = cd[index];
1103
1104 var parts = textinfo.split('+');
1105 var text = [];
1106 var tx;
1107
1108 var hasFlag = function (flag) {
1109 return parts.indexOf(flag) !== -1;
1110 };
1111
1112 if (hasFlag('label')) {
1113 text.push(formatLabel(cd[index].p));
1114 }
1115
1116 if (hasFlag('text')) {
1117 tx = Lib.castOption(trace, cdi.i, 'text');
1118 if (tx === 0 || tx) text.push(tx);
1119 }
1120
1121 if (isWaterfall) {
1122 var delta = +cdi.rawS || cdi.s;
1123 var final = cdi.v;
1124 var initial = final - delta;
1125
1126 if (hasFlag('initial')) text.push(formatNumber(initial));
1127 if (hasFlag('delta')) text.push(formatNumber(delta));
1128 if (hasFlag('final')) text.push(formatNumber(final));
1129 }
1130
1131 if (isFunnel) {
1132 if (hasFlag('value')) text.push(formatNumber(cdi.s));
1133
1134 var nPercent = 0;
1135 if (hasFlag('percent initial')) nPercent++;
1136 if (hasFlag('percent previous')) nPercent++;
1137 if (hasFlag('percent total')) nPercent++;
1138
1139 var hasMultiplePercents = nPercent > 1;
1140
1141 if (hasFlag('percent initial')) {
1142 tx = Lib.formatPercent(cdi.begR);

Callers 1

getTextFunction · 0.85

Calls 3

formatLabelFunction · 0.85
hasFlagFunction · 0.70
formatNumberFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…