use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.
the class LegendTitle method fetchLegendItems.
/**
* 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);
}
if (this.sortOrder.equals(SortOrder.ASCENDING)) {
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++) {
addItemBlock(legendItems.get(i));
}
}
}
} else {
for (int s = this.sources.length - 1; s >= 0; s--) {
LegendItemCollection legendItems = this.sources[s].getLegendItems();
if (legendItems != null) {
for (int i = legendItems.getItemCount() - 1; i >= 0; i--) {
addItemBlock(legendItems.get(i));
}
}
}
}
}
use of org.jfree.chart.LegendItemCollection in project mzmine2 by mzmine.
the class MirrorScanWindow method setScans.
/**
* Based on a data base match to a spectral library
*
* @param row
* @param db
*/
public void setScans(SpectralDBPeakIdentity db) {
Scan scan = db.getQueryScan();
if (scan == null)
return;
// get highest data intensity to calc relative intensity
double mostIntenseQuery = Arrays.stream(db.getQueryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
double mostIntenseDB = Arrays.stream(db.getLibraryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
if (mostIntenseDB == 0d)
logger.warning("This data set has no original data points in the library spectrum (development error)");
if (mostIntenseQuery == 0d)
logger.warning("This data set has no original data points in the query spectrum (development error)");
if (mostIntenseDB == 0d || mostIntenseQuery == 0d)
return;
// get colors for vision
Vision vision = MZmineCore.getConfiguration().getColorVision();
// colors for the different DataPointsTags:
final Color[] colors = new Color[] { // black = filtered
Color.black, // unaligned
ColorPalettes.getNegativeColor(vision), // aligned
ColorPalettes.getPositiveColor(vision) };
// scan a
double precursorMZA = scan.getPrecursorMZ();
double rtA = scan.getRetentionTime();
Double precursorMZB = db.getEntry().getPrecursorMZ();
Double rtB = (Double) db.getEntry().getField(DBEntryField.RT).orElse(0d);
contentPane.removeAll();
// create without data
mirrorSpecrumPlot = SpectrumChartFactory.createMirrorChartPanel("Query: " + scan.getScanDefinition(), precursorMZA, rtA, null, "Library: " + db.getName(), precursorMZB == null ? 0 : precursorMZB, rtB, null, false, true);
mirrorSpecrumPlot.setMaximumDrawWidth(4200);
mirrorSpecrumPlot.setMaximumDrawHeight(2500);
// add data
DataPoint[][] query = new DataPoint[tags.length][];
DataPoint[][] library = new DataPoint[tags.length][];
for (int i = 0; i < tags.length; i++) {
DataPointsTag tag = tags[i];
query[i] = db.getQueryDataPoints(tag);
library[i] = db.getLibraryDataPoints(tag);
}
// add datasets and renderer
// set up renderer
CombinedDomainXYPlot domainPlot = (CombinedDomainXYPlot) mirrorSpecrumPlot.getChart().getXYPlot();
NumberAxis axis = (NumberAxis) domainPlot.getDomainAxis();
axis.setLabel("m/z");
XYPlot queryPlot = (XYPlot) domainPlot.getSubplots().get(0);
XYPlot libraryPlot = (XYPlot) domainPlot.getSubplots().get(1);
// add all datapoints to a dataset that are not present in subsequent masslist
for (int i = 0; i < tags.length; i++) {
DataPointsTag tag = tags[i];
PseudoSpectrumDataSet qdata = new PseudoSpectrumDataSet(true, "Query " + tag.toRemainderString());
for (DataPoint dp : query[i]) {
// not contained in other
if (notInSubsequentMassList(dp, query, i) && mostIntenseQuery > 0)
qdata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseQuery * 100d, null);
}
PseudoSpectrumDataSet ldata = new PseudoSpectrumDataSet(true, "Library " + tag.toRemainderString());
for (DataPoint dp : library[i]) {
if (notInSubsequentMassList(dp, library, i) && mostIntenseDB > 0)
ldata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseDB * 100d, null);
}
Color color = colors[i];
PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(color, false);
PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(color, false);
queryPlot.setDataset(i, qdata);
queryPlot.setRenderer(i, renderer);
libraryPlot.setDataset(i, ldata);
libraryPlot.setRenderer(i, renderer2);
}
// add legend
LegendItem item;
LegendItemCollection collection = new LegendItemCollection();
for (int i = 0; i < tags.length; i++) {
item = new LegendItem(tags[i].toRemainderString(), colors[i]);
collection.add(item);
}
mirrorSpecrumPlot.getChart().removeLegend();
LegendTitle legend = new LegendTitle(() -> collection);
legend.setPosition(RectangleEdge.BOTTOM);
mirrorSpecrumPlot.getChart().addLegend(legend);
// set y axis title
queryPlot.getRangeAxis().setLabel("rel. intensity [%] (query)");
libraryPlot.getRangeAxis().setLabel("rel. intensity [%] (library)");
contentPane.add(mirrorSpecrumPlot, BorderLayout.CENTER);
contentPane.revalidate();
contentPane.repaint();
}
use of org.jfree.chart.LegendItemCollection in project tdq-studio-se by Talend.
the class ChartDecorator method setLegendFont.
/**
* if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
*
* @param chart
*/
private static void setLegendFont(JFreeChart chart) {
Font font;
LegendTitle legend = chart.getLegend();
if (legend != null) {
// $NON-NLS-1$
font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
// get legend label to judge if it contains CJK.
LegendItemSource[] sources = legend.getSources();
Set<String> itemLabels = new HashSet<String>();
for (LegendItemSource source : sources) {
LegendItemCollection legendItems = source.getLegendItems();
for (int i = 0; i < legendItems.getItemCount(); i++) {
String label = legendItems.get(i).getLabel();
if (label != null) {
itemLabels.add(label);
}
}
}
if (isContainCJKCharacter(itemLabels.toArray())) {
font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
}
legend.setItemFont(font);
}
}
use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.
the class MultiplePiePlot method getLegendItems.
/**
* Returns a collection of legend items for the pie chart.
*
* @return The legend items.
*/
@Override
public LegendItemCollection getLegendItems() {
LegendItemCollection result = new LegendItemCollection();
if (this.dataset == null) {
return result;
}
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) {
return result;
}
int section = 0;
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Comparable key = (Comparable) iterator.next();
// TODO: use a generator here
String label = key.toString();
String description = label;
Paint paint = (Paint) this.sectionPaints.get(key);
LegendItem item = new LegendItem(label, description, null, null, getLegendItemShape(), paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
item.setSeriesKey(key);
item.setSeriesIndex(section);
item.setDataset(getDataset());
result.add(item);
section++;
}
if (this.limit > 0.0) {
LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(), this.aggregatedItemsKey.toString(), null, null, getLegendItemShape(), this.aggregatedItemsPaint, Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
result.add(a);
}
return result;
}
use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.
the class CategoryPlotTest method testEquals.
/**
* Test that the equals() method differentiates all the required fields.
*/
@Test
public void testEquals() {
CategoryPlot plot1 = new CategoryPlot();
CategoryPlot plot2 = new CategoryPlot();
assertTrue(plot1.equals(plot2));
assertTrue(plot2.equals(plot1));
// orientation...
plot1.setOrientation(PlotOrientation.HORIZONTAL);
assertFalse(plot1.equals(plot2));
plot2.setOrientation(PlotOrientation.HORIZONTAL);
assertTrue(plot1.equals(plot2));
// axisOffset...
plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
assertFalse(plot1.equals(plot2));
plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
assertTrue(plot1.equals(plot2));
// domainAxis - no longer a separate field but test anyway...
plot1.setDomainAxis(new CategoryAxis("Category Axis"));
assertFalse(plot1.equals(plot2));
plot2.setDomainAxis(new CategoryAxis("Category Axis"));
assertTrue(plot1.equals(plot2));
// domainAxes...
plot1.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
assertFalse(plot1.equals(plot2));
plot2.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
assertTrue(plot1.equals(plot2));
// domainAxisLocation - no longer a separate field but test anyway...
plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
assertFalse(plot1.equals(plot2));
plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
assertTrue(plot1.equals(plot2));
// domainAxisLocations...
plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
assertFalse(plot1.equals(plot2));
plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
assertTrue(plot1.equals(plot2));
// draw shared domain axis...
plot1.setDrawSharedDomainAxis(!plot1.getDrawSharedDomainAxis());
assertFalse(plot1.equals(plot2));
plot2.setDrawSharedDomainAxis(!plot2.getDrawSharedDomainAxis());
assertTrue(plot1.equals(plot2));
// rangeAxis - no longer a separate field but test anyway...
plot1.setRangeAxis(new NumberAxis("Range Axis"));
assertFalse(plot1.equals(plot2));
plot2.setRangeAxis(new NumberAxis("Range Axis"));
assertTrue(plot1.equals(plot2));
// rangeAxes...
plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
assertFalse(plot1.equals(plot2));
plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
assertTrue(plot1.equals(plot2));
// rangeAxisLocation - no longer a separate field but test anyway...
plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
assertFalse(plot1.equals(plot2));
plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
assertTrue(plot1.equals(plot2));
// rangeAxisLocations...
plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
assertFalse(plot1.equals(plot2));
plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
assertTrue(plot1.equals(plot2));
// datasetToDomainAxisMap...
plot1.mapDatasetToDomainAxis(11, 11);
assertFalse(plot1.equals(plot2));
plot2.mapDatasetToDomainAxis(11, 11);
assertTrue(plot1.equals(plot2));
// datasetToRangeAxisMap...
plot1.mapDatasetToRangeAxis(11, 11);
assertFalse(plot1.equals(plot2));
plot2.mapDatasetToRangeAxis(11, 11);
assertTrue(plot1.equals(plot2));
// renderer - no longer a separate field but test anyway...
plot1.setRenderer(new AreaRenderer());
assertFalse(plot1.equals(plot2));
plot2.setRenderer(new AreaRenderer());
assertTrue(plot1.equals(plot2));
// renderers...
plot1.setRenderer(11, new AreaRenderer());
assertFalse(plot1.equals(plot2));
plot2.setRenderer(11, new AreaRenderer());
assertTrue(plot1.equals(plot2));
// rendering order...
plot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
assertFalse(plot1.equals(plot2));
plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
assertTrue(plot1.equals(plot2));
// columnRenderingOrder...
plot1.setColumnRenderingOrder(SortOrder.DESCENDING);
assertFalse(plot1.equals(plot2));
plot2.setColumnRenderingOrder(SortOrder.DESCENDING);
assertTrue(plot1.equals(plot2));
// rowRenderingOrder...
plot1.setRowRenderingOrder(SortOrder.DESCENDING);
assertFalse(plot1.equals(plot2));
plot2.setRowRenderingOrder(SortOrder.DESCENDING);
assertTrue(plot1.equals(plot2));
// domainGridlinesVisible
plot1.setDomainGridlinesVisible(true);
assertFalse(plot1.equals(plot2));
plot2.setDomainGridlinesVisible(true);
assertTrue(plot1.equals(plot2));
// domainGridlinePosition
plot1.setDomainGridlinePosition(CategoryAnchor.END);
assertFalse(plot1.equals(plot2));
plot2.setDomainGridlinePosition(CategoryAnchor.END);
assertTrue(plot1.equals(plot2));
// domainGridlineStroke
Stroke stroke = new BasicStroke(2.0f);
plot1.setDomainGridlineStroke(stroke);
assertFalse(plot1.equals(plot2));
plot2.setDomainGridlineStroke(stroke);
assertTrue(plot1.equals(plot2));
// domainGridlinePaint
plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow));
assertFalse(plot1.equals(plot2));
plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow));
assertTrue(plot1.equals(plot2));
// rangeGridlinesVisible
plot1.setRangeGridlinesVisible(false);
assertFalse(plot1.equals(plot2));
plot2.setRangeGridlinesVisible(false);
assertTrue(plot1.equals(plot2));
// rangeGridlineStroke
plot1.setRangeGridlineStroke(stroke);
assertFalse(plot1.equals(plot2));
plot2.setRangeGridlineStroke(stroke);
assertTrue(plot1.equals(plot2));
// rangeGridlinePaint
plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
assertFalse(plot1.equals(plot2));
plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
assertTrue(plot1.equals(plot2));
// anchorValue
plot1.setAnchorValue(100.0);
assertFalse(plot1.equals(plot2));
plot2.setAnchorValue(100.0);
assertTrue(plot1.equals(plot2));
// rangeCrosshairVisible
plot1.setRangeCrosshairVisible(true);
assertFalse(plot1.equals(plot2));
plot2.setRangeCrosshairVisible(true);
assertTrue(plot1.equals(plot2));
// rangeCrosshairValue
plot1.setRangeCrosshairValue(100.0);
assertFalse(plot1.equals(plot2));
plot2.setRangeCrosshairValue(100.0);
assertTrue(plot1.equals(plot2));
// rangeCrosshairStroke
plot1.setRangeCrosshairStroke(stroke);
assertFalse(plot1.equals(plot2));
plot2.setRangeCrosshairStroke(stroke);
assertTrue(plot1.equals(plot2));
// rangeCrosshairPaint
plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow));
assertFalse(plot1.equals(plot2));
plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow));
assertTrue(plot1.equals(plot2));
// rangeCrosshairLockedOnData
plot1.setRangeCrosshairLockedOnData(false);
assertFalse(plot1.equals(plot2));
plot2.setRangeCrosshairLockedOnData(false);
assertTrue(plot1.equals(plot2));
// foreground domain markers
plot1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);
assertFalse(plot1.equals(plot2));
plot2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);
assertTrue(plot1.equals(plot2));
// background domain markers
plot1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);
assertFalse(plot1.equals(plot2));
plot2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);
assertTrue(plot1.equals(plot2));
// range markers - no longer separate fields but test anyway...
plot1.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
assertFalse(plot1.equals(plot2));
plot2.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
assertTrue(plot1.equals(plot2));
plot1.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
assertFalse(plot1.equals(plot2));
plot2.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
assertTrue(plot1.equals(plot2));
// foreground range markers...
plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
assertFalse(plot1.equals(plot2));
plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
assertTrue(plot1.equals(plot2));
// background range markers...
plot1.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
assertFalse(plot1.equals(plot2));
plot2.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
assertTrue(plot1.equals(plot2));
// annotations
plot1.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0));
assertFalse(plot1.equals(plot2));
plot2.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0));
assertTrue(plot1.equals(plot2));
// weight
plot1.setWeight(3);
assertFalse(plot1.equals(plot2));
plot2.setWeight(3);
assertTrue(plot1.equals(plot2));
// fixed domain axis space...
plot1.setFixedDomainAxisSpace(new AxisSpace());
assertFalse(plot1.equals(plot2));
plot2.setFixedDomainAxisSpace(new AxisSpace());
assertTrue(plot1.equals(plot2));
// fixed range axis space...
plot1.setFixedRangeAxisSpace(new AxisSpace());
assertFalse(plot1.equals(plot2));
plot2.setFixedRangeAxisSpace(new AxisSpace());
assertTrue(plot1.equals(plot2));
// fixed legend items
plot1.setFixedLegendItems(new LegendItemCollection());
assertFalse(plot1.equals(plot2));
plot2.setFixedLegendItems(new LegendItemCollection());
assertTrue(plot1.equals(plot2));
// crosshairDatasetIndex
plot1.setCrosshairDatasetIndex(99);
assertFalse(plot1.equals(plot2));
plot2.setCrosshairDatasetIndex(99);
assertTrue(plot1.equals(plot2));
// domainCrosshairColumnKey
plot1.setDomainCrosshairColumnKey("A");
assertFalse(plot1.equals(plot2));
plot2.setDomainCrosshairColumnKey("A");
assertTrue(plot1.equals(plot2));
// domainCrosshairRowKey
plot1.setDomainCrosshairRowKey("B");
assertFalse(plot1.equals(plot2));
plot2.setDomainCrosshairRowKey("B");
assertTrue(plot1.equals(plot2));
// domainCrosshairVisible
plot1.setDomainCrosshairVisible(true);
assertFalse(plot1.equals(plot2));
plot2.setDomainCrosshairVisible(true);
assertTrue(plot1.equals(plot2));
// domainCrosshairPaint
plot1.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertFalse(plot1.equals(plot2));
plot2.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertTrue(plot1.equals(plot2));
// domainCrosshairStroke
plot1.setDomainCrosshairStroke(new BasicStroke(1.23f));
assertFalse(plot1.equals(plot2));
plot2.setDomainCrosshairStroke(new BasicStroke(1.23f));
assertTrue(plot1.equals(plot2));
plot1.setRangeMinorGridlinesVisible(true);
assertFalse(plot1.equals(plot2));
plot2.setRangeMinorGridlinesVisible(true);
assertTrue(plot1.equals(plot2));
plot1.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertFalse(plot1.equals(plot2));
plot2.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertTrue(plot1.equals(plot2));
plot1.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
assertFalse(plot1.equals(plot2));
plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
assertTrue(plot1.equals(plot2));
plot1.setRangeZeroBaselineVisible(!plot1.isRangeZeroBaselineVisible());
assertFalse(plot1.equals(plot2));
plot2.setRangeZeroBaselineVisible(!plot2.isRangeZeroBaselineVisible());
assertTrue(plot1.equals(plot2));
plot1.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertFalse(plot1.equals(plot2));
plot2.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
assertTrue(plot1.equals(plot2));
plot1.setRangeZeroBaselineStroke(new BasicStroke(1.23f));
assertFalse(plot1.equals(plot2));
plot2.setRangeZeroBaselineStroke(new BasicStroke(1.23f));
assertTrue(plot1.equals(plot2));
// shadowGenerator
plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
assertFalse(plot1.equals(plot2));
plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
assertTrue(plot1.equals(plot2));
plot1.setShadowGenerator(null);
assertFalse(plot1.equals(plot2));
plot2.setShadowGenerator(null);
assertTrue(plot1.equals(plot2));
}
Aggregations