//MATRIX REPRESENTATION var edges; var name; var numVertices = 0; var step = 0; var minV = 0; var maxV = 0; var dict = {}; function preload() { //get the data edges = loadTable('3980.csv', 'csv'); name = "3980.edges"; } function setup() { //create a canvas //make a dictionary -- vertices are key, vertex they have an edge with are values //keep track of numVertices for(var r = 0; r < edges.getRowCount(); r++) { var v1 = edges.getNum(r,0); var v2 = edges.getNum(r,1); if(v1 in dict) { append(dict[v1], v2); } else { dict[v1] = [v1,v2]; } //add edge both ways because it's undirected if(v2 in dict) { append(dict[v2], v1); } else { dict[v2] = [v2,v1]; } } //Count number of vertices for(key in dict) { numVertices++; } //print(numVertices); createCanvas(1000, 1000); } function draw() { clear(); rect(100,100,800,800); //calculate step between vertices on matrix step = 800/numVertices var counter = 0; //make title textSize(20); fill(0) text("Matrix Representation of " + name, 20,20); //loop through vertices in dictionary for(v1 in dict) { edge_arr = dict[v1]; //loop through vertices it has edges to for(a = 0; a <= edge_arr.length; a++) { var counter2 = 0; var v = edge_arr[a]; //loop through vertices in dictinary again for(v2 in dict){ //if they match, fill in the rectange if(v == v2) { fill(0); rect(100+step*counter, 100+step*counter2,step,step); } //interaction piece if(mouseX > 100+step*counter && mouseY > 100+step*counter2 && mouseX < 100+step*counter +step && mouseY < 100+step*counter2+step){ noStroke(); // Don't draw a stroke around rectangles fill(0, 153, 204, 20); //make it pretty transparent rect(100, 100+step*counter2, 800,step); rect(100+step*counter, 100, step, 800); fill(50); textSize(15); //display vertices at the top text("Vertex 1: " + v1 + " Vertex 2: " + v2, 400, 50); } fill(255); //increment counter tracking movement on y-axis counter2++; } } //increment counter tracking movement on x-axis counter++; } }