Skip to content

Commit

Permalink
Network: fit() should not change the passed options (almende#3566)
Browse files Browse the repository at this point in the history
Fixes almende#3543.

None of the options passed in any of the API calls should change the options. This has been registered with issue almende#3548.
  • Loading branch information
wimrijnders authored and yotamberk committed Oct 13, 2017
1 parent 04e67af commit c56fa19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/network/modules/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class View {
fit(options = {nodes:[]}, initialZoom = false) {
let range;
let zoomLevel;
options = Object.assign({}, options);
if (options.nodes === undefined || options.nodes.length === 0) {
options.nodes = this.body.nodeIndices;
}
Expand Down Expand Up @@ -299,4 +300,4 @@ class View {

}

export default View;
export default View;
17 changes: 17 additions & 0 deletions test/Network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ describe('Network', function () {
});


/**
* This is a fix on one issue (#3543), but in fact **all* options for all API calls should
* remain unchanged.
* TODO: extend test for all API calls with options, see #3548
*/
it('does not change the options object passed to fit()', function() {
var [network, data, numNodes, numEdges] = createSampleNetwork({});
var options = {};
network.fit(options);

// options should still be empty
for (var prop in options) {
assert(!options.hasOwnProperty(prop), 'No properties should be present in options, detected property: ' + prop);
}
});


describe('Node', function () {

it('has known font options', function () {
Expand Down

0 comments on commit c56fa19

Please sign in to comment.