Example usage for org.jfree.data Range getCentralValue

List of usage examples for org.jfree.data Range getCentralValue

Introduction

In this page you can find the example usage for org.jfree.data Range getCentralValue.

Prototype

public double getCentralValue() 

Source Link

Document

Returns the central value for the range.

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 ww  w  . j a  v  a 2  s .  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;
}