From 3e96aa903015b710b80b64a3c7d04b2a8337af5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renaud?= Date: Wed, 4 Oct 2017 06:58:17 +0200 Subject: [PATCH] UI: allow preset positions in db for network layout --- imports/client/reducers/nodes.js | 1 + imports/client/ui/components/network/Cytoscape.jsx | 8 +++++++- .../ui/components/networkOptions/NetworkOptions.jsx | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/imports/client/reducers/nodes.js b/imports/client/reducers/nodes.js index 7360c5f..a6180a9 100644 --- a/imports/client/reducers/nodes.js +++ b/imports/client/reducers/nodes.js @@ -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 }) diff --git a/imports/client/ui/components/network/Cytoscape.jsx b/imports/client/ui/components/network/Cytoscape.jsx index 8aa15ae..b30ca15 100644 --- a/imports/client/ui/components/network/Cytoscape.jsx +++ b/imports/client/ui/components/network/Cytoscape.jsx @@ -59,7 +59,7 @@ class Cytoscape extends Component { applyLayout(layoutName) { const layoutConfig = { name : layoutName, - animate: false, + animate: false } if (layoutName == 'spread') { @@ -67,6 +67,12 @@ class Cytoscape extends Component { 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) } diff --git a/imports/client/ui/components/networkOptions/NetworkOptions.jsx b/imports/client/ui/components/networkOptions/NetworkOptions.jsx index 902ef3f..5fb9854 100644 --- a/imports/client/ui/components/networkOptions/NetworkOptions.jsx +++ b/imports/client/ui/components/networkOptions/NetworkOptions.jsx @@ -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',