org.jfree.chart.LegendItemCollection Java Examples

The following examples show how to use org.jfree.chart.LegendItemCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCategoryItemRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example #2
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example #3
Source File: LegendTitle.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fetches the latest legend items.
 */
protected void fetchLegendItems() {
    this.items.clear();
    RectangleEdge p = getPosition();
    if (RectangleEdge.isTopOrBottom(p)) {
        this.items.setArrangement(this.hLayout);
    }
    else {
        this.items.setArrangement(this.vLayout);
    }
    for (int s = 0; s < this.sources.length; s++) {
        LegendItemCollection legendItems = this.sources[s].getLegendItems();
        if (legendItems != null) {
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                LegendItem item = legendItems.get(i);
                Block block = createLegendItemBlock(item);
                this.items.add(block);
            }
        }
    }
}
 
Example #4
Source File: MultiplePiePlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fetches the legend items and checks the values.
 */
@Test
public void testGetLegendItems() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(35.0, "S1", "C1");
    dataset.addValue(45.0, "S1", "C2");
    dataset.addValue(55.0, "S2", "C1");
    dataset.addValue(15.0, "S2", "C2");
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    JFreeChart chart = new JFreeChart(plot);
    LegendItemCollection legendItems = plot.getLegendItems();
    assertEquals(2, legendItems.getItemCount());
    LegendItem item1 = legendItems.get(0);
    assertEquals("S1", item1.getLabel());
    assertEquals("S1", item1.getSeriesKey());
    assertEquals(0, item1.getSeriesIndex());
    assertEquals(dataset, item1.getDataset());
    assertEquals(0, item1.getDatasetIndex());

    LegendItem item2 = legendItems.get(1);
    assertEquals("S2", item2.getLabel());
    assertEquals("S2", item2.getSeriesKey());
    assertEquals(1, item2.getSeriesIndex());
    assertEquals(dataset, item2.getDataset());
    assertEquals(0, item2.getDatasetIndex());
}
 
Example #5
Source File: CategoryPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  By default, this method creates
 * a legend item for each series in each of the datasets.  You can change
 * this behaviour by overriding this method.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    // get the legend items for the datasets...
    for (CategoryDataset dataset: this.datasets.values()) {
        if (dataset != null) {
            int datasetIndex = indexOf(dataset);
            CategoryItemRenderer renderer = getRenderer(datasetIndex);
            if (renderer != null) {
                result.addAll(renderer.getLegendItems());
            }
        }
    }
    return result;
}
 
Example #6
Source File: PolarPlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_Renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
 
Example #7
Source File: LegendTitle.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Fetches the latest legend items.
 */
protected void fetchLegendItems() {
    this.items.clear();
    RectangleEdge p = getPosition();
    if (RectangleEdge.isTopOrBottom(p)) {
        this.items.setArrangement(this.hLayout);   
    }
    else {
        this.items.setArrangement(this.vLayout);   
    }
    for (int s = 0; s < this.sources.length; s++) {
        LegendItemCollection legendItems = this.sources[s].getLegendItems();
        if (legendItems != null) {
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                LegendItem item = legendItems.get(i);
                Block block = createLegendItemBlock(item);
                this.items.add(block);
            }
        }
    }
}
 
Example #8
Source File: PolarPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Some checks for the getLegendItems() method with multiple datasets.
 */
@Test
public void testGetLegendItems2() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    d1.addSeries(new XYSeries("A"));
    d1.addSeries(new XYSeries("B"));
    XYSeriesCollection d2 = new XYSeriesCollection();
    d2.addSeries(new XYSeries("C"));
    d2.addSeries(new XYSeries("D"));
    DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
    PolarPlot plot = new PolarPlot();
    plot.setDataset(d1);
    plot.setDataset(1, d2);
    plot.setRenderer(r);
    plot.setRenderer(1, new DefaultPolarItemRenderer());
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(4, items.getItemCount());
    LegendItem item1 = items.get(0);
    assertEquals("A", item1.getLabel());
    LegendItem item2 = items.get(1);
    assertEquals("B", item2.getLabel());
    LegendItem item3 = items.get(2);
    assertEquals("C", item3.getLabel());
    LegendItem item4 = items.get(3);
    assertEquals("D", item4.getLabel());
}
 
