org.jfree.chart.labels.XYItemLabelGenerator Java Examples
The following examples show how to use
org.jfree.chart.labels.XYItemLabelGenerator.
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: DiagonalLineRenderer.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
public DiagonalLineRenderer() { super(true, true); setDefaultShapesFilled(true); setDrawOutlines(true); setUseFillPaint(true); for (int i = 0; i < plotDiagonalColors.length; i++) { setSeriesShape(i, diagonalPointsShape); setSeriesPaint(i, plotDiagonalColors[i]); setSeriesFillPaint(i, plotDiagonalColors[i]); } setDefaultShapesVisible(true); XYItemLabelGenerator diagonallabelGenerator = new DiagonalLineLabelGenerator(); setDefaultItemLabelGenerator(diagonallabelGenerator); setDefaultItemLabelsVisible(true); setDrawSeriesLineAsPath(true); }
Example #2
Source File: TICPlot.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
public synchronized void addLabelledPeakDataset(final XYDataset dataSet, final String label) { // Add standard peak data set. addPeakDataset(dataSet); // Do we have a label? if (label != null && label.length() > 0) { // Add peak label renderer and data set. final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, false); renderer.setDefaultItemLabelsVisible(labelsVisible == 2); renderer.setDefaultItemLabelPaint(LABEL_COLOR); addDataSetRenderer(dataSet, renderer); renderer.setDrawSeriesLineAsPath(true); renderer.setDefaultItemLabelGenerator(new XYItemLabelGenerator() { @Override public String generateLabel(final XYDataset xyDataSet, final int series, final int item) { return ((PeakDataSet) xyDataSet).isPeak(item) ? label : null; } }); havePeakLabels = true; } }
Example #3
Source File: ScatterPlotRenderer.java From mzmine3 with GNU General Public License v2.0 | 6 votes |
public ScatterPlotRenderer() { super(false, true); ScatterPlotToolTipGenerator toolTipGenerator = new ScatterPlotToolTipGenerator(); setDefaultToolTipGenerator(toolTipGenerator); XYItemLabelGenerator ItemlabelGenerator = new ScatterPlotItemLabelGenerator(); setDefaultItemLabelGenerator(ItemlabelGenerator); setDefaultItemLabelFont(new Font("SansSerif", Font.BOLD, 11)); setDefaultItemLabelPaint(Color.black); setDefaultItemLabelsVisible(false); setSeriesItemLabelsVisible(0, false); setSeriesPaint(0, pointColor); setSeriesShape(0, dataPointsShape); setSeriesItemLabelsVisible(1, false); setSeriesPaint(1, searchColor); setSeriesShape(1, dataPointsShape); setDrawSeriesLineAsPath(true); }
Example #4
Source File: AbstractXYItemRenderer.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Returns the label generator for a data item. This implementation simply * passes control to the {@link #getSeriesItemLabelGenerator(int)} method. * If, for some reason, you want a different generator for individual * items, you can override this method. * * @param series the series index (zero based). * @param item the item index (zero based). * * @return The generator (possibly <code>null</code>). */ @Override public XYItemLabelGenerator getItemLabelGenerator(int series, int item) { // return the generator for ALL series, if there is one... if (this.itemLabelGenerator != null) { return this.itemLabelGenerator; } // otherwise look up the generator table XYItemLabelGenerator generator = (XYItemLabelGenerator) this.itemLabelGeneratorMap.get(series); if (generator == null) { generator = this.baseItemLabelGenerator; } return generator; }
Example #5
Source File: AbstractXYItemRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #6
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 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, XYDataset dataset, int series, int item, boolean selected, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item, selected); if (generator != null) { Font labelFont = getItemLabelFont(series, item, selected); Paint paint = getItemLabelPaint(series, item, selected); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item, selected); } else { position = getNegativeItemLabelPosition(series, item, selected); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #7
Source File: AbstractXYItemRenderer.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #8
Source File: AbstractXYItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #9
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #10
Source File: AbstractXYItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #11
Source File: AbstractXYItemRenderer.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Creates a renderer where the tooltip generator and the URL generator are * both <code>null</code>. */ protected AbstractXYItemRenderer() { super(); this.itemLabelGenerator = null; this.itemLabelGeneratorMap = new HashMap<Integer, XYItemLabelGenerator>(); this.toolTipGenerator = null; this.toolTipGeneratorMap = new HashMap<Integer, XYToolTipGenerator>(); this.urlGenerator = null; this.backgroundAnnotations = new java.util.ArrayList(); this.foregroundAnnotations = new java.util.ArrayList(); this.legendItemLabelGenerator = new StandardXYSeriesLabelGenerator( "{0}"); }
Example #12
Source File: AbstractXYItemRenderer.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #13
Source File: ScatterPlotRenderer.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); String label = generator.generateLabel(dataset, series, item); if ((label == null) || (label.length() == 0)) return; // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation); FontMetrics metrics = g2.getFontMetrics(labelFont); int width = SwingUtilities.computeStringWidth(metrics, label) + 2; int height = metrics.getHeight(); int X = (int) (anchorPoint.getX() - (width / 2)); int Y = (int) (anchorPoint.getY() - (height)); g2.setPaint(searchColor); g2.fillRect(X, Y, width, height); super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative); }
Example #14
Source File: AbstractXYItemRenderer.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * 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). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example #15
Source File: MsSpectrumPlotWindowController.java From old-mzmine3 with GNU General Public License v2.0 | 4 votes |
private void configureRenderer(MsSpectrumDataSet dataset, int datasetIndex) { final MsSpectrumType renderingType = dataset.getRenderingType(); final XYPlot plot = chartNode.getChart().getXYPlot(); // Set renderer AbstractXYItemRenderer newRenderer; switch (renderingType) { case PROFILE: case THRESHOLDED: XYLineAndShapeRenderer newLineRenderer = new XYLineAndShapeRenderer(); final int lineThickness = dataset.getLineThickness(); newLineRenderer.setBaseShape(new Ellipse2D.Double(-2 * lineThickness, -2 * lineThickness, 4 * lineThickness + 1, 4 * lineThickness + 1)); newLineRenderer.setBaseShapesFilled(true); newLineRenderer.setBaseShapesVisible(dataset.getShowDataPoints()); newLineRenderer.setDrawOutlines(false); Stroke baseStroke = new BasicStroke(lineThickness); newLineRenderer.setBaseStroke(baseStroke); newRenderer = newLineRenderer; break; case CENTROIDED: default: XYBarRenderer newBarRenderer = new XYBarRenderer(); // Avoid gradients newBarRenderer.setBarPainter(new StandardXYBarPainter()); newBarRenderer.setShadowVisible(false); newRenderer = newBarRenderer; break; } // Set tooltips for legend newRenderer.setLegendItemToolTipGenerator((ds, series) -> { if (ds instanceof MsSpectrumDataSet) { return ((MsSpectrumDataSet) ds).getDescription(); } else return null; }); // Set color Color baseColor = dataset.getColor(); newRenderer.setBasePaint(JavaFXUtil.convertColorToAWT(baseColor)); // Set label generator XYItemLabelGenerator intelligentLabelGenerator = new IntelligentItemLabelGenerator(chartNode, 100, dataset); newRenderer.setBaseItemLabelGenerator(intelligentLabelGenerator); newRenderer.setBaseItemLabelPaint(JavaFXUtil.convertColorToAWT(labelsColor)); newRenderer.setBaseItemLabelsVisible(itemLabelsVisible.get()); // Set tooltip generator newRenderer.setBaseToolTipGenerator(dataset); plot.setRenderer(datasetIndex, newRenderer); }
Example #16
Source File: PseudoSpectraRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
@Override protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { // super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative); if (generator != null) { String label = generator.generateLabel(dataset, series, item); if (label != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); // split by \n String symbol = "\n"; String[] splitted = label.split(symbol); if (splitted.length > 1) { FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,"); int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight(); // draw more than one row for (int i = 0; i < splitted.length; i++) { int offset = -height * (splitted.length - i - 1); TextUtils.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(), (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } else { // one row TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } } }
Example #17
Source File: XYBarRenderer.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // 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()); } }
Example #18
Source File: XYBarRenderer.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // 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()); } }
Example #19
Source File: GenericChartTheme.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ protected JFreeChart createXYBarChart() throws JRException { IntervalXYDataset tmpDataset = (IntervalXYDataset)getDataset(); boolean isDate = true; if ( getChart().getDataset().getDatasetType() == JRChartDataset.XY_DATASET ){ isDate = false; } ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createXYBarChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression()), isDate, evaluateTextExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression()), tmpDataset, getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false ); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot)jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); // ((XYPlot)plot.getDomainAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((CategoryAxis)plot.getDomainAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); // ((NumberAxis)plot.getRangeAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((NumberAxis)plot.getRangeAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); XYBarRenderer itemRenderer = (XYBarRenderer)xyPlot.getRenderer(); itemRenderer.setBaseItemLabelGenerator((XYItemLabelGenerator)getLabelGenerator()); itemRenderer.setShadowVisible(false); JRBarPlot barPlot = (JRBarPlot)getPlot(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels(); itemRenderer.setBaseItemLabelsVisible( isShowLabels ); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), false, (Comparable<?>)evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable<?>)evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), true, (Comparable<?>)evaluateExpression(barPlot.getRangeAxisMinValueExpression()), (Comparable<?>)evaluateExpression(barPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
Example #20
Source File: XYBarRenderer.java From opensim-gui with Apache License 2.0 | 4 votes |
/** * Draws an item label. This method is overridden so that the bar can be * used to calculate the label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator. * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // 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()); } }
Example #21
Source File: SimpleChartTheme.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ protected JFreeChart createXYBarChart() throws JRException { IntervalXYDataset tmpDataset = (IntervalXYDataset)getDataset(); boolean isDate = true; if ( getChart().getDataset().getDatasetType() == JRChartDataset.XY_DATASET ){ isDate = false; } ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createXYBarChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression()), isDate, evaluateTextExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression()), tmpDataset, getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false ); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot)jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); // ((XYPlot)plot.getDomainAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((CategoryAxis)plot.getDomainAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); // ((NumberAxis)plot.getRangeAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((NumberAxis)plot.getRangeAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); XYBarRenderer itemRenderer = (XYBarRenderer)xyPlot.getRenderer(); itemRenderer.setBaseItemLabelGenerator((XYItemLabelGenerator)getLabelGenerator()); itemRenderer.setShadowVisible(false); JRBarPlot barPlot = (JRBarPlot)getPlot(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels(); itemRenderer.setBaseItemLabelsVisible( isShowLabels ); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), DateTickUnitType.DAY, (Comparable<?>)evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable<?>)evaluateExpression(barPlot.getDomainAxisMaxValueExpression()) ); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), DateTickUnitType.DAY, (Comparable<?>)evaluateExpression(barPlot.getRangeAxisMinValueExpression()), (Comparable<?>)evaluateExpression(barPlot.getRangeAxisMaxValueExpression()) ); return jfreeChart; }
Example #22
Source File: AbstractXYItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 3 votes |
/** * Sets the item label generator for a series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero based). * @param generator the generator (<code>null</code> permitted). */ @Override public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator) { this.itemLabelGeneratorMap.put(series, generator); fireChangeEvent(); }
Example #23
Source File: AbstractXYItemRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 3 votes |
/** * Sets the item label generator for a series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero based). * @param generator the generator (<code>null</code> permitted). */ @Override public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator) { this.itemLabelGeneratorMap.put(series, generator); fireChangeEvent(); }
Example #24
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Sets the default item label generator and, if requested, sends a * {@link RendererChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * @param notify notify listeners? * * @since 1.2.0 * * @see #getBaseItemLabelGenerator() */ public void setBaseItemLabelGenerator(XYItemLabelGenerator generator, boolean notify) { this.baseItemLabelGenerator = generator; if (notify) { fireChangeEvent(); } }
Example #25
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Returns the label generator for a data item. This implementation simply * passes control to the {@link #getSeriesItemLabelGenerator(int)} method. * If, for some reason, you want a different generator for individual * items, you can override this method. * * @param series the series index (zero based). * @param item the item index (zero based). * @param selected is the item selected? * * @return The generator (possibly <code>null</code>). * * @since 1.2.0 */ public XYItemLabelGenerator getItemLabelGenerator(int series, int item, boolean selected) { XYItemLabelGenerator generator = (XYItemLabelGenerator) this.itemLabelGeneratorList.get(series); if (generator == null) { generator = this.baseItemLabelGenerator; } return generator; }
Example #26
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Sets the item label generator for the specified series and, if * requested, sends a {@link RendererChangeEvent} to all registered * listeners. * * @param series the series index. * @param generator the label generator (<code>null</code> permitted); * @param notify notify listeners? * * @see #getSeriesItemLabelGenerator(int) * * @since 1.2.0 */ public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator, boolean notify) { this.itemLabelGeneratorList.set(series, generator); if (notify) { fireChangeEvent(); } }
Example #27
Source File: AbstractXYItemRenderer.java From SIMVA-SoS with Apache License 2.0 | 3 votes |
/** * Sets the item label generator for a series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero based). * @param generator the generator (<code>null</code> permitted). */ @Override public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator) { this.itemLabelGeneratorMap.put(series, generator); fireChangeEvent(); }
Example #28
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Sets the item label generator for the specified series and, if * requested, sends a {@link RendererChangeEvent} to all registered * listeners. * * @param series the series index. * @param generator the label generator (<code>null</code> permitted); * @param notify notify listeners? * * @see #getSeriesItemLabelGenerator(int) * * @since 1.2.0 */ public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator, boolean notify) { this.itemLabelGeneratorList.set(series, generator); if (notify) { fireChangeEvent(); } }
Example #29
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Returns the item label generator for a series. * * @param series the series index (zero based). * * @return The generator (possibly <code>null</code>). * * @see #setSeriesItemLabelGenerator(int, XYItemLabelGenerator) */ public XYItemLabelGenerator getSeriesItemLabelGenerator(int series) { return (XYItemLabelGenerator) this.itemLabelGeneratorList.get(series); }
Example #30
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Returns the base item label generator. * * @return The generator (possibly <code>null</code>). */ public XYItemLabelGenerator getBaseItemLabelGenerator() { return this.baseItemLabelGenerator; }