Skip to content

Histogram2dcontour relayout fix #1520

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
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions src/traces/contour/contours_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

var Lib = require('../../lib');
var attributes = require('./attributes');

module.exports = function handleContourDefaults(traceIn, traceOut, coerce) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Perhaps I'll need to merge/use this in carpet.

var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start');
var contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end');
var missingEnd = (contourStart === false) || (contourEnd === false);

// normally we only need size if autocontour is off. But contour.calc
// pushes its calculated contour size back to the input trace, so for
// things like restyle that can call supplyDefaults without calc
// after the initial draw, we can just reuse the previous calculation
var contourSize = coerce('contours.size');
var autoContour;

if(missingEnd) autoContour = traceOut.autocontour = true;
else autoContour = coerce('autocontour', false);

if(autoContour || !contourSize) coerce('ncontours');
};
20 changes: 3 additions & 17 deletions src/traces/contour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var Lib = require('../../lib');

var hasColumns = require('../heatmap/has_columns');
var handleXYZDefaults = require('../heatmap/xyz_defaults');
var handleStyleDefaults = require('../contour/style_defaults');
var handleContoursDefaults = require('./contours_defaults');
var handleStyleDefaults = require('./style_defaults');
var attributes = require('./attributes');


Expand All @@ -31,21 +32,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('text');
coerce('connectgaps', hasColumns(traceOut));

var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start'),
contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end'),
missingEnd = (contourStart === false) || (contourEnd === false),

// normally we only need size if autocontour is off. But contour.calc
// pushes its calculated contour size back to the input trace, so for
// things like restyle that can call supplyDefaults without calc
// after the initial draw, we can just reuse the previous calculation
contourSize = coerce('contours.size'),
autoContour;

if(missingEnd) autoContour = traceOut.autocontour = true;
else autoContour = coerce('autocontour', false);

if(autoContour || !contourSize) coerce('ncontours');

handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
2 changes: 2 additions & 0 deletions src/traces/histogram2dcontour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
var Lib = require('../../lib');

var handleSampleDefaults = require('../histogram2d/sample_defaults');
var handleContoursDefaults = require('../contour/contours_defaults');
var handleStyleDefaults = require('../contour/style_defaults');
var attributes = require('./attributes');

Expand All @@ -30,5 +31,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
if(autocontour) coerce('ncontours');
else coerce('contours.size');
Copy link
Contributor

@rreusser rreusser Mar 27, 2017

Choose a reason for hiding this comment

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

Can this line get the 🔪 ? It looks like handleContoursDefaults re-coerces this on the next line, but I could be mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh oops. Good call!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's subtle though. Sometimes these things do need re-coercing depending on the coupling between parameter defaults. But this one look like it's maybe redundant.

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 b163ad2


handleContoursDefaults(traceIn, traceOut, coerce);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
};
26 changes: 26 additions & 0 deletions test/jasmine/tests/histogram2d_test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
var Plotly = require('@lib/index');
var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');

var supplyDefaults = require('@src/traces/histogram2d/defaults');
var calc = require('@src/traces/histogram2d/calc');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');

describe('Test histogram2d', function() {
'use strict';
Expand Down Expand Up @@ -132,4 +136,26 @@ describe('Test histogram2d', function() {
]);
});
});

describe('relayout interaction', function() {

afterEach(destroyGraphDiv);

it('should update paths on zooms', function(done) {
var gd = createGraphDiv();

Plotly.newPlot(gd, [{
type: 'histogram2dcontour',
x: [1, 1, 2, 2, 3],
y: [0, 1, 1, 1, 3]
}])
.then(function() {
return Plotly.relayout(gd, 'xaxis.range', [0, 2]);
})
.catch(fail)
.then(done);
});

});

});