Example #9
Source File: CategoryPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  By default, this method creates
 * a legend item for each series in each of the datasets.  You can change
 * this behaviour by overriding this method.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    // get the legend items for the datasets...
    for (CategoryDataset dataset: this.datasets.values()) {
        if (dataset != null) {
            int datasetIndex = indexOf(dataset);
            CategoryItemRenderer renderer = getRenderer(datasetIndex);
            if (renderer != null) {
                result.addAll(renderer.getLegendItems());
            }
        }
    }
    return result;
}
 
Example #10
Source File: MeterPlot.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an item for each interval.
 *
 * @return A collection of legend items.
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    Iterator iterator = this.intervals.iterator();
    while (iterator.hasNext()) {
        MeterInterval mi = (MeterInterval) iterator.next();
        Paint color = mi.getBackgroundPaint();
        if (color == null) {
            color = mi.getOutlinePaint();
        }
        LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(),
                null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0),
                color);
        item.setDataset(getDataset());
        result.add(item);
    }
    return result;
}
 
Example #11
Source File: PolarPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_Renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
 
Example #12
Source File: PolarPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    XYSeriesCollection d = new XYSeriesCollection();
    d.addSeries(new XYSeries("A"));
    d.addSeries(new XYSeries("B"));
    DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
    PolarPlot plot = new PolarPlot();
    plot.setDataset(d);
    plot.setRenderer(r);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
    LegendItem item1 = items.get(0);
    assertEquals("A", item1.getLabel());
    LegendItem item2 = items.get(1);
    assertEquals("B", item2.getLabel());
}
 
Example #13
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a (possibly empty) collection of legend items for the series
 * that this renderer is responsible for drawing.
 *
 * @return The legend item collection (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.plot == null) {
        return new LegendItemCollection();
    }
    LegendItemCollection result = new LegendItemCollection();
    int index = this.plot.getIndexOf(this);
    XYDataset dataset = this.plot.getDataset(index);
    if (dataset != null) {
        int seriesCount = dataset.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }

    }
    return result;
}
 
Example #14
Source File: MeterPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns an item for each interval.
 *
 * @return A collection of legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    Iterator iterator = this.intervals.iterator();
    while (iterator.hasNext()) {
        MeterInterval mi = (MeterInterval) iterator.next();
        Paint color = mi.getBackgroundPaint();
        if (color == null) {
            color = mi.getOutlinePaint();
        }
        LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(),
                null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0),
                color);
        item.setDataset(getDataset());
        result.add(item);
    }
    return result;
}
 
Example #15
Source File: MeterPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an item for each interval.
 *
 * @return A collection of legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    Iterator iterator = this.intervals.iterator();
    while (iterator.hasNext()) {
        MeterInterval mi = (MeterInterval) iterator.next();
        Paint color = mi.getBackgroundPaint();
        if (color == null) {
            color = mi.getOutlinePaint();
        }
        LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(),
                null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0),
                color);
        item.setDataset(getDataset());
        result.add(item);
    }
    return result;
}
 
Example #16
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the radar chart.
 * 
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();

    List keys = null;

    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }

    if (keys != null) {
        int series = 0;
        Iterator iterator = keys.iterator();
        Shape shape = getLegendItemShape();

        while (iterator.hasNext()) {
            String label = iterator.next().toString();
            String description = label;

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke stroke = getSeriesOutlineStroke(series);
            LegendItem item = new LegendItem(label, description, 
                    null, null, shape, paint, stroke, outlinePaint);
            item.setDataset(getDataset());
            result.add(item);
            series++;
        }
    }

    return result;
}
 
