i'm working on creating a Node object that stores data of its parent as well as its children (which is a flexible amount, from 0 to X). using a recursive method data is categorized into the Nodes. for this initial test i'm working with the most basic concept, a family tree.
christian (great grandparent)
dori (grandparent) rosemary (grandparent)
greg (parent) beatrice (parent)
kimi (child)
marcus (child)
now i really don't want to make a family tree (actually trying to show the relationship/break down of a website). but for simplicity's sake i'm starting off with this example. once i figure out how to structure the data i want to give Nodes PVector behaviors -- these Nodes can be drawn into a typical tree diagram format OR change their display according to commonalities (such as representing a hereditary trait -- Nodes that have such trait move to the center of the screen, while relatives reshape around them).
i've made some serious progress with the insertNode() recursive method -- but am running into some problems.
1. insertNode() skips over "christian", "rosemary", "beatrice" from the 2nd line of input data (i believe this is because depth is set to 3 after running through kimi in the previous input line). so it goes straight to depth 3 in the second line (ie "marcus"). if i reset d to 0, insertNode() runs through everyone again and makes 2 christians, versus verifying he's already there and moving on.
2. there's is something really strange going on after "marcus" is put in (you can see from the printlns)
i think i'm getting closer, but this recursion is very tricky to wrap my head around.
if anyone has any suggestions i'd be very grateful.
thank you!
// each Node knows that its name and who its children are
// test data for Node class (real data will be parsed from .csv file) PVector randomVec = new PVector (random (400), random (400));
// initialize depth value int d = 0;
// this will later be pulled from the .csv file String[] testLine = { "christian", "dori", "greg", "kimi", }; String[] testLine1 = { "christian", "rosemary", "beatrice", "marcus" };
// run through the children array for (int j = 0; j < children.size(); j++) {
if (children.get(j).label == newNode.label)
{ if (d < testN.length-1) { d++; children.get(j).insertNode(testN); // inserts the children into a parent } } } }
// otherwise (if there is something in the children array) else {
for (int j = 0; j < children.size(); j++) {
// PROBLEM IS HERE println ("TEST CHILDREN ARRAY:::::: " + children.get(j).label); println ("NEW LABEL::::::: " + newNode.label); println ("NEW DEPTH::::::::::: " + d); // depth = 3 (has been pushed up from previous loop)
new to processing and would really appreciate any help
i'm stumped on the logic of a sketch i'm trying to do -- basically a simple data viz of a family tree. i'm creating a Node class that should recognize its parent and its children -- basically the point i'm confused about is how a Node recognizes who its parent is as well as its children.
one idea is using depth values to categorize the level of the Node in the family tree, another is to create nested HashMaps with each parent as a key to the children (i feel like this is a clunky way to go).
ultimately, i want each Node to be a discrete particle with PVector aspects so i can inform it where to go on the screen (but it always know its order in the family hierarchy).
if you have any suggestions re how a Node can distinguish itself from its children and parent i would be very appreciative.
thank you again for any time you can spare!
(also attached in the sketch is a sample .csv file i will use to parse the data from, which i have some code for the parseData() method but am manually implementing test data points in the sketch while i figure out this Node class problem)
// each category is a Node object
// 1. great grandparent
// 2. grandparent
// 3. parent
// 4. child
// each Node knows that its parent and its children