java/cewolf-1.0/src/main/java/de/laures/cewolf/cpp/RotatedAxisLabels.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 28 Feb 2009 21:31:02 +0100
changeset 1 639991d0808a
permissions -rw-r--r--
Rozbalená knihovna verze 1.0
     1 package de.laures.cewolf.cpp;
     2 
     3 import java.util.Map;
     4 
     5 import org.jfree.chart.JFreeChart;
     6 import org.jfree.chart.axis.CategoryAxis;
     7 import org.jfree.chart.axis.CategoryLabelPositions;
     8 import org.jfree.chart.plot.CategoryPlot;
     9 import org.jfree.data.category.CategoryDataset;
    10 
    11 import de.laures.cewolf.ChartPostProcessor;
    12 
    13 /**
    14 * A cewolf post-processor for rotating and/or removing the labels on the X-Axis
    15 * parameters:
    16 * rotate_at: make the labels vertical
    17 * skip_at: print only some of the labels (so they don't overlap)
    18 * remove_at: don't print any labels
    19 *
    20 * Usage:
    21 * <chart:chartpostprocessor id="labelRotation">
    22 * <chart:param name="rotate_at" value='<%= new Integer(10) %>'/>
    23 * <chart:param name="skip_at" value='<%= new Integer(50) %>'/>
    24 * <chart:param name="remove_at" value='<%= new Integer(100) %>'/>
    25 * </chart:chartpostprocessor>
    26 *
    27 *
    28 * @author Rich Unger
    29 */
    30 
    31 public class RotatedAxisLabels implements ChartPostProcessor {
    32 	
    33 public void processChart(Object chart, Map params) {
    34 		CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot();
    35 
    36 		CategoryAxis axis = plot.getDomainAxis();
    37 
    38 		Number rotateThreshold = (Number) params.get("rotate_at");
    39 		Number skipThreshold = (Number) params.get("skip_at");
    40 		Number removeThreshold = (Number) params.get("remove_at");
    41 
    42 		CategoryDataset dataset = plot.getDataset();
    43 		int iCategoryCount = dataset.getRowCount();
    44 
    45 		if (rotateThreshold != null) 
    46     {
    47       if (iCategoryCount >= rotateThreshold.intValue()) 
    48       {
    49         axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    50       }
    51       else 
    52       {
    53         axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    54       }
    55 
    56     }
    57     
    58 		if (skipThreshold != null) 
    59     {
    60       //this method does nothing in jfreechart .9.18
    61 			//axis.setSkipCategoryLabelsToFit(iCategoryCount >= skipThreshold.intValue());
    62 		}
    63 		
    64     if (removeThreshold != null) 
    65     {
    66 			axis.setTickLabelsVisible(iCategoryCount < removeThreshold.intValue());
    67 		}
    68 	}
    69 	
    70 }