de.laures.cewolf.cpp.SpiderWebEnhancer Maven / Gradle / Ivy
package de.laures.cewolf.cpp;
import java.awt.Color;
import java.awt.Font;
import java.io.Serializable;
import java.util.Map;
import de.laures.cewolf.ChartPostProcessor;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.util.Rotation;
import org.jfree.util.TableOrder;
/**
* A postprocessor for changing details of a Meter plot.
*
interiorGap gap between plot and exterior boundary; default is 0.25, which means 25%
*
headPercent size of the actual dat points; default is 0.01, which means 1% of the plot size
*
startAngle angle at which to start drawing; default is 0
*
webFilled whether to fill the web with color, or just paint the outline; default is true
*
clockWise in which direction to rotate the data
*
orderByRow whether to interpret the data by rows or by columns
*
labelPaint the color of the labels; optional; default #000000 (i.e., black)
*
labelFontName font type of the labels; optional; default SansSerif
*
labelFontSize font size of the labels; optional; default 10
*
labelBold for the font type of the labels; true/false; optional; default false
*
labelItalic for the font type of the labels; true/false; optional; default false
*
* Usage:
* <chart:chartpostprocessor id="thermometerEnhancer">
* <chart:param name="interiorGap" value="0.25" />
* <chart:param name="headPercent" value="0.01" />
* <chart:param name="startAngle" value="30" />
* <chart:param name="webFilled" value="true" />
* <chart:param name="clockWise" value="true" />
* <chart:param name="orderByRow" value="true" />
* <chart:param name="labelPaint" value="#FFFFAA" />
* <chart:param name="labelFontName" value="Serif" />
* <chart:param name="labelFontSize" value="14" />
* <chart:param name="labelBold" value="false" />
* <chart:param name="labelItalic" value="true" />
* </chart:chartpostprocessor>
*/
public class SpiderWebEnhancer implements ChartPostProcessor, Serializable
{
static final long serialVersionUID = 3693171934091003109L;
public void processChart (JFreeChart chart, Map params) {
double interiorGap = 0.25;
double headPercent = 0.01;
double startAngle = 0.0;
boolean webFilled = true;
boolean clockWise = false;
boolean orderByRow = true;
Color labelPaint = new Color(0, 0, 0);
String labelFontName = "SansSerif";
int labelFontSize = 10;
boolean isBold = false;
boolean isItalic = false;
String str = params.get("interiorGap");
if (str != null) {
try {
interiorGap = Double.parseDouble(str);
} catch (NumberFormatException nfex) { }
}
str = params.get("headPercent");
if (str != null) {
try {
headPercent = Double.parseDouble(str);
} catch (NumberFormatException nfex) { }
}
str = params.get("startAngle");
if (str != null) {
try {
startAngle = Double.parseDouble(str);
} catch (NumberFormatException nfex) { }
}
str = params.get("webFilled");
if (str != null)
webFilled = "true".equals(str);
str = params.get("clockWise");
if (str != null)
clockWise = "true".equals(str);
str = params.get("orderByRow");
if (str != null)
orderByRow = "true".equals(str);
str = params.get("labelPaint");
if (str != null && str.trim().length() > 0) {
try {
labelPaint = Color.decode(str);
} catch (NumberFormatException nfex) { }
}
str = params.get("labelFontName");
if (str != null && str.trim().length() > 0)
labelFontName = str.trim();
str = params.get("labelFontSize");
if (str != null && str.trim().length() > 0) {
try {
labelFontSize = Integer.parseInt(str);
if (labelFontSize < 1)
labelFontSize = 10;
} catch (NumberFormatException nfex) { }
}
str = params.get("labelBold");
if (str != null)
isBold = "true".equals(str.toLowerCase());
str = params.get("labelItalic");
if (str != null)
isItalic = "true".equals(str.toLowerCase());
Plot plot = chart.getPlot();
if (plot instanceof SpiderWebPlot) {
SpiderWebPlot swplot = (SpiderWebPlot) plot;
swplot.setStartAngle(startAngle);
swplot.setInteriorGap(interiorGap);
swplot.setHeadPercent(headPercent);
swplot.setWebFilled(webFilled);
swplot.setLabelPaint(labelPaint);
Font font = new Font(labelFontName,
(isBold ? Font.BOLD : 0) + (isItalic ? Font.ITALIC : 0),
labelFontSize);
swplot.setLabelFont(font);
if (clockWise)
swplot.setDirection(Rotation.CLOCKWISE);
else
swplot.setDirection(Rotation.ANTICLOCKWISE);
if (orderByRow)
swplot.setDataExtractOrder(TableOrder.BY_ROW);
else
swplot.setDataExtractOrder(TableOrder.BY_COLUMN);
}
}
}