mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
* Create standardized text render method * Document renderText options and enable configurable decoration width * Add tests for font rendering * Split color definition to it's own file * renderText supports setting styles * Mock context needs to track textBaseline * renderText can set textAlign and textBaseline * renderText does not mutate the context + translate/rotate * Explicitly set the text decoration style * Move useStroke logic into renderText * Cartesian scale: Update computeLabelItems to avoid duplicate allocations
104 lines
2.5 KiB
TypeScript
104 lines
2.5 KiB
TypeScript
import { PointStyle } from '../index.esm';
|
|
import { Color } from '../color';
|
|
import { ChartArea } from '../geometric';
|
|
import { CanvasFontSpec } from './helpers.options';
|
|
|
|
/**
|
|
* Clears the entire canvas associated to the given `chart`.
|
|
* @param {Chart} chart - The chart for which to clear the canvas.
|
|
*/
|
|
export function clear(chart: { ctx: CanvasRenderingContext2D }): void;
|
|
|
|
export function clipArea(ctx: CanvasRenderingContext2D, area: ChartArea): void;
|
|
|
|
export function unclipArea(ctx: CanvasRenderingContext2D): void;
|
|
|
|
export interface DrawPointOptions {
|
|
pointStyle: PointStyle;
|
|
rotation?: number;
|
|
radius: number;
|
|
borderWidth: number;
|
|
}
|
|
|
|
export function drawPoint(ctx: CanvasRenderingContext2D, options: DrawPointOptions, x: number, y: number): void;
|
|
|
|
/**
|
|
* Converts the given font object into a CSS font string.
|
|
* @param font a font object
|
|
* @return The CSS font string. See https://developer.mozilla.org/en-US/docs/Web/CSS/font
|
|
*/
|
|
export function toFontString(font: { size: number; family: string; style?: string; weight?: string }): string | null;
|
|
|
|
export interface RenderTextOpts {
|
|
/**
|
|
* The fill color of the text. If unset, the existing
|
|
* fillStyle property of the canvas is unchanged.
|
|
*/
|
|
color?: Color;
|
|
|
|
/**
|
|
* The width of the strikethrough / underline
|
|
* @default 2
|
|
*/
|
|
decorationWidth?: number;
|
|
|
|
/**
|
|
* The max width of the text in pixels
|
|
*/
|
|
maxWidth?: number;
|
|
|
|
/**
|
|
* A rotation to be applied to the canvas
|
|
* This is applied after the translation is applied
|
|
*/
|
|
rotation?: number;
|
|
|
|
/**
|
|
* Apply a strikethrough effect to the text
|
|
*/
|
|
strikethrough?: boolean;
|
|
|
|
/**
|
|
* The color of the text stroke. If unset, the existing
|
|
* strokeStyle property of the context is unchanged
|
|
*/
|
|
strokeColor?: Color;
|
|
|
|
/**
|
|
* The text stroke width. If unset, the existing
|
|
* lineWidth property of the context is unchanged
|
|
*/
|
|
strokeWidth?: number;
|
|
|
|
/**
|
|
* The text alignment to use. If unset, the existing
|
|
* textAlign property of the context is unchanged
|
|
*/
|
|
textAlign: CanvasTextAlign;
|
|
|
|
/**
|
|
* The text baseline to use. If unset, the existing
|
|
* textBaseline property of the context is unchanged
|
|
*/
|
|
textBaseline: CanvasTextBaseline;
|
|
|
|
/**
|
|
* If specified, a translation to apply to the context
|
|
*/
|
|
translation?: [number, number];
|
|
|
|
/**
|
|
* Underline the text
|
|
*/
|
|
underline?: boolean;
|
|
}
|
|
|
|
export function renderText(
|
|
ctx: CanvasRenderingContext2D,
|
|
text: string | string[],
|
|
x: number,
|
|
y: number,
|
|
font: CanvasFontSpec,
|
|
opts?: RenderTextOpts
|
|
): void;
|