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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:26:26+00:00 2026-06-14T23:26:26+00:00

I have a list of json objects. var Planets = [ {name:maths, percComp: 2,

  • 0

I have a list of json objects.

var Planets = [
            {name:"maths", percComp: "2", preReq: "english"},
            {name:"english", percComp: "20", preReq: "geog"},
            {name:"geog", percComp: "57", preReq: "maths"}          
        ];

These objects are planets that i will add to a universe. They are school subjects

I also have a planet class

function Planet(planet, index)
    {
        this.name = planet.name;
        this.percComp = planet.percComp;
        this.preReq = planet.preReq;
        CreatePlanet(this, index);
        this.line = paper.path('');

        function RedrawLine(planetFrom, planetTo, strokeWidth)
        {
            line.attr({
                path:"M" + planetFrom.attrs.cx + "," + planetFrom.attrs.cy + "L"+ planetTo.attrs.cx + "," + planetTo.attrs.cy,
                "stroke-width": strokeWidth
            }); 
        }

        function CreatePlanet(planet)
        {
            var planetName = planet.name;
            planetName = paper.circle(200 * index, 100, 80/index);
            planetName.attr({ 
                fill:'red',
                stroke: '#3b4449',
                'stroke-width': 6               
            });

            SetGlow(30, true, 0, 0, 'grey', planetName)
            SetHover(planetName);
        }

        function SetHover(planet)
        {
            var radius = planet.attrs.r;
            planet.mouseover(function(){
                this.animate({ r: radius * 1.3}, 150)
            }).mouseout(function(){
                this.animate({ r: radius}, 150)
            })
        }

        function SetGlow(width, fill, offSetx, offsety, color, planet)
        {
            planet.glow({
                width: 30,
                fill: true,
                offsetx: 0,
                offsety: 0,
                color: 'grey'
            });
        }

    }

The code to initiate the program is

var element = document.getElementById('Main-Content')
var paper = new Raphael(element, 1000, 1000);


    window.onload = function()
    {

        var planetsSet = paper.set();

        var index = 1;
        $(jQuery.parseJSON(JSON.stringify(Planets))).each(function(){
            var planet = new Planet(this, index);
            planetsSet.push(planet);
            index++;
        });

        for (i=0; i<planetsSet.length; i++)
        {
            var planetTo = planetsSet[i];
                            // This is a test to see if RedrawLine works
                            var planeFrom = planetsFrom[i+1];
            planetTo.RedrawLine(planetTo, planeFrom, 30)
            var preReq = this.preReq;          
        }
    }

The code populates the screen with 3 planets. I am trying to connect these with a line. The line will connect a planet with its pre requisite that is declared in the json object. So maths has a pre requisite english, and english has a pre requisite geog. I have a function in the Planet class that will draw the line, but I cant access the objects after they have been drawn.

Is this a problem with Raphael or can it be done?

  • 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-14T23:26:27+00:00Added an answer on June 14, 2026 at 11:26 pm

    several errors in your approach:

    • Paper.set is not Array, use Array for such purpse
    • you messed scopes, pass paper to your object constructor
    • public methods should be declared at least as this.method not just function method()
    • keep a public properties of your planet in this.property object or at least not call this.planet as PlanetName.
    • you forget to use this.line in your redraw method

    little code to fill the void:

    var planetsSet = [];
    

    working sample

    homework:

    Remove planetFrom from RedrawLine method parameters, to be possible call this method as
    PlanetFrom.RedrawLine(planetTo);

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

Sidebar

Related Questions

I have a large list of objects inside JSON like this: var data =
I'm having a problem. I have the list of JSON objects in a separate
I am trying to output some Java objects as JSON, they have List properties
I have a Java (Spring MVC) backend that returns POJOs as JSON objects as
I have a JSON object like such: var list = {'name1' : {'element1': 'value1'},
I have list of objects which are returned from mvc controller as Json. I'm
I'm working on JavaScript and I have this JSON object: var obj ={name :
I have some JSON objects that I want to process on Client Side, but
I have a list of places in listview which i got from parsing JSON.
I am trying to build JSON from two fields. Say, I have a list

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.