Search in sources :

Example 51 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlot method drawDomainMarkers.

/**
 * Draws the domain markers (if any) for an axis and layer.  This method is
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 *
 * @see #drawRangeMarkers(Graphics2D, Rectangle2D, int, Layer)
 */
protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) {
    CategoryItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }
    Collection markers = getDomainMarkers(index, layer);
    CategoryAxis axis = getDomainAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            CategoryMarker marker = (CategoryMarker) iterator.next();
            r.drawDomainMarker(g2, this, axis, marker, dataArea);
        }
    }
}
Also used : AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Iterator(java.util.Iterator) LegendItemCollection(org.jfree.chart.LegendItemCollection) Collection(java.util.Collection) AxisCollection(org.jfree.chart.axis.AxisCollection)

Example 52 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlot method getDataRange.

/**
 * Returns the range of data values that will be plotted against the range
 * axis.  If the dataset is <code>null</code>, this method returns
 * <code>null</code>.
 *
 * @param axis  the axis.
 *
 * @return The data range.
 */
@Override
public Range getDataRange(ValueAxis axis) {
    Range result = null;
    List<CategoryDataset> mappedDatasets = new ArrayList<CategoryDataset>();
    int rangeIndex = findRangeAxisIndex(axis);
    if (rangeIndex >= 0) {
        mappedDatasets.addAll(datasetsMappedToRangeAxis(rangeIndex));
    } else if (axis == getRangeAxis()) {
        mappedDatasets.addAll(datasetsMappedToRangeAxis(0));
    }
    // of the ranges.
    for (CategoryDataset d : mappedDatasets) {
        CategoryItemRenderer r = getRendererForDataset(d);
        if (r != null) {
            result = Range.combine(result, r.findRangeBounds(d));
        }
    }
    return result;
}
Also used : AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryDataset(org.jfree.data.category.CategoryDataset) ArrayList(java.util.ArrayList) Range(org.jfree.data.Range) Paint(java.awt.Paint)

Example 53 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlot method getRendererForDataset.

/**
 * Returns the renderer for the specified dataset.  If the dataset doesn't
 * belong to the plot, this method will return <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The renderer (possibly <code>null</code>).
 */
public CategoryItemRenderer getRendererForDataset(CategoryDataset dataset) {
    int datasetIndex = indexOf(dataset);
    if (datasetIndex < 0) {
        return null;
    }
    CategoryItemRenderer renderer = this.renderers.get(datasetIndex);
    if (renderer == null) {
        return getRenderer();
    }
    return renderer;
}
Also used : AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Paint(java.awt.Paint)

Example 54 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testMapDatasetToDomainAxis.

@Test
public void testMapDatasetToDomainAxis() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(11, xAxis2);
    // add a second dataset
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);
    assertEquals(xAxis, plot.getDomainAxisForDataset(99));
    // now map the dataset to the second xAxis
    plot.mapDatasetToDomainAxis(99, 11);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(99));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 55 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testSetRenderer.

/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
@Test
public void testSetRenderer() {
    CategoryPlot plot = new CategoryPlot();
    CategoryItemRenderer renderer = new LineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Test(org.junit.Test)

Aggregations

CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)70 CategoryPlot (org.jfree.chart.plot.CategoryPlot)36 Test (org.junit.Test)32 CategoryAxis (org.jfree.chart.axis.CategoryAxis)23 CategoryDataset (org.jfree.data.category.CategoryDataset)20 AbstractCategoryItemRenderer (org.jfree.chart.renderer.category.AbstractCategoryItemRenderer)14 Paint (java.awt.Paint)13 NumberAxis (org.jfree.chart.axis.NumberAxis)13 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)12 DefaultCategoryItemRenderer (org.jfree.chart.renderer.category.DefaultCategoryItemRenderer)12 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)12 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)11 ValueAxis (org.jfree.chart.axis.ValueAxis)10 CategoryToolTipGenerator (org.jfree.chart.labels.CategoryToolTipGenerator)10 CategoryURLGenerator (org.jfree.chart.urls.CategoryURLGenerator)10 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)9 JFreeChart (org.jfree.chart.JFreeChart)6 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)5 Rectangle2D (java.awt.geom.Rectangle2D)4