Skip to content

Commit

Permalink
Types: Allow font to be partial scriptable and individually scriptable (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
LeeLenaleee committed May 25, 2022
1 parent ebcaff1 commit 5173d05
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions types/index.esm.d.ts
Expand Up @@ -38,6 +38,7 @@ export interface ScriptableLineSegmentContext {

export type Scriptable<T, TContext> = T | ((ctx: TContext, options: AnyObject) => T | undefined);
export type ScriptableOptions<T, TContext> = { [P in keyof T]: Scriptable<T[P], TContext> };
export type ScriptableAndScriptableOptions<T, TContext> = Scriptable<T, TContext> | ScriptableOptions<T, TContext>;
export type ScriptableAndArray<T, TContext> = readonly T[] | Scriptable<T, TContext>;
export type ScriptableAndArrayOptions<T, TContext> = { [P in keyof T]: ScriptableAndArray<T[P], TContext> };

Expand Down Expand Up @@ -2310,7 +2311,7 @@ export interface LegendOptions<TType extends ChartType> {
* Font of label
* @see Defaults.font
*/
font: FontSpec;
font: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableChartContext>;
/**
* Padding between rows of colored boxes.
* @default 10
Expand Down Expand Up @@ -2371,7 +2372,7 @@ export interface LegendOptions<TType extends ChartType> {
/**
* see Fonts
*/
font: FontSpec;
font: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableChartContext>;
position: 'center' | 'start' | 'end';
padding?: number | ChartArea;
/**
Expand Down Expand Up @@ -2405,7 +2406,7 @@ export interface TitleOptions {
* @see Defaults.color
*/
color: Color;
font: FontSpec;
font: ScriptableAndScriptableOptions<Partial<FontSpec>, 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
Expand Down Expand Up @@ -2636,7 +2637,7 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
* See Fonts
* @default {weight: 'bold'}
*/
titleFont: Scriptable<FontSpec, ScriptableTooltipContext<TType>>;
titleFont: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableTooltipContext<TType>>;
/**
* Spacing to add to top and bottom of each title line.
* @default 2
Expand Down Expand Up @@ -2666,7 +2667,7 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
* See Fonts.
* @default {}
*/
bodyFont: Scriptable<FontSpec, ScriptableTooltipContext<TType>>;
bodyFont: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableTooltipContext<TType>>;
/**
* Horizontal alignment of the body text lines.
* @default 'left'
Expand All @@ -2691,7 +2692,7 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
* See Fonts
* @default {weight: 'bold'}
*/
footerFont: Scriptable<FontSpec, ScriptableTooltipContext<TType>>;
footerFont: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableTooltipContext<TType>>;
/**
* Horizontal alignment of the footer text lines.
* @default 'left'
Expand Down Expand Up @@ -2926,7 +2927,7 @@ export interface TickOptions {
/**
* see Fonts
*/
font: Scriptable<FontSpec, ScriptableScaleContext>;
font: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableScaleContext>;
/**
* Sets the offset of the tick labels from the axis
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<Partial<FontSpec>, ScriptableCartesianScaleContext>;
/** Padding to apply around scale labels. */
padding: number | {
/** Padding on the (relative) top side of this axis label. */
Expand Down Expand Up @@ -3406,7 +3417,7 @@ export type RadialLinearScaleOptions = CoreScaleOptions & {
color: Scriptable<Color, ScriptableScalePointLabelContext>;
/**
*/
font: Scriptable<FontSpec, ScriptableScalePointLabelContext>;
font: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableScalePointLabelContext>;

/**
* Callback function to transform data labels to point labels. The default implementation simply returns the current string.
Expand Down

0 comments on commit 5173d05

Please sign in to comment.