Thank all of you very much for sharing 👍
I tried many ways to build flow through meta nodes json, none of them worked very well. 😟😟😟
SO I developed a set of functions for automatic programmatically adding nodes implemented based on simulated drag and drop
, hoping to help someone.
- First I would create a node json string
let NODE_RELATION = {
root: [{
"type": "gongwei",
"name": "gongwei_1",
"parent_id": -1,
"children": [{
"parent_id": 1,
"type": "pipeline",
"name": "pipeline_1",
"children": [{
"type": "analyze",
"name": "analyze_1",
"parent_id": 3,
"children": []
}]
}]
}, {
"parent_id": -1,
"type": "gongwei",
"name": "gongwei_2",
"children": []
}]
}
- In the second part🚗🚗🚗, I will create a function that adds nodes. In this function, the mousedown function will be used,-
- then the flowy.drag object will be dynamically modified (atrr left and top) to move the object's position to the middle of the screen.
- finally, the mouseup function will be used to release drag object.
- It should be noted that offset and px will change according to the screen size.
function add_node(node_type, node_name, parent_node_id) {
offset_y = 35
offset_x = 200
$(`#${node_type}`).click()
let evt = new MouseEvent("mousedown", {
bubbles: true,
cancelable: true,
view: window,
});
$(`input[value="${node_name}"]`).parent()[0].dispatchEvent(evt);
console.log('flowy.drag()', flowy.drag())
if (parent_node_id == -1) {
flowy.drag().style.left = '900px'
flowy.drag().style.top = '150px'
} else {
flowy.drag().style.left = flowy.blocks()[parent_node_id].x + offset_x + "px"
flowy.drag().style.top = flowy.blocks()[parent_node_id].y + offset_y + "px"
}
let evt1 = new MouseEvent("mouseup", {
bubbles: true,
cancelable: true,
view: window,
});
$('#canvas')[0].dispatchEvent(evt1);
}
- Finally, the final flowy can be constructed by the meta node NODE_RELATION data json according to the number of layers.
add_node('root', 'root', -1)
for (let level_1 of NODE_RELATION['root']) {
add_node(level_1['type'], level_1['name'], level_1['parent_id'])
}
- If you need all the codes you can contact me ❤❤❤

Originally posted by @wscjxky in #110 (comment)
Thank all of you very much for sharing 👍
I tried many ways to build flow through meta nodes json, none of them worked very well. 😟😟😟
SO I developed a set of functions for automatic programmatically adding nodes implemented based on simulated drag and drop
, hoping to help someone.
Originally posted by @wscjxky in #110 (comment)