Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:06:43+00:00 2026-05-25T20:06:43+00:00

How do I add labels to edges in arbor.js It is a graph visualization

  • 0

How do I add labels to edges in arbor.js
It is a graph visualization library.

Suppose A and B are nodes and E is the edge
One crude way would be insert a “text node” T
and join A-T and T-B

But i don’t want to this, is there any other way?

Here’s the sample code

var theUI = {
  nodes:{A:{color:"red", shape:"dot", alpha:1}, 
      B:{color:"#b2b19d", shape:"dot", alpha:1}, 
      C:{color:"#b2b19d", shape:"dot", alpha:1}, 
      D:{color:"#b2b19d", shape:"dot", alpha:1},
  },
  edges:{
      A:{
          B:{length:.8},
          C:{length:.8},
          D:{length:.8}
           }
  }
}

var sys = arbor.ParticleSystem()
sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015})
sys.renderer = Renderer("#sitemap")
sys.graft(theUI) 

In this, A is connected to B, C and D.
How to supply label to edges?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:06:44+00:00Added an answer on May 25, 2026 at 8:06 pm

    arbor.js allows you to write a code to render the whole graph. You can do whatever you want in render method including drawing edges titles which you can store in a separate map.

    Just override method render in Renderer this way:

    redraw:function()
    {
        ctx.fillStyle = "white";
        ctx.fillRect (0,0, canvas.width, canvas.height);
    
        particleSystem.eachEdge (function (edge, pt1, pt2)
        {
            ctx.strokeStyle = "rgba(0,0,0, .333)";
            ctx.lineWidth = 1;
            ctx.beginPath ();
            ctx.moveTo (pt1.x, pt1.y);
            ctx.lineTo (pt2.x, pt2.y);
            ctx.stroke ();
    
            ctx.fillStyle = "black";
            ctx.font = 'italic 13px sans-serif';
            ctx.fillText (edge.data.name, (pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2);
    
        });
    
        particleSystem.eachNode (function (node, pt)
        {
            var w = 10;
            ctx.fillStyle = "orange";
            ctx.fillRect (pt.x-w/2, pt.y-w/2, w,w);
            ctx.fillStyle = "black";
            ctx.font = 'italic 13px sans-serif';
            ctx.fillText (node.name, pt.x+8, pt.y+8);
        });       
       };
    

    This code expected data property of each edge to be filled while initialization.

    I create all nodes and edges manually using my custom map and methods addNode/addEdge, bu I suppose you can change a little your code to initialize edges with custom data this way:

    var theUI = {
      nodes:{A:{color:"red", shape:"dot", alpha:1}, 
          B:{color:"#b2b19d", shape:"dot", alpha:1}, 
          C:{color:"#b2b19d", shape:"dot", alpha:1}, 
          D:{color:"#b2b19d", shape:"dot", alpha:1},
      },
      edges:{
          A:{
              B:{length:.8, data:{name:"A->B"}},
              C:{length:.8, data:{name:"A->C"}},
              D:{length:.8, data:{name:"A->D"}}
               }
      }
    }

    P.S.: take a look at this example, I learned a lot from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add colours to the edges of the graph which I created
I want to add three labels into a cell dynamically, cell is created dynamically
i want to add images or labels with image in it to a panel
how we could add a special class for labels and errors for a zend-form-element
I have a JPanel subclass on which I add buttons, labels, tables, etc. To
I am trying to draw a graph using Graphviz, but I need to add
In graphviz I would like to have an edge that doesn't cross the node.
stripchart : x <- c(2, 8, 11, 19) stripchart(x) How do you add labels
I've successfully been able to add controls (labels, images, buttons, etc) to a panel
I am working on something similar to a canvas, users can add drag labels

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.