Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
UI: allow preset positions in db for network layout
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed Oct 4, 2017
1 parent 6156b40 commit 3e96aa9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions imports/client/reducers/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function nodes(state = initialState, action) {
.map(d => JSON.parse(JSON.stringify(d)))
.map( (n,i) => {
n.data.i = i // add index as reference
n.storedPosition = Object.assign({}, n.position) // backup position from the db
return n
})

Expand Down
8 changes: 7 additions & 1 deletion imports/client/ui/components/network/Cytoscape.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ class Cytoscape extends Component {
applyLayout(layoutName) {
const layoutConfig = {
name : layoutName,
animate: false,
animate: false
}

if (layoutName == 'spread') {
layoutConfig.minDist= 50 // Minimum distance between nodes
layoutConfig.padding= 80 // Padding
}

if (layoutName == 'preset') {
const {nodes} = this.props.elements
// get positions from the db
layoutConfig.positions = (n) => (nodes[n.data('i')].storedPosition)
}

this.cy.layout(layoutConfig)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MenuItem from 'material-ui/MenuItem'
import ArrowDropRight from 'material-ui/svg-icons/navigation-arrow-drop-right'

const layouts = [
'preset',
'cose', // uncaught 'prototype' Error
'spread', // CPU overhead
'random',
Expand Down

0 comments on commit 3e96aa9

Please sign in to comment.