Search in sources :

Example 1 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ImageTitle method drawVertical.

/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawVertical(Graphics2D g2, Rectangle2D chartArea) {
    double startX = 0.0;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    if (padding != null) {
        topSpace = padding.calculateTopOutset(h);
        bottomSpace = padding.calculateBottomOutset(h);
        leftSpace = padding.calculateLeftOutset(w);
        rightSpace = padding.calculateRightOutset(w);
    }
    if (getPosition() == RectangleEdge.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else {
        startX = chartArea.getMaxX() - rightSpace - w;
    }
    // what is our alignment?
    VerticalAlignment alignment = getVerticalAlignment();
    double startY = 0.0;
    if (alignment == VerticalAlignment.CENTER) {
        startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
    } else if (alignment == VerticalAlignment.TOP) {
        startY = chartArea.getMinY() + topSpace;
    } else if (alignment == VerticalAlignment.BOTTOM) {
        startY = chartArea.getMaxY() - bottomSpace - h;
    }
    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Also used : Size2D(org.jfree.chart.util.Size2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) VerticalAlignment(org.jfree.chart.util.VerticalAlignment)

Example 2 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ImageTitle method drawHorizontal.

/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) {
    double startY = 0.0;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    topSpace = padding.calculateTopOutset(h);
    bottomSpace = padding.calculateBottomOutset(h);
    leftSpace = padding.calculateLeftOutset(w);
    rightSpace = padding.calculateRightOutset(w);
    if (getPosition() == RectangleEdge.TOP) {
        startY = chartArea.getY() + topSpace;
    } else {
        startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h;
    }
    // what is our alignment?
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    double startX = 0.0;
    if (horizontalAlignment == HorizontalAlignment.CENTER) {
        startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
    } else if (horizontalAlignment == HorizontalAlignment.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
    }
    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Also used : Size2D(org.jfree.chart.util.Size2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) HorizontalAlignment(org.jfree.chart.util.HorizontalAlignment)

Example 3 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @return A pie chart.
 *
 * @since 1.0.7
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, Locale locale) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) RectangleInsets(org.jfree.chart.util.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 4 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings that compares 2 datasets.
 * The colour of each section will be determined by the move from the value
 * for the same key in <code>previousDataset</code>. ie if value1 > value2
 * then the section will be in green (unless <code>greenForIncrease</code>
 * is <code>false</code>, in which case it would be <code>red</code>).
 * Each section can have a shade of red or green as the difference can be
 * tailored between 0% (black) and percentDiffForMaxScale% (bright
 * red/green).
 * <p>
 * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a
 * difference of 5% will have a half shade of red/green, a difference of
 * 10% or more will have a maximum shade/brightness of red/green.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 * <p>
 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
 * Xhenseval</a>.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param previousDataset  the dataset for the last run, this will be used
 *                         to compare each key in the dataset
 * @param percentDiffForMaxScale scale goes from bright red/green to black,
 *                               percentDiffForMaxScale indicate the change
 *                               required to reach top scale.
 * @param greenForIncrease  an increase since previousDataset will be
 *                          displayed in green (decrease red) if true.
 * @param legend  a flag specifying whether or not a legend is required.
 * @param subTitle displays a subtitle with colour scheme if true
 * @param showDifference  create a new dataset that will show the %
 *                        difference between the two datasets.
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean subTitle, boolean showDifference) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    List keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }
    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (Iterator it = keys.iterator(); it.hasNext(); ) {
        Comparable key = (Comparable) it.next();
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);
        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue);
            }
        }
    }
    if (showDifference) {
        plot.setDataset(series);
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("Tahoma", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }
    currentTheme.apply(chart);
    return chart;
}
Also used : DefaultPieDataset(org.jfree.data.pie.DefaultPieDataset) Color(java.awt.Color) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Font(java.awt.Font) TextTitle(org.jfree.chart.title.TextTitle) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) Iterator(java.util.Iterator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) RectangleInsets(org.jfree.chart.util.RectangleInsets) List(java.util.List)

Example 5 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ChartFactory method createPolarChart.

/**
 * Creates a polar plot for the specified dataset (x-values interpreted as
 * angles in degrees).  The chart object returned by this method uses a
 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for
 * the radial axis.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param legend  legend required?
 *
 * @return A chart.
 */
public static JFreeChart createPolarChart(String title, XYDataset dataset, boolean legend) {
    PolarPlot plot = new PolarPlot();
    plot.setDataset(dataset);
    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAxisLineVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxis(rangeAxis);
    plot.setRenderer(new DefaultPolarItemRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) PolarPlot(org.jfree.chart.plot.PolarPlot) DefaultPolarItemRenderer(org.jfree.chart.renderer.DefaultPolarItemRenderer) RectangleInsets(org.jfree.chart.util.RectangleInsets)

Aggregations

RectangleInsets (org.jfree.chart.util.RectangleInsets)44 Rectangle2D (java.awt.geom.Rectangle2D)21 Shape (java.awt.Shape)13 Font (java.awt.Font)11 FontMetrics (java.awt.FontMetrics)10 AlphaComposite (java.awt.AlphaComposite)8 Composite (java.awt.Composite)8 Paint (java.awt.Paint)8 AxisState (org.jfree.chart.axis.AxisState)8 AxisSpace (org.jfree.chart.axis.AxisSpace)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 Iterator (java.util.Iterator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 RectangleEdge (org.jfree.chart.util.RectangleEdge)6 BasicStroke (java.awt.BasicStroke)4 Rectangle (java.awt.Rectangle)4 Stroke (java.awt.Stroke)4 Point2D (java.awt.geom.Point2D)4