Example usage for org.jfree.data Range Range

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

Introduction

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

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

From source file:org.adempiere.apps.graph.PerformanceIndicator.java

private JFreeChart createChart() {
    JFreeChart chart = null;/*from w w w  . j a  va  2 s . co m*/

    //   Set Text
    StringBuffer text = new StringBuffer(m_goal.getName());
    if (m_goal.isTarget())
        text.append(": ").append(m_goal.getPercent()).append("%");
    else
        text.append(": ").append(s_format.format(m_goal.getMeasureActual()));

    m_text = text.toString();

    //   ToolTip
    text = new StringBuffer();
    if (m_goal.getDescription() != null)
        text.append(m_goal.getDescription()).append(": ");
    text.append(s_format.format(m_goal.getMeasureActual()));
    if (m_goal.isTarget())
        text.append(" ").append(Msg.getMsg(Env.getCtx(), "of")).append(" ")
                .append(s_format.format(m_goal.getMeasureTarget()));
    setToolTipText(text.toString());
    //
    //setBackground(m_goal.getColor());
    setForeground(GraphUtil.getForeground(getBackground()));
    //   Performance Line
    int percent = m_goal.getPercent();
    if (percent > 100) //   draw 100% line
        m_line = s_width100;
    else //   draw Performance Line
        m_line = s_width100 * m_goal.getGoalPerformanceDouble();

    String title = m_text;
    DefaultValueDataset data = new DefaultValueDataset((float) m_goal.getPercent());
    MeterPlot plot = new MeterPlot(data);

    MColorSchema colorSchema = m_goal.getColorSchema();
    int rangeLo = 0;
    int rangeHi = 0;
    for (int i = 1; i <= 4; i++) {
        switch (i) {
        case 1:
            rangeHi = colorSchema.getMark1Percent();
            break;
        case 2:
            rangeHi = colorSchema.getMark2Percent();
            break;
        case 3:
            rangeHi = colorSchema.getMark3Percent();
            break;
        case 4:
            rangeHi = colorSchema.getMark4Percent();
            break;
        }
        if (rangeHi == 9999)
            rangeHi = (int) Math.floor(rangeLo * 1.5);
        if (rangeLo < rangeHi) {
            plot.addInterval(new MeterInterval("Normal", //label
                    new Range(rangeLo, rangeHi), //range
                    colorSchema.getColor(rangeHi), new BasicStroke(7.0f),
                    //Color.lightGray
                    new Color(-13091716)
            //Color.gray 
            ));
            rangeLo = rangeHi;
        }
    }
    plot.setRange(new Range(0, rangeLo));

    plot.setDialBackgroundPaint(new Color(-13091716));//Color.GRAY);
    plot.setUnits(m_goal.getName());
    plot.setDialShape(DialShape.CHORD);//CIRCLE);        
    //plot.setDialBackgroundPaint(new GradientPaint(0, 0, m_goal.getColor(), 0, 1000, Color.black));
    plot.setNeedlePaint(Color.white);
    plot.setTickSize(2000);
    plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    plot.setTickLabelPaint(Color.white);
    plot.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));

    chart = new JFreeChart(m_text, new Font("SansSerif", Font.BOLD, 15), plot, false);

    return chart;
}

From source file:edu.utexas.ece.pharos.proteus3.sensors.CompassChartGUI.java

