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

Add labels to edges #7

Open
blumonkey opened this issue May 20, 2016 · 3 comments
Open

Add labels to edges #7

blumonkey opened this issue May 20, 2016 · 3 comments

Comments

@blumonkey
Copy link

Not an issue, but an enhancement?

How can I add labels to the edges so that they are more descriptive in the relation between nodes? Can anyone please direct me in the right direction?

Thank You!

@dbvrac
Copy link

dbvrac commented Nov 29, 2016

Did you ever figure out how to do this?
Thanks!

@mayinghan
Copy link

Any update?

@mayinghan
Copy link

I actually figured it out. Inside 'updateGraph' method, do:

const p = paths.enter().append("g");
//already given
    paths.enter()
      .append("path")
      .style('marker-end', 'url(#end-arrow)')
      .classed("link", true)
      .attr('id', d => {
        console.log(d.id);
        return "path" + d.id;
      })
      .attr("d", function (d) {
        return "M" + d.source.x + "," + d.source.y + "L" + d.target.x + "," + d.target.y;
      })
      .on("mousedown", function (d) {
        thisGraph.pathMouseDown.call(thisGraph, d3.select(this), d);
        }
      )
      .on("mouseup", function (d) {
        state.mouseDownLink = null;
      });
//start new code here
    p.append("text").attr("dy", -20)
      .append("textPath")
      .attr('id', d => {
        return ''+d.id;
      })
      
      .attr("text-anchor", "start")
      .style("font-size", 25)
      .style("fill", "#000")
      .style("text-anchor", "middle")
      .attr("startOffset", "50%")
      .attr("xlink:href", function(d) {
        console.log(d.id);
        return "#path" + d.id;
      })
      .text(function(d) {
        
        return d.func;
      });

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

No branches or pull requests

3 participants