Example usage for org.jfree.data.general DatasetUtilities isEmptyOrNull

List of usage examples for org.jfree.data.general DatasetUtilities isEmptyOrNull

Introduction

In this page you can find the example usage for org.jfree.data.general DatasetUtilities isEmptyOrNull.

Prototype

public static boolean isEmptyOrNull(XYDataset dataset) 

Source Link

Document

Returns true if the dataset is empty (or null), and false otherwise.

Usage

From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java

/**
 * draw//  w  w  w  .  java  2  s .  c  o  m
 *
 * @param g2 the graphics
 * @param dataArea where the data area is
 * @param index which data set
 * @param info info
 * @param crosshairState crosshairState
 *
 * @return any drawn
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    XYDataset dataset = getDataset(index);
    if (DatasetUtilities.isEmptyOrNull(dataset)) {
        return false;
    }

    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    AxisLocation rangeAxisLocation = getRangeAxisLocation(index);
    AxisLocation domainAxisLocation = getDomainAxisLocation(index);
    RectangleEdge rangeEdge = getRangeAxisEdge();
    RectangleEdge domainEdge = getDomainAxisEdge();
    int seriesCount = dataset.getSeriesCount();
    //        System.out.println ("********************************");
    for (int series = seriesCount - 1; series >= 0; series--) {
        int itemCount = dataset.getItemCount(series);
        int[] xs = new int[itemCount];
        int[] ys = new int[itemCount];
        g2.setStroke(getRendererForDataset(dataset).getSeriesStroke(series));
        g2.setPaint(getRendererForDataset(dataset).getSeriesPaint(series));
        int pointCnt = 0;
        for (int item = 0; item < itemCount; item++) {
            double x1 = dataset.getXValue(series, item);
            double y1 = dataset.getYValue(series, item);
            if (!timeseries.valuesOk(index, x1, y1)) {
                if (pointCnt > 0) {
                    g2.drawPolyline(xs, ys, pointCnt);
                    pointCnt = 0;
                }
                continue;
            }
            double transX = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
            double transY = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
            if (!dataArea.contains(transX, transY)) {
                continue;
            }

            xs[pointCnt] = (int) (transX + 0.5);
            ys[pointCnt] = (int) (transY + 0.5);
            pointCnt++;
            if (pointCnt > 10) {
                g2.drawPolyline(xs, ys, pointCnt);
                xs[0] = xs[pointCnt - 1];
                ys[0] = ys[pointCnt - 1];
                pointCnt = 1;
            }

        }
        if (pointCnt > 1) {
            g2.drawPolyline(xs, ys, pointCnt);
        }
        long t2 = System.currentTimeMillis();
        //            System.err.println("time:" + (t2 - t1) + "ms #" + itemCount);
    }
    return true;
}

From source file:org.openfaces.component.chart.impl.plots.XYPlotAdapter.java

@Override
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {
    final XYItemRenderer renderer = getRenderer();
    final boolean customRenderingModeEnabled = renderer instanceof AreaFillRenderer;

    if (!customRenderingModeEnabled) {
        return super.render(g2, dataArea, index, info, crosshairState);
    }/* w w w .j  ava2  s.  c o  m*/

    XYDataset xyDataset = getDataset(index);
    final boolean isDataSetNotEmpty = !DatasetUtilities.isEmptyOrNull(xyDataset);

    if (!isDataSetNotEmpty) {
        return false;
    }
    ValueAxis xValueAxis = getDomainAxisForDataset(index);
    ValueAxis yValueAxis = getRangeAxisForDataset(index);
    XYItemRenderer xyItemRenderer = findRenderer(index);

    if (xValueAxis == null || yValueAxis == null || xyItemRenderer == null) {
        return false;
    }

    XYItemRendererState state = xyItemRenderer.initialise(g2, dataArea, this, xyDataset, info);
    boolean isReverseSeriesRenderingOrder = getSeriesRenderingOrder() == SeriesRenderingOrder.REVERSE;
    int totalRendererPasses = xyItemRenderer.getPassCount();
    int totalSeries = xyDataset.getSeriesCount();

    if (isReverseSeriesRenderingOrder) {
        for (int seriesIndex = totalSeries - 1; seriesIndex >= 0; seriesIndex--) {
            renderItems(g2, dataArea, info, crosshairState, xyDataset, xValueAxis, yValueAxis, xyItemRenderer,
                    state, totalRendererPasses, seriesIndex);
        }
    } else {
        for (int seriesIndex = 0; seriesIndex < totalSeries; seriesIndex++) {
            renderItems(g2, dataArea, info, crosshairState, xyDataset, xValueAxis, yValueAxis, xyItemRenderer,
                    state, totalRendererPasses, seriesIndex);
        }
    }

    return true;
}

