@@ -4,26 +4,31 @@ import cytoscape from 'cytoscape';
4
4
import klay from 'cytoscape-klay' ;
5
5
6
6
import axios from 'axios' ;
7
- import isNull from 'lodash/isNull' ;
8
7
import equal from 'fast-deep-equal' ;
9
8
import RefreshIcon from '@material-ui/icons/Refresh' ;
10
9
11
10
import Background from '../public/canvas_bg.png' ;
12
11
import CyStyle from '../public/cy-style.json' ;
13
- import { get } from 'lodash' ;
14
12
15
13
cytoscape . use ( klay )
16
14
17
- // TODO : update subtree to be able to click nodes in subtrees
18
-
19
15
class Canvas extends React . Component {
20
16
constructor ( props ) {
21
17
super ( props ) ;
22
18
this . state = {
23
19
canvasElements : CytoscapeComponent . normalizeElements ( this . props . elements ) ,
24
- currentSubtree : null
20
+ hasSubtree : false ,
21
+ // static copy of topmost tree
22
+ topTree : null
25
23
}
26
24
25
+ // create topTree
26
+ var treeData = [ ]
27
+ for ( var { data :d } of this . state . canvasElements ) {
28
+ treeData . push ( d ) ;
29
+ } ;
30
+ this . state . topTree = treeData ;
31
+
27
32
this . showSidebar = this . showSidebar . bind ( this ) ;
28
33
this . showSubTree = this . showSubTree . bind ( this ) ;
29
34
this . removeSubTree = this . removeSubTree . bind ( this ) ;
@@ -42,10 +47,10 @@ class Canvas extends React.Component {
42
47
}
43
48
} )
44
49
. then ( res => {
45
- if ( ! isNull ( this . state . currentSubtree ) && this . state . currentSubtree !== res . data ) {
46
- this . removeSubTree ( this . state . currentSubtree ) ;
50
+ if ( this . state . hasSubtree && this . state . topTree . includes ( node ) ) {
51
+ this . removeSubTree ( ) ;
47
52
}
48
- this . setState ( { currentSubtree : res . data } ) ;
53
+ this . setState ( { hasSubtree : true } ) ;
49
54
this . cy . add ( res . data ) ;
50
55
this . runLayout ( ) ;
51
56
} )
@@ -54,17 +59,9 @@ class Canvas extends React.Component {
54
59
} )
55
60
}
56
61
57
- removeSubTree ( currentSubtree ) {
62
+ removeSubTree ( ) {
58
63
this . reloadCanvas ( ) ;
59
- // const nodes = currentSubtree.nodes;
60
- // for (let i = 0; i < nodes.length; i++) {
61
- // if (nodes[i].data._type == 'child' || nodes[i].data.id === 'root') {
62
- // let el = this.cy.getElementById(nodes[i].data.id);
63
- // this.cy.remove(el);
64
- // }
65
- // }
66
- // this.runLayout();
67
- // this.setState({currentSubtree: null});
64
+ this . setState ( { hasSubtree : false } ) ;
68
65
}
69
66
70
67
runLayout ( ) {
@@ -79,15 +76,15 @@ class Canvas extends React.Component {
79
76
reloadCanvas ( ) {
80
77
this . setState ( {
81
78
canvasElements : CytoscapeComponent . normalizeElements ( this . props . elements ) ,
82
- currentSubtree : null
79
+ hasSubtree : false ,
80
+ showParticipants : true
83
81
} ) ;
84
82
this . cy . elements ( ) . remove ( ) ;
85
83
this . cy . add ( this . state . canvasElements ) ;
86
84
this . runLayout ( ) ;
87
85
}
88
86
89
87
componentDidMount ( ) {
90
- console . log ( 'mounted' )
91
88
this . cy . ready ( ( ) => {
92
89
// left-click
93
90
this . cy . on ( 'tap' , event => {
0 commit comments