Skip to content

Commit

Permalink
Resolve #140
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanbalci committed Oct 12, 2022
1 parent 74b4512 commit 2158ae4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Expand all edges in the graph.
Load elements from JSON string.

`api.saveJson(elems, filename)`
Saves elements in JSON format to a file. Default value for `elems` is all the elements. Default value for `filename` is 'expand-collapse-output.json'
Return elements in JSON format and saves them to a file if a file name is provided via `filename` parameter. Default value for `elems` is all the elements.

## Events
Notice that following events are performed for *each* node that is collapsed/expanded. Also, notice that any post-processing layout is performed *after* the event.
Expand Down
11 changes: 6 additions & 5 deletions cytoscape-expand-collapse.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/demo-compounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ function main() {
});

document.getElementById('saveAsJson').addEventListener('click', function () {
api.saveJson(cy.$());
api.saveJson(cy.$(), 'expand-collapse-output.json');
});

document.getElementById('loadFromJson').addEventListener('click', function () {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
};

api.saveJson = function (elems, filename) {
saveLoadUtils.saveJson(elems, filename);
return saveLoadUtils.saveJson(elems, filename);
};

return api; // Return the API instance
Expand Down
7 changes: 4 additions & 3 deletions src/saveLoadUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ function saveLoadUtilities(cy, api) {
o.nodes.push(jsonObj);
}

if (!filename) {
filename = 'expand-collapse-output.json';
let stringifiedJSON = JSON.stringify(o);
if (filename) {
str2file(stringifiedJSON, filename);
}
str2file(JSON.stringify(o), filename);
return stringifiedJSON;
}
};
}
Expand Down

0 comments on commit 2158ae4

Please sign in to comment.