mardi 27 octobre 2015

Processing link() returning multiple links

I have a pretty basic scatter plot which shows the largest impact craters on earth. The y-axis is diameter, the x is age.

I am trying to create an interaction where when you click a data point on the graph a link displaying the craters wiki page opens.

I have it working, but when you click the data point a page opens for every entry in the loop. I get a dozen+ of the same page.

Is there a way to make it only return one entry. I tried noLoop(); this works, it only returns the relevant entry, but it stops the program, making it so I can longer click on other data points.

I included relevant code below.

  // data point draw loop
for (int row = 0; row < rowNumber; row++) {

// define/load table again
Table craterWiki = loadTable("craterWiki.tsv");

// crater names displayed above data point and in center
String craterName = craterWiki.getString(row, 0);

// crater location displayed in center
String craterLocation = craterWiki.getString(row, 1);

// crater size displayed in center
String craterCountry = craterWiki.getString(row, 2);

String craterLink = craterWiki.getString(row, 5);

// crater size displayed in center
float craterSize = craterWiki.getFloat(row,  3);
float y = map(craterSize, 0, 300, 825, 100);

// crater age displayed in center
float craterAge = craterWiki.getFloat(row, 4);
float x = map(craterAge, 0, 2250, 100, 1024);

// data point ellipse based off of the actual diameter of the crater (craterSize)
noStroke();
fill(#FFBA00, 180);
ellipse(x, y, dataWH*craterSize/45, dataWH*craterSize/45);


// mouse interaction
textAlign(CENTER);
fill(180, 200);

// when mouse is over the craterSize ellipse display the text below
if(dist(x, y, mouseX, mouseY) < (dataWH*craterSize/45))  {

  pushMatrix();
  translate(infox,infoy);
  text( "Crater Name: " + craterName, 0, 0);
  text( "Location: " + craterLocation, 0 , 60);
  text( "Country: " + craterCountry, 0 , 80);
  text( "Age: " + craterAge +" million years", 0 , 40);
  text( "Diameter: " + craterSize + "km", 0 , 20);
  popMatrix();

  //second ellipse is also created when the mouse is over the craterSize ellipse
  int dataWH = 12;
  text(craterName, x, y - dataWH*craterSize/90 - 5);
  fill(#FFD564, 180);
  ellipse(x, y, dataWH*craterSize/45, dataWH*craterSize/45);

// if mouse pressed display crater wiki page
 if (mousePressed) { 
   link(craterLink); 
  }
 }
}

If more information is required please let me know.

Aucun commentaire:

Enregistrer un commentaire