org.jfree.chart.labels.PieSectionLabelGenerator Java Examples

The following examples show how to use org.jfree.chart.labels.PieSectionLabelGenerator. 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: OrdersChartPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	
	JFreeChart chart=null ;
	try {
		if(PropertyUtils.getProperty(new OrderEntry(), p) instanceof Date)
		{
			chart = ChartFactory.createTimeSeriesChart("Orders", "Date", "Value", getTimeDataSet(), true, true,false);

		}
		else
		{
			chart = ChartFactory.createPieChart3D("Orders", getPieDataSet(), false, true, true);
			PiePlot plot = (PiePlot) chart.getPlot();
			PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"),new DecimalFormat("0.00%"));
			plot.setLabelGenerator(generator);
				
		}
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		logger.error(e);
	}
	return chart;
}
 
Example #2
Source File: TypeRepartitionPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	
	JFreeChart chart = ChartFactory.createPieChart3D("Type repartition", getDataSet(), false,true, true);

	PiePlot plot = (PiePlot) chart.getPlot();
	plot.setSectionPaint("B", Color.BLACK);
	plot.setSectionPaint("W", Color.WHITE);
	plot.setSectionPaint("U", Color.BLUE);
	plot.setSectionPaint("G", Color.GREEN);
	plot.setSectionPaint("R", Color.RED);
	plot.setSectionPaint("multi", Color.YELLOW);
	plot.setSectionPaint("uncolor", Color.GRAY);

	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"),
			new DecimalFormat("0.00%"));
	plot.setLabelGenerator(generator);
	
	return chart;
}
 
Example #3
Source File: RarityRepartitionPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	JFreeChart chart = ChartFactory.createPieChart3D("Rarity repartition", getDataSet(), false, true, true);
	PiePlot plot = (PiePlot) chart.getPlot();
	
	for(MTGRarity r : MTGRarity.values())
	{
		plot.setSectionPaint(r.toPrettyString(),r.toColor());
	}
	

	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"),new DecimalFormat("0.00%"));
	plot.setLabelGenerator(generator);
	
	return chart;
}
 
Example #4
Source File: ManaRepartitionPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	
	JFreeChart chart = ChartFactory.createPieChart3D("Color repartition", // chart title
			getDataSet(), // data
			false, // include legend
			true, true);
	
	PiePlot plot = (PiePlot) chart.getPlot();
	
	for(MTGColor c : MTGColor.values())
	{
		plot.setSectionPaint(c,c.toColor());
		
	}
	plot.setSectionPaint("Multi", Color.YELLOW);
	plot.setSectionPaint("multi", Color.YELLOW);
	
	plot.setSimpleLabels(true);

	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{1}", new DecimalFormat("0"),
			new DecimalFormat("0.00%"));
	plot.setLabelGenerator(generator);

	return chart;
}
 
Example #5
Source File: StatisticsController.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
@Secured({"ROLE_ADMIN","ROLE_SURVEY_ADMIN"})
private JFreeChart createChart(PieDataset pieDataset, String title) {
try{
	JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false,true,false);

	chart.setBackgroundPaint(null);//this line necessary for transparency of background
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setOpaque(false); //this line necessary for transparency of background
       chartPanel.setBackground(new Color(0, 0, 0, 0)); //this line necessary for transparency of background
       
	PiePlot plot = (PiePlot) chart.getPlot();
	
	//Color[] colors = {new Color(170, 195, 217, 255),new Color(246, 140, 31, 255),new Color(204, 204, 204, 255),new Color(231, 238, 144, 255),new Color(51, 51, 51, 255),new Color(101, 125, 151, 255),new Color(0, 102, 255, 255)}; 
	//PieRenderer renderer = new PieRenderer(colors); 
	//renderer.setColor(plot, pieDataset);
	
	
	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0}:{1}%"); 
	plot.setLabelGenerator(generator);
	
	plot.setStartAngle(270);
	plot.setDirection(Rotation.CLOCKWISE);
	
	return chart;
} catch (Exception e) {
	log.error(e.getMessage(),e);
	throw (new RuntimeException(e));
}
}
 
Example #6
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();

		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//
