sabartley
YaBB Newbies
Offline
Posts: 4
Project
Feb 15th , 2010, 7:50pm
Hello, I am trying to figure out what could be the problem with my code. I am sort of following Ben Fry's example of locations on a map but with countries instead of his example of U.S. states. I have two classes: Data_Visualization and Loader. I have also added all the files I need for this to run. I know I have a ton of errors but I was hoping maybe I could get some help with this. Thanks.Data_Visualization class: PImage mapImage; int rowCount; Loader dataTable, locationTable; float dataMin = MAX_FLOAT; float dataMax = MIN_FLOAT; void setup() { size(720, 360); mapImage = loadImage("world_outline_map_720.jpg"); locationTable = new Loader("locations.csv"); rowCount = locationTable.getRowCount(); //Read the data table dataTable = new Loader("values.csv"); //Finding the min and max values for(int row = 0; row < rowCount; row++){ float value = dataTable.getFloat(row, 1); if(value > dataMax){ dataMax = value; } if(value < dataMin){ dataMin = value; } } } void draw(){ background(255); image(mapImage,0,0); //Drawing attributes for the ellipses smooth(); fill(192,0,0); //red noStroke(); //Draw a data point for each location for(int row = 0; row < rowCount; row++){ String abbrev = dataTable.getRowName(row); float x = locationTable.getFloat(abbrev, 1); float y = locationTable.getFloat(abbrev, 2); drawData(x, y, abbrev); } //Map the size of ellipse to the data value void drawData(float x, float y, String abbrev){ float value = dataTable.getFloat(abbrev, 1); float mapped = map(value, dataMin, dataMax, 2, 40); ellipse(x, y, mapped, mapped); //draw the ellipse } //Loop through the rows of the location file and draw the points. for(int row = 0; row < rowCount; row++){ float x = locationTable.getFloat(row, 1); float y = locationTable.getFloat(row, 2); ellipse(x,y,9,9); } }Loader class: class Loader { String[] lines; int rowIndex; Loader(String filename){ lines = loadStrings("locations.csv"); // lines = loadStrings("values.csv"); println("there are " + lines.length + " lines"); } int getRowCount(){ return lines.length; } float getFloat(int rowIndex, int column){ String x = lines[rowIndex]; String[] y = split(x,','); return(Float.parseFloat(y[column])); } public float getFloat(int rowName, int column){ String a = lines[rowName]; String[] b = split(a,','); return(Float.parseFloat(b[column])); //return parseFloat(rowName, column); } String getRowName(int row){ return; } } I got my project to run with the ellipses matching my locations file to the countries, but now I can't get the project to run when I try to set Min and Max values for the ellipses. For example I have China as one of my countries so the map should show that ellipse as the largest. (In my values.csv file, China has the largest value).