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

feat: Avoid overlap between group nodes #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion cytoscape-expand-collapse.js

This file was deleted.

3 changes: 2 additions & 1 deletion nr-cytoscape-expand-collapse.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions nr-cytoscape-expand-collapse.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
Embeddable Minimum Strictly-Compliant Promises/A+ 1.1.1 Thenable
Copyright (c) 2013-2014 Ralf S. Engelschall (http://engelschall.com)
Licensed under The MIT License (http://opensource.org/licenses/MIT)
*/

/*! Bezier curve function generator. Copyright Gaetan Renaudeau. MIT License: http://en.wikipedia.org/wiki/MIT_License */

/*! Runge-Kutta spring physics function generator. Adapted from Framer.js, copyright Koen Bok. MIT License: http://en.wikipedia.org/wiki/MIT_License */
72 changes: 69 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nr-cytoscape-expand-collapse",
"version": "1.0.0",
"version": "1.0.3",
"description": "This extension provides an interface to expand-collapse nodes",
"main": "./src/index.js",
"spm": {
Expand Down Expand Up @@ -40,6 +40,7 @@
},
"peerDependencies": {
"cytoscape": "^3.3.0",
"cytoscape-fcose": "^2.2.0"
"cytoscape-fcose": "^2.2.0",
"cytoscape-dagre": "^2.5.0"
}
}
35 changes: 29 additions & 6 deletions src/elementUtilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const relayout = require("./reLayout");
const { reLayout } = require("./reLayout");
const { runLayoutAsync } = require("./layoutUtilities");

function elementUtilities(cy) {
return {
Expand Down Expand Up @@ -48,11 +47,35 @@ function elementUtilities(cy) {
if (typeof layoutBy === "function") {
layoutBy();
} else if (layoutBy != null) {
var layout = cy.layout(layoutBy);
if (layout && layout.run) {
await reLayout(layout);
relayout(cy, layoutBy);
var hasGroups = !!cy
.nodes()
.filter((node) => node.data().type === "group").length;

if (hasGroups) {
// get positions of nodes before preset layout
const positions = {};
(cy?.scratch("_cyExpandCollapse")?.positions ?? []).forEach(
({ nodeId, position }) => {
positions[nodeId] = position;
}
);

// run preset layout with the positions
await runLayoutAsync(
cy.layout({
name: "preset",
fit: false,
positions: positions,
zoom: cy.zoom(),
pan: cy.pan(),
padding: layoutBy?.padding ?? 50,
animate: layoutBy?.animate ?? true,
animationDuration: layoutBy?.animationDuration ?? 500,
animationEasing: layoutBy?.animationEasing,
})
);
}
cy.scratch("_cyExpandCollapse").positions = null;
}
},
convertToRenderedPosition: function (modelPosition) {
Expand Down
31 changes: 31 additions & 0 deletions src/getSupportCy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const cytoscape = require("cytoscape");
const fcose = require("cytoscape-fcose");
const dagre = require("cytoscape-dagre");

/**
* Creates a new support cytoscape instance with the same elements and style as the provided instance,
* and attaches it to a container with the ID "support-map".
*
* @param {Object} cy - The original Cytoscape instance.
* @returns {Object} The new Cytoscape instance.
*/
function getSupportCy(cy) {
const cyJson = cy.json();

let cont = document.getElementById("support-map");
cont.style.width = cy.container().clientWidth + "px";
cont.style.height = cy.container().clientHeight + "px";

cytoscape.use(fcose);
cytoscape.use(dagre);
const supportCy = cytoscape({
container: cont,
elements: cyJson.elements,
styleEnabled: true,
style: cyJson.style,
});

return supportCy;
}

module.exports = getSupportCy;
Loading
Loading