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 8340969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:19:53+00:00 2026-06-09T05:19:53+00:00

I am trying RaphaelJS for drawing graph theory style graphs. For example: While it

  • 0

I am trying RaphaelJS for drawing graph theory style graphs. For example:

enter image description here

While it is easy to create circles/nodes in RaphaelJS, I haven’t figured out how to associate each node with a label (and having the label inside each node).

Is this feasible with RaphaelJS?

  • 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-06-09T05:19:55+00:00Added an answer on June 9, 2026 at 5:19 am

    I’d write a little bit of code to manage a series of such nodes using default styles, allowing for overrides as desired.

    // "Constructor" -- accepts a Raphael paper to use as background object and default values for node radius, node style, and label style.
    function NodeManager( paper, node_radius, node_style, label_style )
    {
        this.paper = paper;
        this.nodes = {};
        this.node_radius = node_radius || 24;
        this.node_style = node_style || { fill: 'white', stroke: 'black', 'stroke-width': 3 };
        this.label_style = label_style || { fill: 'black', stroke: 'none', 'font-family': 'Arial,Helvetica,sans-serif', 'font-size': 32, 'font-weight': 600 };
    }
    
    // Add a node to the paper.  
    // Code is an arbitrary or symbolic name; 
    // x and y are the coordinates the node is centered on; 
    // label is the node's textual content (no clipping is performed, so be careful!); 
    // node_radius, node_style, and label_style are optional, and can be used to override the appearance of this node.
    NodeManager.prototype.addNode = function addNode( code, x, y, label, node_radius, node_style, label_style )
    {
        var node = this.paper.circle( x, y, node_radius || this.node_radius ).attr( node_style || this.node_style );
        var label_object = this.paper.text( x, y, label ).attr( label_style || this.label_style );
        this.nodes[code] =
            {
                x: x,
                y: y,
                r: node_radius || this.node_radius,
                node: node,
                label: label_object
            };
    }
    
    // Connect the nodes corresponding to the two given codes.  connection_style can be used to override the appearance of the connective link, but the default node_style will be used if it isn't specified.
    NodeManager.prototype.connectNodes = function connectNodes( code1, code2, connection_style )
    {  
        var angle = Math.atan2(this.nodes[code2].y - this.nodes[code1].y, this.nodes[code2].x - this.nodes[code1].x );      //  this will be the angle from point to point
        var inverse_angle = angle + Math.PI;
    
        ox1 = this.nodes[code1].x + Math.cos( angle ) * this.nodes[code1].r;
        oy1 = this.nodes[code1].y + Math.sin( angle ) * this.nodes[code1].r;
    
        ox2 = this.nodes[code2].x + Math.cos( inverse_angle ) * this.nodes[code2].r;
        oy2 = this.nodes[code2].y + Math.sin( inverse_angle ) * this.nodes[code2].r;
    
        var pathstr = "M" + ox1 + "," + oy1 + " L" + ox2 + "," + oy2;
    
        var path = this.paper.path( pathstr ).attr( connection_style || this.node_style );
    }
    

    Check out this fiddle to see a little example of the results.

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

Sidebar

Related Questions

I'm trying to use jQuery and RaphaelJS to: Create circles Display some information when
I'm trying to create a draggable graph similar to http://raphaeljs.com/graffle.html (works in both 1.5.2
I'm trying to create an easy play / pause button system with Raphael but
I'm trying to create a little free-hand drawing app, and to figure out a
I was trying to draw the raphaeljs piechart. I used the same example as
I'm trying to use a raphael.js example located here: http://raphaeljs.com/pie.html but I want to
I am trying to create a pie chart and am customizing the example here:
I'm trying to create an animation where I create 4 circles in Raphael 10
I am trying to construct a customized map in raphaeljs , in this i
Possible Duplicate: Raphaeljs and Internet Explorer, problem when clicking an element I'm trying to

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.