Skip to content

Make restyling arrayOk attribute redo calcdata #1488

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

Merged
merged 1 commit into from
Mar 16, 2017
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
12 changes: 10 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,17 @@ function _restyle(gd, aobj, _traces) {
helpers.manageArrayContainers(param, newVal, undoit);
flags.docalc = true;
}
// all the other ones, just modify that one attribute
else param.set(newVal);
else {
var moduleAttrs = (contFull._module || {}).attributes || {};
var valObject = Lib.nestedProperty(moduleAttrs, ai).get() || {};

if(valObject.arrayOk && (Array.isArray(newVal) || Array.isArray(oldVal))) {
flags.docalc = true;
Copy link
Contributor Author

@etpinard etpinard Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, calls like restyle(gd, 'marker.size', [[10, 30, 20]]) worked only when one or several axis autorange were turned on as this too clears gd.calcdata.

This here now ensures that restyling any arrayOk key clears gd.calcdata.

Copy link
Contributor Author

@etpinard etpinard Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson using _module.attributes here to find the arrayOk keys worked surprisingly well. We could declare a few more keys in the attributes to resolve #648 at some point.

}

// all the other ones, just modify that one attribute
param.set(newVal);
}
}

// swap the data attributes of the relevant x and y axes?
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,36 @@ describe('Test plot api', function() {
expect(gd.calcdata).toBeDefined();
});

it('should do full replot when arrayOk attributes are updated', function() {
var gd = {
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
layout: {}
};

mockDefaultsAndCalc(gd);
Plotly.restyle(gd, 'marker.color', [['red', 'green', 'blue']]);
expect(gd.calcdata).toBeUndefined();
Copy link
Contributor Author

@etpinard etpinard Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means restyle clears gd.calcdata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that Plotly.plot is mocked in this suite.

expect(PlotlyInternal.plot).toHaveBeenCalled();

mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'marker.color', 'yellow');
expect(gd.calcdata).toBeUndefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();

mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'marker.color', 'blue');
expect(gd.calcdata).toBeDefined();
expect(PlotlyInternal.plot).not.toHaveBeenCalled();

mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'marker.color', [['red', 'blue', 'green']]);
expect(gd.calcdata).toBeUndefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();
});

it('calls plot on xgap and ygap styling', function() {
var gd = {
data: [{z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], showscale: false, type: 'heatmap'}],
Expand Down