use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class BarRenderer method drawItemLabel.
/**
* 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 data the dataset.
* @param row the row.
* @param column the column.
* @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, CategoryDataset data, int row, int column, CategoryPlot plot, CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) {
String label = generator.generateLabel(data, row, column);
if (label == null) {
// nothing to do
return;
}
Font labelFont = getItemLabelFont(row, column);
g2.setFont(labelFont);
Paint paint = getItemLabelPaint(row, column);
g2.setPaint(paint);
// find out where to place the label...
ItemLabelPosition position;
if (!negative) {
position = getPositiveItemLabelPosition(row, column);
} else {
position = getNegativeItemLabelPosition(row, column);
}
// work out the label anchor point...
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());
if (isInternalAnchor(position.getItemLabelAnchor())) {
Shape bounds = TextUtils.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) {
TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
}
use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
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 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, CategoryDataset dataset, int row, int column, double x, double y, boolean negative) {
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null) {
Font labelFont = getItemLabelFont(row, column);
Paint paint = getItemLabelPaint(row, column);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = generator.generateLabel(dataset, row, column);
ItemLabelPosition position;
if (!negative) {
position = getPositiveItemLabelPosition(row, column);
} else {
position = getNegativeItemLabelPosition(row, column);
}
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
}
use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ChartFactory method createWaterfallChart.
/**
* Creates a waterfall chart. The chart object returned by this method
* uses a {@link CategoryPlot} instance as the plot, with a
* {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
* range axis, and a {@link WaterfallBarRenderer} as the renderer.
*
* @param title the chart title ({@code null} permitted).
* @param categoryAxisLabel the label for the category axis
* ({@code null} permitted).
* @param valueAxisLabel the label for the value axis ({@code null}
* permitted).
* @param dataset the dataset for the chart ({@code null} permitted).
* @param orientation the plot orientation (horizontal or vertical)
* ({@code null} NOT permitted).
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return A waterfall chart.
*/
public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
Args.nullNotPermitted(orientation, "orientation");
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
categoryAxis.setCategoryMargin(0.0);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
WaterfallBarRenderer renderer = new WaterfallBarRenderer();
if (orientation == PlotOrientation.HORIZONTAL) {
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI / 2.0);
renderer.setDefaultPositiveItemLabelPosition(position);
renderer.setDefaultNegativeItemLabelPosition(position);
} else if (orientation == PlotOrientation.VERTICAL) {
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
renderer.setDefaultPositiveItemLabelPosition(position);
renderer.setDefaultNegativeItemLabelPosition(position);
}
if (tooltips) {
StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
renderer.setDefaultToolTipGenerator(generator);
}
if (urls) {
renderer.setDefaultItemURLGenerator(new StandardCategoryURLGenerator());
}
CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
plot.clearRangeMarkers();
Marker baseline = new ValueMarker(0.0);
baseline.setPaint(Color.BLACK);
plot.addRangeMarker(baseline, Layer.FOREGROUND);
plot.setOrientation(orientation);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ChartFactory method createBarChart.
/**
* Creates a bar chart. The chart object returned by this method uses a
* {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
* for the domain axis, a {@link NumberAxis} as the range axis, and a
* {@link BarRenderer} as the renderer.
*
* @param title the chart title ({@code null} permitted).
* @param categoryAxisLabel the label for the category axis
* ({@code null} permitted).
* @param valueAxisLabel the label for the value axis
* ({@code null} permitted).
* @param dataset the dataset for the chart ({@code null} permitted).
* @param orientation the plot orientation (horizontal or vertical)
* ({@code null} not permitted).
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return A bar chart.
*/
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
Args.nullNotPermitted(orientation, "orientation");
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
BarRenderer renderer = new BarRenderer();
if (orientation == PlotOrientation.HORIZONTAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
renderer.setDefaultPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
renderer.setDefaultNegativeItemLabelPosition(position2);
} else if (orientation == PlotOrientation.VERTICAL) {
ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
renderer.setDefaultPositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
renderer.setDefaultNegativeItemLabelPosition(position2);
}
if (tooltips) {
renderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setDefaultItemURLGenerator(new StandardCategoryURLGenerator());
}
CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
plot.setOrientation(orientation);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
use of org.jfree.chart.labels.ItemLabelPosition in project seng438-a3-R41Ryan by seng438-winter-2022.
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 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, CategoryDataset dataset, int row, int column, double x, double y, boolean negative) {
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null) {
Font labelFont = getItemLabelFont(row, column);
Paint paint = getItemLabelPaint(row, column);
g2.setFont(labelFont);
g2.setPaint(paint);
String label = generator.generateLabel(dataset, row, column);
ItemLabelPosition position;
if (!negative) {
position = getPositiveItemLabelPosition(row, column);
} else {
position = getNegativeItemLabelPosition(row, column);
}
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