Example usage for org.jfree.chart.plot CategoryPlot getOrientation

List of usage examples for org.jfree.chart.plot CategoryPlot getOrientation

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot getOrientation.

Prototype

@Override
public PlotOrientation getOrientation() 

Source Link

Document

Returns the orientation of the plot.

Usage

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel/*from   w  ww  . ja  va  2s. co  m*/
 * @param category
 * @param y
 * @return
 */
public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot xyp = (CategoryPlot) plot;
        CategoryDataset cds = xyp.getDataset();
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Comparable<?> categoryKey = cds.getColumnKey(category);
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea,
                xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

private void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {
    Line2D line = null;//from   w  w  w  .  ja  va 2s . com
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    }

    g2.setPaint(domainGridlinePaint);
    Stroke stroke = plot.getDomainGridlineStroke();

    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }

    g2.setStroke(stroke);
    g2.draw(line);
}

From source file:soap.ui.stats.LineAndShapeRendererMapToBar.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null)
        return;//from   ww w.ja  v  a  2s  . co  m

    PlotOrientation orientation = plot.getOrientation();

    // current data point which is associated to a serie...
    double x1 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    int seriesCount = mBarRenderer.getPlot().getDataset().getRowCount();
    int categoryCount = mBarRenderer.getPlot().getDataset().getColumnCount();
    if (seriesCount > 1 && mNumSerie < seriesCount) {
        double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount, seriesCount);
        x1 = x1 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);

    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }

    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = createTransformedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = createTransformedShape(shape, x1, y1);
    }
    if (isDrawShapes()) {
        if (getItemShapeFilled(row, column)) {
            g2.setPaint(getItemPaint(row, column));
            g2.fill(shape);
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }

    if (isDrawLines()) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0 = domainAxis.getCategoryStart(column - 1, getColumnCount(), dataArea,
                        plot.getDomainAxisEdge());
                //  seriesCount = getRowCount();
                //  categoryCount = getColumnCount();
                if (seriesCount > 1 && mNumSerie < seriesCount) {
                    double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
                    double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount,
                            seriesCount);
                    x0 = x0 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }

                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(row, column)) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
        if (entities != null && shape != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.addEntity(entity);
        }
    }
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

protected Axis getAxis(JFreeChart chart, PlotOrientation dir) {
    try {//from  w  w  w  . j  av  a2s.  com
        CategoryPlot p = chart.getCategoryPlot();
        if (dir.equals(p.getOrientation()))
            return p.getRangeAxis();
        else
            return p.getDomainAxis();
    } catch (Exception e) {
        return null;
    }
}

From source file:org.jfree.chart.demo.GanttRenderer2.java

protected void drawTask(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    PlotOrientation plotorientation = categoryplot.getOrientation();
    org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    Number number = ganttcategorydataset.getEndValue(i, j);
    if (number == null)
        return;//from   w w  w  .j av a  2  s . co  m
    double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
    Number number1 = ganttcategorydataset.getStartValue(i, j);
    if (number1 == null)
        return;
    double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
    if (d1 < d) {
        double d2 = d1;
        d1 = d;
        d = d2;
        Number number2 = number1;
        number1 = number;
        number = number2;
    }
    int k = countNonNullValues(ganttcategorydataset, j);
    if (k == 0)
        return;
    int l = countPriorNonNullValues(ganttcategorydataset, j, i);
    double d3 = (categoryaxis.getCategoryEnd(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())
            - categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()))
            / (double) k;
    double d4 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d,
            categoryplot.getDomainAxisEdge()) + d3 * (double) l;
    double d5 = Math.abs(d1 - d);
    java.awt.geom.Rectangle2D.Double double1 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d, d4, d5, d3);
    else if (plotorientation == PlotOrientation.VERTICAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d4, d1, d3, d5);
    java.awt.geom.Rectangle2D.Double double2 = null;
    java.awt.geom.Rectangle2D.Double double3 = null;
    Number number3 = ganttcategorydataset.getPercentComplete(i, j);
    double d6 = getStartPercent();
    double d7 = getEndPercent();
    if (number3 != null) {
        double d8 = number3.doubleValue();
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d, d4 + d6 * d3, d5 * d8, d3 * (d7 - d6));
            double3 = new java.awt.geom.Rectangle2D.Double(d + d5 * d8, d4 + d6 * d3, d5 * (1.0D - d8),
                    d3 * (d7 - d6));
        } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1 + d5 * (1.0D - d8), d3 * (d7 - d6),
                    d5 * d8);
            double3 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1, d3 * (d7 - d6), d5 * (1.0D - d8));
        }
    }
    Paint paint = getItemPaint(i, j);
    graphics2d.setPaint(paint);
    graphics2d.fill(double1);
    if (double2 != null) {
        graphics2d.setPaint(getCompletePaint());
        graphics2d.fill(double2);
    }
    if (double3 != null) {
        graphics2d.setPaint(getIncompletePaint());
        graphics2d.fill(double3);
    }
    if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
        java.awt.Stroke stroke = getItemOutlineStroke(i, j);
        Paint paint1 = getItemOutlinePaint(i, j);
        if (stroke != null && paint1 != null) {
            graphics2d.setStroke(stroke);
            graphics2d.setPaint(paint1);
            graphics2d.draw(double1);
        }
    }
    org.jfree.chart.labels.CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, ganttcategorydataset, i, j, categoryplot, categoryitemlabelgenerator, double1,
                false);
    if (categoryitemrendererstate.getInfo() != null) {
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection != null) {
            String s = null;
            CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j);
            if (categorytooltipgenerator != null)
                s = categorytooltipgenerator.generateToolTip(ganttcategorydataset, i, j);
            String s1 = null;
            if (getItemURLGenerator(i, j) != null)
                s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j);
            CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset,
                    ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j));
            entitycollection.add(categoryitementity);
        }
    }
}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private Paint getAreaFillPaint(CategoryPlot plot, Double plotWidth, Double plotHeight, Color mainColor,
        Color secondaryColor) {/*from  w  w  w  .j a  v a  2  s  . c o m*/
    return (plot.getOrientation() == PlotOrientation.VERTICAL)
            ? new GradientPaint(0.0f, 0.0f, mainColor, 0.0f, plotHeight.floatValue(), secondaryColor, true)
            : new GradientPaint(plotWidth.floatValue(), 0.0f, mainColor, 0.0f, 0.0f, secondaryColor, true);
}

