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

Function renderText

src/helpers/helpers.canvas.ts:449–491  ·  view source on GitHub ↗
(
  ctx: CanvasRenderingContext2D,
  text: string | string[],
  x: number,
  y: number,
  font: CanvasFontSpec,
  opts: RenderTextOpts = {}
)

Source from the content-addressed store, hash-verified

447 * Render text onto the canvas
448 */
449export function renderText(
450 ctx: CanvasRenderingContext2D,
451 text: string | string[],
452 x: number,
453 y: number,
454 font: CanvasFontSpec,
455 opts: RenderTextOpts = {}
456) {
457 const lines = isArray(text) ? text : [text];
458 const stroke = opts.strokeWidth > 0 && opts.strokeColor !== '';
459 let i: number, line: string;
460
461 ctx.save();
462 ctx.font = font.string;
463 setRenderOpts(ctx, opts);
464
465 for (i = 0; i < lines.length; ++i) {
466 line = lines[i];
467
468 if (opts.backdrop) {
469 drawBackdrop(ctx, opts.backdrop);
470 }
471
472 if (stroke) {
473 if (opts.strokeColor) {
474 ctx.strokeStyle = opts.strokeColor;
475 }
476
477 if (!isNullOrUndef(opts.strokeWidth)) {
478 ctx.lineWidth = opts.strokeWidth;
479 }
480
481 ctx.strokeText(line, x, y, opts.maxWidth);
482 }
483
484 ctx.fillText(line, x, y, opts.maxWidth);
485 decorateText(ctx, x, y, line, opts);
486
487 y += Number(font.lineHeight);
488 }
489
490 ctx.restore();
491}
492
493/**
494 * Add a path of a rectangle with rounded corners to the current sub-path

Callers 7

drawLabelsMethod · 0.85
drawTitleMethod · 0.85
fillTextMethod · 0.85
drawTitleMethod · 0.85
drawMethod · 0.85
drawPointLabelsFunction · 0.85
drawLabelsMethod · 0.85

Calls 6

isArrayFunction · 0.85
setRenderOptsFunction · 0.85
drawBackdropFunction · 0.85
isNullOrUndefFunction · 0.85
decorateTextFunction · 0.85
fillTextMethod · 0.80

Tested by

no test coverage detected