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

Function horizontalAlignTitle

src/components/legend/draw.js:59–79  ·  view source on GitHub ↗
(titleEl, legendObj, bw)

Source from the content-addressed store, hash-verified

57
58// After legend dimensions are calculated the title can be aligned horizontally left, center, right
59function horizontalAlignTitle(titleEl, legendObj, bw) {
60 if((legendObj.title.side !== 'top center') && (legendObj.title.side !== 'top right')) return;
61
62 var font = legendObj.title.font;
63 var lineHeight = font.size * LINE_SPACING;
64 var titleOffset = 0;
65 var textNode = titleEl.node();
66
67 var width = Drawing.bBox(textNode).width; // width of the title text
68
69 if(legendObj.title.side === 'top center') {
70 titleOffset = 0.5 * (legendObj._width - 2 * bw - 2 * constants.titlePad - width);
71 } else if(legendObj.title.side === 'top right') {
72 titleOffset = legendObj._width - 2 * bw - 2 * constants.titlePad - width;
73 }
74
75 svgTextUtils.positionText(titleEl,
76 bw + constants.titlePad + titleOffset,
77 bw + lineHeight
78 );
79}
80
81
82function drawOne(gd, opts) {

Callers 1

computeLegendDimensionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…