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

Method draw

src/plugins/plugin.tooltip.js:1098–1149  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

1096 }
1097
1098 draw(ctx) {
1099 const options = this.options.setContext(this.getContext());
1100 let opacity = this.opacity;
1101
1102 if (!opacity) {
1103 return;
1104 }
1105
1106 this._updateAnimationTarget(options);
1107
1108 const tooltipSize = {
1109 width: this.width,
1110 height: this.height
1111 };
1112 const pt = {
1113 x: this.x,
1114 y: this.y
1115 };
1116
1117 // IE11/Edge does not like very small opacities, so snap to 0
1118 opacity = Math.abs(opacity) < 1e-3 ? 0 : opacity;
1119
1120 const padding = toPadding(options.padding);
1121
1122 // Truthy/falsey value for empty tooltip
1123 const hasTooltipContent = this.title.length || this.beforeBody.length || this.body.length || this.afterBody.length || this.footer.length;
1124
1125 if (options.enabled && hasTooltipContent) {
1126 ctx.save();
1127 ctx.globalAlpha = opacity;
1128
1129 // Draw Background
1130 this.drawBackground(pt, ctx, tooltipSize, options);
1131
1132 overrideTextDirection(ctx, options.textDirection);
1133
1134 pt.y += padding.top;
1135
1136 // Titles
1137 this.drawTitle(pt, ctx, options);
1138
1139 // Body
1140 this.drawBody(pt, ctx, options);
1141
1142 // Footer
1143 this.drawFooter(pt, ctx, options);
1144
1145 restoreTextDirection(ctx);
1146
1147 ctx.restore();
1148 }
1149 }
1150
1151 /**
1152 * Drops the active elements whose data is hidden or no longer exists, after the chart

Callers

nothing calls this directly

Calls 10

getContextMethod · 0.95
drawBackgroundMethod · 0.95
drawTitleMethod · 0.95
drawBodyMethod · 0.95
drawFooterMethod · 0.95
toPaddingFunction · 0.85
overrideTextDirectionFunction · 0.85
restoreTextDirectionFunction · 0.85
setContextMethod · 0.80

Tested by

no test coverage detected