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

Function calcTexttemplate

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

Source from the content-addressed store, hash-verified

1000}
1001
1002function calcTexttemplate(fullLayout, cd, index, xa, ya) {
1003 var trace = cd[0].trace;
1004 var texttemplate = Lib.castOption(trace, index, 'texttemplate');
1005 if (!texttemplate) return '';
1006 var isHistogram = trace.type === 'histogram';
1007 var isWaterfall = trace.type === 'waterfall';
1008 var isFunnel = trace.type === 'funnel';
1009 var isHorizontal = trace.orientation === 'h';
1010
1011 var pLetter, pAxis;
1012 var vLetter, vAxis;
1013 if (isHorizontal) {
1014 pLetter = 'y';
1015 pAxis = ya;
1016 vLetter = 'x';
1017 vAxis = xa;
1018 } else {
1019 pLetter = 'x';
1020 pAxis = xa;
1021 vLetter = 'y';
1022 vAxis = ya;
1023 }
1024
1025 function formatLabel(u) {
1026 return tickText(pAxis, pAxis.c2l(u), true).text;
1027 }
1028
1029 function formatNumber(v) {
1030 return tickText(vAxis, vAxis.c2l(v), true).text;
1031 }
1032
1033 var cdi = cd[index];
1034 var obj = {};
1035
1036 obj.label = cdi.p;
1037 obj.labelLabel = obj[pLetter + 'Label'] = formatLabel(cdi.p);
1038
1039 var tx = Lib.castOption(trace, cdi.i, 'text');
1040 if (tx === 0 || tx) obj.text = tx;
1041
1042 obj.value = cdi.s;
1043 obj.valueLabel = obj[vLetter + 'Label'] = formatNumber(cdi.s);
1044
1045 var pt = {};
1046 appendArrayPointValue(pt, trace, cdi.i);
1047
1048 if (isHistogram || pt.x === undefined) pt.x = isHorizontal ? obj.value : obj.label;
1049 if (isHistogram || pt.y === undefined) pt.y = isHorizontal ? obj.label : obj.value;
1050 if (isHistogram || pt.xLabel === undefined) pt.xLabel = isHorizontal ? obj.valueLabel : obj.labelLabel;
1051 if (isHistogram || pt.yLabel === undefined) pt.yLabel = isHorizontal ? obj.labelLabel : obj.valueLabel;
1052
1053 if (isWaterfall) {
1054 obj.delta = +cdi.rawS || cdi.s;
1055 obj.deltaLabel = formatNumber(obj.delta);
1056 obj.final = cdi.v;
1057 obj.finalLabel = formatNumber(obj.final);
1058 obj.initial = obj.final - obj.delta;
1059 obj.initialLabel = formatNumber(obj.initial);

Callers 1

getTextFunction · 0.85

Calls 2

formatLabelFunction · 0.85
formatNumberFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…