Skip to content

Commit e6c4ba7

Browse files
committed
multiple levels of subtrees viewable
1 parent c308a77 commit e6c4ba7

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
nodes = {}
77
edges = []
88

9+
# TODO: look through SDF version documentation to decide what should be in the schema_key_dict
10+
# TODO: move support to SDF version 1.3
11+
912
# SDF version 1.2
1013
schema_key_dict = {
1114
'root': ['@id', 'name', 'description', 'comment', 'qnode', '@type', 'minDuration', 'maxDuration', 'repeatable', 'TA1explanation', 'importance', 'qlabel'],
@@ -174,6 +177,7 @@ def get_nodes_and_edges(schema):
174177
# TODO: and, xor gate
175178
# TODO: optional nodes -- the option is in the cy-style json
176179
# bug? it doesn't show up on parent node
180+
# found: parent node does not have optional key and overwrites child node keys
177181

178182
# === are these two necessary? / what are these for ===
179183
# TODO: entities

static/src/template/Canvas.jsx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ import cytoscape from 'cytoscape';
44
import klay from 'cytoscape-klay';
55

66
import axios from 'axios';
7-
import isNull from 'lodash/isNull';
87
import equal from 'fast-deep-equal';
98
import RefreshIcon from '@material-ui/icons/Refresh';
109

1110
import Background from '../public/canvas_bg.png';
1211
import CyStyle from '../public/cy-style.json';
13-
import { get } from 'lodash';
1412

1513
cytoscape.use(klay)
1614

17-
// TODO : update subtree to be able to click nodes in subtrees
18-
1915
class Canvas extends React.Component {
2016
constructor(props) {
2117
super(props);
2218
this.state = {
2319
canvasElements: CytoscapeComponent.normalizeElements(this.props.elements),
24-
currentSubtree: null
20+
hasSubtree: false,
21+
// static copy of topmost tree
22+
topTree: null
2523
}
2624

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+
2732
this.showSidebar = this.showSidebar.bind(this);
2833
this.showSubTree = this.showSubTree.bind(this);
2934
this.removeSubTree = this.removeSubTree.bind(this);
@@ -42,10 +47,10 @@ class Canvas extends React.Component {
4247
}
4348
})
4449
.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();
4752
}
48-
this.setState({currentSubtree: res.data});
53+
this.setState({hasSubtree: true});
4954
this.cy.add(res.data);
5055
this.runLayout();
5156
})
@@ -54,17 +59,9 @@ class Canvas extends React.Component {
5459
})
5560
}
5661

57-
removeSubTree(currentSubtree) {
62+
removeSubTree() {
5863
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});
6865
}
6966

7067
runLayout() {
@@ -79,15 +76,15 @@ class Canvas extends React.Component {
7976
reloadCanvas() {
8077
this.setState({
8178
canvasElements: CytoscapeComponent.normalizeElements(this.props.elements),
82-
currentSubtree: null
79+
hasSubtree: false,
80+
showParticipants: true
8381
});
8482
this.cy.elements().remove();
8583
this.cy.add( this.state.canvasElements );
8684
this.runLayout();
8785
}
8886

8987
componentDidMount() {
90-
console.log('mounted')
9188
this.cy.ready(() => {
9289
// left-click
9390
this.cy.on('tap', event => {

0 commit comments

Comments
 (0)