Search in sources :

Example 1 with CustomPieSectionLabelGenerator

use of org.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator in project cytoscape-impl by cytoscape.

the class PieLayer 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);
    final List<?> keys = dataset.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final String k = (String) keys.get(i);
        final Color c = colors.size() > i ? colors.get(i) : DEFAULT_ITEM_BG_COLOR;
        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.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with CustomPieSectionLabelGenerator

use of org.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator in project cytoscape-impl by cytoscape.

the class RingLayer method createChart.

private JFreeChart createChart(final PieDataset dataset, final double sectionDepth, final double interiorGap) {
    JFreeChart chart = ChartFactory.createRingChart(// 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 RingPlot plot = (RingPlot) 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.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setBackgroundAlpha(0.0f);
    plot.setShadowPaint(TRANSPARENT_COLOR);
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);
    plot.setInnerSeparatorExtension(0);
    plot.setOuterSeparatorExtension(0);
    plot.setSectionDepth(sectionDepth);
    plot.setInteriorGap(interiorGap);
    // Labels don't look good if it has multiple rings, so only show them when there's only one ring
    plot.setLabelGenerator(showItemLabels && datasetList.size() == 1 ? new CustomPieSectionLabelGenerator(labels) : null);
    plot.setSimpleLabels(true);
    plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
    plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
    plot.setLabelShadowPaint(TRANSPARENT_COLOR);
    plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
    final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    plot.setSeparatorStroke(stroke);
    plot.setSeparatorPaint(borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
    final List<?> keys = dataset.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final String k = (String) keys.get(i);
        final Color c = colors.size() > i ? colors.get(i) : DEFAULT_ITEM_BG_COLOR;
        plot.setSectionPaint(k, c);
        plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
        plot.setSectionOutlineStroke(k, stroke);
    }
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) RingPlot(org.jfree.chart.plot.RingPlot) CustomPieSectionLabelGenerator(org.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator) Color(java.awt.Color) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

BasicStroke (java.awt.BasicStroke)2 Color (java.awt.Color)2 CustomPieSectionLabelGenerator (org.cytoscape.ding.internal.charts.CustomPieSectionLabelGenerator)2 JFreeChart (org.jfree.chart.JFreeChart)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 PiePlot (org.jfree.chart.plot.PiePlot)1 RingPlot (org.jfree.chart.plot.RingPlot)1