Skip to content

Commit 34ed36e

Browse files
committed
fixed using common load for optional layout
1 parent 31f6cec commit 34ed36e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/graph_app.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,9 @@ function onMqttMessage(e){
8484
const topic = e.detail.topic
8585
const data = e.detail.payload
8686
//console.log(`graph_app> ${topic} => ${JSON.stringify(data)}`);
87-
//TODO select sub topic of new graph vs update
8887
const action = topic.split('/')[1]
8988
if(action == "reload"){
90-
physics.pause()
91-
render.pause()
92-
gio.import_json(data)
93-
render.fitLabels()
94-
physics.create_bodies(parent_div)
95-
render.create_graph()
96-
mutate.all_groups(graph)
97-
physics.resume()
98-
render.resume()
89+
common_load(null, true, null, data)
9990
}else if(action == "update"){
10091
for(const vertex of data.vertices){
10192
let v = graph.vertices[vertex.id]
@@ -107,13 +98,19 @@ function onMqttMessage(e){
10798
}
10899

109100

110-
async function common_load(file,reload,config=null){
101+
async function common_load(file,reload,config=null,graph_input=null){
111102
if(reload){
112-
console.log(`graph_app> reloading file : ${file.name}`)
103+
console.log(`graph_app> reloading`)
113104
physics.pause()
114105
render.pause()
115106
}
116-
await gio.import_file(file,config)
107+
if(graph_input){
108+
console.log("graph_app> mqtt : graph_input")
109+
gio.import_json(graph_input)
110+
}else{
111+
console.log(`graph_app> file : ${file.name}`)
112+
await gio.import_file(file,config)
113+
}
117114
console.log(graph)
118115
if(!reload){
119116
//required svg before create_graph()

0 commit comments

Comments
 (0)