// http://www.census.gov/popest/data/datasets.html
// An INTERACTIVE bar chart visualizer
// As long as label-value pairs are provided it will draw a bar chart
// Uses array initialization, and is more general in terms of
// the size of the screen, number of bars, etc.
// Row 0: the labels to display under the bars
// Row 1:the frequencies as collected during the in class survey
String[][] population;
// Font stuff
PFont tnr;
void setup() {
size(800, 800);
smooth();
background(255);
fill(0);
// Read data from file
String[] lines = loadStrings("NST2012.csv");
//println(lines);
// Create data arrays
// labels = new String[lines.length];
// num = new int[lines.length];
population = new String[2][lines.length];
// Populate them (parse the data)
for (int i=0; i < lines.length; i++) {
// First split each line using commas as separator
String[] pieces = split(lines[i], ",");
// labels[i] = pieces[4];
// num[i] = int(pieces[5]);
population[0][i]=pieces[4];
population[1][i]=pieces[5];
}
// Fonts
tnr = createFont("Times New Roman", 48);
} // setup()
void draw() {
background(176, 226, 255);
// set up plot dimensions relative to screen size
float x = width * 0.05;
float y = height * 0.75;
float delta = width * 0.9 / population[0].length;
float w = delta * 0.8;
int high = 0;
for (int i=0; i is in the bounds of rect
return (mx >= x) && (mx <= x + w) && (my >= y) && (my <= y + h);
} // inBox()