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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:16:53+00:00 2026-06-06T04:16:53+00:00

I am creating a module to graphically visualize workflows using raphael,which take data from

  • 0

I am creating a module to graphically visualize workflows using raphael,which take data from a data base. For this i have created a class called “FlowEdit”, and created move, up and dragger function according to raphael.

But in move function when i am trying to access connections list using object reference, than i am unable to reference it, it gives undefined error.

Code for the class is this:-

        //class definition
        function FlowView(list) {
        this.list = list;
        this.connections = [];
        this.r = Raphael("holder", 1400, 500);
        this.shapes = [];
        this.texts = [];
        this.y_center = 500 / 2;
        //box size
        this.r_width = 60;
        this.r_height = 40;
        // To define virtual regions
        this.x_offset = 50;
        this.y_offset = 40;
        this.x_start = 40;
        //this.color, this.tempS, this.tempT;
        //Define position in y direction
        this.top_count = [0];
        this.bottom_count = [0];
        //Initialize Top_count & Bottom_Count Arrays
        for (var i = 0; i < this.list.length; i++) {
            this.top_count.push(0);
            this.bottom_count.push(0);
        }
    }
    ;

    // Give starting points from list
    FlowView.prototype.start_point = function () {
        var start_list = [];
        for (var i in this.list) {
            if (this.list[i][1] == this.list[i][2][0]) {
                start_list.push(this.list[i][1]);
            }
        }
        return start_list;
    };

    //For Finding index of an element in list
    FlowView.prototype.index_of = function (curr_point) {
        for (var i in this.list) {
            if (this.list[i][1] == curr_point) {
                return i;
            }
        }
    };

    //add next function
    FlowView.prototype.add_next = function () {
        for (var i in this.list) {
            if (this.list[i][3][0] == "NULL") {
                //For all last nodes add same to their next
                this.list[i][3][0] = this.list[i][1];
            }
            if (this.list[i][3].length == 0) {
                //For all last nodes add same to their next
                this.list[i][3].push(this.list[i][1]);
            }
        }
    };

    //For given next of all nodes add previous to those nodes
    FlowView.prototype.add_previous = function () {
        for (var i in this.list) {
            for (var j in this.list[i][3]) {
                //For all next add current node to their previous list
                var curr_index = this.index_of(this.list[i][3][j]);
                if (this.list[curr_index][2].indexOf(this.list[i][1]) == -1 && (curr_index != i)) {
                    this.list[curr_index][2].push(this.list[i][1]);
                }
            }
        }
        //Add previous of all start node
        for (var i in this.list) {
            if (this.list[i][2].length == 0) {
                this.list[i][2].push(this.list[i][1]);
            }
        }
    };


    //Region update recursively
    FlowView.prototype.region_update = function (curr_index) {
        if (this.list[curr_index][1] != this.list[curr_index][3][0]) {
            for (var i in this.list[curr_index][3]) {
                var next_index = this.index_of(this.list[curr_index][3][i]);
                if (this.list[next_index][0] < this.list[curr_index][0] + 1) {
                    this.list[next_index][0] = this.list[curr_index][0] + 1;
                    this.region_update(next_index);
                }
            }
        }
    };

    //Draw the workflow for given data structure
    FlowView.prototype.construct = function () {
        var open = this.start_point();
        var close = [];

        while (open.length != 0) {
            var curr_point = open.shift();
            var curr_index = this.index_of(curr_point);
            //document.write(curr_index);
            //draw box
            var curr_region = this.list[curr_index][0];
            //document.write(curr_region);
            var x_cord = parseInt(curr_region) * (this.x_offset + this.r_width) + this.x_start;
            //document.write(x_start);
            var y_cord = 0;

            if (this.top_count[curr_region] == 0 && this.bottom_count[curr_region] == 0) {
                y_cord = this.y_center - this.r_height / 2;
                this.top_count[curr_region] = 1;
                this.bottom_count[curr_region] = 1;
            }
            else if (this.top_count[curr_region] <= this.bottom_count[curr_region]) {
                y_cord = this.y_center - this.r_height / 2 - this.top_count[curr_region] * (this.y_offset + this.r_height);
                this.top_count[curr_region] = this.top_count[curr_region] + 1;
            }
            else {
                y_cord = this.y_center + this.r_height / 2 + this.bottom_count[curr_region] * (this.y_offset + this.r_height) - this.r_height;
                this.bottom_count[curr_region] = this.bottom_count[curr_region] + 1;
            }

            //drawing the box
            this.shapes[this.list[curr_index][1]] = this.r.rect(x_cord, y_cord, this.r_width, this.r_height, 10);
            this.texts[this.list[curr_index][1]] = this.r.text(x_cord + this.r_width / 2, y_cord + this.r_height / 2, this.list[curr_index][1]);
            // Adding next nodes to open list
            for (var i in this.list[curr_index][3]) {
                //If not in open than add to open
                if (this.list[curr_index][3][0] != this.list[curr_index][1]) {
                    if (open.indexOf(this.list[curr_index][3][i]) == -1 && close.indexOf(this.list[curr_index][3][i]) == -1) {
                        open.push(this.list[curr_index][3][i]);
                    }
                }
            }
            //Increasing region index for each next node
            this.region_update(curr_index);
            close.push(curr_point);
            //document.write(open.toString()+"</br>");
            //document.write(close.toString()+"</br>");
        }
        for (var j in this.list) {
            if (this.list[j][1] != this.list[j][3][0]) {
                for (var i in this.list[j][3]) {
                    //make link for each previous
                    if (close.indexOf(this.list[j][3][i]) != -1) {
                                 this.connections.push(this.r.connection(this.shapes[this.list[j][1]], this.shapes[this.list[j][3][i]], "bcd"));
                    }
                }
            }
        }
    };

    FlowView.prototype.dragger = function () {
        // Original cords for main element
        this.ox = this.type == "ellipse" ? this.attr("cx") : this.attr("x");
        this.oy = this.type == "ellipse" ? this.attr("cy") : this.attr("y");
        if (this.type != "text") this.animate({"fill-opacity":.2}, 500);

        // Original co-ords for pair element
        this.pair.ox = this.pair.type == "ellipse" ? this.pair.attr("cx") : this.pair.attr("x");
        this.pair.oy = this.pair.type == "ellipse" ? this.pair.attr("cy") : this.pair.attr("y");
        if (this.pair.type != "text") this.pair.animate({"fill-opacity":.2}, 500);
    };

    FlowView.prototype.move = function (dx, dy) {
        // Move main element
        var att = this.type == "ellipse" ? {cx:this.ox + dx, cy:this.oy + dy} :
        {x:this.ox + dx, y:this.oy + dy};
        this.attr(att);
        // Move paired element
        att = this.pair.type == "ellipse" ? {cx:this.pair.ox + dx, cy:this.pair.oy + dy} :
        {x:this.pair.ox + dx, y:this.pair.oy + dy};
        this.pair.attr(att);
        //document.write("adass");
        //document.write(x_offset);
        // Move connections
        for (var i = this.connections.length; i--;) {
             this.r.connection(this.connections[i]);
        }
        this.r.safari();
    };


    FlowView.prototype.up = function () {
        // Fade original element on mouse up
        if (this.type != "text") this.animate({"fill-opacity":0}, 500);

        // Fade paired element on mouse up
        if (this.pair.type != "text") this.pair.animate({"fill-opacity":0}, 500);
        // Move connections
    };


    FlowView.prototype.drag_initialize = function () {

        for (var i in this.shapes) {
            var color = Raphael.getColor();
            var tempS = this.shapes[i].attr({fill:color, stroke:color, "fill-opacity":0, "stroke-width":2, cursor:"move"});
            var tempT = this.texts[i].attr({fill:color, stroke:"none", "font-size":15, cursor:"move"});
            this.shapes[i].drag(this.move, this.dragger, this.up);
            this.texts[i].drag(this.move, this.dragger, this.up);

            // Associate the elements
            tempS.pair = tempT;
            tempT.pair = tempS;
        }
    };

