//SPLOM //Be patient with me... I run very very slowly var data; var min_num; var min_pop; var min_year; var max_num = 0; var max_pop = 0; var max_year = 0 var array = []; function preload() { data = loadTable('health.csv', 'csv', 'header'); } function setup() { createCanvas(1000,1000); for(var r = 0; r < data.getRowCount(); r++) { var num = data.getNum(r,3); var pop = data.getNum(r,4); var year = data.getNum(r,5); append(array, [num,pop,year]); } min_num = min(data.getColumn(3)); min_pop = min(data.getColumn(4)); min_year = min(data.getColumn(5)); max_num = max(data.getColumn(3)); max_pop = max(data.getColumn(4)); max_year = max(data.getColumn(5)); } function draw() { clear(); textSize(20); fill(0); text("SPLOM: Number of Disease, Population, Year", 50, 50); textSize(10); //axes drawn (draw little lines on axes) line(200,200,200,800); line(200,200,800,200); line(200,800,800,800); line(800,200,800,800); line(200,400,800,400); line(200,600,800,600); line(400,200,400,800); line(600,200,600,800); text("Number", 650, 300); text("Population", 425, 500); text("Year", 250, 700); //label axes better than this fill(255,0,0); text(min_year, 180, 815); text(max_year, 380, 815); //text(min_year, 180, 800); don't need text(max_year, 180, 615); text(min_num, 605, 390); text(max_num, 805, 390); //text(min_num, 200, 805); don't need text(max_num, 605, 210); text(min_pop, 415, 595); text(max_pop, 540, 595); //text(min_pop, 200, 805); don't need text(max_pop, 410, 410); fill(0); //This bit is sooo slow... it's interactive if you can wait long enough (like 30 seconds per movement...)! for(var r = 0; r < array.length; r++) { num_y= map(array[r][0], min_num, max_num, 400, 200); num_x = map(array[r][0], min_num, max_num, 600, 800); pop_x = map(array[r][1], min_pop, max_pop, 400, 600) pop_y = map(array[r][1], min_pop, max_pop, 600, 400); year_y = map(array[r][2], min_year, max_year, 800, 600); year_x = map(array[r][2], min_year, max_year, 200, 400); fill(0); ellipse(num_x, num_y, 3,3); ellipse(pop_x, num_y, 3,3); ellipse(year_x, num_y, 3,3); ellipse(num_x, pop_y, 3,3); ellipse(num_x, year_y, 3,3); ellipse(pop_x, pop_y, 3,3); ellipse(pop_x, year_y, 3,3); ellipse(year_x, pop_y, 3,3); ellipse(year_x, year_y, 3,3); fill(0,0,255); if(dist(num_x, num_y, mouseX, mouseY) < 5) { text("Number " + array[r][0] + " Number: " + array[r][0], num_x + 5, num_y +5); } if(dist(pop_x, num_y, mouseX, mouseY) < 5) { text("Population " + array[r][1] + " Number: " + array[r][0], pop_x + 5, num_y +5); } if(dist(year_x, num_y, mouseX, mouseY) < 5) { text("Year " + array[r][2] + " Number: " + array[r][0], year_x + 5, num_y +5); } if(dist(num_x, pop_y, mouseX, mouseY) < 5) { text("Number " + array[r][0] + " Population: " + array[r][1], num_x + 5, pop_y +5); } if(dist(num_x, year_y, mouseX, mouseY) < 5) { text("Number " + array[r][0] + " Year: " + array[r][2], num_x + 5, year_y +5); } if(dist(pop_x, pop_y, mouseX, mouseY) < 5) { text("Population " + array[r][1] + " Population: " + array[r][1], pop_x + 5, pop_y +5); } if(dist(pop_x, year_y, mouseX, mouseY) < 5) { text("Population " + array[r][1] + " Year: " + array[r][2], pop_x + 5, year_y +5); } if(dist(year_x, pop_y, mouseX, mouseY) < 5) { text("Year " + array[r][2] + " Population: " + array[r][1], year_x + 5, pop_y +5); } if(dist(year_x, year_y, mouseX, mouseY) < 5) { text("Year " + array[r][2] + " Year: " + array[r][2], year_x + 5, year_y +5); } } }