MCPcopy
hub / github.com/chartjs/Chart.js / drawTitle

Method drawTitle

src/plugins/plugin.tooltip.js:756–784  ·  src/plugins/plugin.tooltip.js::Tooltip.drawTitle
(pt, ctx, options)

Source from the content-addressed store, hash-verified

754 }
755
756 drawTitle(pt, ctx, options) {
757 const title = this.title;
758 const length = title.length;
759 let titleFont, titleSpacing, i;
760
761 if (length) {
762 const rtlHelper = getRtlAdapter(options.rtl, this.x, this.width);
763
764 pt.x = getAlignedX(this, options.titleAlign, options);
765
766 ctx.textAlign = rtlHelper.textAlign(options.titleAlign);
767 ctx.textBaseline = class="st">'middle';
768
769 titleFont = toFont(options.titleFont);
770 titleSpacing = options.titleSpacing;
771
772 ctx.fillStyle = options.titleColor;
773 ctx.font = titleFont.string;
774
775 for (i = 0; i < length; ++i) {
776 ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2);
777 pt.y += titleFont.lineHeight + titleSpacing; class="cm">// Line Height and spacing
778
779 if (i + 1 === length) {
780 pt.y += options.titleMarginBottom - titleSpacing; class="cm">// If Last, add margin, remove spacing
781 }
782 }
783 }
784 }
785
786 /**
787 * @private

Callers 1

drawMethod · 0.95

Calls 6

getRtlAdapterFunction · 0.85
getAlignedXFunction · 0.85
toFontFunction · 0.85
textAlignMethod · 0.80
fillTextMethod · 0.80
xMethod · 0.80

Tested by

no test coverage detected