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

Implement remove edge from clustering #71

Merged
merged 2 commits into from
Jul 18, 2019
Merged
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
59 changes: 46 additions & 13 deletions lib/network/modules/Clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ class ClusterEngine {
}
} else {
// Create a new cluster group
clusters.push({ nodes: childNodesObj, edges: childEdgesObj })
clusters.push({
nodes: childNodesObj,
edges: childEdgesObj
})
}
}
}
Expand Down Expand Up @@ -460,7 +463,11 @@ class ClusterEngine {

// Only edges from the cluster outwards are being replaced.
if (childNodesObj[otherNodeId] === undefined) {
createEdges.push({ edge: edge, fromId: fromId, toId: toId })
createEdges.push({
edge: edge,
fromId: fromId,
toId: toId
})
}
}
}
Expand Down Expand Up @@ -525,7 +532,9 @@ class ClusterEngine {

// hide the replaced edge
this._backupEdgeOptions(edge)
edge.setOptions({ physics: false })
edge.setOptions({
physics: false
})
}
}

Expand Down Expand Up @@ -689,7 +698,9 @@ class ClusterEngine {
*/
_backupEdgeOptions(edge) {
if (this.clusteredEdges[edge.id] === undefined) {
this.clusteredEdges[edge.id] = { physics: edge.options.physics }
this.clusteredEdges[edge.id] = {
physics: edge.options.physics
}
}
}

Expand All @@ -701,7 +712,9 @@ class ClusterEngine {
_restoreEdge(edge) {
let originalOptions = this.clusteredEdges[edge.id]
if (originalOptions !== undefined) {
edge.setOptions({ physics: originalOptions.physics })
edge.setOptions({
physics: originalOptions.physics
})
delete this.clusteredEdges[edge.id]
}
}
Expand Down Expand Up @@ -741,7 +754,10 @@ class ClusterEngine {
maxY = node.y > maxY ? node.y : maxY
}

return { x: 0.5 * (minX + maxX), y: 0.5 * (minY + maxY) }
return {
x: 0.5 * (minX + maxX),
y: 0.5 * (minY + maxY)
}
}

/**
Expand Down Expand Up @@ -802,11 +818,17 @@ class ClusterEngine {
typeof options.releaseFunction === 'function'
) {
let positions = {}
let clusterPosition = { x: clusterNode.x, y: clusterNode.y }
let clusterPosition = {
x: clusterNode.x,
y: clusterNode.y
}
for (let nodeId in containedNodes) {
if (containedNodes.hasOwnProperty(nodeId)) {
let containedNode = this.body.nodes[nodeId]
positions[nodeId] = { x: containedNode.x, y: containedNode.y }
positions[nodeId] = {
x: containedNode.x,
y: containedNode.y
}
}
}
let newPositions = options.releaseFunction(clusterPosition, positions)
Expand Down Expand Up @@ -848,7 +870,9 @@ class ClusterEngine {
containedNode.vx = clusterNode.vx
containedNode.vy = clusterNode.vy

containedNode.setOptions({ physics: true })
containedNode.setOptions({
physics: true
})

delete this.clusteredNodes[nodeId]
}
Expand Down Expand Up @@ -895,7 +919,10 @@ class ClusterEngine {
toId,
transferEdge,
otherCluster.clusterEdgeProperties,
{ hidden: false, physics: true }
{
hidden: false,
physics: true
}
)
} else {
this._restoreEdge(transferEdge)
Expand Down Expand Up @@ -1247,7 +1274,9 @@ class ClusterEngine {
// cache the options before changing
this._backupEdgeOptions(edge)
// disable physics and hide the edge
edge.setOptions({ physics: false })
edge.setOptions({
physics: false
})
}
}
}
Expand All @@ -1259,7 +1288,9 @@ class ClusterEngine {
clusterId: clusterNode.id,
node: this.body.nodes[nodeId]
}
this.body.nodes[nodeId].setOptions({ physics: false })
this.body.nodes[nodeId].setOptions({
physics: false
})
}
}
}
Expand Down Expand Up @@ -1478,12 +1509,14 @@ class ClusterEngine {
// TODO: check that it works for both edges clustered
// (This might be paranoia)
} else {
delete this._clusterEdges[edgeId]
this._restoreEdge(edge)
Copy link
Member

Choose a reason for hiding this comment

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

this is the meaningful part of the diff

// This should not be happening, the state should
// be properly updated at this point.
//
// If it *is* reached during normal operation, then we have to implement
// undo clustering for this edge here.
throw new Error('remove edge from clustering not implemented!')
// throw new Error('remove edge from clustering not implemented!')
}
})

Expand Down