// Code from Visualizing Data, First Edition, Copyright 2008 Ben Fry. import java.util.ArrayList; class Item { String title; String type; String subject1; float dewey; ArrayList Years; ArrayList Ckouts; ArrayList AvgDurs; float hue; int saturation; int brightness; float nodeRadius; float xPos; float yPos; float zPos; Item(String title, String type, String subject1, float dewey, float avgDur, int numCkouts, int year, float hue, float nodeRadius) { Years = new ArrayList(); Ckouts = new ArrayList(); AvgDurs = new ArrayList(); this.title = title.trim(); this.type = type; this.subject1 = subject1; this.dewey = dewey; this.Years.add(year); this.Ckouts.add(numCkouts); this.AvgDurs.add(avgDur); this.hue = hue; this.nodeRadius = nodeRadius; } public PVector calcNodeCoords(PVector stageCorner) { PVector position; int secondDigit = calcDig(2, dewey); int thirdDigit = calcDig(3, dewey); int numYearsInTop = this.Years.size(); float x = stageCorner.x; if(stageCorner.x > 0){ x = stageCorner.x - 15*secondDigit; }else if (stageCorner.x < 0){ x = stageCorner.x + 15*secondDigit; } float y = stageCorner.y; if(stageCorner.y > 0){ y = stageCorner.y - 15*thirdDigit; }else if (stageCorner.y < 0){ y = stageCorner.y + 15*thirdDigit; } float z = stageCorner.z; if(stageCorner.z > 0){ z = stageCorner.z - 30 - 50*numYearsInTop; }else if (stageCorner.z < 0){ z = stageCorner.z + 30 + 50*(numYearsInTop-1); } position = new PVector(x, y, z); //Check within bounds //-------------------- //being over conservative here.... maxLen is the shortest distance //from the center to one of the edges of the penta-cube // float maxLen = Global.stageBounds*PApplet.cos(36); // float distance = PVector.dist(position, Global.stageCenter); // if(distance > maxLen) { // float diff = distance - maxLen; // PVector oppPos = PVector.mult(position, -1); // oppPos = PVector.mult(oppPos, ((float)0.35*(diff/distance))); // position.add(oppPos); // } return position; } int calcDig(int digPos, float dew){ int digit = 0; if(digPos == 2){ if(10 <= dew && dew < 100){ int tenMultiple = ((int)(dew/10))*10; digit = (int)dew - tenMultiple; } else if(100 <= dew){ int hundMultiple = ((int)(dew/100))*100; digit = ((int)dew - hundMultiple)/10; } } else if(digPos == 3){ if(0 <= dew && dew < 10){ digit = (int)dew; } else if(10 <= dew && dew < 1000){ int tenMultiple = ((int)(dew/10))*10; digit = (int)(dew - tenMultiple); } } return digit; } }