From: Evert Timberg Date: Sat, 1 May 2021 17:30:14 +0000 (-0400) Subject: Enable scriptable element chart options (#9012) X-Git-Tag: v3.2.1~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=49e7edae49467fd74a52b3cc934b33ad0219554e;p=thirdparty%2FChart.js.git Enable scriptable element chart options (#9012) --- diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index dbb34fefb..3066472c0 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -604,7 +604,7 @@ export interface DatasetControllerChartComponent extends ChartComponent { }; } -export interface Defaults extends CoreChartOptions, ElementChartOptions, PluginChartOptions { +export interface Defaults extends CoreChartOptions, ElementChartOptions, PluginChartOptions { scale: ScaleOptionsByType; scales: { @@ -641,7 +641,7 @@ export interface Defaults extends CoreChartOptions, ElementChartOptio export type Overrides = { [key in ChartType]: CoreChartOptions & - ElementChartOptions & + ElementChartOptions & PluginChartOptions & DatasetChartOptions & ScaleChartOptions & @@ -1887,16 +1887,17 @@ export const BarElement: ChartComponent & { new (cfg: AnyObject): BarElement; }; -export interface ElementOptionsByType { - arc: ArcOptions & ArcHoverOptions; - bar: BarOptions & BarHoverOptions; - line: LineOptions & LineHoverOptions; - point: PointOptions & PointHoverOptions; -} -export interface ElementChartOptions { - elements: Partial; +export interface ElementOptionsByType { + arc: ScriptableAndArrayOptions>; + bar: ScriptableAndArrayOptions>; + line: ScriptableAndArrayOptions>; + point: ScriptableAndArrayOptions>; } +export type ElementChartOptions = { + elements: ElementOptionsByType +}; + export class BasePlatform { /** * Called at chart construction time, returns a context2d instance implementing @@ -3321,7 +3322,7 @@ export type ScaleChartOptions = { export type ChartOptions = DeepPartial< CoreChartOptions & - ElementChartOptions & + ElementChartOptions & PluginChartOptions & DatasetChartOptions & ScaleChartOptions & diff --git a/types/tests/elements/scriptable_element_options.ts b/types/tests/elements/scriptable_element_options.ts new file mode 100644 index 000000000..0776ec0a0 --- /dev/null +++ b/types/tests/elements/scriptable_element_options.ts @@ -0,0 +1,49 @@ +import { Chart } from '../../index.esm'; + +const chart = new Chart('id', { + type: 'line', + data: { + labels: [], + datasets: [] + }, + options: { + elements: { + line: { + borderWidth: () => 2, + }, + point: { + pointStyle: (ctx) => 'star', + } + } + } +}); + +const chart2 = new Chart('id', { + type: 'bar', + data: { + labels: [], + datasets: [] + }, + options: { + elements: { + bar: { + borderWidth: (ctx) => 2, + } + } + } +}); + +const chart3 = new Chart('id', { + type: 'doughnut', + data: { + labels: [], + datasets: [] + }, + options: { + elements: { + arc: { + borderWidth: (ctx) => 3, + } + } + } +});