//Copyright 2005 Sean McCullough //banksean at yahoo int H = 600; int W = 800; float G = 0.750; float scaleFactor = 1.0; float transX = 0; float transY = 0; HashMap gdpByNation = new HashMap(); Graph g = new Graph(); PFont font; // The font must be located in the sketch's // "data" directory to load successfully boolean doneLoading = false; int fCount = 0; void setup() { size(W,H); framerate(30); smooth(); font = loadFont("EurostileRegular-14.vlw"); textFont(font, 14); g = buildExportAtlasGraph(); doneLoading= true; } void draw() { background(0); translate(transX, transY); scale((float)scaleFactor); if (g != null && doneLoading) { doLayout(); if (fCount > 100) { g.draw(); } fCount++; } } void doLayout() { if (g == null || !doneLoading) { return; } //calculate forces on each node //calculate spring forces on each node for (int i=0; i 0) { if (importNation.startsWith(", ")) { importNation = importNation.substring(2); } if (importNation.lastIndexOf(" ") != -1) { String percent = importNation.substring(importNation.lastIndexOf(" ")); importNation = normalizeNation(importNation.substring(0,importNation.lastIndexOf(" "))); try { float pct = Float.parseFloat(percent); println("\t" + importNation + ": " + pct); ForcedNode imNode = getNationNode(importNation); Float gdp = (Float)gdpByNation.get(importNation); if (gdp != null) { SpringEdge edge = new SpringEdge(imNode, exNode); edge.setNaturalLength(250-(float)pct); edge.setStiffness(0.001*pct); //0.05); edge.setWeight(pct/10); edge.setLabel(pct + "%"); g.addEdge(edge); } else { println("couldn't find GDP for " + importNation); imNode.setMass(1); } } catch (Exception ex) { ex.printStackTrace(); } } else { println ("\t " + importNation + " no percent"); } } } } return g; } ForcedNode getNationNode(String name) { ForcedNode exNode = (ForcedNode)g.getNode(name); if (exNode == null) { Float egdp = (Float)gdpByNation.get(name); exNode = new ForcedNode(new Vector3D(W/4 + random(W/2), H/4 + random(H/2), 0)); exNode.setId(name); exNode.setLabel(name); if (egdp != null) { exNode.setMass((float)((Math.sqrt(egdp.floatValue())))); exNode.setAltLabel("$" + egdp); g.addNode(exNode); } else { println("couldn't find GDP for " + name); exNode.setMass(1); } } return exNode; }