var table; var canvasWidth = 2800; var canvasHeight = 2800; let matrix_max = 0; let matrix_min = Number.MAX_SAFE_INTEGER; function preload() { table = loadTable('686.edges', 'tsv', 'header'); } function setup() { frameRate(10); createCanvas(canvasWidth, canvasHeight); for (let r = 0; r < table.getRowCount(); r++) { for (let c = 0; c < table.getColumnCount(); c++) { for (let i = 0; i < table.getString(r, c).split(" ").length; i++) { let num = parseInt(table.getString(r, c).split(" ")[i]); if ( num > matrix_max ) { matrix_max = num; } else if (num < matrix_min) { matrix_min = num; } } } } } function draw() { clear(); fill(0); textSize(16); background(237,244,237); var axis_intercept_x = 100; var axis_intercept_y = 120; var axis_y_end_height = canvasHeight/2; var axis_x_end_width = canvasWidth/2; let cell_w = map(matrix_min+1, matrix_min, matrix_max, axis_intercept_x, axis_x_end_width) - axis_intercept_x; let cell_h = map(matrix_min+1, matrix_min, matrix_max, axis_intercept_y, axis_y_end_height) - axis_intercept_y; axis_x_end_width += cell_w*(matrix_max-matrix_min); axis_y_end_height += cell_h*(matrix_max-matrix_min); line(axis_intercept_x, axis_intercept_y, axis_x_end_width, axis_intercept_y); line(axis_intercept_x, axis_intercept_y, axis_intercept_x, axis_y_end_height); for (let r = 0; r < table.getRowCount(); r++) { for (let c = 0; c < table.getColumnCount(); c++) { let x_val = parseInt(table.getString(r, c).split(" ")[0]); let y_val = parseInt(table.getString(r, c).split(" ")[1]); let pos_x = map(x_val, matrix_min, matrix_max, axis_intercept_x, axis_x_end_width); let pos_y = map(y_val, matrix_min, matrix_max, axis_intercept_y, axis_y_end_height); var d = dist(mouseX, mouseY, (pos_x + pos_x + 2*cell_w)/2, (pos_y + pos_y + 2*cell_h)/2); if (d < cell_w || d < cell_h) { noStroke(); textSize(14); fill(58,183,149); var msg = x_val + " " + y_val; text(msg, mouseX-20, mouseY-15); } stroke(255); fill(222,78,100); rect(pos_x, pos_y, 2*cell_w, 2*cell_h); } } textSize(9); let textPadding = 10; for (let i = matrix_min; i < matrix_max+2; i++) { let pos_x = map(i, matrix_min, matrix_max, axis_intercept_x, axis_x_end_width); let pos_y = map(i, matrix_min, matrix_max, axis_intercept_y, axis_y_end_height); line(pos_x, axis_intercept_y, pos_x, axis_y_end_height+2*cell_h); line(axis_intercept_x, pos_y, axis_x_end_width+2*cell_w, pos_y); if( i <= matrix_max ){ text(i, axis_intercept_x-textPadding-10, pos_y+textPadding); rotate(PI/2); text(i, axis_intercept_y-textPadding-10, -(pos_x+textPadding-5)); rotate(-(PI/2)); } } }