Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix options update when changing to shared opts #10451

Merged
merged 1 commit into from Jun 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/controllers/controller.bar.js
Expand Up @@ -350,11 +350,7 @@ export default class BarController extends DatasetController {
const base = vScale.getBasePixel();
const horizontal = vScale.isHorizontal();
const ruler = this._getRuler();
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);

this.updateSharedOptions(sharedOptions, mode, firstOpts);
const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);

for (let i = start; i < start + count; i++) {
const parsed = this.getParsed(i);
Expand Down
8 changes: 2 additions & 6 deletions src/controllers/controller.bubble.js
Expand Up @@ -85,9 +85,7 @@ export default class BubbleController extends DatasetController {
updateElements(points, start, count, mode) {
const reset = mode === 'reset';
const {iScale, vScale} = this._cachedMeta;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
const iAxis = iScale.axis;
const vAxis = vScale.axis;

Expand All @@ -101,7 +99,7 @@ export default class BubbleController extends DatasetController {
properties.skip = isNaN(iPixel) || isNaN(vPixel);

if (includeOptions) {
properties.options = this.resolveDataElementOptions(i, point.active ? 'active' : mode);
properties.options = sharedOptions || this.resolveDataElementOptions(i, point.active ? 'active' : mode);

if (reset) {
properties.options.radius = 0;
Expand All @@ -110,8 +108,6 @@ export default class BubbleController extends DatasetController {

this.updateElement(point, i, properties, mode);
}

this.updateSharedOptions(sharedOptions, mode, firstOpts);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/controllers/controller.doughnut.js
Expand Up @@ -170,9 +170,7 @@ export default class DoughnutController extends DatasetController {
const animateScale = reset && animationOpts.animateScale;
const innerRadius = animateScale ? 0 : this.innerRadius;
const outerRadius = animateScale ? 0 : this.outerRadius;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
let startAngle = this._getRotation();
let i;

Expand All @@ -199,7 +197,6 @@ export default class DoughnutController extends DatasetController {

this.updateElement(arc, i, properties, mode);
}
this.updateSharedOptions(sharedOptions, mode, firstOpts);
}

calculateTotal() {
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/controller.line.js
Expand Up @@ -49,9 +49,7 @@ export default class LineController extends DatasetController {
updateElements(points, start, count, mode) {
const reset = mode === 'reset';
const {iScale, vScale, _stacked, _dataset} = this._cachedMeta;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
const {sharedOptions, includeOptions} = this._getSharedOptions(start, mode);
const iAxis = iScale.axis;
const vAxis = vScale.axis;
const {spanGaps, segment} = this.options;
Expand Down Expand Up @@ -84,8 +82,6 @@ export default class LineController extends DatasetController {

prevParsed = parsed;
}

this.updateSharedOptions(sharedOptions, mode, firstOpts);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/core/core.datasetController.js
Expand Up @@ -840,6 +840,18 @@ export default class DatasetController {
return !sharedOptions || isDirectUpdateMode(mode) || this.chart._animationsDisabled;
}

/**
* @todo v4, rename to getSharedOptions and remove excess functions
*/
_getSharedOptions(start, mode) {
const firstOpts = this.resolveDataElementOptions(start, mode);
const previouslySharedOptions = this._sharedOptions;
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions) || (sharedOptions !== previouslySharedOptions);
this.updateSharedOptions(sharedOptions, mode, firstOpts);
return {sharedOptions, includeOptions};
}

/**
* Utility for updating an element with new properties, using animations when appropriate.
* @protected
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/controller.line/radius/scriptable-to-value.js
@@ -0,0 +1,32 @@
module.exports = {
config: {
type: 'line',
data: {
labels: ['A', 'B', 'C'],
datasets: [{
data: [12, 19, 3]
}]
},
options: {
animation: {
duration: 0
},
backgroundColor: 'red',
radius: () => 20,
scales: {
x: {display: false},
y: {display: false}
}
}
},
options: {
canvas: {
height: 256,
width: 512
},
run: (chart) => {
chart.options.radius = 5;
chart.update();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.