Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
257 lines (227 sloc) 7.98 KB
/*
Takes in user input and switches the relevant boolean value.
*/
void userInputHandler(){
if(key == '1'){ SHOW_AXIS = !SHOW_AXIS; }
if(key == '2'){ SHOW_GUI = !SHOW_GUI; }
if(key == '3'){ INVERT_COLORS = !INVERT_COLORS; }
if(key == '4'){ SHOW_HELP_MENU = !SHOW_HELP_MENU; }
}
/*
Renders the axis if SHOW_AXIS is true.
*/
void draw_axis(boolean show_axis){
if(show_axis) {
pushMatrix();
translate(0,0,0); // reset to origin
stroke(0, 0, 0);
strokeWeight(0.5);
line(-MAX_RENDER_DIST, 0, 0, MAX_RENDER_DIST, 0, 0);
line(0, -MAX_RENDER_DIST, 0, 0, MAX_RENDER_DIST, 0);
line(0, 0, -MAX_RENDER_DIST, 0, 0, MAX_RENDER_DIST);
popMatrix();
// TODO: fix it
fill(0);
pushMatrix();
drawAxisLabelsHelper(-MAX_RENDER_DIST, 0, 0);
text("PC1", 0, 0, 0);
popMatrix();
pushMatrix();
drawAxisLabelsHelper(MAX_RENDER_DIST, 0, 0);
text("PC1", 0, 0, 0);
popMatrix();
pushMatrix();
drawAxisLabelsHelper(0, MAX_RENDER_DIST, 0);
text("PC2", 0, 0, 0);
popMatrix();
pushMatrix();
drawAxisLabelsHelper(0, -MAX_RENDER_DIST, 0);
text("PC2", 0, 0, 0);
popMatrix();
pushMatrix();
drawAxisLabelsHelper(0, 0, MAX_RENDER_DIST);
text("PC3", 0, 0, 0);
popMatrix();
pushMatrix();
drawAxisLabelsHelper(0, 0, -MAX_RENDER_DIST);
text("PC3", 0, 0, 0);
popMatrix();
}
}
/*
Renders the input box and dropdown scrollable list of results.
*/
void renderSearchGUI(boolean SHOW_GUI) {
if (cp5.getWindow().isMouseOver()) { // The mouse is on the GUI, so disable the camera controls for clicks.
cam.setActive(false);
} else {
cam.setActive(true); // Return normal camera control becauser the user is off the GUI
}
if (SHOW_GUI) {
if (USER_IS_SEARCHING) {
USER_IS_SEARCHING = !USER_IS_SEARCHING;
SELECTED_TITLES.clear();
// Get text in the textField and search. Populate SELECTED_TITLES with the results. Finally, poopulate and show the dropdown list.
String inputvalue = cp5.get(Textfield.class, "input").getText();
for (String title : TITLE_MAP.keySet()) {
// TODO: simply this!
if (match(title.toLowerCase(), inputvalue.toLowerCase()) != null && !cp5.get(Textfield.class, "input").getText().equals("")) {
SELECTED_TITLES.add(title);
}
}
cp5.get(ScrollableList.class, "dropdown").setItems(SELECTED_TITLES);
cp5.get(ScrollableList.class, "dropdown").show();
// TODO: This is probably the cause of your OOM error
} else if (cp5.get(Textfield.class, "input").getText().equals("")) {
SELECTED_TITLES.clear(); // lol
cp5.get(ScrollableList.class, "dropdown").hide();
}
if (SELECTED_TITLES.size() > 0) {
drawEdges();
}
// Disable camera orientation to draw the GUI
hint(DISABLE_DEPTH_TEST);
noLights();
cam.beginHUD();
cp5.draw();
cam.endHUD();
hint(ENABLE_DEPTH_TEST);
}
}
/*
A switch to indicate if the user has clicked the submit button to get search results.
USER_IS_SEARCHING is a global variable declared in wikiGraph.pde.
*/
public void submit(int theValue){
println("Search button pressed.");
USER_IS_SEARCHING = true;
}
/*
A switch to indicate if the user has clicked the "help" button.
SHOW_HELP_MENU is a global variable defined in wikiGraph.pde.
*/
public void help(){
println("Help putton pressed.");
SHOW_HELP_MENU = !SHOW_HELP_MENU;
}
/*
Iterative function to print the edges between articles until it reaches the Philosophy article.
Starts at the article has selected in the ScrollableList
*/
void drawEdges(){
String selectedValue;
// Get the selected article from the dropdwon list in the GUI
int val = (int)cp5.get(ScrollableList.class, "dropdown").getValue();
if (val >= SELECTED_TITLES.size()) {
selectedValue = TITLE_MAP.get(SELECTED_TITLES.get(0)).title;
} else {
selectedValue = TITLE_MAP.get(SELECTED_TITLES.get(val)).title;
}
Edge edge = EDGE_MAP.get(selectedValue);
edge.drawLine();
while(match(edge.parent.toLowerCase(), "philosophy") == null){
edge = EDGE_MAP.get(edge.parent);
edge.drawLine();
}
}
/*
TODO: What does this do?
*/
void checkArticles(){
for (Article anArticle : TITLE_MAP.values()) {
if (checkboxLevel.getArrayValue()[anArticle.level] == 1) {
if (SELECTED_TITLES.size() > 0) { // user selected some titles
if (SELECTED_TITLES.contains(anArticle.title)) {
anArticle.display(255);
anArticle.visible = true;
}
else {
anArticle.display(10.0);
anArticle.visible = false;
}
} else {
anArticle.display(255);
anArticle.visible = true;
}
} else{
anArticle.visible = false;
}
}
}
/*
Displays the titles of Articles when the mouse hovers nearby.
*/
public void displayTitleOnHover(){
float minDist = MAX_FLOAT;
Article toPrint = new Article();
float[] coord;
float mouseObjectDistance;
for (Article article: TITLE_MAP.values()) {
coord = article.prComps;
pushMatrix();
translate(coord[0], coord[1], coord[2]);
mouseObjectDistance = sq(mouseX-screenX(0, 0, 0))+sq(mouseY-screenY(0, 0, 0));
if(mouseObjectDistance < minDist && mouseObjectDistance < 20){
minDist = mouseObjectDistance;
toPrint = article;
}
popMatrix();
}
if (toPrint.visible) { // Only display the article title if is not hidden.
toPrint.writeTitle();
}
}
/*
Displays the "about" and "help" text.
*/
public void helpMenu(){
hint(DISABLE_DEPTH_TEST); // This hint must be called before and after the UI is written to the screen.
cam.beginHUD();
textMode(SHAPE);
// Grey background
fill(color(30,30,30, 240));
rect(0,0, width, height);
// Title, subtitle
fill(color(360));
textAlign(CENTER);
textSize(85);
text("WikiGraph", width/2, height/5);
textSize(30);
text("A visualization of Wikipedia articles", width/2, height/5 + 50);
// Instructions and explanation
float step = 27;
textAlign(LEFT);
textSize(step-2); // adds a 2 unit buffer between the lines
text("This is an interactive 3D visualization representing a sample of roughly 16,000 articles ", 40, height/3 + step);
text("from Wikipedia. The articles were collected using a Python web crawler. The ", 40, height/3 + step*2);
text("X, Y, and Z coordinates were determined from the first, second, and third Principle ", 40, height/3 + step*3);
text("Components of the articles' text. Color and size were chosen by the remaining components.", 40, height/3 + step * 4);
text("Click and drag your mouse to rotate the camera around the space. Holding the control key ", 40, height/3 + step * 6);
text("will pan your camera. Use the numbered buttons at the top to subset the layers of ", 40, height/3 + step * 7);
text("Wikipedia (Philosophy is at layer 0). Use the search bar to find a specific article and ", 40, height/3 + step * 8);
text("see how it leads back to Philosophy. Have fun! ", 40, height/3 + step * 9);
text("Some articles with particularly long and interesting paths include \"The Washington ", 40, height/3 + step * 11);
text("Redskins Name Controversy\", \"Rape\", and \"Software Design\". Also, try searching ", 40, height/3 + step * 12);
text("\"Upanishads\" and pay close attention to the surrounding articles. ", 40, height/3 + step * 13);
cam.endHUD();
hint(ENABLE_DEPTH_TEST);
}
/*
Invert the colors to try to help people that are color blind.
Deadline came up too fast to do this well... man isn't that poignant.
*/
void invertColors(boolean invert) {
if (invert) {
println("Inverting colors");
filter(INVERT);
}
}
/*
Shows the help menu. Meant to be done with the SHOW_HELP_MENU variable.
*/
void showHelpMenu(boolean showHelpMenu) {
if(showHelpMenu) {
println("Showing help menu.");
helpMenu();
}
}
You can’t perform that action at this time.