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

Function appendBarText

src/traces/bar/plot.js:531–732  ·  view source on GitHub ↗
(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, opts, makeOnCompleteCallback)

Source from the content-addressed store, hash-verified

529}
530
531function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, opts, makeOnCompleteCallback) {
532 var xa = plotinfo.xaxis;
533 var ya = plotinfo.yaxis;
534
535 var fullLayout = gd._fullLayout;
536 var textPosition;
537
538 function appendTextNode(bar, text, font) {
539 var textSelection = Lib.ensureSingle(bar, 'text')
540 .text(text)
541 .attr({
542 class: 'bartext bartext-' + textPosition,
543 'text-anchor': 'middle',
544 // prohibit tex interpretation until we can handle
545 // tex and regular text together
546 'data-notex': 1
547 })
548 .call(Drawing.font, font)
549 .call(svgTextUtils.convertToTspans, gd);
550
551 return textSelection;
552 }
553
554 // get trace attributes
555 var trace = cd[0].trace;
556 var isHorizontal = trace.orientation === 'h';
557
558 var text = getText(fullLayout, cd, i, xa, ya);
559
560 textPosition = getTextPosition(trace, i);
561
562 // compute text position
563 var inStackOrRelativeMode = opts.mode === 'stack' || opts.mode === 'relative';
564
565 var calcBar = cd[i];
566 var isOutmostBar = !inStackOrRelativeMode || calcBar._outmost;
567 var hasB = calcBar.hasB;
568 var barIsRounded = r && r - overhead > TEXTPAD;
569
570 if (
571 !text ||
572 textPosition === 'none' ||
573 ((calcBar.isBlank || x0 === x1 || y0 === y1) && (textPosition === 'auto' || textPosition === 'inside'))
574 ) {
575 bar.select('text').remove();
576 return;
577 }
578
579 var layoutFont = fullLayout.font;
580 var barColor = style.getBarColor(cd[i], trace);
581 var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor);
582 var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont);
583 var insidetextanchor = trace.insidetextanchor || 'end';
584
585 // Special case: don't use the c2p(v, true) value on log size axes,
586 // so that we can get correctly inside text scaling
587 var di = bar.datum();
588 if (isHorizontal) {

Callers 1

plotFunction · 0.85

Calls 8

getTextFunction · 0.85
getTextPositionFunction · 0.85
appendTextNodeFunction · 0.85
textfitsInsideBarFunction · 0.85
toMoveOutsideBarFunction · 0.85
toMoveInsideBarFunction · 0.85
recordMinTextSizeFunction · 0.85
transitionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…