From: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Date: Wed, 25 May 2022 11:49:12 +0000 (+0200) Subject: Types: Allow font to be partial scriptable and individually scriptable (#10364) X-Git-Tag: v3.8.0~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5173d05978e02dbe3f00961f441e406c8118dc3b;p=thirdparty%2FChart.js.git Types: Allow font to be partial scriptable and individually scriptable (#10364) * allow font scriptable to return partial object and be scriptable * add other elements as scriptable * rename variable for context to resolve lint issue * add duplicate font for non scriptable * change to scriptableOptions * fix parameter * missing space * Change name of helper function to match other helper function --- diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 9c00dc5a5..adbdca765 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -38,6 +38,7 @@ export interface ScriptableLineSegmentContext { export type Scriptable = T | ((ctx: TContext, options: AnyObject) => T | undefined); export type ScriptableOptions = { [P in keyof T]: Scriptable }; +export type ScriptableAndScriptableOptions = Scriptable | ScriptableOptions; export type ScriptableAndArray = readonly T[] | Scriptable; export type ScriptableAndArrayOptions = { [P in keyof T]: ScriptableAndArray }; @@ -2310,7 +2311,7 @@ export interface LegendOptions { * Font of label * @see Defaults.font */ - font: FontSpec; + font: ScriptableAndScriptableOptions, ScriptableChartContext>; /** * Padding between rows of colored boxes. * @default 10 @@ -2371,7 +2372,7 @@ export interface LegendOptions { /** * see Fonts */ - font: FontSpec; + font: ScriptableAndScriptableOptions, ScriptableChartContext>; position: 'center' | 'start' | 'end'; padding?: number | ChartArea; /** @@ -2405,7 +2406,7 @@ export interface TitleOptions { * @see Defaults.color */ color: Color; - font: FontSpec; + font: ScriptableAndScriptableOptions, ScriptableChartContext>; /** * Marks that this box should take the full width/height of the canvas (moving other boxes). If set to `false`, places the box above/beside the @@ -2636,7 +2637,7 @@ export interface TooltipOptions extends Cor * See Fonts * @default {weight: 'bold'} */ - titleFont: Scriptable>; + titleFont: ScriptableAndScriptableOptions, ScriptableTooltipContext>; /** * Spacing to add to top and bottom of each title line. * @default 2 @@ -2666,7 +2667,7 @@ export interface TooltipOptions extends Cor * See Fonts. * @default {} */ - bodyFont: Scriptable>; + bodyFont: ScriptableAndScriptableOptions, ScriptableTooltipContext>; /** * Horizontal alignment of the body text lines. * @default 'left' @@ -2691,7 +2692,7 @@ export interface TooltipOptions extends Cor * See Fonts * @default {weight: 'bold'} */ - footerFont: Scriptable>; + footerFont: ScriptableAndScriptableOptions, ScriptableTooltipContext>; /** * Horizontal alignment of the footer text lines. * @default 'left' @@ -2926,7 +2927,7 @@ export interface TickOptions { /** * see Fonts */ - font: Scriptable; + font: ScriptableAndScriptableOptions, ScriptableScaleContext>; /** * Sets the offset of the tick labels from the axis */ @@ -3029,6 +3030,16 @@ export type CartesianTickOptions = TickOptions & { maxTicksLimit: number; } +export interface ScriptableCartesianScaleContext { + scale: keyof CartesianScaleTypeRegistry; + type: string; +} + +export interface ScriptableChartContext { + chart: Chart; + type: string; +} + export interface CartesianScaleOptions extends CoreScaleOptions { /** * Scale boundary strategy (bypassed by min/max time options) @@ -3089,7 +3100,7 @@ export interface CartesianScaleOptions extends CoreScaleOptions { /** Color of the axis label. */ color: Color; /** Information about the axis title font. */ - font: FontSpec; + font: ScriptableAndScriptableOptions, ScriptableCartesianScaleContext>; /** Padding to apply around scale labels. */ padding: number | { /** Padding on the (relative) top side of this axis label. */ @@ -3406,7 +3417,7 @@ export type RadialLinearScaleOptions = CoreScaleOptions & { color: Scriptable; /** */ - font: Scriptable; + font: ScriptableAndScriptableOptions, ScriptableScalePointLabelContext>; /** * Callback function to transform data labels to point labels. The default implementation simply returns the current string.