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

Contour restyle zmin zmax #1653

Merged
merged 5 commits into from
May 9, 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
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 an 'editType' flaglist
if(valObject.editType === 'docalc') {
flags.docalc = true;
}
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, {editType: 'docalc'}),
zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'})
},
{ 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, {editType: 'docalc'}),
zmax: extendFlat({}, colorscaleAttrs.zmax, {editType: 'docalc'})
},
{ 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', 'editType']);

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