}
final DefaultTree tree = new DefaultTree();
System.out.println("Reading " + inputFile);
AbstractReader reader =
TreeReaderFactory.createTreeReader(inputFile, tree);
TreemapVisualization visualization =
new TreemapVisualization(tree, Strip.instance);
if (reader != null && reader.load()) {
System.out.println("Done.");
for (Iterator iter = visual.keySet().iterator();
iter.hasNext();
) {
String key = (String) iter.next();
String value = (String) visual.get(key);
visualization.setVisualColumn(
key,
tree.getColumn(value));
}
final Column order = visualization.getVisualColumn("sort");
final Column size = visualization.getVisualColumn(Visualization.VISUAL_SIZE);
Permutation perm = visualization.getPermutation();
perm.sort(new RowComparator() {
public int compare(int row1, int row2) {
if (tree.isLeaf(row1) && tree.isLeaf(row2)) {
return size.compare(row1, row2);
}
else {
return order.compare(row1, row2);
}
}
public boolean isValueUndefined(int row) {
return order.isValueUndefined(row);
}
});
visualization.setPermutation(perm);
System.out.println("Rendering " + inputFile);
Rectangle bounds = new Rectangle(0, 0, width, height);
BufferedImage image =
new BufferedImage(
width,
height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) image.getGraphics();
visualization.paint(g2d, bounds);
try {
System.out.println("Done.\nSaving to " + outputFile);
ImageIO.write(image, "png", new File(outputFile));
System.out.println("Done.");
}