Search in sources :

Example 51 with LegendItem

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

the class XYAreaRenderer2Test method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);
    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);
    XYAreaRenderer2 r = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/
    new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.LegendItem) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 52 with LegendItem

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

the class MultiplePiePlotTest method testGetLegendItems.

/**
 * 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());
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 53 with LegendItem

use of org.jfree.chart.LegendItem in project mzmine2 by mzmine.

the class MsMsVisualizerWindow method actionPerformed.

/**
 * @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);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) LegendItemCollection(org.jfree.chart.LegendItemCollection) ExitCode(net.sf.mzmine.util.ExitCode) Color(java.awt.Color) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) LegendItem(org.jfree.chart.LegendItem) Parameter(net.sf.mzmine.parameters.Parameter) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) CursorPosition(net.sf.mzmine.modules.visualization.tic.CursorPosition)

Aggregations

LegendItem (org.jfree.chart.LegendItem)53 Paint (java.awt.Paint)26 Test (org.junit.Test)25 NumberAxis (org.jfree.chart.axis.NumberAxis)21 JFreeChart (org.jfree.chart.JFreeChart)19 LegendItemCollection (org.jfree.chart.LegendItemCollection)19 XYPlot (org.jfree.chart.plot.XYPlot)19 Stroke (java.awt.Stroke)18 Shape (java.awt.Shape)17 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)13 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeries (org.jfree.data.xy.XYSeries)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 GradientPaint (java.awt.GradientPaint)7 BasicStroke (java.awt.BasicStroke)6 Iterator (java.util.Iterator)5 List (java.util.List)5