Skip to content

Commit 03d1d5c

Browse files
LeeLenaleeeJacco van den Berg
andauthored
Allow array's in backgroundColor defaults and add hover background and 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]>
1 parent 22a0ba9 commit 03d1d5c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/types/index.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,12 +1611,22 @@ export interface CoreChartOptions<TType extends ChartType> extends ParsingOption
16111611
* base background color
16121612
* @see Defaults.backgroundColor
16131613
*/
1614-
backgroundColor: Scriptable<Color, ScriptableContext<TType>>;
1614+
backgroundColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
1615+
/**
1616+
* base hover background color
1617+
* @see Defaults.hoverBackgroundColor
1618+
*/
1619+
hoverBackgroundColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
16151620
/**
16161621
* base border color
16171622
* @see Defaults.borderColor
16181623
*/
1619-
borderColor: Scriptable<Color, ScriptableContext<TType>>;
1624+
borderColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
1625+
/**
1626+
* base hover border color
1627+
* @see Defaults.hoverBorderColor
1628+
*/
1629+
hoverBorderColor: ScriptableAndArray<Color, ScriptableContext<TType>>;
16201630
/**
16211631
* base font
16221632
* @see Defaults.font

test/types/defaults.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ Chart.defaults.font.size = '8';
1616
// @ts-expect-error should be number
1717
Chart.defaults.font.size = () => '10';
1818

19+
Chart.defaults.backgroundColor = 'red';
20+
Chart.defaults.backgroundColor = ['red', 'blue'];
21+
Chart.defaults.backgroundColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue';
22+
23+
Chart.defaults.borderColor = 'red';
24+
Chart.defaults.borderColor = ['red', 'blue'];
25+
Chart.defaults.borderColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue';
26+
27+
Chart.defaults.hoverBackgroundColor = 'red';
28+
Chart.defaults.hoverBackgroundColor = ['red', 'blue'];
29+
Chart.defaults.hoverBackgroundColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue';
30+
31+
Chart.defaults.hoverBorderColor = 'red';
32+
Chart.defaults.hoverBorderColor = ['red', 'blue'];
33+
Chart.defaults.hoverBorderColor = (ctx) => ctx.datasetIndex % 2 === 0 ? 'red' : 'blue';
34+
1935
Chart.defaults.font = {
2036
family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
2137
size: 10

0 commit comments

Comments
 (0)