Example #17
Source File: RadarChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
public LegendItemCollection getLegendItems() {
  final LegendItemCollection result = new LegendItemCollection();
  if ( getDataset() == null ) {
    return result;
  }
  List keys = null;
  final CategoryDataset dataset = getDataset();
  final TableOrder dataExtractOrder = getDataExtractOrder();
  if ( dataExtractOrder == TableOrder.BY_ROW ) {
    keys = dataset.getRowKeys();
  } else if ( dataExtractOrder == TableOrder.BY_COLUMN ) {
    keys = dataset.getColumnKeys();
  }
  if ( keys == null ) {
    return result;
  }

  int series = 0;
  final Iterator iterator = keys.iterator();
  final Shape shape = getLegendItemShape();
  while ( iterator.hasNext() ) {
    final Comparable key = (Comparable) iterator.next();
    if ( key instanceof GridCategoryItem ) {
      continue;
    }
    final String label = key.toString();
    final Paint paint = getSeriesPaint( series );
    final Paint outlinePaint = getSeriesOutlinePaint( series );
    final Stroke stroke = getSeriesOutlineStroke( series );
    final LegendItem item = new LegendItem( label, label,
      null, null, shape, paint, stroke, outlinePaint );
    item.setDataset( getDataset() );
    item.setSeriesKey( key );
    item.setSeriesIndex( series );
    result.add( item );
    series++;
  }
  return result;
}
 
Example #18
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example #19
Source File: 1_XYPlot.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        if (dataset != null) {
            XYItemRenderer renderer = getRenderer(datasetIndex);
            if (renderer == null) {
                renderer = getRenderer(0);
            }
            if (renderer != null) {
                int seriesCount = dataset.getSeriesCount();
                for (int i = 0; i < seriesCount; i++) {
                    if (renderer.isSeriesVisible(i)
                            && renderer.isSeriesVisibleInLegend(i)) {
                        LegendItem item = renderer.getLegendItem(
                                datasetIndex, i);
                        if (item != null) {
                            result.add(item);
                        }
                    }
                }
            }
        }
    }
    return result;
}
 
Example #20
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    for (XYDataset dataset : this.datasets.values()) {
        if (dataset == null) {
            continue;
        }
        int datasetIndex = indexOf(dataset);
        XYItemRenderer renderer = getRenderer(datasetIndex);
        if (renderer == null) {
            renderer = getRenderer(0);
        }
        if (renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                if (renderer.isSeriesVisible(i)
                        && renderer.isSeriesVisibleInLegend(i)) {
                    LegendItem item = renderer.getLegendItem(
                            datasetIndex, i);
                    if (item != null) {
                        result.add(item);
                    }
                }
            }
        }
    }
    return result;
}
 
Example #21
Source File: 1_XYPlot.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        if (dataset != null) {
            XYItemRenderer renderer = getRenderer(datasetIndex);
            if (renderer == null) {
                renderer = getRenderer(0);
            }
            if (renderer != null) {
                int seriesCount = dataset.getSeriesCount();
                for (int i = 0; i < seriesCount; i++) {
                    if (renderer.isSeriesVisible(i)
                            && renderer.isSeriesVisibleInLegend(i)) {
                        LegendItem item = renderer.getLegendItem(
                                datasetIndex, i);
                        if (item != null) {
                            result.add(item);
                        }
                    }
                }
            }
        }
    }
    return result;
}
 
Example #22
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some more cloning checks.
 */
@Test
public void testCloning3() {
    LegendItemCollection c1 = new LegendItemCollection();
    CategoryPlot p1 = new CategoryPlot();
    p1.setFixedLegendItems(c1);
    CategoryPlot p2 = null;
    try {
        p2 = (CategoryPlot) p1.clone();
    }
    catch (CloneNotSupportedException e) {
        fail("Cloning failed.");
        return;
    }
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    c1.add(new LegendItem("X", "XX", "tt", "url", true,
            new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red,
            true, Color.yellow, new BasicStroke(1.0f), true,
            new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f),
            Color.green));
    assertFalse(p1.equals(p2));
    p2.getFixedLegendItems().add(new LegendItem("X", "XX", "tt", "url",
            true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true,
            Color.red, true, Color.yellow, new BasicStroke(1.0f), true,
            new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f),
            Color.green));
    assertTrue(p1.equals(p2));
}
 
Example #23
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    // check the case where there is a secondary dataset that doesn't
    // have a renderer (i.e. falls back to renderer 0)
    XYDataset d0 = createDataset1();
    XYDataset d1 = createDataset2();
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setRenderer(0, r0);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
 
Example #24
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example #25
Source File: PiePlotTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Item 1", 1.0);
    dataset.setValue("Item 2", 2.0);
    dataset.setValue("Item 3", 0.0);
    dataset.setValue("Item 4", null);

    PiePlot plot = new PiePlot(dataset);
    plot.setIgnoreNullValues(false);
    plot.setIgnoreZeroValues(false);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(4, items.getItemCount());

    // check that null items are ignored if requested
    plot.setIgnoreNullValues(true);
    items = plot.getLegendItems();
    assertEquals(3, items.getItemCount());

    // check that zero items are ignored if requested
    plot.setIgnoreZeroValues(true);
    items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());

    // check that negative items are always ignored
    dataset.setValue("Item 5", -1.0);
    items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
 
Example #26
Source File: SpiderWebPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example #27
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    for (XYDataset dataset : this.datasets.values()) {
        if (dataset == null) {
            continue;
        }
        int datasetIndex = indexOf(dataset);
        XYItemRenderer renderer = getRenderer(datasetIndex);
        if (renderer == null) {
            renderer = getRenderer(0);
        }
        if (renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                if (renderer.isSeriesVisible(i)
                        && renderer.isSeriesVisibleInLegend(i)) {
                    LegendItem item = renderer.getLegendItem(
                            datasetIndex, i);
                    if (item != null) {
                        result.add(item);
                    }
                }
            }
        }
    }
    return result;
}
 
Example #28
Source File: SpiderWebPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example #29
Source File: MsMsVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {

  String command = event.getActionCommand();

  if (command.equals("SHOW_SPECTRUM")) {
    CursorPosition pos = getCursorPosition();
    if (pos != null) {
      SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber());
    }
  }

  if (command.equals("SETUP_AXES")) {
    AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot());
    dialog.setVisible(true);
  }

  if (command.equals("SHOW_DATA_POINTS")) {
    IDAPlot.switchDataPointsVisible();
  }

  if (command.equals("SWITCH_TOOLTIPS")) {
    if (tooltipMode) {
      IDAPlot.showPeaksTooltips(false);
      toolBar.setTooltipButton(false);
      tooltipMode = false;
    } else {
      IDAPlot.showPeaksTooltips(true);
      toolBar.setTooltipButton(true);
      tooltipMode = true;
    }
  }

  if (command.equals("FIND_SPECTRA")) {

    // Parameters
    final DoubleParameter inputMZ =
        new DoubleParameter("Ion m/z", "m/z value of ion to search for.");

    final MZToleranceParameter inputMZTolerance = new MZToleranceParameter();

    final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity",
        "Only ions with intensities above this value will be searched for.");

    final BooleanParameter inputNL = new BooleanParameter("Neutral Loss",
        "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.",
        false);

    final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color",
        "The color which the data points will be marked with.", Colors.values());

    Parameter<?>[] parameters = new Parameter<?>[5];
    parameters[0] = inputMZ;
    parameters[1] = inputMZTolerance;
    parameters[2] = inputIntensity;
    parameters[3] = inputNL;
    parameters[4] = inputColors;

    final ParameterSet parametersSearch = new SimpleParameterSet(parameters);
    ExitCode exitCode = parametersSearch.showSetupDialog(this, true);

    if (exitCode != ExitCode.OK)
      return;

    double searchMZ = parametersSearch.getParameter(inputMZ).getValue();
    MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue();
    double minIntensity = parametersSearch.getParameter(inputIntensity).getValue();
    boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue();

    Color highligtColor = Color.red;;
    if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) {
      highligtColor = Color.green;
    }
    if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) {
      highligtColor = Color.blue;
    }

    // Find and highlight spectra with specific ion
    dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss,
        highligtColor);

    // Add legend entry
    LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems();
    chartLegend.add(new LegendItem("Ion: " + searchMZ, "",
        "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: "
            + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity,
        "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor));
    IDAPlot.getXYPlot().setFixedLegendItems(chartLegend);
  }

}
 
Example #30
Source File: 1_MultiplePiePlot.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}