Skip to content

Commit

Permalink
Allow array's in backgroundColor defaults and add hover background an…
Browse files Browse the repository at this point in the history
…d border color to defaults (#11931)

* Allow array as default and add extra default options

* Add test

---------

Co-authored-by: Jacco van den Berg <[email protected]>
  • Loading branch information
LeeLenaleee and Jacco van den Berg authored Oct 15, 2024
1 parent 22a0ba9 commit 03d1d5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1611,12 +1611,22 @@ export interface CoreChartOptions<TType extends ChartType> extends ParsingOption
* base background color
* @see Defaults.backgroundColor
*/
backgroundColor: Scriptable<Color, ScriptableContext<TType>>;
backgroundColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
/**
* base hover background color
* @see Defaults.hoverBackgroundColor
*/
hoverBackgroundColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
/**
* base border color
* @see Defaults.borderColor
*/
borderColor: Scriptable<Color, ScriptableContext<TType>>;
borderColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
/**
* base hover border color
* @see Defaults.hoverBorderColor
*/
hoverBorderColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
/**
* base font
* @see Defaults.font
Expand Down
16 changes: 16 additions & 0 deletions test/types/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03d1d5c

Please sign in to comment.