pls. give link to video , code source…
some things could be more easy with
Table table;
void setup() {
table = loadTable("data.txt", "csv");
for a unknown content better start with
Table table;
int i, k, trows, tcols;
void setup() {
table = loadTable("test.csv", "tsv"); // "test.tsv" // "test.csv" , "tsv" // "test.dat" , "header , csv"
trows=table.getRowCount();
tcols=table.getColumnCount();
println(trows + " rows/lines in table "); //(? - header ?)
println(tcols + " cols in table");
println("header: ");
for ( i =0; i < tcols; i++) {
println("col: "+i+" "+ table.getColumnTitle(i));
}
for ( k =0; k < trows; k++) {
for ( i =0; i < tcols; i++) {
println("row: "+k+" col: "+i+" string: "+table.getString(k, i));
}
}
}
with this table ( string ) and usage of
table.getFloat(k, i)
there is no need for more string or float arrays.
// ____________
for your Boards class
float _score1
should be the row array of data, not one single value.
and actually a tablerow works fine ( instead of a String array of one line )
my version:
Table table;
int i, k, trows, tcols;
float rwidth=0; //(width-40)/tcols;
float rhighrange = 0;
int max;
boolean dprint = true; // print first calc only
My_graph[] charts;
void setup() {
size(500, 500);
background(100, 100, 0);
check_table();
get_ranges();
charts = new My_graph[trows];
for ( k =0; k < trows; k++) {
charts[k] = new My_graph(table.getRow(k), 10, 20+k*(130+5), width-20 , 130, 0, max); //
charts[k].draw();
}
}
// tools: get the data and check for columns, rows, and data range
void check_table() {
table = loadTable("data.txt", "csv"); // "test.tsv" // "test.txt" , "tsv" // "test.dat" , "header , csv"
trows=table.getRowCount();
tcols=table.getColumnCount();
if (dprint) println(trows + " rows/lines in table "); //(? - header ?)
if (dprint) println(tcols + " cols in table");
if (dprint) println("header: ");
for ( i =0; i < tcols; i++) {
if (dprint) println("col: "+i+" "+ table.getColumnTitle(i));
}
for ( k =0; k < trows; k++) {
for ( i =0; i < tcols; i++) {
if (dprint) println("row: "+k+" col: "+i+" string: "+table.getString(k, i));
}
if (dprint) println(" ");
}
}
void get_ranges() {
rwidth=(width-40)/(tcols);
for ( k =0; k < trows; k++) {
for ( i =1; i < tcols; i++) {
float getfnum = table.getFloat(k, i);
if ( getfnum > rhighrange ) rhighrange = getfnum;
}
}
max = ceil(rhighrange/100.0); // need a loop for 10 100 1000
max = max*100;
if (dprint) println("highest value: "+rhighrange+" max "+max+" rwidth "+rwidth);
}
class My_graph {
TableRow data;
int posX, posY, wX, hY;
float nullr, highr;
PFont f;
float local_rwidth;
// expect data = {"name","1","2","3","4","5.66","6"...}
My_graph(TableRow _data, int _posX, int _posY, int _wX, int _hY, float _nullr, float _highr) {
data = _data;
posX = _posX;
posY = _posY;
wX = _wX;
hY = _hY;
nullr = _nullr;
highr = _highr;
f = createFont ("Arial", 32, false);
local_rwidth = (wX-20)/tcols;
}
void draw() {
// background and header
pushMatrix();
translate (posX, posY);
fill(200, 200, 0);
rect(1, 1, wX-1, hY-1);
// print NAME
fill(255);
textFont(f, 20);
textAlign(CENTER);
text(data.getString(0), wX/2, 20);
textFont(f, 10);
// print range
text(nf(nullr, 1, 1), 30, 25 + 100 );
text(nf(highr, 1, 1), 30, 25);
// make graph bars
color cbar = color(random(50,255),random(50,255),random(50,255));
for ( i =1; i < tcols; i++) {
float getfnum = data.getFloat(i);
float bar = map(getfnum/(-nullr+highr), 0, 1.0, 0, hY-25);
fill(cbar);
rect(i*(local_rwidth+2), 25, local_rwidth-1, 100);
fill(0);
rect(i*(local_rwidth+2), 25, local_rwidth-1, 100-bar);
// print vals
fill(255);
text(nf(getfnum, 1, 1), i*(local_rwidth+2)+20, 35);
}
popMatrix();
}
}
//______________ UNUSED _____________ OLD ( not Class ) WAY
//void draw() {
//background(100, 100, 0);
//graph_rows();
//}
void graph_rows() {
for ( k =0; k < trows; k++) {
graph_row(k);
}
}
void graph_row(int k) {
text("0", 30, 40 + 100 );
text(max, 30, 40);
text(table.getString(k, 0), width/2, 30 + k*130);
for ( i =1; i < tcols; i++) {
float getfnum = table.getFloat(k, i);
float bar = map(getfnum/max, 0.0, 1.0, 0, 100);
fill(0, 200, 0);
rect(i*(rwidth+2), 40+ k*130, rwidth-1, 100);
fill(0);
rect(i*(rwidth+2), 40+ k*130, rwidth-1, 100-bar);
fill(255);
text(nf(getfnum, 1, 1), i*(rwidth+2)+10, 50+ k*130);
if (dprint) println("k "+k+" i "+i+" val "+getfnum+" bar "+nf(bar, 1, 1));
}
dprint = false;
}
so actually what is the difference between the class and the old function
( i leave the OLD CODE at the end )
in that case?
the class contains a row data copy,
and is just used once for printing.
so the class array holds a copy of all data
and is actually UNUSED, and from this view unnecessary.
but was a good exercise for me.