jerosoler / Drawflow

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

Label for connector lines #18

Open taroongunessee opened 4 years ago

taroongunessee commented 4 years ago

Hello, is it possible to add labels to connector lines? For example, Yes/No or If/Else?

jerosoler commented 4 years ago

Hi!

I'ts possible with css: image

For example:

.drawflow-node.multiple .outputs .output:nth-child(1):before {
    display: block;
    content: "Yes";
    position: relative;
    right: 30px;
  }
 .drawflow-node.multiple .outputs .output:nth-child(2):before {
    display: block;
    content: "No";
    position: relative;
    right: 30px;
 }

In case use the classname "multiple"

editor.addNode(name, inputs, outputs, posx, posy, class, data, html);

Does the solution work for you?

taroongunessee commented 4 years ago

Hello, can the label be drawn alongside the connector line/path please? That will be much better and appealing. Thanks

jerosoler commented 4 years ago

In the center of line?

image

taroongunessee commented 4 years ago

Yes, or even something like this:

Screenshot_2020-07-31 Flow Builder - MessageBird

lozzo commented 4 years ago

@taroongunessee you may need to add for svg image

aughey commented 3 years ago

Labeling ports with css can be impractical when nodes and ports are generated dynamically. In my case, I'm creating nodes on a remote system, and the remote system will "describe" what the inputs and output are. I need to label each input and output with a name to indicate what type of data goes into that port.

gunasekharravilla commented 3 years ago

@taroongunessee you may need to add for svg image

how did you do that? please share the code snippet for dynamic labelling by user

Boffice commented 3 years ago

Any plans to add this as an actual js parameter instead of css class ?

gunasekharravilla commented 3 years ago

yes @jerosoler many people are looking for dynamic connection labelling

please plan to implement it

rwnobrega commented 3 years ago

[...]

image

[...]

Dear @jerosoler, thanks a lot for this amazing library!

Any hint on how to right-align all the labels in this example?

Edit:

Nevermind, found the solution:

display: block;
content: "Content";
transform: translate(-20px);
text-align: right;
float: right;
hi-reeve commented 3 years ago

any update on this issue? any plan on updating this?

shadab19it commented 3 years ago

yes, please share the code snippet for dynamic connection labeling

Aravinda93 commented 3 years ago

@jerosoler Hello, Thanks a lot for this amazing library. I have a requirement to add multiple Labels on Connector so wanted to confirm if this has been implemented. It would be really nice to have the option to add multiple Labels on Connector. Something like this I want to design my application:

CPT2111081318-1890x906 (1)

jerosoler commented 3 years ago

Hi @Aravinda93

It is not yet implemented. But I want to implement this system.

https://github.com/jerosoler/Drawflow/issues/45#issuecomment-701554099

So if you have any suggestions, please comment.

Aravinda93 commented 3 years ago

@jerosoler Thanks a lot for the response. This is a really nice library so I have decided to use this in one of our applications. It would be nice to see the option to add multiple labels on the Connector. T

Thanks for the nice project, have a great day :)

jerosoler commented 2 years ago

Function for add label in the center:

    let label1 = document.querySelector(".connection.node_in_node-2.node_out_node-1.output_1.input_1");

    addLabelText(label1, "Something");

    function addLabelText(bgPath, labelText)
    {
        const newid = [bgPath.classList].join().replace(/\s/g, '');
        bgPath.childNodes[0].id = newid; 
        let textElem = document.createElementNS(bgPath.namespaceURI, "text");
        let textElemPath = document.createElementNS(bgPath.namespaceURI, "textPath");
        textElemPath.setAttribute("href", `#${newid}`);
        textElemPath.setAttribute("text-anchor", "middle");
        textElemPath.setAttribute("startOffset", "50%");
        textElemPath.classList.add("label-text");
        textElemPath.textContent = labelText;
        textElem.appendChild(textElemPath); 
        bgPath.appendChild(textElem);
    }

image

hi-reeve commented 2 years ago

Function for add label in the center:

    let label1 = document.querySelector(".connection.node_in_node-2.node_out_node-1.output_1.input_1");

    addLabelText(label1, "Something");

    function addLabelText(bgPath, labelText)
    {
        const newid = [bgPath.classList].join().replace(/\s/g, '');
        bgPath.childNodes[0].id = newid; 
        let textElem = document.createElementNS(bgPath.namespaceURI, "text");
        let textElemPath = document.createElementNS(bgPath.namespaceURI, "textPath");
        textElemPath.setAttribute("href", `#${newid}`);
        textElemPath.setAttribute("text-anchor", "middle");
        textElemPath.setAttribute("startOffset", "50%");
        textElemPath.classList.add("label-text");
        textElemPath.textContent = labelText;
        textElem.appendChild(textElemPath); 
        bgPath.appendChild(textElem);
    }

