Skip to content

Contour restyle zmin zmax #1653

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 5 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,11 @@ function _restyle(gd, aobj, _traces) {
flags.docalc = true;
}

// some attributes declare a 'recalc' flag
if(valObject.recalc) {
flags.docalc = true;
Copy link
Contributor Author

@etpinard etpinard May 8, 2017

Choose a reason for hiding this comment

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

... slowly migrating to something better than those ugly recalcAttrs lists in restyle and relayout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Down the line, this is going to require valObject.dostyle, .doplot, .doCamera etc etc... would we be better off with something like valObject.editType = 'docalc' etc? Which presumably we could use like a flaglist (and validate as such in plotschema_test)?

💯 🍻 for getting this effort going!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

valObject.editType = 'docalc'

Right. I guess that scales better. Thanks 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 413e545

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍
I guess later this can change to something like

if(valObject.editType) {
    valObject.editType.split('+').forEach(function(flag) {
        flags[flag] = true;
    });
}

But don't need to do that now - lets wait until we have validation of editType, perhaps in plotschema_test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But don't need to do that now - lets wait until we have validation of editType, perhaps in plotschema_test?

Yep, that's what I was thinking. Referencing #648


// all the other ones, just modify that one attribute
param.set(newVal);
}
Expand Down
7 changes: 5 additions & 2 deletions src/traces/contour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ module.exports = extendFlat({}, {
})
}
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
colorscaleAttrs, {
autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}),
zmin: extendFlat({}, colorscaleAttrs.zmin, {recalc: true}),
zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true})
},
{ colorbar: colorbarAttrs }
);
5 changes: 4 additions & 1 deletion src/traces/histogram2dcontour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = extendFlat({}, {
contours: contourAttrs.contours,
line: contourAttrs.line
},
colorscaleAttrs,
colorscaleAttrs, {
zmin: extendFlat({}, colorscaleAttrs.zmin, {recalc: true}),
zmax: extendFlat({}, colorscaleAttrs.zmax, {recalc: true})
},
{ colorbar: colorbarAttrs }
);
66 changes: 66 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,72 @@ describe('Test plot api', function() {
expect(PlotlyInternal.plot.calls.count()).toEqual(2);
});

it('should clear calcdata when restyling \'zmin\' and \'zmax\' on contour traces', function() {
var contour = {
data: [{
type: 'contour',
z: [[1, 2, 3], [1, 2, 1]]
}]
};

var histogram2dcontour = {
data: [{
type: 'histogram2dcontour',
x: [1, 1, 2, 2, 2, 3],
y: [0, 0, 0, 0, 1, 3]
}]
};

var mocks = [contour, histogram2dcontour];

mocks.forEach(function(gd) {
mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'zmin', 0);
expect(gd.calcdata).toBeUndefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();

mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'zmax', 10);
expect(gd.calcdata).toBeUndefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();
});
});

it('should not clear calcdata when restyling \'zmin\' and \'zmax\' on heatmap traces', function() {
var heatmap = {
data: [{
type: 'heatmap',
z: [[1, 2, 3], [1, 2, 1]]
}]
};

var histogram2d = {
data: [{
type: 'histogram2d',
x: [1, 1, 2, 2, 2, 3],
y: [0, 0, 0, 0, 1, 3]
}]
};

var mocks = [heatmap, histogram2d];

mocks.forEach(function(gd) {
mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'zmin', 0);
expect(gd.calcdata).toBeDefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();

mockDefaultsAndCalc(gd);
PlotlyInternal.plot.calls.reset();
Plotly.restyle(gd, 'zmax', 10);
expect(gd.calcdata).toBeDefined();
expect(PlotlyInternal.plot).toHaveBeenCalled();
});
});

it('ignores undefined values', function() {
var gd = {
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/plotschema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('plot schema', function() {
var valObject = valObjects[attr.valType],
opts = valObject.requiredOpts
.concat(valObject.otherOpts)
.concat(['valType', 'description', 'role']);
.concat(['valType', 'description', 'role', 'recalc']);

Object.keys(attr).forEach(function(key) {
expect(opts.indexOf(key) !== -1).toBe(true, key, attr);
Expand Down