Extracting Data and Redrawing Via Mouse Selection
in
Programming Questions
•
2 years ago
I'm very new to Processing and am currently creating a program that draws line graphs from an array (generated from a csv file). From this drawing I would like to allow someone to select portions of the data to redraw on another section of the screen. This redrawing could be anything from a pie chart to bar graph of the selected portion of the array. I currently have the array drawn, but I don't know how to extract portions of the array data from my mouse selection to redraw. Any help would be greatly appreciated.
Below is my code that reads the csv file and illustrates the data. I have also begun to create my area of selection via mouse coordinates. Unfortunately I am unable to share my data (depth.csv), which hopefully won't impede any assistance I may receive. Again, thank you.
- float[][] data;
- String [] rowNames;
- String [] columnNames;
- float[] depth;
- int rowCount;
- int columnCount;
- float selectionStartX;
- float selectionStartY;
- void setup () {
- size(1600,950);
- smooth();
- }
- void draw () {
- background(255);
- data = tableData ();
- for (int i = 3; i < columnCount; i++) {
- drawDataCurve(i, i);
- }
- noFill();
- strokeWeight(.5);
- stroke(0);
- if (mousePressed) {
- rect(selectionStartX, selectionStartY, mouseX-selectionStartX, mouseY-selectionStartY);
- }
- }
- void mousePressed() {
- selectionStartX = mouseX;
- selectionStartY = mouseY;
- }
- float [][] tableData () {
- String[] rows = loadStrings("Depth.csv");
- String[] columns = split(rows[0], '\t');
- columnNames = subset(columns, 0);
- columnCount = columnNames.length-1;
- rowNames = new String[rows.length-1];
- rowCount = rowNames.length-1;
- float[][] tableInfo = new float[rows.length][];
- for (int i = 0; i < rows.length; i++) {
- tableInfo[i] = float(split(rows[i], TAB));
- }
- return tableInfo;
- }
- void drawDataCurve(int A, int B) {
- fill(0);
- noStroke();
- beginShape();
- for (int row = 1; row < rowCount; row++) {
- float x = map(data[row][A], 0, width/2, 30+(50*B), 70+(50*B));
- float y = map(data[row][0], 0, data[rowCount][0], 100, height/2);
- vertex(x, y);
- }
- noStroke();
- vertex(30+(50*B), height/2);
- vertex(30+(50*B), 100);
- endShape(CLOSE);
- }
1