Help with block diagram in a 2D graph
in
Programming Questions
•
4 months ago
Hello! I need help to represent a block diagram in a 2D representation.
The question is this, I have a database with 10 patients and 16 variables, use the last two variables to represent the graph in 2D, and I want to pass the mouse over each ball out me a bar chart with values of this row to the corresponding values except the last two are the ones I use for 2D representation.
I got the 2D representation, and tell me the results with the command string, but instead want a block diagram ...
The code that I have is this:
color[] minard = {#666666, #607F9C, #E9CCAE, #FFFFF3, #D01312};
color[] palette = minard;
PFont labelFont;
Table datos;
int rowCount;
int var;
int [][] variables;
int d = 10;
float xmin, xmax, ymin, ymax;
void setup() {
size(1000, 600);
datos = new Table("datos.tsv");
rowCount = datos.getRowCount();
println("Numero de casos = " + rowCount);
var = datos.getColumnCount();
println("Numero de variables = " + var);
labelFont = loadFont("GillSans-Bold-18.vlw");
smooth();
}
void draw() {
background(palette[0]);
textFont(labelFont);
stroke(180);
fill(180);
// Calculo del máximo y mínimo del PCA para los ejes x e y
float xmin =datos.getFloat(0,var-2);
float xmax =datos.getFloat(0,var-2);
for(int f = 0;f < rowCount; f++) {
float mat =datos.getFloat(f,var-2);
if (mat < xmin) {
xmin=mat;
}
if (mat > xmax){
xmax=mat;
}
}
float ymin =datos.getFloat(0,var-1);
float ymax =datos.getFloat(0,var-1);
for(int j = 0;j < rowCount; j++) {
float mat =datos.getFloat(j,var-1);
if (mat < ymin) {
ymin=mat;
}
if (mat > ymax){
ymax=mat;
}
}
// Line title PCA
textAlign(CENTER);
text("PCA",425,30);
// Line and labels for X axis
textAlign(CENTER);
line(200, 400, 650, 400);
text (xmin, 200, 420);
text (xmax, 650,420);
text("1ra Componente", 420, 445);
text("x min",200,450);
text("x max",650,450);
// Line and labels for Y axis
textAlign(RIGHT);
line(200, 50, 200, 400);
text (ymax, 195, 50);
text (ymin, 195,400);
text("2da Componente", 180, 250);
text("y max",100,50);
text("y min",100,400);
// Gets data, draws dots
for (int row = 0; row < rowCount; row++) {
// Para visualizar las variables
String dato = datos.getString(row, 0);
// score1
float score1 = datos.getFloat(row, var-2);
float x = map(score1, xmin+(xmin/10), xmax+(xmax/10), 200, 650);
// score2
float score2 = datos.getFloat(row, var-1);
float y = map(score2, ymin+(ymin/10), ymax+(ymax/10), 400, 50);
noStroke();
fill(#FFBA00, 180);
ellipse(x, y, d, d);
textAlign(LEFT);
fill(180);
if(dist(x, y, mouseX, mouseY) < (d/2+1)) {
text(dato, x, y - 10);
}
}
}
The table is:
class Table {
String[][] data = null;
int columns = 0; // number of columns
Table(String filename) {
ArrayList<String[]> rows = new ArrayList<String[]>();
String[] fileContents = loadStrings(filename);
// read each line into list
for (int i = 0; i < fileContents.length; i++) {
String row = fileContents[i];
if (trim(row).length() == 0) {
continue; // skip empty rows
}
if (row.startsWith("#")) {
continue; // skip comment lines
}
// split the row on the tabs
String[] pieces = split(row, TAB);
// add to the table array
rows.add(pieces);
if (pieces.length != 0) {
columns = pieces.length;
}
}
// convert list to String[][]
data = new String[rows.size()][columns];
for (int i = 0; i < rows.size(); i++) {
data[i] = rows.get(i);
}
}// fin del table
int getRowCount() {
return data.length;
}
int getColumnCount(){
return columns;
}
// rest of class is the same
// find a row by its name, returns -1 if no row found
int getRowIndex(String name) {
for (int i = 0; i < rowCount; i++) {
if (data[i][0].equals(name)) {
return i;
}
}
println("No row named '" + name + "' was found");
return -1;
}
String getRowName(int row) {
return getString(row, 0);
}
String getString(int rowIndex, int column) {
return data[rowIndex][column];
}
String getString(String rowName, int column) {
return getString(getRowIndex(rowName), column);
}
int getInt(String rowName, int column) {
return parseInt(getString(rowName, column));
}
int getInt(int rowIndex, int column) {
return parseInt(getString(rowIndex, column));
}
float getFloat(String rowName, int column) {
return parseFloat(getString(rowName, column));
}
float getFloat(int rowIndex, int column) {
return parseFloat(getString(rowIndex, column));
}
void setRowName(int row, String what) {
data[row][0] = what;
}
void setString(int rowIndex, int column, String what) {
data[rowIndex][column] = what;
}
void setString(String rowName, int column, String what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = what;
}
void setInt(int rowIndex, int column, int what) {
data[rowIndex][column] = str(what);
}
void setInt(String rowName, int column, int what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
void setFloat(int rowIndex, int column, float what) {
data[rowIndex][column] = str(what);
}
void setFloat(String rowName, int column, float what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
}
I put some pictures to make it look:
1