From d21444a4330b2cb4bcca3cdbe0d7b200822ca940 Mon Sep 17 00:00:00 2001 From: Jacco van den Berg Date: Tue, 15 Oct 2024 20:00:22 +0200 Subject: [PATCH 1/2] Allow array as default and add extra default options --- src/types/index.d.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/types/index.d.ts b/src/types/index.d.ts index fcdd44fe06b..5690a432e60 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1611,12 +1611,22 @@ export interface CoreChartOptions extends ParsingOption * base background color * @see Defaults.backgroundColor */ - backgroundColor: Scriptable>; + backgroundColor: ScriptableAndArray>; + /** + * base hover background color + * @see Defaults.hoverBackgroundColor + */ + hoverBackgroundColor: ScriptableAndArray>; /** * base border color * @see Defaults.borderColor */ - borderColor: Scriptable>; + borderColor: ScriptableAndArray>; + /** + * base hover border color + * @see Defaults.hoverBorderColor + */ + hoverBorderColor: ScriptableAndArray>; /** * base font * @see Defaults.font From 7c733fd06c9d88fe068bbaa41c5b512c03f80714 Mon Sep 17 00:00:00 2001 From: Jacco van den Berg Date: Tue, 15 Oct 2024 20:03:33 +0200 Subject: [PATCH 2/2] Add test --- test/types/defaults.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/types/defaults.ts b/test/types/defaults.ts index 84071849245..ae3eff23ac5 100644 --- a/test/types/defaults.ts +++ b/test/types/defaults.ts @@ -16,6 +16,22 @@ Chart.defaults.font.size = '8'; // @ts-expect-error should be number Chart.defaults.font.size = () => '10'; +Chart.defaults.backgroundColor = 'red'; +Chart.defaults.backgroundColor = ['red', 'blue']; +Chart.defaults.backgroundColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue'; + +Chart.defaults.borderColor = 'red'; +Chart.defaults.borderColor = ['red', 'blue']; +Chart.defaults.borderColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue'; + +Chart.defaults.hoverBackgroundColor = 'red'; +Chart.defaults.hoverBackgroundColor = ['red', 'blue']; +Chart.defaults.hoverBackgroundColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue'; + +Chart.defaults.hoverBorderColor = 'red'; +Chart.defaults.hoverBorderColor = ['red', 'blue']; +Chart.defaults.hoverBorderColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue'; + Chart.defaults.font = { family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", size: 10