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

tmp added to object[] for every attribute tmp has #13

Open
kelseyleftwich opened this issue Jun 3, 2013 · 1 comment
Open

tmp added to object[] for every attribute tmp has #13

kelseyleftwich opened this issue Jun 3, 2013 · 1 comment
Assignees
Labels

Comments

@kelseyleftwich
Copy link
Contributor

I think there is a bug in bargraph.js in the for-loop on lines 64 thru 90.

The outer for-loop iterates through the items in data.
The inner for-loop iterates through the keys in each item.

In the inner for-loop, you check to see if the key matches a string. If it matches, you change an attribute in tmp and then push it to object[]. The problem is, there are multiple keys in each data item, so tmp gets pushed to object[] multiple times.

@kelseyleftwich
Copy link
Contributor Author

You want to move object.push(tmp) outside and after the inner for-loop but inside the outer for-loop.

            //Convert the data from the controller
            //Should be mobed to controller
            for (var i = 0; i < data.length; i++){ //for every element in data array
                var tmp = {};
                for(var key in data[i]){ //for every attribute of the element
                    compItem = key;;
                    //see if it matches one of the following terms and add value and key to tmp
                    if (compItem == "dns_name"){
                        tmp.dns_name = data[i][key];
                        object.push(tmp); //<=== REMOVE!!!
                    }
                    else if(compItem == "datacenter_id" || compItem == "host_id"){
                        tmp.group = data[i][key];
                        object.push(tmp); //<=== REMOVE!!!
                    }
                    else if(compItem == "gathered"){
                        tmp.gathered = data[i][key];
                        object.push(tmp); //<=== REMOVE!!!
                    }
                    else if(compItem == "destination_ip" || compItem == "source_ip" ){
                        tmp.dns_name = (data[i].destination_ip
                                        + " - " + data[i].source_ip);
                        object.push(tmp); //<=== REMOVE!!!
                    }
                    else if(data[i].hasOwnProperty(key)){
                        tmp.data = data[i][key];
                        object.push(tmp); //<=== REMOVE!!!
                    }
                }
                //*********** ADD IT HERE ****************
            }
            //Set up graph
            console.log(object);
            makeGraph(object, compItem);
        }, "json");

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

No branches or pull requests

2 participants