//		}

		Integer baseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
		JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null;
		
		piePlot.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize));

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example #7
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #8
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #9
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPie3DChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart3D(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());

	PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPie3DPlot jrPie3DPlot = (JRPie3DPlot)getPlot();
	double depthFactor = jrPie3DPlot.getDepthFactorDouble() == null ? JRPie3DPlot.DEPTH_FACTOR_DEFAULT : jrPie3DPlot.getDepthFactorDouble();
	boolean isCircular =  jrPie3DPlot.getCircular() == null ? false : jrPie3DPlot.getCircular();
	piePlot3D.setDepthFactor(depthFactor);
	piePlot3D.setCircular(isCircular);

	boolean isShowLabels = jrPie3DPlot.getShowLabels() == null ? true : jrPie3DPlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPie3DPlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot3D.setLabelGenerator(labelGenerator);
		}
		else if (jrPie3DPlot.getLabelFormat() != null)
		{
			piePlot3D.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPie3DPlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot3D.setLabelGenerator(
//				new StandardPieSectionLabelGenerator(itemLabel.getMask())
//				);
//		}
		else
		{
			piePlot3D.setLabelGenerator(
					new StandardPieSectionLabelGenerator()
					);
		}

		Integer baseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
		JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null;
		piePlot3D.setLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize));

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot3D.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot3D.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot3D.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot3D.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot3D.setLabelGenerator(null);
	}
	
	if (jrPie3DPlot.getLegendLabelFormat() != null)
	{
		piePlot3D.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPie3DPlot.getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example #10
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart);
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}// the default section label is just the key, so there's no need to set localized number formats
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//		}

		piePlot.setLabelFont(
			fontUtil.getAwtFont(
				getFont(itemLabel == null ? null : itemLabel.getFont()), 
				getLocale()
				)
			);

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(),
					NumberFormat.getNumberInstance(getLocale()),
					NumberFormat.getPercentInstance(getLocale()))
			);
	}// the default legend label is just the key, so there's no need to set localized number formats
	
	return jfreeChart;
}
 
Example #11
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #12
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPie3DChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart3D(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());

	PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPie3DPlot jrPie3DPlot = (JRPie3DPlot)getPlot();
	double depthFactor = jrPie3DPlot.getDepthFactorDouble() == null ? JRPie3DPlot.DEPTH_FACTOR_DEFAULT : jrPie3DPlot.getDepthFactorDouble();
	boolean isCircular =  jrPie3DPlot.getCircular() == null ? false : jrPie3DPlot.getCircular();
	piePlot3D.setDepthFactor(depthFactor);
	piePlot3D.setCircular(isCircular);

	boolean isShowLabels = jrPie3DPlot.getShowLabels() == null ? true : jrPie3DPlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPie3DPlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot3D.setLabelGenerator(labelGenerator);
		}
		else if (jrPie3DPlot.getLabelFormat() != null)
		{
			piePlot3D.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPie3DPlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot3D.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//		}
		
		if (itemLabel != null && itemLabel.getFont() != null)
		{
			piePlot3D.setLabelFont(getFontUtil().getAwtFont(itemLabel.getFont(), getLocale()));
		}
		else
		{
			piePlot3D.setLabelFont(getFontUtil().getAwtFont(new JRBaseFont(getChart(), null), getLocale()));
		}

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot3D.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot3D.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot3D.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot3D.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot3D.setLabelGenerator(null);
	}

	if (jrPie3DPlot.getLegendLabelFormat() != null)
	{
		piePlot3D.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(jrPie3DPlot.getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example #13
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createPieChart() throws JRException
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createPieChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			(PieDataset)getDataset(),
			isShowLegend(),
			true,
			false
			);

	configureChart(jfreeChart, getPlot());
	PiePlot piePlot = (PiePlot)jfreeChart.getPlot();
	//plot.setStartAngle(290);
	//plot.setDirection(Rotation.CLOCKWISE);
	//plot.setNoDataMessage("No data to display");
	JRPiePlot jrPiePlot = (JRPiePlot)getPlot();
	boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular();
	piePlot.setCircular(isCircular);

	boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
	
	if (isShowLabels)
	{
		PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator();
		JRItemLabel itemLabel = jrPiePlot.getItemLabel();
		if (labelGenerator != null)
		{
			piePlot.setLabelGenerator(labelGenerator);
		}
		else if (jrPiePlot.getLabelFormat() != null)
		{
			piePlot.setLabelGenerator(
				new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), 
						NumberFormat.getNumberInstance(getLocale()),
		                NumberFormat.getPercentInstance(getLocale()))
				);
		}
//		else if (itemLabel != null && itemLabel.getMask() != null)
//		{
//			piePlot.setLabelGenerator(
//					new StandardPieSectionLabelGenerator(itemLabel.getMask())
//					);
//		}
		
		if (itemLabel != null && itemLabel.getFont() != null)
		{
			piePlot.setLabelFont(getFontUtil().getAwtFont(itemLabel.getFont(), getLocale()));
		}
		else
		{
			piePlot.setLabelFont(getFontUtil().getAwtFont(new JRBaseFont(getChart(), null), getLocale()));
		}

		if (itemLabel != null && itemLabel.getColor() != null)
		{
			piePlot.setLabelPaint(itemLabel.getColor());
		}
		else
		{
			piePlot.setLabelPaint(getChart().getForecolor());
		}

		if (itemLabel != null && itemLabel.getBackgroundColor() != null)
		{
			piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor());
		}
		else
		{
			piePlot.setLabelBackgroundPaint(getChart().getBackcolor());
		}
	}
	else
	{
		piePlot.setLabelGenerator(null);
	}
	
	if (jrPiePlot.getLegendLabelFormat() != null)
	{
		piePlot.setLegendLabelGenerator(
			new StandardPieSectionLabelGenerator(((JRPiePlot)getPlot()).getLegendLabelFormat(), 
					NumberFormat.getNumberInstance(getLocale()),
	                NumberFormat.getPercentInstance(getLocale()))
			);
	}
	
	return jfreeChart;
}
 
Example #14
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #15
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 * 
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys, 
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, 
        PiePlotState state) {
    
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            1.0f));

    RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, 
            0.18, 0.18, 0.18, 0.18);
    Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right, 
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);
            
            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), 
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();
            
            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out, 
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg, 
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null 
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }
            
            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y, 
                    TextAnchor.CENTER);
            
        }
    }
   
    g2.setComposite(originalComposite);

}
 
Example #16
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #17
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 * 
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys, 
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, 
        PiePlotState state) {
    
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            1.0f));

    RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, 
            0.18, 0.18, 0.18, 0.18);
    Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right, 
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);
            
            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), 
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();
            
            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out, 
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg, 
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null 
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }
            
            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y, 
                    TextAnchor.CENTER);
            
        }
    }
   
    g2.setComposite(originalComposite);

}
 
Example #18
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #19
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example #20
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 * 
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys, 
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, 
        PiePlotState state) {
    
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            1.0f));

    RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, 
            0.18, 0.18, 0.18, 0.18);
    Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right, 
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);
            
            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), 
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();
            
            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out, 
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg, 
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null 
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }
            
            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y, 
                    TextAnchor.CENTER);
            
        }
    }
   
    g2.setComposite(originalComposite);

}
 
Example #21
Source File: PiePlot.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the legend label generator and sends a {@link PlotChangeEvent} to 
 * all registered listeners.
 * 
 * @param generator  the generator (<code>null</code> not permitted).
 * 
 * @see #getLegendLabelGenerator()
 */
public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
    if (generator == null) {
        throw new IllegalArgumentException("Null 'generator' argument.");
    }
    this.legendLabelGenerator = generator;
    fireChangeEvent();
}
 
Example #22
Source File: PiePlot.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets the legend label generator and sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param generator  the generator (<code>null</code> not permitted).
 *
 * @see #getLegendLabelGenerator()
 */
public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
    if (generator == null) {
        throw new IllegalArgumentException("Null 'generator' argument.");
    }
    this.legendLabelGenerator = generator;
    fireChangeEvent();
}
 
Example #23
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 3 votes vote down vote up
/**
 * Sets the legend label generator and sends a {@link PlotChangeEvent} to 
 * all registered listeners.
 * 
 * @param generator  the generator (<code>null</code> not permitted).
 * 
 * @see #getLegendLabelGenerator()
 */
public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
    if (generator == null) {
        throw new IllegalArgumentException("Null 'generator' argument.");
    }
    this.legendLabelGenerator = generator;
    notifyListeners(new PlotChangeEvent(this));
}
 
Example #24
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the legend label generator and sends a {@link PlotChangeEvent} to 
 * all registered listeners.
 * 
 * @param generator  the generator (<code>null</code> not permitted).
 * 
 * @see #getLegendLabelGenerator()
 */
public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
    if (generator == null) {
        throw new IllegalArgumentException("Null 'generator' argument.");
    }
    this.legendLabelGenerator = generator;
    notifyListeners(new PlotChangeEvent(this));
}
 
Example #25
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the legend label tool tip generator.
 *
 * @return The legend label tool tip generator (possibly <code>null</code>).
 *
 * @see #setLegendLabelToolTipGenerator(PieSectionLabelGenerator)
 */
public PieSectionLabelGenerator getLegendLabelToolTipGenerator() {
    return this.legendLabelToolTipGenerator;
}
 
Example #26
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the legend label tool tip generator and sends a
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param generator  the generator (<code>null</code> permitted).
 *
 * @see #getLegendLabelToolTipGenerator()
 */
public void setLegendLabelToolTipGenerator(
        PieSectionLabelGenerator generator) {
    this.legendLabelToolTipGenerator = generator;
    fireChangeEvent();
}
 
Example #27
Source File: PiePlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the legend label generator.
 *
 * @return The legend label generator (never <code>null</code>).
 *
 * @see #setLegendLabelGenerator(PieSectionLabelGenerator)
 */
public PieSectionLabelGenerator getLegendLabelGenerator() {
    return this.legendLabelGenerator;
}
 
Example #28
Source File: PiePlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the section label generator and sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param generator  the generator (<code>null</code> permitted).
 *
 * @see #getLabelGenerator()
 */
public void setLabelGenerator(PieSectionLabelGenerator generator) {
    this.labelGenerator = generator;
    fireChangeEvent();
}
 
Example #29
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the legend label generator and sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param generator  the generator (<code>null</code> not permitted).
 *
 * @see #getLegendLabelGenerator()
 */
public void setLegendLabelGenerator(PieSectionLabelGenerator generator) {
    ParamChecks.nullNotPermitted(generator, "generator");
    this.legendLabelGenerator = generator;
    fireChangeEvent();
}
 
Example #30
Source File: PiePlot.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the legend label tool tip generator.
 *
 * @return The legend label tool tip generator (possibly <code>null</code>).
 *
 * @see #setLegendLabelToolTipGenerator(PieSectionLabelGenerator)
 */
public PieSectionLabelGenerator getLegendLabelToolTipGenerator() {
    return this.legendLabelToolTipGenerator;
}