Anonymous - 2012-07-29

Sorry, the AggregateLayout.translate does indeed return the locations with user translations - I was looking it up after the CircleLayout had already reset it! :-) Which means I have a workaround for this:

Now, this now need access to the AggregateLayout, which I am obtaining through the getGraphLayout() call. I'm also using commons-math and Guava in the utility function (also, forgive me my generics):

public void setGraph(Graph<Note, Weight> graph) {
Graph<Note, Weight> oldGraph = getGraph();
if (oldGraph != null && !oldGraph.getVertices().isEmpty() && getGraphLayout().getLayouts().containsKey(this)) {
Point2D average = averagePoint(oldGraph.getVertices());
getGraphLayout().put(this, average);


private Point2D averagePoint(Collection<Note> notes) {
List<Double> xs = Lists.newArrayList();
List<Double> ys = Lists.newArrayList();
for (Note note : notes) {
Point2D point = getGraphLayout().transform(note);
double x = StatUtils.mean(Doubles.toArray(xs));
double y = StatUtils.mean(Doubles.toArray(ys));
return new Point2D.Double(x, y);

(of course, this will break if the user changes the mutable oldGraph and it would be better if the Graph were an ObservableGraph and we didn't need to respond to explicit setGraph calls at all)