Using above code i am able to draw graph & drag items,but when i drag items the connected path are not dragged along it.So where i am doing wrong. For making connection i used the same code given in raphael demos..

  • 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-06T04:16:56+00:00Added an answer on June 6, 2026 at 4:16 am

    Hi I found the answer to the problem.
    In the move function i return another function and while calling drag i give the object argument in move function hence the context of current object is passed. Now changed move function is:-

        FlowView.prototype.move = function (obj) {
    
            // Move main element
            return function(dx, dy){
                var att = this.type == "ellipse" ? {cx:this.ox + dx, cy:this.oy + dy} :
                {x:this.ox + dx, y:this.oy + dy};
                this.attr(att);
                // Move paired element
                att = this.pair.type == "ellipse" ? {cx:this.pair.ox + dx, cy:this.pair.oy + dy} :
                {x:this.pair.ox + dx, y:this.pair.oy + dy};
                this.pair.attr(att);
                // Move connections
                for (var i = obj.connections.length; i--;) {
                    obj.r.connection(obj.connections[i]);
                }
                obj.r.safari();
            }
        };
    

    And calling the drag with

        this.shapes[i].drag(this.move(this), this.dragger, this.up);
        this.texts[i].drag(this.move(this), this.dragger, this.up);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a Joomla module which loads some data from a slow source, so
I am creating a custom module in magento.I have created block class and phtml
I am creating a table using the python module reportlab. In this table, I
I'm creating additional module to already multi-module maven project. And for this one I
I'm creating a DotNetNuke module that needs to read entries from a SQL Server
I have a Drupal module creating a page via hook_menu(). I am trying to
In the meanwhile, I was creating module catalogs to load the modules using Unity.
So I've created my first Orchard module, which is essentially just a CRUD in
I was creating a http module and while debugging I noticed something which at
I am creating a module in python, in which I am receiving the date

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.