MCPcopy Create free account
hub / github.com/chartjs/Chart.js / drawTitle

Method drawTitle

src/plugins/plugin.tooltip.js:814–842  ·  view source on GitHub ↗
(pt, ctx, options)

Source from the content-addressed store, hash-verified

812 }
813
814 drawTitle(pt, ctx, options) {
815 const title = this.title;
816 const length = title.length;
817 let titleFont, titleSpacing, i;
818
819 if (length) {
820 const rtlHelper = getRtlAdapter(options.rtl, this.x, this.width);
821
822 pt.x = getAlignedX(this, options.titleAlign, options);
823
824 ctx.textAlign = rtlHelper.textAlign(options.titleAlign);
825 ctx.textBaseline = 'middle';
826
827 titleFont = toFont(options.titleFont);
828 titleSpacing = options.titleSpacing;
829
830 ctx.fillStyle = options.titleColor;
831 ctx.font = titleFont.string;
832
833 for (i = 0; i < length; ++i) {
834 ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2);
835 pt.y += titleFont.lineHeight + titleSpacing; // Line Height and spacing
836
837 if (i + 1 === length) {
838 pt.y += options.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
839 }
840 }
841 }
842 }
843
844 /**
845 * @private

Callers 1

drawMethod · 0.95

Calls 5

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

Tested by

no test coverage detected