use of org.jfree.chart.labels.ItemLabelPosition in project mzmine2 by mzmine.
the class SpectraIdentificationLipidSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
totalSteps = massList.length;
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
// Check if lipids should be modified
if (searchForModifications == true) {
lipidModificationMasses = getLipidModificationMasses(lipidModification);
}
// Calculate how many possible lipids we will try
totalSteps = (((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length);
// Combine Strings
String annotation = "";
// Try all combinations of fatty acid lengths and double bonds
for (int j = 0; j < selectedLipids.length; j++) {
int numberOfAcylChains = selectedLipids[j].getNumberOfAcylChains();
int numberOfAlkylChains = selectedLipids[j].getNumberofAlkyChains();
for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
for (int i = 0; i < massList.length; i++) {
searchedMass = massList[i].getMZ();
// Task canceled?
if (isCanceled())
return;
// than minimal length, skip this lipid
if (((chainLength > 0) && (chainLength < minChainLength))) {
continue;
}
// doesn't make sense, so let's skip such lipids
if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
continue;
}
// Prepare a lipid instance
LipidIdentity lipidChain = new LipidIdentity(selectedLipids[j], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
annotation = findPossibleLipid(lipidChain, searchedMass);
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
annotation = findPossibleLipidModification(lipidChain, searchedMass);
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
}
finishedSteps++;
}
}
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of org.jfree.chart.labels.ItemLabelPosition in project aspro by JMMC-OpenDev.
the class InterferometerMapPanel method postInit.
/**
* This method is useful to set the models and specific features of initialized swing components :
*/
private void postInit() {
this.chart = ChartUtils.createSquareXYLineChart(null, null, true);
this.xyPlot = (SquareXYPlot) this.chart.getPlot();
final XYItemRenderer lineRenderer = this.xyPlot.getRenderer();
lineRenderer.setDefaultStroke(ChartUtils.LARGE_STROKE);
// Use Bubble Renderer for the first dataset :
this.xyPlot.setRenderer(0, new FastXYBubbleRenderer());
// Use Line Renderer for the second dataset :
this.xyPlot.setRenderer(1, lineRenderer);
// hide axes at [0,0] :
this.xyPlot.setDomainZeroBaselineVisible(false);
this.xyPlot.setRangeZeroBaselineVisible(false);
final XYItemRenderer renderer = this.xyPlot.getRenderer();
// station labels :
renderer.setDefaultItemLabelGenerator(new NameLabelGenerator());
renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BOTTOM_RIGHT));
renderer.setDefaultItemLabelsVisible(true);
// create new JMMC annotation (moving position):
this.aJMMC = AsproChartUtils.createJMMCAnnotation();
this.xyPlot.getRenderer().addAnnotation(this.aJMMC, Layer.BACKGROUND);
// add listener :
this.chart.addProgressListener(this);
this.chartPanel = ChartUtils.createSquareChartPanel(this.chart);
this.chartPanel.setMinimumSize(new Dimension(100, 100));
this.add(this.chartPanel);
}
use of org.jfree.chart.labels.ItemLabelPosition in project graphcode2vec by graphcode2vec.
the class BarRenderer method drawItemLabelForBar.
/**
* Draws an item label. This method is used for bars instead of
* {@link #drawItemLabel()} so that the bar can be used to calculate the
* label anchor point.
*
* @param g2 the graphics device.
* @param dataset the dataset.
* @param row the row.
* @param column the column.
* @param selected is the item selected?
* @param plot the plot.
* @param generator the label generator.
* @param bar the bar.
* @param negative a flag indicating a negative value.
*
* @since 1.2.0
*/
protected void drawItemLabelForBar(Graphics2D g2, CategoryPlot plot, CategoryDataset dataset, int row, int column, boolean selected, CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) {
String label = generator.generateLabel(dataset, row, column);
if (label == null) {
// nothing to do
return;
}
Font labelFont = getItemLabelFont(row, column, selected);
g2.setFont(labelFont);
Paint paint = getItemLabelPaint(row, column, selected);
g2.setPaint(paint);
// find out where to place the label...
ItemLabelPosition position = null;
if (!negative) {
position = getPositiveItemLabelPosition(row, column, selected);
} else {
position = getNegativeItemLabelPosition(row, column, selected);
}
// work out the label anchor point...
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());
if (isInternalAnchor(position.getItemLabelAnchor())) {
Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
if (bounds != null) {
if (!bar.contains(bounds.getBounds2D())) {
if (!negative) {
position = getPositiveItemLabelPositionFallback();
} else {
position = getNegativeItemLabelPositionFallback();
}
if (position != null) {
anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());
}
}
}
}
if (position != null) {
TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
}
use of org.jfree.chart.labels.ItemLabelPosition in project graphcode2vec by graphcode2vec.
the class AbstractCategoryItemRenderer method drawItemLabel.
/**
* Draws an item label.
*
* @param g2 the graphics device.
* @param orientation the orientation.
* @param dataset the dataset.
* @param row the row.
* @param column the column.
* @param selected is the item selected?
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param negative indicates a negative value (which affects the item
* label position).
*
* @since 1.2.0
*/
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, CategoryDataset dataset, int row, int column, boolean selected, double x, double y, boolean negative) {
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column, selected);
if (generator != null) {
Font labelFont = getItemLabelFont(row, column, selected);
Paint paint = getItemLabelPaint(row, column, selected);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = generator.generateLabel(dataset, row, column);
ItemLabelPosition position = null;
if (!negative) {
position = getPositiveItemLabelPosition(row, column, selected);
} else {
position = getNegativeItemLabelPosition(row, column, selected);
}
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
}
use of org.jfree.chart.labels.ItemLabelPosition in project graphcode2vec by graphcode2vec.
the class YIntervalRenderer method drawAdditionalItemLabel.
/**
* Draws an item label.
*
* @param g2 the graphics device.
* @param orientation the orientation.
* @param dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param negative indicates a negative value (which affects the item
* label position).
*/
private void drawAdditionalItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y) {
if (this.additionalItemLabelGenerator == null) {
return;
}
Font labelFont = getItemLabelFont(series, item, false);
Paint paint = getItemLabelPaint(series, item, false);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = this.additionalItemLabelGenerator.generateLabel(dataset, series, item);
ItemLabelPosition position = getNegativeItemLabelPosition(series, item, false);
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
Aggregations