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

Method drawBackground

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

Source from the content-addressed store, hash-verified

1017 }
1018
1019 drawBackground(pt, ctx, tooltipSize, options) {
1020 const {xAlign, yAlign} = this;
1021 const {x, y} = pt;
1022 const {width, height} = tooltipSize;
1023 const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(options.cornerRadius);
1024
1025 ctx.fillStyle = options.backgroundColor;
1026 ctx.strokeStyle = options.borderColor;
1027 ctx.lineWidth = options.borderWidth;
1028
1029 ctx.beginPath();
1030 ctx.moveTo(x + topLeft, y);
1031 if (yAlign === 'top') {
1032 this.drawCaret(pt, ctx, tooltipSize, options);
1033 }
1034 ctx.lineTo(x + width - topRight, y);
1035 ctx.quadraticCurveTo(x + width, y, x + width, y + topRight);
1036 if (yAlign === 'center' && xAlign === 'right') {
1037 this.drawCaret(pt, ctx, tooltipSize, options);
1038 }
1039 ctx.lineTo(x + width, y + height - bottomRight);
1040 ctx.quadraticCurveTo(x + width, y + height, x + width - bottomRight, y + height);
1041 if (yAlign === 'bottom') {
1042 this.drawCaret(pt, ctx, tooltipSize, options);
1043 }
1044 ctx.lineTo(x + bottomLeft, y + height);
1045 ctx.quadraticCurveTo(x, y + height, x, y + height - bottomLeft);
1046 if (yAlign === 'center' && xAlign === 'left') {
1047 this.drawCaret(pt, ctx, tooltipSize, options);
1048 }
1049 ctx.lineTo(x, y + topLeft);
1050 ctx.quadraticCurveTo(x, y, x + topLeft, y);
1051 ctx.closePath();
1052
1053 ctx.fill();
1054
1055 if (options.borderWidth > 0) {
1056 ctx.stroke();
1057 }
1058 }
1059
1060 /**
1061 * Update x/y animation targets when _active elements are animating too

Callers 1

drawMethod · 0.95

Calls 2

drawCaretMethod · 0.95
toTRBLCornersFunction · 0.85

Tested by

no test coverage detected