Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Processing sketch (Processing 3.3.7) which does the following: Displays your chosen map Displays a title describing the type of data being visualized Displays

Write a Processing sketch (Processing 3.3.7) which does the following:

Displays your chosen map Displays a title describing the type of data being visualized Displays a subtitle describing the specific statistic being visualized Visualizes one statistic from the dataset that is described by the subtitle Allows the user to toggle using a space bar to display a different statistic and appropriately changes the title. There should be a smooth transition from displaying one statistic to another, just like the book example (you can use the Integrator.pde file referenced in the book example)

Additional Requirements:

Make sure to follow design considerations you learned about in previous weeks You should visualize at least 3 different statistics that you will toggle through Your code should be well documented and follow standard programming guidelines: proper use of whitespaces, appropriate variable names, etc. Your code should run without errors: ANY ERRORS THAT PREVENT EXECUTION WILL RESULTS IN ZERO POINTS!

What i have so Far: Farmers Market

Data:

Farmers Market.csv

map.png

locations.tsv // Global Variables PFont font; PImage mapImage; FloatTable locationTable; FloatTable dataTable; float dataMin = MAX_FLOAT; float dataMax = MIN_FLOAT; int rowCount; void setup() { // font = loadFont("Univers-Bold-12.vlw"); // textFont(font); size(650,400); dataTable = new FloatTable("Farmers Market.csv"); mapImage = loadImage("map.png"); locationTable = new FloatTable("locations.tsv"); rowCount = locationTable.getRowCount(); // Read the data table. // Find the minimum and maximum values. for (int row = 0; row < rowCount; row++) { float value = dataTable.getFloat(row, 0); if (value > dataMax) { dataMax = value; } if (value < dataMin) { dataMin = value; } } } void draw() { background(255); image(mapImage, 0, 0); smooth( ); fill(192, 0, 0); noStroke( ); for (int row = 0; row < rowCount; row++) { float x = locationTable.getFloat(row, 0); float y = locationTable.getFloat(row, 1); // drawData(x, y, abbrev); drawColorData(x,y,row); } } void mousePressed() { // Use this function to toggle over visualizations // Or you can use key pressed } void drawLegend() { } void drawData(float x, float y, int row) { // Get data value for state float value = dataTable.getFloat(row, 0); // Re-map the value to a number between 2 and 30 float mapped = map(value, dataMin, dataMax, 2, 30); // Draw an ellipse for this item ellipse(x, y, mapped, mapped); } void drawColorData(float x, float y, int row) { float value = dataTable.getFloat(row, 0); float percent = norm(value, dataMin, dataMax); color between = lerpColor(#FF4422, #4422CC, percent); // red to blue fill(between); float radius = percent * 20; ellipse(x, y, radius, radius); }

FloatTable: Errors out line 125 // first line of the file should be the column headers // first column should be the row titles // all other values are expected to be floats // getFloat(0, 0) returns the first data value in the upper lefthand corner // files should be saved as "text, tab-delimited" // empty rows are ignored // extra whitespace is ignored class FloatTable { int rowCount; int columnCount; float[][] data; String[] rowNames; String[] columnNames; FloatTable(String filename) { String[] rows = loadStrings(filename); String[] columns = split(rows[0], TAB); columnNames = subset(columns, 1); // upper-left corner ignored scrubQuotes(columnNames); columnCount = columnNames.length; rowNames = new String[rows.length-1]; data = new float[rows.length-1][]; // start reading at row 1, because the first row was only the column headers for (int i = 1; i < rows.length; i++) { if (trim(rows[i]).length() == 0) { continue; // skip empty rows } if (rows[i].startsWith("#")) { continue; // skip comment lines } // split the row on the tabs String[] pieces = split(rows[i], TAB); scrubQuotes(pieces); // copy row title rowNames[rowCount] = pieces[0]; // copy data into the table starting at pieces[1] data[rowCount] = parseFloat(subset(pieces, 1)); // increment the number of valid rows found so far rowCount++; } // resize the 'data' array as necessary data = (float[][]) subset(data, 0, rowCount); } void scrubQuotes(String[] array) { for (int i = 0; i < array.length; i++) { if (array[i].length() > 2) { // remove quotes at start and end, if present if (array[i].startsWith("\"") && array[i].endsWith("\"")) { array[i] = array[i].substring(1, array[i].length() - 1); } } // make double quotes into single quotes array[i] = array[i].replaceAll("\"\"", "\""); } } int getRowCount() { return rowCount; } String getRowName(int rowIndex) { return rowNames[rowIndex]; } String[] getRowNames() { return rowNames; } // Find a row by its name, returns -1 if no row found. // This will return the index of the first row with this name. // A more efficient version of this function would put row names // into a Hashtable (or HashMap) that would map to an integer for the row. int getRowIndex(String name) { for (int i = 0; i < rowCount; i++) { if (rowNames[i].equals(name)) { return i; } } //println("No row named '" + name + "' was found"); return -1; } // technically, this only returns the number of columns // in the very first row (which will be most accurate) int getColumnCount() { return columnCount; } String getColumnName(int colIndex) { return columnNames[colIndex]; } String[] getColumnNames() { return columnNames; } float getFloat(int rowIndex, int col) { // Remove the 'training wheels' section for greater efficiency // It's included here to provide more useful error messages // begin training wheels if ((rowIndex < 0) || (rowIndex >= data.length)) { throw new RuntimeException("There is no row " + rowIndex); } if ((col < 0) || (col >= data[rowIndex].length)) { throw new RuntimeException("Row " + rowIndex + " does not have a column " + col); } // end training wheels return data[rowIndex][col]; } boolean isValid(int row, int col) { if (row < 0) return false; if (row >= rowCount) return false; //if (col >= columnCount) return false; if (col >= data[row].length) return false; if (col < 0) return false; return !Float.isNaN(data[row][col]); } float getColumnMin(int col) { float m = Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { if (!Float.isNaN(data[i][col])) { if (data[i][col] < m) { m = data[i][col]; } } } return m; } float getColumnMax(int col) { float m = -Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { if (isValid(i, col)) { if (data[i][col] > m) { m = data[i][col]; } } } return m; } float getRowMin(int row) { float m = Float.MAX_VALUE; for (int i = 0; i < columnCount; i++) { if (isValid(row, i)) { if (data[row][i] < m) { m = data[row][i]; } } } return m; } float getRowMax(int row) { float m = -Float.MAX_VALUE; for (int i = 1; i < columnCount; i++) { if (!Float.isNaN(data[row][i])) { if (data[row][i] > m) { m = data[row][i]; } } } return m; } float getTableMin() { float m = Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (isValid(i, j)) { if (data[i][j] < m) { m = data[i][j]; } } } } return m; } float getTableMax() { float m = -Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (isValid(i, j)) { if (data[i][j] > m) { m = data[i][j]; } } } } return m; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions