Search in sources :

Example 46 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class XYDifferenceRenderer method drawItemPass1.

/**
 * Draws the visual representation of a single data item, second pass.  In
 * the second pass, the renderer draws the lines and shapes for the
 * individual points in the two series.
 *
 * @param x_graphics  the graphics device.
 * @param x_dataArea  the area within which the data is being drawn.
 * @param x_info  collects information about the drawing.
 * @param x_plot  the plot (can be used to obtain standard color
 *         information etc).
 * @param x_domainAxis  the domain (horizontal) axis.
 * @param x_rangeAxis  the range (vertical) axis.
 * @param x_dataset  the dataset.
 * @param x_series  the series index (zero-based).
 * @param x_item  the item index (zero-based).
 * @param x_crosshairState  crosshair information for the plot
 *                          (<code>null</code> permitted).
 */
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) {
    Shape l_entityArea = null;
    EntityCollection l_entities = null;
    if (null != x_info) {
        l_entities = x_info.getOwner().getEntityCollection();
    }
    Paint l_seriesPaint = getItemPaint(x_series, x_item);
    Stroke l_seriesStroke = getItemStroke(x_series, x_item);
    x_graphics.setPaint(l_seriesPaint);
    x_graphics.setStroke(l_seriesStroke);
    PlotOrientation l_orientation = x_plot.getOrientation();
    RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
    RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
    double l_x0 = x_dataset.getXValue(x_series, x_item);
    double l_y0 = x_dataset.getYValue(x_series, x_item);
    double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
    double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
    if (getShapesVisible()) {
        Shape l_shape = getItemShape(x_series, x_item);
        if (l_orientation == PlotOrientation.HORIZONTAL) {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_y1, l_x1);
        } else {
            l_shape = ShapeUtilities.createTranslatedShape(l_shape, l_x1, l_y1);
        }
        if (l_shape.intersects(x_dataArea)) {
            x_graphics.setPaint(getItemPaint(x_series, x_item));
            x_graphics.fill(l_shape);
        }
        l_entityArea = l_shape;
    }
    // add an entity for the item...
    if (null != l_entities) {
        if (null == l_entityArea) {
            l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
        }
        String l_tip = null;
        XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item);
        if (null != l_tipGenerator) {
            l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
        }
        String l_url = null;
        XYURLGenerator l_urlGenerator = getURLGenerator();
        if (null != l_urlGenerator) {
            l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
        }
        XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
        l_entities.add(l_entity);
    }
    // draw the item label if there is one...
    if (isItemLabelVisible(x_series, x_item)) {
        drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0));
    }
    int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis);
    int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis);
    updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex, l_rangeAxisIndex, l_x1, l_y1, l_orientation);
    if (0 == x_item) {
        return;
    }
    double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
    double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
    Line2D l_line = null;
    if (PlotOrientation.HORIZONTAL == l_orientation) {
        l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
    } else if (PlotOrientation.VERTICAL == l_orientation) {
        l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
    }
    if ((null != l_line) && l_line.intersects(x_dataArea)) {
        x_graphics.setPaint(getItemPaint(x_series, x_item));
        x_graphics.setStroke(getItemStroke(x_series, x_item));
        x_graphics.draw(l_line);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) XYItemEntity(org.jfree.chart.entity.XYItemEntity) EntityCollection(org.jfree.chart.entity.EntityCollection) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 47 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class XYLineAndShapeRenderer method drawPrimaryLineAsPath.

/**
 * Draws the item (first pass). This method draws the lines
 * connecting the items. Instead of drawing separate lines,
 * a GeneralPath is constructed and drawn at the end of
 * the series painting.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataArea  the area within which the data is being drawn.
 */
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    State s = (State) state;
    // update path to reflect latest point
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        float x = (float) transX1;
        float y = (float) transY1;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            x = (float) transY1;
            y = (float) transX1;
        }
        if (s.isLastPointGood()) {
            s.seriesPath.lineTo(x, y);
        } else {
            s.seriesPath.moveTo(x, y);
        }
        s.setLastPointGood(true);
    } else {
        s.setLastPointGood(false);
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
        // draw path
        drawFirstPassShape(g2, pass, series, item, s.seriesPath);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CrosshairState(org.jfree.chart.plot.CrosshairState) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 48 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project qpid-broker-j by apache.

the class BaseChartBuilderTest method testBuildChart.

@Test
public void testBuildChart() {
    BaseChartBuilder chartBuilder = new ChartBuilder(_seriesBuilder, _strokeAndPaintApplier, _datasetHolder) {

        @Override
        protected JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) {
            assertEquals(CHART_TITLE, title);
            assertEquals(X_TITLE, xAxisTitle);
            assertEquals(Y_TITLE, yAxisTitle);
            return _jFreeChart;
        }
    };
    JFreeChart chart = chartBuilder.buildChart(_chartingDefinition);
    assertEquals(BaseChartBuilder.BLUE_GRADIENT, chart.getBackgroundPaint());
    assertEquals("The *second* subtitle of the generated chart should have the text from the chart definition", CHART_SUB_TITLE, ((TextTitle) chart.getSubtitle(1)).getText());
    verify(_seriesPainter).applySeriesAppearance(_jFreeChart, _seriesDefinitions, _strokeAndPaintApplier);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Dataset(org.jfree.data.general.Dataset) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 49 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project mzmine2 by mzmine.

the class ChartGestureDragDiffHandler method getOrientation.

/**
 * use default orientation or orientation of axis
 *
 * @param event
 * @return
 */
public Orientation getOrientation(ChartGestureEvent event) {
    ChartEntity ce = event.getEntity();
    if (ce instanceof AxisEntity) {
        JFreeChart chart = event.getChart();
        PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
        if (chart.getXYPlot() != null)
            plotorient = chart.getXYPlot().getOrientation();
        else if (chart.getCategoryPlot() != null)
            plotorient = chart.getCategoryPlot().getOrientation();
        Entity entity = event.getGesture().getEntity();
        if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL)) || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
            orient = Orientation.HORIZONTAL;
        else
            orient = Orientation.VERTICAL;
    }
    return orient;
}
Also used : AxisEntity(org.jfree.chart.entity.AxisEntity) AxisEntity(org.jfree.chart.entity.AxisEntity) ChartEntity(org.jfree.chart.entity.ChartEntity) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) PlotOrientation(org.jfree.chart.plot.PlotOrientation) ChartEntity(org.jfree.chart.entity.ChartEntity) JFreeChart(org.jfree.chart.JFreeChart)

Example 50 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project Openfire by igniterealtime.

the class GraphEngine method createTimeAreaChart.

/**
     * Generates a generic Time Area Chart.
     *
     * @param title      the title of the Chart.
     * @param valueLabel the Y Axis label.
     * @param data       the data to populate with.
     * @return the generated Chart.
     */
private JFreeChart createTimeAreaChart(String title, String color, String valueLabel, XYDataset data) {
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    DateAxis xAxis = generateTimeAxis();
    NumberAxis yAxis = new NumberAxis(valueLabel);
    NumberFormat formatter = NumberFormat.getNumberInstance(JiveGlobals.getLocale());
    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(0);
    yAxis.setNumberFormatOverride(formatter);
    XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);
    renderer.setOutline(true);
    return createChart(title, data, xAxis, yAxis, orientation, renderer, GraphDefinition.getDefinition(color));
}
Also used : XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberFormat(java.text.NumberFormat)

Aggregations

PlotOrientation (org.jfree.chart.plot.PlotOrientation)100 Paint (java.awt.Paint)52 RectangleEdge (org.jfree.ui.RectangleEdge)49 Rectangle2D (java.awt.geom.Rectangle2D)40 EntityCollection (org.jfree.chart.entity.EntityCollection)39 Line2D (java.awt.geom.Line2D)29 Stroke (java.awt.Stroke)20 Shape (java.awt.Shape)19 GeneralPath (java.awt.geom.GeneralPath)14 Range (org.jfree.data.Range)14 GradientPaint (java.awt.GradientPaint)13 JFreeChart (org.jfree.chart.JFreeChart)11 CategoryAxis (org.jfree.chart.axis.CategoryAxis)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Point2D (java.awt.geom.Point2D)9 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)9 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 AlphaComposite (java.awt.AlphaComposite)6 BasicStroke (java.awt.BasicStroke)6 Composite (java.awt.Composite)6