Example usage for org.jfree.data.general HeatMapUtilities createHeatMapImage

List of usage examples for org.jfree.data.general HeatMapUtilities createHeatMapImage

Introduction

In this page you can find the example usage for org.jfree.data.general HeatMapUtilities createHeatMapImage.

Prototype

public static BufferedImage createHeatMapImage(HeatMapDataset dataset, PaintScale paintScale) 

Source Link

Document

Creates an image that displays the values from the specified dataset.

Usage

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapWorker.java

protected Void doInBackground() throws Exception {
    // this is a SwingWorker thread from its pool, give it a recognizable name
    Thread.currentThread().setName("PortHeatMapWorker");

    JFreeChart Chart = PlotPanel.getHeatChart();

    logger.info("Worker Building HeatMapPlot");
    MessageManager.getInstance()//from   w  ww . j av a2s  .c o  m
            .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building HeatMapPlot"));

    PortHeatMapDataSet pHeatMap = null;
    if (UseService) {
        SMT_UpdateService updateService = SMT_UpdateService.getInstance();
        History = updateService.getCollection();
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet(History, IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet(History, IncludedDepths);
    } else if (History != null) {
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet(History, IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet(History, IncludedDepths);
    } else {
        // FIXME - eliminate this, for test purposes only
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedDepths);
    }
    //    logger.fine("Finished creating dataset");
    //    logger.fine("Max X: " + pHeatMap.getMaximumXValue());
    //    logger.fine("Max Y: " + pHeatMap.getMaximumYValue());
    //    logger.fine("Max Z: " + pHeatMap.getMaximumZValue());
    //    
    // if any of these "maximum" values are illegal, stop here and return null
    if (!pHeatMap.isValid()) {
        logger.severe("Invalid HeatMap, check OMS Collection or Depth filter (empty or null)");
        MessageManager.getInstance().postMessage(new SmtMessage(SmtMessageType.SMT_MSG_SEVERE,
                "Invalid HeatMap, check OMS Collection or Depth filter (empty or null)"));
        PlotPanel.setHeatMapDataSet(null);
        return null;
    }

    PlotPanel.setHeatMapDataSet(pHeatMap);

    Range fixedXRange = new Range(0, pHeatMap.getMaximumXValue()); // time #
    Range fixedYRange = new Range(0, pHeatMap.getMaximumYValue()); // port #
    Range fixedZRange = new Range(0, pHeatMap.getMaximumZValue()); // % Util

    // there are 3 valid paint scales, 0, 1, & 2
    LookupPaintScale paintScale = PaintScaleFactory.getLookupPaintScale(1, 0, fixedZRange.getUpperBound(),
            fixedZRange.getUpperBound());
    ValueAxis paintAxis = PaintScaleFactory.getPaintScaleAxis(0, fixedZRange.getUpperBound(),
            PortHeatMapPlotPanel.UtilizationAxisLabel);

    BufferedImage image = HeatMapUtilities.createHeatMapImage(pHeatMap, paintScale);
    XYDataImageAnnotation ann = new XYDataImageAnnotation(image, fixedXRange.getLowerBound(),
            fixedYRange.getLowerBound(), fixedXRange.getUpperBound(), fixedYRange.getUpperBound(), true);
    XYPlot plot = (XYPlot) Chart.getPlot();
    plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND);

    // finally, show the heatmap
    PaintScaleLegend psLegend = new PaintScaleLegend(paintScale, paintAxis);
    psLegend.setMargin(new RectangleInsets(3, 40, 3, 10));
    psLegend.setPosition(RectangleEdge.TOP); // location (within NORTH) of
                                             // heatmap legend
    psLegend.setAxisOffset(4.0);
    psLegend.setFrame(new BlockBorder(Color.GRAY));
    Chart.addSubtitle(psLegend);

    // fix the sliders ranges, and set them for the middle
    if ((pHeatMap != null) && (PlotPanel != null)) {
        PlotPanel.getTimeSlider().setMinimum((int) fixedXRange.getLowerBound());
        PlotPanel.getTimeSlider().setMaximum((int) fixedXRange.getUpperBound());
        PlotPanel.getTimeSlider().setValue((int) fixedXRange.getCentralValue());

        PlotPanel.getPortSlider().setMinimum((int) fixedYRange.getLowerBound());
        PlotPanel.getPortSlider().setMaximum((int) fixedYRange.getUpperBound());
        PlotPanel.getPortSlider().setValue((int) fixedYRange.getCentralValue());

        HeatMapDepthPanel hmdp = new HeatMapDepthPanel(pHeatMap);
        PlotPanel.replaceDepthPanel(hmdp);
    }
    return null;
}

From source file:edu.purdue.cc.bionet.ui.HeatMap.java

/**
 * This method retrieves a heatmap image from jfreechart and places it on the panel
 * along with black divider lines and labels to create a heat map graph.
 * //w w w  . j a  va2  s  .c o m
 * @param g The Graphics for the jpanel.
 */
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (moleculeList.size() > 0) {
        float tickStep;
        BufferedImage drawing = HeatMapUtilities.createHeatMapImage(this.getDataset(), this.spectrum);
        int leftEdge = this.getWidth() / 8;
        int topEdge = this.getHeight() / 32;
        int bottomEdge = this.getHeight() * 7 / 8;
        int rightEdge = this.getWidth() * 31 / 32;
        mapPosition = new Rectangle(leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge);
        g.drawImage(drawing, leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge,
                this.getBackground(), this);
        // y-axis
        int yAxisPos = leftEdge - 1;
        //      g.drawLine( yAxisPos, topEdge, yAxisPos, bottomEdge );
        tickStep = (bottomEdge - topEdge) / (float) moleculeList.size();
        for (int i = 0; i <= moleculeList.size(); i++) {
            int tickY = Math.round(topEdge + i * tickStep);
            g.drawLine(rightEdge, tickY, yAxisPos - tickSize, tickY);
            if (i < moleculeList.size()) {
                String name = this.moleculeList.get(this.moleculeList.size() - 1 - i).toString();
                g.drawString(name, yAxisPos - 4 - g.getFontMetrics().stringWidth(name),
                        (int) (tickY + tickStep));
            }
        }

        // x-axis
        int xAxisPos = bottomEdge;
        tickStep = (rightEdge - leftEdge) / (float) moleculeList.size();
        //      g.drawLine( leftEdge, xAxisPos, rightEdge, xAxisPos );
        for (int i = 0; i <= moleculeList.size(); i++) {
            int tickX = (int) (leftEdge + i * tickStep);
            g.drawLine(tickX, topEdge, tickX, xAxisPos + tickSize);
        }
        // transform clockwise 90 degrees for the vertical text
        AffineTransform at = new AffineTransform();
        at.quadrantRotate(3);
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.transform(at);
        for (int i = 0; i < moleculeList.size(); i++) {
            int tickX = Math.round(leftEdge + i * tickStep);
            String name = this.moleculeList.get(i).toString();
            g2d.drawString(name, -(int) (xAxisPos + 4 + g.getFontMetrics().stringWidth(name)),
                    (int) (tickX + tickStep));
        }
    }
}