function getGradient(ctx, chartArea) {
const chartWidth = chartArea.right - chartArea.left;
const chartHeight = chartArea.bottom - chartArea.top;
- if (gradient === null || width !== chartWidth || height !== chartHeight) {
+ if (!gradient || width !== chartWidth || height !== chartHeight) {
// Create the gradient because this is either the first render
// or the size of the chart has changed
width = chartWidth;
if (!chartArea) {
// This case happens on initial chart load
- return null;
+ return;
}
return getGradient(ctx, chartArea);
},
datasetIndex: number
}
-export type Scriptable<T, TContext> = T | ((ctx: TContext, options: AnyObject) => T);
+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 ScriptableAndArray<T, TContext> = readonly T[] | Scriptable<T, TContext>;
export type ScriptableAndArrayOptions<T, TContext> = { [P in keyof T]: ScriptableAndArray<T[P], TContext> };
* base color
* @see Defaults.color
*/
- color: Color;
+ color: Scriptable<Color, ScriptableContext<TType>>;
/**
* base background color
* @see Defaults.backgroundColor
*/
- backgroundColor: Color;
+ backgroundColor: Scriptable<Color, ScriptableContext<TType>>;
/**
* base border color
* @see Defaults.borderColor
*/
- borderColor: Color;
+ borderColor: Scriptable<Color, ScriptableContext<TType>>;
/**
* base font
* @see Defaults.font
*/
- font: FontSpec;
+ font: Scriptable<Partial<FontSpec>, ScriptableContext<TType>>;
/**
* Resizes the chart canvas when its container does (important note...).
* @default true
/**
* Returns the string representation of the tick value as it should be displayed on the chart. See callback.
*/
- callback: (tickValue: number | string, index: number, ticks: Tick[]) => string | number | null | undefined;
+ callback: (this: Scale, tickValue: number | string, index: number, ticks: Tick[]) => string | number | null | undefined;
/**
* If true, show tick labels.
* @default true
--- /dev/null
+import { ChartConfiguration } from '../index.esm';
+
+const getConfig = (): ChartConfiguration<'bar'> => {
+ return {
+ type: 'bar',
+ data: {
+ datasets: []
+ },
+ options: {
+ backgroundColor: (context) => context.active ? '#fff' : undefined,
+ font: (context) => context.datasetIndex === 1 ? { size: 10 } : { size: 12, family: 'arial' }
+ }
+ };
+};
+