Skip to content

Contour auto persist #1338

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 3 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,10 @@ function _restyle(gd, aobj, _traces) {
flags.docolorbars = true;
}

if(recalcAttrs.indexOf(ai) !== -1) {
var aiArrayStart = ai.indexOf('['),
aiAboveArray = aiArrayStart === -1 ? ai : ai.substr(0, aiArrayStart);

if(recalcAttrs.indexOf(aiAboveArray) !== -1) {
// major enough changes deserve autoscale, autobin, and
// non-reversed axes so people don't get confused
if(['orientation', 'type'].indexOf(ai) !== -1) {
Expand All @@ -1622,8 +1625,8 @@ function _restyle(gd, aobj, _traces) {
}
flags.docalc = true;
}
else if(replotAttrs.indexOf(ai) !== -1) flags.doplot = true;
else if(autorangeAttrs.indexOf(ai) !== -1) flags.docalcAutorange = true;
else if(replotAttrs.indexOf(aiAboveArray) !== -1) flags.doplot = true;
else if(autorangeAttrs.indexOf(aiAboveArray) !== -1) flags.docalcAutorange = true;
}

// do we need to force a recalc?
Expand Down
22 changes: 22 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,28 @@ describe('Test plot api', function() {
expect(gd._fullData[1].marker.color).toBe(colorDflt[1]);
});

it('should redo auto z/contour when editing z array', function() {
var gd = {
data: [{type: 'contour', z: [[1, 2], [3, 4]]}]
};

mockDefaultsAndCalc(gd);

expect(gd.data[0].zauto).toBe(true);
expect(gd.data[0].zmin).toBe(1);
expect(gd.data[0].zmax).toBe(4);

expect(gd.data[0].autocontour).toBe(true);
expect(gd.data[0].contours).toEqual({start: 0.5, end: 3.5, size: 0.5});

Plotly.restyle(gd, {'z[0][0]': 10});
Copy link
Contributor

Choose a reason for hiding this comment

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

Really. This works? That's awesome!

Copy link
Contributor

Choose a reason for hiding this comment

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

This makes #144 obsolete.


expect(gd.data[0].zmin).toBe(2);
expect(gd.data[0].zmax).toBe(10);

expect(gd.data[0].contours).toEqual({start: 3, end: 9, size: 1});
});

});

describe('Plotly.deleteTraces', function() {
Expand Down