java/cewolf-1.0/src/main/java/de/laures/cewolf/cpp/RotatedAxisLabels.java
changeset 1 639991d0808a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/cpp/RotatedAxisLabels.java	Sat Feb 28 21:31:02 2009 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +package de.laures.cewolf.cpp;
     1.5 +
     1.6 +import java.util.Map;
     1.7 +
     1.8 +import org.jfree.chart.JFreeChart;
     1.9 +import org.jfree.chart.axis.CategoryAxis;
    1.10 +import org.jfree.chart.axis.CategoryLabelPositions;
    1.11 +import org.jfree.chart.plot.CategoryPlot;
    1.12 +import org.jfree.data.category.CategoryDataset;
    1.13 +
    1.14 +import de.laures.cewolf.ChartPostProcessor;
    1.15 +
    1.16 +/**
    1.17 +* A cewolf post-processor for rotating and/or removing the labels on the X-Axis
    1.18 +* parameters:
    1.19 +* rotate_at: make the labels vertical
    1.20 +* skip_at: print only some of the labels (so they don't overlap)
    1.21 +* remove_at: don't print any labels
    1.22 +*
    1.23 +* Usage:
    1.24 +* <chart:chartpostprocessor id="labelRotation">
    1.25 +* <chart:param name="rotate_at" value='<%= new Integer(10) %>'/>
    1.26 +* <chart:param name="skip_at" value='<%= new Integer(50) %>'/>
    1.27 +* <chart:param name="remove_at" value='<%= new Integer(100) %>'/>
    1.28 +* </chart:chartpostprocessor>
    1.29 +*
    1.30 +*
    1.31 +* @author Rich Unger
    1.32 +*/
    1.33 +
    1.34 +public class RotatedAxisLabels implements ChartPostProcessor {
    1.35 +	
    1.36 +public void processChart(Object chart, Map params) {
    1.37 +		CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot();
    1.38 +
    1.39 +		CategoryAxis axis = plot.getDomainAxis();
    1.40 +
    1.41 +		Number rotateThreshold = (Number) params.get("rotate_at");
    1.42 +		Number skipThreshold = (Number) params.get("skip_at");
    1.43 +		Number removeThreshold = (Number) params.get("remove_at");
    1.44 +
    1.45 +		CategoryDataset dataset = plot.getDataset();
    1.46 +		int iCategoryCount = dataset.getRowCount();
    1.47 +
    1.48 +		if (rotateThreshold != null) 
    1.49 +    {
    1.50 +      if (iCategoryCount >= rotateThreshold.intValue()) 
    1.51 +      {
    1.52 +        axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    1.53 +      }
    1.54 +      else 
    1.55 +      {
    1.56 +        axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    1.57 +      }
    1.58 +
    1.59 +    }
    1.60 +    
    1.61 +		if (skipThreshold != null) 
    1.62 +    {
    1.63 +      //this method does nothing in jfreechart .9.18
    1.64 +			//axis.setSkipCategoryLabelsToFit(iCategoryCount >= skipThreshold.intValue());
    1.65 +		}
    1.66 +		
    1.67 +    if (removeThreshold != null) 
    1.68 +    {
    1.69 +			axis.setTickLabelsVisible(iCategoryCount < removeThreshold.intValue());
    1.70 +		}
    1.71 +	}
    1.72 +	
    1.73 +}