I have data from two csv files that I import as Tables. The first file contains country names and their population. The second file contains migration flows between countries over 4 time periods. The files would look like this in table form:
File 1:
+----------+------------+
| country | population |
+----------+------------+
| countryA | 100000 |
+----------+------------+
| countryB | 200000 |
+----------+------------+
| countryC | 300000 |
+----------+------------+
...
File 2:
+----------------+--------------+---------+---------+---------+---------+
| country_origin | country_dest | mig1990 | mig1995 | mig2000 | mig2005 |
+----------------+--------------+---------+---------+---------+---------+
| countryA | countryB | 100 | 100 | 100 | 100 |
+----------------+--------------+---------+---------+---------+---------+
| countryA | countryC | 200 | 200 | 200 | 200 |
+----------------+--------------+---------+---------+---------+---------+
| countryB | countryA | 300 | 300 | 300 | 300 |
+----------------+--------------+---------+---------+---------+---------+
| countryB | countryC | 400 | 400 | 400 | 400 |
+----------------+--------------+---------+---------+---------+---------+
...
I would like to visualize the countries as spheres (with size corresponding to population size) and connect them with lines (with line thickness corresponding to migration flow size). The spheres are located randomly in space. The spheres are colored with sequential colors using lerpColor() and initial values start = color(204, 102, 0);
and end = color(0, 102, 153);
The lines have a color gradient between the starting sphere and the end sphere.
I’ve created a class “Country”, which takes the following parameters:
// Instance Variables
int population;
PVector coordinates;
float posx, posy, posz;
color sphereColor;
int[] flowNumArray;
String origin;
String destination;
int mig1990, mig1995, mig2000, mig2005;
// Constructor Declaration of Class <-- this is a function, only call when we want a new item
// To create a new instance
Country(int population, float posx, float posy, float posz, color sphereColor, String origin, String destination, int mig1990, int mig1995, int mig2000, int mig2005) {
this.population = population;
this.coordinates = new PVector(posx, posy, posz);
this.sphereColor = sphereColor;
this.origin = origin;
this.destination = destination;
this.flowNumArray = new int[] {
mig1990, mig1995, mig2000, mig2005
};
}
}
Now I’m struggling to add the values from both tables into my class so that each instance contains all the values that are associated with a country. The challenge is that the population table is much shorter than the migration table, so I can’t just loop over the values. When I call this in my for-loop for the population table:
countries.add(new Country(countryName, posx, posy, posz, sphereColor));
I get the error The constructor "Country(String, float, float, float, int)" does not exist
(I understand why but how do I fix it?)
I suppose I need a (or two?) for loop that takes all the values from either table and adds them to a Country instance. Or I create the instance in one for-loop and then append it in a second for-loop based on the condition that the country==country_origin
? I would appreciate if you could show me some skeleton code on how to do this. Thanks!