From source file:org.openfaces.component.chart.impl.plots.GridCategoryPlotAdapter.java

@Override
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CategoryCrosshairState crossHairState) {
    final boolean customRenderingModeEnabled = getRenderer() != null
            && getRenderer() instanceof AreaFillRenderer;

    if (!customRenderingModeEnabled) {
        return super.render(g2, dataArea, index, info, crossHairState);
    }//from   ww  w .  j ava  2 s .  co  m

    CategoryItemRenderer categoryItemRenderer = getRenderer(index);
    CategoryDataset categoryDataset = getDataset(index);

    boolean isDataSetNotEmpty = !DatasetUtilities.isEmptyOrNull(categoryDataset);
    boolean isAscendingRowOrdering = getRowRenderingOrder() == SortOrder.ASCENDING;

    if (!isDataSetNotEmpty || categoryItemRenderer == null) {
        return false;
    }
    CategoryItemRendererState rendererState = categoryItemRenderer.initialise(g2, dataArea, this, index, info);
    rendererState.setCrosshairState(crossHairState);
    int totalRows = categoryDataset.getRowCount();

    if (isAscendingRowOrdering) {
        for (int currentRowIndex = 0; currentRowIndex < totalRows; currentRowIndex++) {
            renderColumns(g2, rendererState, dataArea, categoryItemRenderer, categoryDataset, index,
                    currentRowIndex);
        }
    } else {
        for (int currentRowIndex = totalRows - 1; currentRowIndex >= 0; currentRowIndex--) {
            renderColumns(g2, rendererState, dataArea, categoryItemRenderer, categoryDataset, index,
                    currentRowIndex);
        }
    }

    return true;
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer)./*  w ww.  jav a 2 s.c  o  m*/
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    //drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have a maximum value to use on the axes
        if (this.maxValue == DEFAULT_MAX_VALUE)
            calculateMaxValue(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle()
                    + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3));

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / (catCount > 2 ? catCount : 3));
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    //drawOutline(g2, area);
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).//from ww w. j  a  v a 2  s  .c  o m
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();

    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have origin and maximum value for each axis
        ensureBoundaryValues(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            if (isAxisTickVisible()) {
                drawTicks(g2, radarArea, angle, cat);
            }
            drawLabel(g2, area, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}

From source file:ucar.unidata.idv.control.chart.MyXYPlot.java

/**
 * Draws a representation of the data within the dataArea region, using the
 * current renderer./*from w  w w.ja  v  a2  s. c o  m*/
 * <P>
 * The <code>info</code> and <code>crosshairState</code> arguments may be
 * <code>null</code>.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset index.
 * @param info  an optional object for collection dimension information.
 * @param crosshairState  collects crosshair information
 *                        (<code>null</code> permitted).
 *
 * @return A flag that indicates whether any data was actually rendered.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    boolean foundData = false;
    XYDataset dataset = getDataset(index);
    if (!DatasetUtilities.isEmptyOrNull(dataset)) {
        foundData = true;
        ValueAxis xAxis = getDomainAxisForDataset(index);
        ValueAxis yAxis = getRangeAxisForDataset(index);
        XYItemRenderer renderer = getRenderer(index);
        if (renderer == null) {
            renderer = getRenderer();
        }

        XYItemRendererState state = renderer.initialise(g2, dataArea, this, dataset, info);
        int passCount = renderer.getPassCount();

        SeriesRenderingOrder seriesOrder = getSeriesRenderingOrder();
        ucar.unidata.util.Trace.call1("render", " pass:" + passCount);
        if (seriesOrder == SeriesRenderingOrder.REVERSE) {
            //render series in reverse order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = seriesCount - 1; series >= 0; series--) {
                    int itemCount = dataset.getItemCount(series);
                    ucar.unidata.util.Trace.call1("series loop",
                            " items=" + itemCount + " renderer:" + renderer.getClass().getName());
                    for (int item = 0; item < itemCount; item++) {
                        renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item,
                                crosshairState, pass);
                    }
                    ucar.unidata.util.Trace.call2("series loop");
                }
            }
        } else {
            //render series in forward order
            for (int pass = 0; pass < passCount; pass++) {
                int seriesCount = dataset.getSeriesCount();
                for (int series = 0; series < seriesCount; series++) {
                    int itemCount = dataset.getItemCount(series);
                    for (int item = 0; item < itemCount; item++) {
                        renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item,
                                crosshairState, pass);
                    }
                }
            }
        }
        ucar.unidata.util.Trace.call2("render");
    }
    return foundData;
}