From 04accf966ab4c46a26faa69e01d773a64bdab404 Mon Sep 17 00:00:00 2001 From: miles Date: Mon, 23 Jul 2012 22:53:04 +0000 Subject: [PATCH] Fully operational image generation, independent of JHeatChart libraries. svn path=/; revision=368 --- Personnel/miles/2/src/Heatmap.java | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Personnel/miles/2/src/Heatmap.java b/Personnel/miles/2/src/Heatmap.java index 2a77845..2182f40 100644 --- a/Personnel/miles/2/src/Heatmap.java +++ b/Personnel/miles/2/src/Heatmap.java @@ -4,6 +4,7 @@ import java.io.*; import java.util.Properties; import java.util.Scanner; import java.awt.*; +import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.BufferedImageOp; import java.awt.image.ImageProducer; @@ -39,7 +40,7 @@ public class Heatmap { } private static void generateHeatMapImage(Species[] species) { - /* + File output = new File("heatMap"); int heatMapHeight = 25*allClusterIDs.length; @@ -63,32 +64,49 @@ public class Heatmap { } } - + int speciesNameLength = 200; int chartWidth = heatMapWidth + 50; - int chartHeight = heatMapHeight + 300; + int chartHeight = heatMapHeight + speciesNameLength; BufferedImage chartImage = new BufferedImage(chartWidth, chartHeight, imageType); Graphics2D chartGraphics = chartImage.createGraphics(); Color background = new Color(255, 255, 255); chartGraphics.setColor(background); chartGraphics.fillRect(0, 0, chartWidth, chartHeight); - chartGraphics.drawImage(heatMapImage, 50, 300, null); + chartGraphics.drawImage(heatMapImage, 50, speciesNameLength, null); chartGraphics.setColor(Color.black); chartGraphics.drawString("Heat Map", 25, 25); for (int c = 0; c < allClusterIDs.length; c ++) { String clusterID = Integer.toString(allClusterIDs[c]); - chartGraphics.drawString(clusterID, 5, (315 + c*25)); + chartGraphics.drawString(clusterID, 5, (speciesNameLength + 15 + c*25)); } + + for (int s = 0; s < species.length; s ++) { + int valueXPos = 70 + (s * 25); + int valueYPos = speciesNameLength - 5; + // Create 270 degree rotated transform. + AffineTransform transform = chartGraphics.getTransform(); + AffineTransform originalTransform = (AffineTransform) transform.clone(); + transform.rotate(Math.toRadians(270), valueXPos, valueYPos); + chartGraphics.setTransform(transform); + + // Draw the string. + chartGraphics.drawString(species[s].name, valueXPos, valueYPos); + + // Revert to original transform before rotation. + chartGraphics.setTransform(originalTransform); + } + try { ImageIO.write((RenderedImage) chartImage, "gif", output); } catch (IOException e) { System.out.println("Unable to write Heat Map Image"); } - */ - + + /* double[][] heatMapVals = new double[allClusterIDs.length][species.length]; for (int s = 0; s < species.length; s ++) { for (int c = 0; c < allClusterIDs.length; c ++) { @@ -126,6 +144,7 @@ public class Heatmap { } catch (IOException e) { System.out.println("Unable to write image to file"); } + */ } -- 2.34.1