Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom css for different lines #180

Closed
usama4850 opened this issue Jun 2, 2021 · 6 comments
Closed

Custom css for different lines #180

usama4850 opened this issue Jun 2, 2021 · 6 comments
Assignees
Labels

Comments

@usama4850
Copy link

hi
is it possible to have custom styles for different lines like 1 line color is blue other is yellow when I export the diagram and import it to another canvas it retains its lines color?
Please help

@jerosoler jerosoler self-assigned this Jun 3, 2021
@jerosoler jerosoler added the Style label Jun 3, 2021
@jerosoler
Copy link
Owner

Hello @usama4850

There are not many options.

It would be this option by css with the color by type of output_1 output_2 ....

image

Witch css:

.drawflow .connection.output_2 .main-path {
    stroke: red;
}
.drawflow .connection.output_3 .main-path {
    stroke: #ff9900;
}

Another option is to look at this PR #122

Jero

@usama4850
Copy link
Author

usama4850 commented Jun 3, 2021 via email

@usama4850
Copy link
Author

Hello @usama4850

There are not many options.

It would be this option by css with the color by type of output_1 output_2 ....

image

Witch css:

.drawflow .connection.output_2 .main-path {
    stroke: red;
}
.drawflow .connection.output_3 .main-path {
    stroke: #ff9900;
}

Another option is to look at this PR #122

Jero

I want different lines from one output on the basics of classes
like I make a click function on output it appears options to choose the connection color I need to save this styles in JSON so next time when I import my JSON on another editor it retains the colors of connection

@jerosoler
Copy link
Owner

That is a bit tricky.
I would have to overwrite some functions

@usama4850
Copy link
Author

usama4850 commented Jun 6, 2021 via email

@jerosoler
Copy link
Owner

The most reasonable way I can find would be this:

Detect the changes in the dom and add the class of the exit node.

This works on importing and creating new entries.

Adding between editor and editor.start

const editor = new Drawflow(id);

  const config = { attributes: true, childList: true, subtree: true };

    const callback = function(mutationsList, observer) {
      // Use traditional 'for loops' for IE 11
      for(const mutation of mutationsList) {
          if (mutation.type === 'childList') {
              if(mutation.addedNodes[0]) {
                if(mutation.addedNodes[0].nodeName === "svg" && mutation.addedNodes[0].classList[0] === "connection") {
                  if(mutation.addedNodes[0].classList.length > 4) {
                  console.log('A child node has been added or removed.');
                    const node_id = parseInt(mutation.addedNodes[0].classList[2].slice(14));
                    const info_node = editor.getNodeFromId(node_id);
                    mutation.addedNodes[0].classList.add(info_node.class);
                   //console.log(mutation);
                  }
                }

              }
          }
          else if (mutation.type === 'attributes') {
              if(mutation.attributeName === "class") {
                if(mutation.target.nodeName === "svg" && mutation.target.classList[0] === "connection") {
                  if(mutation.target.classList.length > 4 && mutation.target.classList.length < 6) {
                      //console.log("add class");
                      const node_id = parseInt(mutation.target.classList[2].slice(14));
                      const info_node = editor.getNodeFromId(node_id);
                      console.log(info_node);
                      mutation.target.classList.add(info_node.class);
                }
              }
          }
      }
    }
  };
  const observer = new MutationObserver(callback);
  observer.observe(id, config);

  editor.reroute = true;
  editor.reroute_fix_curvature = true;

  editor.start();

and css

<style>
.connection.CLASS_NODE_NAME.output_1 path {
  stroke: red;
}

.connection.CLASS_NODE_NAME.output_2 path {
  stroke: green;
}
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants