org.jfree.chart.util.Rotation Java Examples

The following examples show how to use org.jfree.chart.util.Rotation. 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: PieChartWrapper.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createChart() {
    // create the chart...
    pieDataSet = createDataset();
    final JFreeChart chart = ChartFactory.createPieChart3D("", // chart
            // title
            pieDataSet, // data
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.getTitle().setPaint(new Color(0x5E5E5E));
    chart.setBorderVisible(false);
    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setStartAngle(290);
    plot.setBackgroundPaint(Color.white);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");
    plot.setLabelGenerator(new JFreeChartLabelCustom());

    final List keys = pieDataSet.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        final Comparable key = (Comparable) keys.get(i);
        int colorIndex = i % CHART_COLOR_STR.size();
        plot.setSectionPaint(key, Color.decode("0x" + CHART_COLOR_STR.get(colorIndex)));
    }
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}
 
Example #2
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the direction in which the pie sections are drawn and sends a 
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 * 
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    notifyListeners(new PlotChangeEvent(this));

}
 
Example #3
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 * 
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    if (extract == null) {
        throw new IllegalArgumentException("Null 'extract' argument.");
    }
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();
    
    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #4
Source File: PiePlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private double calculateAngleForValue(double value, double total) {
    if (this.direction == Rotation.CLOCKWISE) {
        return this.startAngle - (value / total * 360.0);
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        return this.startAngle + (value / total * 360.0);
    }
    throw new RuntimeException("Unrecognised Rotation type.");
}
 
Example #5
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Sets the direction in which the pie sections are drawn and sends a 
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 * 
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    notifyListeners(new PlotChangeEvent(this));

}
 
Example #6
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    if (extract == null) {
        throw new IllegalArgumentException("Null 'extract' argument.");
    }
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #7
Source File: PiePlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the direction in which the pie sections are drawn and sends a 
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 * 
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    fireChangeEvent();

}
 
Example #8
Source File: PiePlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the direction in which the pie sections are drawn and sends a
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 *
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    fireChangeEvent();

}
 
Example #9
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    
    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);
    
    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18, 
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);
    
    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
    
    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;
}
 
Example #10
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a shape representing the hotspot for a pie section.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the data is being rendered.
 * @param selected  is the item selected?
 *
 * @return A shape equal to the hot spot for a data item.
 */
public Shape createHotSpotShape(Graphics2D g2, Rectangle2D dataArea,
        int section, boolean selected) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return null;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    double total = DatasetUtilities.calculatePieDatasetTotal(this.dataset);
    double lead = 0.0;
    if (this.direction == Rotation.CLOCKWISE) {
        for (int i = 0; i < section; i++) {
            n = this.dataset.getValue(i);
            if (n != null) {
                value = n.doubleValue();
                if (value >= 0.0) {
                    lead = lead + value;
                }
            }
        }
        angle1 = getStartAngle() - lead / total * 360.0;
        angle2 = angle1 - value / total * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = getStartAngle() + lead / total * 360.0;
        angle2 = angle1 + value / total * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(dataArea,
                dataArea, angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);
        return arc;
    }
    return null;
}
 
Example #11
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param selected  is the item selected?
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, boolean selected, 
        Rectangle2D dataArea, PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, selected);
            Shape savedClip = g2.getClip();
            g2.clip(arc);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key, selected);
            Stroke outlineStroke = lookupSectionOutlineStroke(key,
                    selected);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            g2.setClip(savedClip);

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #12
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    
    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);
    
    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18, 
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);
    
    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
    
    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;
}
 
Example #13
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.selectedItemAttributes = new PieSelectionAttributes();
    this.shadowGenerator = new DefaultShadowGenerator();
}
 
Example #14
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #15
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #16
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    
    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);
    
    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18, 
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);
    
    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
    
    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;
}
 
Example #17
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #18
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the direction in which the radar axes are drawn and sends a
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 *
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    fireChangeEvent();
}
 
Example #19
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the direction in which the radar axes are drawn and sends a
 * {@link PlotChangeEvent} to all registered listeners.
 * 
 * @param direction  the direction (<code>null</code> not permitted).
 * 
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    fireChangeEvent();
}
 
Example #20
Source File: PiePlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the direction in which the pie sections are drawn (clockwise or 
 * anti-clockwise).
 *
 * @return The direction (never <code>null</code>).
 * 
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}
 
Example #21
Source File: PiePlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the direction in which the pie sections are drawn (clockwise or
 * anti-clockwise).
 *
 * @return The direction (never <code>null</code>).
 *
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}
 
Example #22
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the direction in which the radar axes are drawn
 * (clockwise or anti-clockwise).
 * 
 * @return The direction (never <code>null</code>).
 * 
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}
 
Example #23
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the direction in which the radar axes are drawn
 * (clockwise or anti-clockwise).
 *
 * @return The direction (never <code>null</code>).
 *
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}
 
Example #24
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 2 votes vote down vote up
/**
 * Returns the direction in which the pie sections are drawn (clockwise or 
 * anti-clockwise).
 *
 * @return The direction (never <code>null</code>).
 * 
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}
 
Example #25
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 2 votes vote down vote up
/**
 * Returns the direction in which the pie sections are drawn (clockwise or 
 * anti-clockwise).
 *
 * @return The direction (never <code>null</code>).
 * 
 * @see #setDirection(Rotation)
 */
public Rotation getDirection() {
    return this.direction;
}