Search in sources :

Example 1 with CustomPieSectionLabelGenerator

use of org.baderlab.csplugins.enrichmentmap.style.charts.CustomPieSectionLabelGenerator in project EnrichmentMapApp by BaderLab.

the class RadialHeatMapLayer method createChart.

@Override
protected JFreeChart createChart(final PieDataset dataset) {
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    null, // data
    dataset, // include legend
    false, // tooltips
    false, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setCircular(true);
    plot.setStartAngle(startAngle);
    plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setInteriorGap(INTERIOR_GAP);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setShadowPaint(TRANSPARENT_COLOR);
    plot.setShadowXOffset(0.0);
    plot.setShadowYOffset(0.0);
    plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
    plot.setSimpleLabels(true);
    plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
    plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
    plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
    plot.setLabelShadowPaint(TRANSPARENT_COLOR);
    plot.setLabelPaint(labelColor);
    final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    Color upperColor = Color.BLUE;
    Color zeroColor = Color.WHITE;
    Color lowerColor = Color.RED;
    Color nanColor = DEFAULT_ITEM_BG_COLOR;
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        final int colorsSize = colors != null ? colors.size() : 0;
        if (colorsSize > 0)
            upperColor = colors.get(0);
        if (colorsSize > 1)
            zeroColor = colors.get(1);
        if (colorsSize > 2)
            lowerColor = colors.get(2);
        if (colorsSize > 3)
            nanColor = colors.get(3);
    }
    final List<?> keys = dataset.getKeys();
    final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
    for (int i = 0; i < keys.size(); i++) {
        String k = (String) keys.get(i);
        Double v = values.size() > i ? values.get(i) : null;
        final Color c;
        if (v == null)
            c = nanColor;
        else
            c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
        plot.setSectionPaint(k, c);
        plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
        plot.setSectionOutlineStroke(k, stroke);
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) CustomPieSectionLabelGenerator(org.baderlab.csplugins.enrichmentmap.style.charts.CustomPieSectionLabelGenerator) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 CustomPieSectionLabelGenerator (org.baderlab.csplugins.enrichmentmap.style.charts.CustomPieSectionLabelGenerator)1 JFreeChart (org.jfree.chart.JFreeChart)1 PiePlot (org.jfree.chart.plot.PiePlot)1 RectangleInsets (org.jfree.ui.RectangleInsets)1