Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released

A number of changes were made to the configuration options passed to the `Chart` constructor. Those changes are documented below.

#### Generic changes

* Indexable options are now looping. `backgroundColor: ['red', 'green']` will result in alternating `'red'` / `'green'` if there are more than 2 data points.

#### Specific changes

* `hover.animationDuration` is now configured in `animation.active.duration`
* `responsiveAnimationDuration` is now configured in `animation.resize.duration`
* Polar area `startAngle` option is now consistent with `Radar`, 0 is at top and value is in degrees. Default is changed from `-½π` to `0`.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/helpers.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function resolve(inputs, context, index, info) {
cacheable = false;
}
if (index !== undefined && isArray(value)) {
value = value[index];
value = value[index % value.length];
cacheable = false;
}
if (value !== undefined) {
Expand Down
45 changes: 45 additions & 0 deletions test/fixtures/controller.bar/backgroundColor/loopable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4, 5],
datasets: [
{
// option in dataset
data: [0, 2, 3, 4, 5, 6],
backgroundColor: [
'#ff0000',
'#00ff00',
'#0000ff'
]
},
{
// option in element (fallback)
data: [6, 5, 4, 3, 2, 1],
}
]
},
options: {
legend: false,
title: false,
elements: {
rectangle: {
backgroundColor: [
'#000000',
'#888888'
]
}
},
scales: {
x: {display: false},
y: {display: false}
}
}
},
options: {
canvas: {
height: 256,
width: 512
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions test/specs/helpers.options.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ describe('Chart.helpers.options', function() {
});
it ('should fallback if an indexable option value is undefined', function() {
var input = [42, undefined, 'bar'];
expect(resolve([input], undefined, 5)).toBe(undefined);
expect(resolve([input], undefined, 1)).toBe(undefined);
expect(resolve([input, 'foo'], undefined, 1)).toBe('foo');
expect(resolve([input, 'foo'], undefined, 5)).toBe('foo');
});
it ('should loop if an indexable option index is out of bounds', function() {
var input = [42, undefined, 'bar'];
expect(resolve([input], undefined, 3)).toBe(42);
expect(resolve([input, 'foo'], undefined, 4)).toBe('foo');
expect(resolve([input, 'foo'], undefined, 5)).toBe('bar');
});
it ('should not handle indexable options if index is undefined', function() {
var array = [42, 'foo', 'bar'];
Expand Down Expand Up @@ -211,7 +216,7 @@ describe('Chart.helpers.options', function() {
};
expect(resolve([input, 'foo'], {v: 42}, 0)).toBe(42);
expect(resolve([input, 'foo'], {v: 42}, 1)).toBe('foo');
expect(resolve([input, 'foo'], {v: 42}, 5)).toBe('foo');
expect(resolve([input, 'foo'], {v: 42}, 5)).toBe('bar');
expect(resolve([input, ['foo', 'bar']], {v: 42}, 1)).toBe('bar');
});
});
Expand Down