From source file:edu.cuny.jfree.chart.renderer.category.ValueListShapeRenderer.java

@Override
public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea,
        final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis,
        final CategoryDataset dataset, final int row, final int column, final int pass) {

    final ListCategoryDataset setData = (ListCategoryDataset) dataset;

    final List list = setData.getList(row, column);
    if (list == null) {
        return;/*from  w  w  w  .j  a va 2s .  co m*/
    }

    final PlotOrientation orientation = plot.getOrientation();
    final double x = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        final Number value = (Number) iterator.next();
        final double y = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column);

        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y, x);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x, y);
        }
        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                g2.setPaint(getItemPaint(row, column));
                g2.fill(shape);
            } else {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);
            }
        }
        g2.setPaint(getItemPaint(row, column));

        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y, x, value.doubleValue() < 0.0D);
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x, y, value.doubleValue() < 0.0D);
            }
        }

        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if ((entities != null) && (shape != null)) {
                String tip = null;
                final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(dataset, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                }
                final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private void addItemLine(CategoryPlot plot, Collection<Line2D> lines, double previousItemX,
        double previousItemY, double currentItemX, double currentItemY) {

    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        lines.add(new Line2D.Double(previousItemX, previousItemY, currentItemX, currentItemY));
    } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        lines.add(new Line2D.Double(previousItemY, previousItemX, currentItemY, currentItemX));
    }//from  ww w  .  j av  a2 s .c om
}

From source file:org.jfree.eastwood.GCategoryAxis.java

/**
 * Creates a temporary list of ticks that can be used when drawing the axis.
 *
 * @param g2  the graphics device (used to get font measurements).
 * @param state  the axis state./*  w  w w.j av a  2  s .c  o  m*/
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = null;
    if (this.labels == null) {
        categories = plot.getCategories();
    } else {
        categories = new java.util.ArrayList(this.labels);
        // handle a little quirk in the Google Chart API - for a horizontal
        // bar chart, the labels on the axis get applied in reverse order
        // relative to the data values
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            Collections.reverse(categories);
        }
    }
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position = getCategoryLabelPositions().getLabelPosition(edge);
        float r = getMaximumCategoryLabelWidthRatio();
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, edge);
        } else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            } else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();
            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, position, g2));
            } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, position, g2));
            }
            Tick tick = new CategoryTick(category, label, position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java

/**
 * This function is taken directly from JFreeChart with adjustments to draw differently colored
 * items./*  w  w w  .  ja va 2  s .co  m*/
 * 
 * When updating JFreeChart this function must probably be adapted.
 * 
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset;
    List values = dataSet.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (getUseSeriesOffset()) {
            x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow,
                    visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
        } else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        int idx = dataSet.getValueIndex(row, column, i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, idx);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }
}