jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.74k stars 737 forks source link

How to change color of path by node id? #435

Open dotrungit91 opened 2 years ago

dotrungit91 commented 2 years ago

I want to change color of path with input node type. Thank?

image

jerosoler commented 2 years ago

Use event connectionCreated to detec connection and add css class to line.

In the event you can see what types of nodes they are with getNodeFromId

dotrungit91 commented 2 years ago

@jerosoler I render connection by data. So i can't detect with event connectionCreated

jerosoler commented 2 years ago

What do you mean "data"? For import method?

Is for import method use event "import" and loop connections for the import data.

urveerendra commented 2 years ago

Add these lines in "this.editor.on('connectionCreated', (connection: any) => { console.log(connection) }" like below, e.g.,

       this.editor.on('connectionCreated', (connection: any) => {
        let outputConnectedNode = this.editor.getNodeFromId(connection.output_id);
        let inputConnectedNode = this.editor.getNodeFromId(connection.input_id);
        // if required check for appropriate outputConnectedNode and inputConnectedNode
        if(outputConnectedNode.class = "<check class>" || inputConnectedNode.class = "<check class>")
        // add a custom class for the connection created
         document.getElementsByClassName("node_out_node-"+ connection.output_id +" "+ "node_in_node-"+ connection.input_id)[0].classList.add("greenClass");
    }
And then add css for the custom class
.greenClass path{
  stroke: green;
}