Note that there are some explanatory texts on larger screens.

plurals
  1. POString equals commands do not line up with rows of source tsv file
    primarykey
    data
    text
    <p>I am coding a simple diagram that parses a .tsv file that has 6 columns and 9 rows. I am attempting to put some text on my diagram that is coloured according to the data existing in the third column. I am able to get all the colours on the screen, but for some reason, the text that ends up red is the text corresponding to the row (in the tsv file) BELOW the row whose text I want to be red. For example, while I want the Liberal candidate to have a fill of (200,60,60), the Parti Quebecois candidate appearing in the row below instead becomes red. Following, the New Dem party candidate ends up with the fill of (155,191,219). The code appears as follows:</p> <pre><code>PImage mapOfCanada; // background map Premier[] premiers; // premiers data void setup() { size(800, 800); // modified mapOfCanada from http://www.theblog.ca/map-canada mapOfCanada = loadImage("bigmapofcanada.png"); // from http://en.wikipedia.org/wiki/List_of_current_Canadian_first_ministers Table table = new Table("premiers.tsv"); int rows = table.getRowCount(); premiers = new Premier[rows]; // read through each row of the source data to populate our premiers array for (int i=0; i&lt;rows; i++) { String name = table.getString(i, 0); String province = table.getString(i, 1); String party = table.getString(i, 2); String imgFile = table.getString(i, 3); PImage img = loadImage(imgFile); float x = table.getFloat(i,4); float y = table.getFloat(i,5); premiers[i] = new Premier(name, province, party, img, x, y); } } void draw() { background(255); // draw the background image with a light tint tint(255, 25); image(mapOfCanada, 0, 0); // draw each premier noTint(); for (Premier premier : premiers) { image(premier.img, premier.x, premier.y); } //drawing lines for those premier images that cannot fit in the alloted province space line(158,560,145,460); //Alberta line(300,560,340,500); //Manitoba line(650,365,670,410); //Newfoundland line(750,385,710,535); //PEI line(730,575,720,550); //Nova Scotia line(670,595,680,560); //New Brunswick //adding text labels for (Premier premier : premiers) { //reading through the source data in a loop textSize(10); //making the text size small yet readable textAlign(CENTER); //making sure the text is centered above the image text(premier.name, premier.x+50, premier.y-10); //positioning the text in relation to the x and y coordinates on the source data { String string1 = new String("Liberal"); String string2 = new String("Parti Quebecois"); String string3 = new String("New Democratic"); String string4 = new String ("Progressive Conservative"); String string5 = new String ("Saskatchewan Party"); String string6 = new String ("Yukon Party"); if (premier.party.equals("Liberal")) { fill(200,60,60); } else if (premier.party.equals("Parti Quebecois")) { fill(155,191,219); } else if (premier.party.equals("New Democratic")) { fill(180,151,107); } else if(premier.party.equals("Progressive Conservative")) { fill(96,104,250); } else if(premier.party.equals("Saskatchewan Party")) { fill (107,180,119); } else if(premier.party.equals("Yukon Party")) { fill (47,85,232); } else { fill (0,0,0); } } } } class Premier { String name, province, party; PImage img; // this is the thumbnail image float x, y; // these are the coordinates for the thumbnail Premier(String name, String province, String party, PImage img, float x, float y) { this.name = name; this.province = province; this.party = party; this.img = img; this.x = x; this.y = y; } } </code></pre> <p>Any help re: what I'm doing wrong would be much appreciated! I've edited the post to feature the full code.</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload