osx - Parallel Coordinates program written with Processing can't show anything in Mac -
so write parallel coordinates program processing in mac pro. however, can't see lines on screen when try run program. confused because program runs pretty in friend's windows based computer. tried add "noloop()" in end of "draw()" function , works. still can't figure out reasons. knows specific reason? in advance!
floattable data; string datapath = "cars.csv"; int numrows; int numcols; int[] colmin; int[] colmax; string[] colnames; float plotx1, ploty1; float plotx2, ploty2; float diffbetweenxcoords; pfont titlefont; pfont labelfont; pfont axislimitsfont; color[] axiscolor = { #333333, #000000 }; color[] fontaxiscolor = { #333333, #ff2222 }; color[] fontlimitscolor = { #555555, #ff2222 }; color trianglecolor = #888888; color[] linescolor = { #ed1317, #1397ed }; int[] axisorder; boolean[] axisflipped; // setup void setup() { size(1000, 500); // read data data = new floattable(datapath); numrows = data.getrowcount(); numcols = data.getcolumncount(); colnames = data.getcolumnnames(); colmin = new int[ numcols ]; colmax = new int[ numcols ]; axisorder = new int[ numcols ]; axisflipped = new boolean[ numcols ]; for(int col = 0; col < numcols; col++) { float maxnumber = data.getcolumnmax(col); float minnumber = data.getcolumnmin(col); colmin[col] = int(floor(minnumber)); colmax[col] = int(ceil(maxnumber)); axisorder[col] = col; axisflipped[col] = false; } // fonts titlefont = createfont("verdana", 16); labelfont = createfont("verdana bold", 11); axislimitsfont = createfont("georgia", 11); // plot area limits plotx1 = 30; plotx2 = width - plotx1; ploty1 = 60; ploty2 = height - ploty1; diffbetweenxcoords = (plotx2 - plotx1) / (numcols - 1); if(frame != null) { frame.settitle(datapath); } smooth(); } // draw void draw() { // background background(240); // draw plot area fill(240); nostroke(); rect(plotx1, ploty1, plotx2 - plotx1, ploty2 - ploty1); //drawtitle(); drawaxis(); drawlines(); } void drawaxis() { float xcoordsforaxis = plotx1; float yaxislbl = ploty2 + 40; float yminlbl = ploty2 + 15; float ymaxlbl = ploty1 - 7; float ytrimin = ploty1 - 25; float ytrimax = ploty1 - 35; strokecap(project); strokeweight(1); stroke(0); for( int col = 0; col < numcols; col++, xcoordsforaxis += diffbetweenxcoords ) { int coltodraw = axisorder[col]; // draw axis stroke(axiscolor[0]); line(xcoordsforaxis, ploty1, xcoordsforaxis, ploty2); // label min/max textalign(center); textfont(axislimitsfont); fill(fontlimitscolor[0]); if( axisflipped[coltodraw]) { text( colmin[coltodraw], xcoordsforaxis, ymaxlbl); text( colmax[coltodraw], xcoordsforaxis, yminlbl); } else { text( colmin[coltodraw], xcoordsforaxis, yminlbl); text( colmax[coltodraw], xcoordsforaxis, ymaxlbl); } // axis label textfont( labelfont ); fill(fontaxiscolor[0]); text( colnames[coltodraw], xcoordsforaxis, yaxislbl ); // triangle fill(trianglecolor); nostroke(); if( axisflipped[coltodraw] ) { triangle(xcoordsforaxis - 3, ytrimax, xcoordsforaxis, ytrimin, xcoordsforaxis + 3, ytrimax); } else { triangle(xcoordsforaxis - 3, ytrimin, xcoordsforaxis, ytrimax, xcoordsforaxis + 3, ytrimin); } } } void drawlines() { nofill(); strokeweight(1); for(int row = 0; row < numrows; row++) { beginshape(); for(int column = 0; column < numcols; column++) { int coltodraw = axisorder[column]; if(data.isvalid(row, column)) { float cmax = ( axisflipped[coltodraw] ? colmin[coltodraw] : colmax[coltodraw] ); float cmin = ( axisflipped[coltodraw] ? colmax[coltodraw] : colmin[coltodraw] ); float value = data.getfloat(row, coltodraw); float x = plotx1 + diffbetweenxcoords * coltodraw; float y = map(value, cmin, cmax, ploty2, ploty1); //stroke(#5679c1); if(coltodraw == 0) { stroke( lerpcolor(linescolor[0], linescolor[1], map(value, cmin, cmax, 0., 1.) ), 150 ); } vertex(x, y); } } endshape(); } } class floattable { int rowcount; int columncount; float[][] data; string[] rownames; string[] columnnames; floattable(string filename) { string[] rows = loadstrings(filename); string[] columns = split(rows[0], tab); columnnames = subset(columns, 1); // upper-left corner ignored scrubquotes(columnnames); columncount = columnnames.length; rownames = new string[rows.length-1]; data = new float[rows.length-1][]; // start reading @ row 1, because first row column headers (int = 1; < rows.length; i++) { if (trim(rows[i]).length() == 0) { continue; // skip empty rows } if (rows[i].startswith("#")) { continue; // skip comment lines } // split row on tabs string[] pieces = split(rows[i], tab); scrubquotes(pieces); // copy row title rownames[rowcount] = pieces[0]; // copy data table starting @ pieces[1] data[rowcount] = parsefloat(subset(pieces, 1)); // increment number of valid rows found far rowcount++; } // resize 'data' array necessary data = (float[][]) subset(data, 0, rowcount); } void scrubquotes(string[] array) { (int = 0; < array.length; i++) { if (array[i].length() > 2) { // remove quotes @ start , end, if present if (array[i].startswith("\"") && array[i].endswith("\"")) { array[i] = array[i].substring(1, array[i].length() - 1); } } // make double quotes single quotes array[i] = array[i].replaceall("\"\"", "\""); } } int getrowcount() { return rowcount; } string getrowname(int rowindex) { return rownames[rowindex]; } string[] getrownames() { return rownames; } // find row name, returns -1 if no row found. // return index of first row name. // more efficient version of function put row names // hashtable (or hashmap) map integer row. int getrowindex(string name) { (int = 0; < rowcount; i++) { if (rownames[i].equals(name)) { return i; } } //println("no row named '" + name + "' found"); return -1; } // technically, returns number of columns // in first row (which accurate) int getcolumncount() { return columncount; } string getcolumnname(int colindex) { return columnnames[colindex]; } string[] getcolumnnames() { return columnnames; } float getfloat(int rowindex, int col) { // remove 'training wheels' section greater efficiency // it's included here provide more useful error messages // begin training wheels if ((rowindex < 0) || (rowindex >= data.length)) { throw new runtimeexception("there no row " + rowindex); } if ((col < 0) || (col >= data[rowindex].length)) { throw new runtimeexception("row " + rowindex + " not have column " + col); } // end training wheels return data[rowindex][col]; } boolean isvalid(int row, int col) { if (row < 0) return false; if (row >= rowcount) return false; //if (col >= columncount) return false; if (col >= data[row].length) return false; if (col < 0) return false; return !float.isnan(data[row][col]); } float[] getcolumnminmax(int col) { float min = float.max_value; float max = -float.max_value; (int = 0; < rowcount; i++) { if (!float.isnan(data[i][col])) { if (data[i][col] < min) { min = data[i][col]; } if (data[i][col] > max) { max = data[i][col]; } } } float[] toret = { min, max }; return toret; } float getcolumnmin(int col) { float m = float.max_value; (int = 0; < rowcount; i++) { if (!float.isnan(data[i][col])) { if (data[i][col] < m) { m = data[i][col]; } } } return m; } float getcolumnmax(int col) { float m = -float.max_value; (int = 0; < rowcount; i++) { if (isvalid(i, col)) { if (data[i][col] > m) { m = data[i][col]; } } } return m; } float getrowmin(int row) { float m = float.max_value; (int = 0; < columncount; i++) { if (isvalid(row, i)) { if (data[row][i] < m) { m = data[row][i]; } } } return m; } float getrowmax(int row) { float m = -float.max_value; (int = 1; < columncount; i++) { if (!float.isnan(data[row][i])) { if (data[row][i] > m) { m = data[row][i]; } } } return m; } float gettablemin() { float m = float.max_value; (int = 0; < rowcount; i++) { (int j = 0; j < columncount; j++) { if (isvalid(i, j)) { if (data[i][j] < m) { m = data[i][j]; } } } } return m; } float gettablemax() { float m = -float.max_value; (int = 0; < rowcount; i++) { (int j = 0; j < columncount; j++) { if (isvalid(i, j)) { if (data[i][j] > m) { m = data[i][j]; } } } } return m; } }
when tried draw points rather lines, works! things become quite weird:)
here lines in .csv file:
make mpg cylinders displacement (cu in) horsepower weight (lb) acceleration (sec) year origin
chevrolet 18 8 307 130 3504 12 70 1
buick 15 8 350 165 3693 11.5 70 1
plymouth 18 8 318 150 3436 11 70 1
amc 16 8 304 150 3433 12 70 1
ford 17 8 302 140 3449 10.5 70 1
ford 15 8 429 198 4341 10 70 1
chevrolet 14 8 454 220 4354 9 70 1
plymouth 14 8 440 215 4312 8.5 70 1
pontiac 14 8 455 225 4425 10 70 1
amc 15 8 390 190 3850 8.5 70 1
dodge 15 8 383 170 3563 10 70 1
plymouth 14 8 340 160 3609 8 70 1
chevrolet 15 8 400 150 3761 9.5 70 1
buick 14 8 455 225 3086 10 70 1
toyota 24 4 113 95 2372 15 70 3
plymouth 22 6 198 95 2833 15.5 70 1
amc 18 6 199 97 2774 15.5 70 1
ford 21 6 200 85 2587 16 70 1
datsun 27 4 97 88 2130 14.5 70 3
volkswagen 26 4 97 46 1835 20.5 70 2
peugeot 25 4 110 87 2672 17.5 70 2
audi 24 4 107 90 2430 14.5 70 2
saab 25 4 104 95 2375 17.5 70 2
bmw 26 4 121 113 2234 12.5 70 2
Comments
Post a Comment