/**
 * Creates a chart./*from   www.ja v  a  2s  .  c  o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Proteus III Compass Measurements", // chart title
            "Time (s)", // x axis label
            "Angle (degrees)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customization...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setRange(new Range(0, 140));

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    // change the auto tick unit selection to integer units only...
    //        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //rangeAxis.setRange(new Range(-Math.PI, Math.PI));
    rangeAxis.setRange(new Range(-180, 180));

    return chart;

}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcMethanolMethilAcetate() throws Exception {
    super.setTitle("P vs x1");
    double T = 25;

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("methanol");
    comps[1] = db.getComp("methyl-acetate");

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setComponents(comps);// ww w . j  a v  a 2  s.c o m

    cosmosac.setTemperature(T + 273.15);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.5785;
    parAntoine[0][1] = 3638.27;
    parAntoine[0][2] = 239.500;
    parAntoine[1][0] = 14.2456;
    parAntoine[1][1] = 2662.78;
    parAntoine[1][2] = 219.690;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot2;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot2 = (XYPlot) chart.getPlot();
    plot2.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot2.getRangeAxis().setRange(new Range(15.0, 30.0));

    plot2.setDataset(dataset);

    XYSplineRenderer r = new XYSplineRenderer();
    BasicStroke stroke = new BasicStroke(2f);
    r.setStroke(stroke);
    plot2.setRenderer(r);
    r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel, BorderLayout.CENTER);

    add(jp);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java

/**
 * Returns the range of values the renderer requires to display all the 
 * items from the specified dataset./*from ww  w . j  ava  2  s .  c  om*/
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 * 
 * @return The range (<code>null</code> if the dataset is <code>null</code> 
 *         or empty).
 */
public Range findRangeBounds(XYDataset dataset) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();
    double lvalue;
    double uvalue;
    if (dataset instanceof VectorXYDataset) {
        VectorXYDataset vdataset = (VectorXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double delta = vdataset.getDeltaYValue(series, item);
                if (delta < 0.0) {
                    uvalue = vdataset.getYValue(series, item);
                    lvalue = uvalue + delta;
                } else {
                    lvalue = vdataset.getYValue(series, item);
                    uvalue = lvalue + delta;
                }
                minimum = Math.min(minimum, lvalue);
                maximum = Math.max(maximum, uvalue);
            }
        }
    } else {
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                lvalue = dataset.getYValue(series, item);
                uvalue = lvalue;
                minimum = Math.min(minimum, lvalue);
                maximum = Math.max(maximum, uvalue);
            }
        }
    }
    if (minimum > maximum) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:scrum.server.common.BurndownChart.java

private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay,
        Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit,
        float widthPerDay) {
    DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay,
            freeDays);// w ww.  j a  v  a 2 s  .c om

    double tick = 1.0;
    double max = BurndownChart.getMaximum(data);

    while (max / tick > 25) {
        tick *= 2;
        if (max / tick <= 25)
            break;
        tick *= 2.5;
        if (max / tick <= 25)
            break;
        tick *= 2;
    }
    double valueLabelTickUnit = tick;
    double upperBoundary = Math.min(max * 1.1f, max + 3);

    if (!Sys.isHeadless())
        LOG.warn("GraphicsEnvironment is not headless");
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true,
            false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = chart.getXYPlot();
    // plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // plot.setOutlineVisible(false);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);
    // plot.setRangeCrosshairPaint(Color.lightGray);
    // plot.setRangeMinorGridlinePaint(Color.lightGray);
    // plot.setDomainCrosshairPaint(Color.blue);
    // plot.setDomainMinorGridlinePaint(Color.green);
    // plot.setDomainTickBandPaint(Color.green);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2f));

    renderer.setSeriesPaint(0, COLOR_PAST_LINE);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE);
    renderer.setSeriesStroke(1,
            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0));
    renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE);
    renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    DateAxis domainAxis1 = new DateAxis();
    String dateFormat = "d.";
    widthPerDay -= 5;
    if (widthPerDay > 40) {
        dateFormat = "EE " + dateFormat;
    }
    if (widthPerDay > 10) {
        float spaces = widthPerDay / 2.7f;
        dateFormat = Str.multiply(" ", (int) spaces) + dateFormat;
    }
    domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US));
    domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit));
    domainAxis1.setAxisLineVisible(false);
    Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis());
    domainAxis1.setRange(range);

    DateAxis domainAxis2 = new DateAxis();
    domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    domainAxis2.setTickMarksVisible(false);
    domainAxis2.setTickLabelsVisible(false);
    domainAxis2.setRange(range);

    plot.setDomainAxis(0, domainAxis2);
    plot.setDomainAxis(1, domainAxis1);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit));

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(upperBoundary);

    plot.setRangeAxis(rangeAxis);

    return chart;
}

