Skip to content

Commit

Permalink
Using a single layout reference
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Nov 24, 2023
1 parent e1c8c92 commit 6c27d44
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions public/diagram/diagram.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let cy
let currentElements = []
let layout

function initializeCytoscape(container) {
const fontFace = {
Expand Down Expand Up @@ -107,23 +108,15 @@ function initializeCytoscape(container) {
},
],
})
}

function updateLayout() {
updateNodes(cy.elements())
}

function updateNodes(elements) {
const layout = elements.layout({
layout = cy.layout({
name: "cose",
animate: false,
nodeDimensionsIncludeLabels: true,
fit: true,
nodeOverlap: 4,
randomize: false,
})

layout.run()
}

function objectsPositionChanged() {
Expand All @@ -142,13 +135,8 @@ function reloadDiagram(elements) {
cy.filter((element) => !ids.includes(element.id())).remove()
const newElements = elements.filter((element) => !cy.hasElementWithId(element.data.id))
if (newElements.length) {
const shouldUpdateLayout = !objectsKeepTheirPosition() || cy.elements().length === 0
const addedNodes = cy.add(newElements)
if (shouldUpdateLayout) {
updateLayout()
} else {
updateNodes(readyForLayoutElems(addedNodes))
}
cy.add(newElements)
layout.run()
}
}

Expand Down

0 comments on commit 6c27d44

Please sign in to comment.