float[][] data = { {1,2},{3,4}, {5,6}, {3.3333,3}, {10,4}, {12,10} }; float[] bubbleData = { 26, 39, 77, 14, 2, 1 }; float basicArea = 10; float minX, maxX, minY, maxY; float screenMinX, screenMaxX, screenMinY, screenMaxY; float padding = 50.0; void setup(){ size(600,600); // calculate limits minX = 0; minY = 0; maxX = 0; maxY = 0; for(int i = 0; i < data.length; i++){ if(data[i][0] > maxX) maxX = data[i][0]; if(data[i][1] > maxY) maxY = data[i][1]; } screenMinX = padding; screenMaxX = width - padding; screenMinY = height - padding; screenMaxY = padding; } float[] myScale(float x, float y){ float[] result = { ((x - minX) / (maxX-minX)) * (screenMaxX-screenMinX) + screenMinX, ((y - minY) / (maxY-minY)) * (screenMaxY-screenMinY) + screenMinY }; return result; } void draw(){ background(64); stroke(255); fill(255); int tooltip = -1; for(int i = 0; i < data.length; i++){ float[] coords = myScale(data[i][0], data[i][1]); float area = basicArea * bubbleData[i]; float r = sqrt(area/PI); ellipse(coords[0], coords[1], r, r); if(dist(coords[0], coords[1], mouseX, mouseY) < r){ tooltip = i; } } // tooltip? if(tooltip != -1){ fill(255); rect(mouseX, mouseY, 100,60); fill(0); text("Data:\n" + "x: " + data[tooltip][0] + "\ny: " + data[tooltip][1] + "\nz: " + bubbleData[tooltip], mouseX+10, mouseY+10); } // draw scale stroke(224,224,224); fill(255); // horizontal line(screenMinX - 5, screenMinY + 5, screenMaxX + 5, screenMinY + 5); // vertical line(screenMinX - 5, screenMinY + 5, screenMinX - 5, screenMaxY - 5); // draw tick marks for(int i = 0; i <= maxX; i+= 1){ float[] coords = myScale(i,0); line(coords[0], screenMinY, coords[0], screenMinY + 10); text(i, coords[0], screenMinY + 20); } // vertical tick marks for(int i = 0; i <= maxY; i+= 1){ float[] coords = myScale(0,i); line(screenMinX - 10, coords[1], screenMinX, coords[1] ); text(i, screenMinX - 20, coords[1]); } }