From source file:org.mwc.asset.netasset2.sensor2.VSensor.java

protected void setTimePeriod(final Integer secs) {
    _visibleTimePeriod = secs;/*from w  w  w.  j a  va 2 s. c  o  m*/

    if (_timeNow != 0) {
        if (secs == 0) {
            _dateAxis.setAutoRange(true);
        } else {
            final long startTime = _timeNow - (secs * 1000);
            final Range newR = new Range(startTime, _timeNow);
            _dateAxis.setRange(newR, true, true);
        }

    }
}

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  av a  2 s .co 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:org.jfree.data.Range.java

/**
 * Returns a new range that spans both <code>range1</code> and 
 * <code>range2</code>.  This method has a special handling to ignore
 * Double.NaN values./*from w ww .j av  a2s . c o m*/
 *
 * @param range1  the first range (<code>null</code> permitted).
 * @param range2  the second range (<code>null</code> permitted).
 *
 * @return A new range (possibly <code>null</code>).
 *
 * @since 1.0.15
 */
public static Range combineIgnoringNaN(Range range1, Range range2) {
    if (range1 == null) {
        if (range2 != null && range2.isNaNRange()) {
            return null;
        }
        return range2;
    }
    if (range2 == null) {
        if (range1.isNaNRange()) {
            return null;
        }
        return range1;
    }
    double l = min(range1.getLowerBound(), range2.getLowerBound());
    double u = max(range1.getUpperBound(), range2.getUpperBound());
    if (Double.isNaN(l) && Double.isNaN(u)) {
        return null;
    }
    return new Range(l, u);
}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * This method is needed for displaying the graph in the correct range (not too zoomed out or in)
 * @param dataset the dataset which needs to be plotted
 * @author Muhammad Omer Saeed/*from  w w w . j a  va  2s . c  om*/
 */

public Range findRangeBounds(XYDataset dataset) {

    if (dataset != null) {

        XYSeriesCollection collection = (XYSeriesCollection) dataset;
        List<XYSeries> series = collection.getSeries();
        double max = Double.MIN_VALUE, min = Double.MAX_VALUE;

        for (XYSeries s : series) {
            for (int i = 0; i < s.getItemCount(); i++) {
                PrismXYDataItem item = (PrismXYDataItem) s.getDataItem(i);

                if ((item.getYValue() - item.getError()) < min) {
                    min = (item.getYValue() - item.getError());
                }

                if ((item.getYValue() + item.getError()) > max) {
                    max = (item.getYValue() + item.getError());
                }
            }
        }

        if (max == Double.MIN_VALUE && min == Double.MAX_VALUE) {
            return null;
        } else
            return new Range(min, max);
    } else {
        return null;
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java

/**
 * Initializes the reference set bounds.
 *//*from  w  ww.  j  a  v a  2s .com*/
protected void initializeReferenceSetBounds() {
    if (referenceSet == null) {
        return;
    }

    double domainMin = Double.POSITIVE_INFINITY;
    double domainMax = Double.NEGATIVE_INFINITY;
    double rangeMin = Double.POSITIVE_INFINITY;
    double rangeMax = Double.NEGATIVE_INFINITY;

    for (Solution solution : referenceSet) {
        domainMin = Math.min(domainMin, getValue(solution, 0));
        domainMax = Math.max(domainMax, getValue(solution, 0));
        rangeMin = Math.min(rangeMin, getValue(solution, 1));
        rangeMax = Math.max(rangeMax, getValue(solution, 1));
    }

    domainMax += (domainMax - domainMin);
    rangeMax += (rangeMax - rangeMin);

    referenceDomainBounds = new Range(domainMin, domainMax);
    referenceRangeBounds = new Range(rangeMin, rangeMax);
}