We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all, I want to have 2 checkbox filters in my processing datavisualization. The checkboxes must filter the numbers (nr) from 1-7 (1checkbox) and numbers 8-13 (1 checkbox). The problem is: I have no clue how to do this. Is there anyone who can help me with this?
Table table;
String[] land={};
float[] bbp = {};
int[] nr = {};
float r = random(250);
void setup (){
table = loadTable("data.csv", "header");
for (TableRow row : table.rows()) {
land = append(land, row.getString("land"));
bbp = append(bbp, row.getFloat("bbp"));
nr = append(nr, row.getInt("nr"));
println(land.length);
}
size(2000,600);
background(240);
smooth();
stroke(50,50,50,50);
strokeWeight(2);
}
void draw (){
background(240);
line(0, height/2, width, height/2);
for(int i=0; i< nr.length;i++){
float c = nr[i]*12;
fill(250, c,c,200);
ellipse(nr[i]*110 -20 , height/2, bbp[i]*3, bbp[i]*3);
fill(30);
pushMatrix();
translate(nr[i]*110 -20, height/2 - bbp[i]/2);
rotate(radians(-45));
text(land[i],-50 ,50);
text(bbp[i],10,10);
textSize(18);
popMatrix();
text("BBP per land plaats 1t/m13",10 ,height/3);
text("Bron: https://nl.wikipedia.org/wiki/Lijst_van_landen_naar_bbp_per_hoofd_van_de_bevolking", height/2, width/4);
smooth();
}
}
Data (csv): land,bbp,nr
Luxemburg,104.5,13 Noorwegen,79.1,12 Qatar,68.9,11 Zwitserland,67.6,10 Denemarken,56.1,9 Ierland,51.4,8 Nederland,48.2,7 Verenigde Arabische Emiraten,46.9,6 Verenigde Staten, 46.4,5 Oostenrijk,46.0,4 Australie,45.6,3 Finland,44.5,2 Zweden,44.0,1
Answers
OK, first some general advice: You don't need
smooth()
, because it is default. And if you use it, it doesn't make sense to call it multiple times. Same withtextSize()
, if it doesn't change, just put it into setup().Then to adress your problem, if i understand it correctly:
You would need two variables (boolean) that store if the first or second part of your data shall be displayed.
You would have to draw two buttons.
If the mouse gets pressed you have to check if the position is over one of the buttons. If yes, you can toggle one of the variables between true and false.
Last step would then be to draw your circles depending on the state of the variables and their nr-value.
Spoiler-alert: Here is a working example, so if you want to figure it out for yourself, you can maybe only read the post above.
I added some functions to make it more structured.
Thank you so much! I'll try to figure it out myself with this.