image

Function for add label in the center:

    let label1 = document.querySelector(".connection.node_in_node-2.node_out_node-1.output_1.input_1");

    addLabelText(label1, "Something");

    function addLabelText(bgPath, labelText)
    {
        const newid = [bgPath.classList].join().replace(/\s/g, '');
        bgPath.childNodes[0].id = newid; 
        let textElem = document.createElementNS(bgPath.namespaceURI, "text");
        let textElemPath = document.createElementNS(bgPath.namespaceURI, "textPath");
        textElemPath.setAttribute("href", `#${newid}`);
        textElemPath.setAttribute("text-anchor", "middle");
        textElemPath.setAttribute("startOffset", "50%");
        textElemPath.classList.add("label-text");
        textElemPath.textContent = labelText;
        textElem.appendChild(textElemPath); 
        bgPath.appendChild(textElem);
    }

image

are you gonna add this to the next release?

jerosoler commented 2 years ago

@zynth17 I don't think so, if I added it it would be in some other more native way.

AK3030 commented 2 years ago

How would I go about rotating the text of the label so that it's always horizontal?

shamilyn commented 2 years ago

@jerosoler, I need to add an input field dynamically at the center of the connector to name the connector while clicking it...

Is there any other sample code available for that??

jerosoler commented 2 years ago

You can use the "clickEnd" event to detect if a line was clicked.

And javascript

if(this.connection_selected != null) {
 //Your code to add label
}
itsrajatcodehub commented 1 year ago

Hi @jerosoler Thanks for the great Library!

how to set the label after import the complete flow ?

this is how I'm setting the label save

after the import I want the label on its place save2

how to do this ?

jerosoler commented 1 year ago

Use event "import" to add the text again.

mushzak commented 1 year ago

add text label function works but how I can add to into the drowflow data structure?

mushzak commented 1 year ago
image

how I can fix this rotation issue?

mushzak commented 1 year ago
image
mushzak commented 1 year ago

anyone had this issue and know the solution?

mushzak commented 1 year ago

the second question is: Is there any way to save this into the structure?

jerosoler commented 1 year ago

First question: Provide a codepeen to reproduce your code.

Second question: You can save data as follows. In this case it is the html of the node, but it could save in the connection as well.

mushzak commented 1 year ago
image

I'm using this function to add labels, it look like this

image

and it is correct only for right side:

image
mushzak commented 1 year ago

First question: Provide a codepeen to reproduce your code.

Second question: You can save data as follows. In this case it is the html of the node, but it could save in the connection as well.

I don't see label into html of the node

Tirguy commented 1 year ago

Hi!

I'ts possible with css: image

For example:

.drawflow-node.multiple .outputs .output:nth-child(1):before {
    display: block;
    content: "Yes";
    position: relative;
    right: 30px;
  }
 .drawflow-node.multiple .outputs .output:nth-child(2):before {
    display: block;
    content: "No";
    position: relative;
    right: 30px;
 }

In case use the classname "multiple"

editor.addNode(name, inputs, outputs, posx, posy, class, data, html);

Does the solution work for you?

It's exactly what i need...

But how can i include this JS to describe the label of each points (input or output) in the node ? I try to put this code in tag, but not seems to work...

Does this code if for all node or just for one node ? because i will need to put different names for the first output of my different nodes...

At the end of my project, module should look like this picture : image But with name on each input and output that can be different on each point... I will search a solution later to change the color of each line between each input/output point which will give me a more readable digram

jerosoler commented 1 year ago

This css is for node with "ClassName" "multiple"

The class parameter in node.

editor.addNode(name, inputs, outputs, posx, posy, class, data, html);
celevra commented 8 months ago

i'm designing an Firewall Rule Generatror

that means from one node you can make a connection to "namend" inputs like Port 443, Port 8080 and so on For that i would need a lable next to the "dot" CSS is here not possible because they will be generated, every dot should have an attribute like "name"

parthsavaliya1 commented 7 months ago

@jerosoler i want to add label with background color and some background property in connection line. is there any solution ?