📄 spiderwebplot.java
字号:
//// SERIES OUTLINE STROKE /////////////////////
/**
* Returns the outline stroke for ALL series in the plot.
*
* @return The stroke (possibly <code>null</code>).
*/
public Stroke getSeriesOutlineStroke() {
return this.seriesOutlineStroke;
}
/**
* Sets the outline stroke for ALL series in the plot. If this is set to
* </code> null</code>, then a list of paints is used instead (to allow
* different colors to be used for each series).
*
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setSeriesOutlineStroke(Stroke stroke) {
this.seriesOutlineStroke = stroke;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the stroke for the specified series.
*
* @param series the series index (zero-based).
*
* @return The stroke (never <code>null</code>).
*/
public Stroke getSeriesOutlineStroke(int series) {
// return the override, if there is one...
if (this.seriesOutlineStroke != null) {
return this.seriesOutlineStroke;
}
// otherwise look up the paint list
Stroke result = this.seriesOutlineStrokeList.getStroke(series);
if (result == null) {
result = this.baseSeriesOutlineStroke;
}
return result;
}
/**
* Sets the stroke used to fill a series of the radar and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param series the series index (zero-based).
* @param stroke the stroke (<code>null</code> permitted).
*/
public void setSeriesOutlineStroke(int series, Stroke stroke) {
this.seriesOutlineStrokeList.setStroke(series, stroke);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the base series stroke. This is used when no other stroke is
* available.
*
* @return The stroke (never <code>null</code>).
*/
public Stroke getBaseSeriesOutlineStroke() {
return this.baseSeriesOutlineStroke;
}
/**
* Sets the base series stroke.
*
* @param stroke the stroke (<code>null</code> not permitted).
*/
public void setBaseSeriesOutlineStroke(Stroke stroke) {
if (stroke == null) {
throw new IllegalArgumentException("Null 'stroke' argument.");
}
this.baseSeriesOutlineStroke = stroke;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the shape used for legend items.
*
* @return The shape (never <code>null</code>).
*
* @see #setLegendItemShape(Shape)
*/
public Shape getLegendItemShape() {
return this.legendItemShape;
}
/**
* Sets the shape used for legend items and sends a {@link PlotChangeEvent}
* to all registered listeners.
*
* @param shape the shape (<code>null</code> not permitted).
*
* @see #getLegendItemShape()
*/
public void setLegendItemShape(Shape shape) {
if (shape == null) {
throw new IllegalArgumentException("Null 'shape' argument.");
}
this.legendItemShape = shape;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the series label font.
*
* @return The font (never <code>null</code>).
*
* @see #setLabelFont(Font)
*/
public Font getLabelFont() {
return this.labelFont;
}
/**
* Sets the series label font and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param font the font (<code>null</code> not permitted).
*
* @see #getLabelFont()
*/
public void setLabelFont(Font font) {
if (font == null) {
throw new IllegalArgumentException("Null 'font' argument.");
}
this.labelFont = font;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the series label paint.
*
* @return The paint (never <code>null</code>).
*
* @see #setLabelPaint(Paint)
*/
public Paint getLabelPaint() {
return this.labelPaint;
}
/**
* Sets the series label paint and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*
* @see #getLabelPaint()
*/
public void setLabelPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.labelPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the label generator.
*
* @return The label generator (never <code>null</code>).
*
* @see #setLabelGenerator(CategoryItemLabelGenerator)
*/
public CategoryItemLabelGenerator getLabelGenerator() {
return this.labelGenerator;
}
/**
* Sets the label generator and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param generator the generator (<code>null</code> not permitted).
*
* @see #getLabelGenerator()
*/
public void setLabelGenerator(CategoryItemLabelGenerator generator) {
if (generator == null) {
throw new IllegalArgumentException("Null 'generator' argument.");
}
this.labelGenerator = generator;
}
/**
* Returns the tool tip generator for the plot.
*
* @return The tool tip generator (possibly <code>null</code>).
*
* @see #setToolTipGenerator(CategoryToolTipGenerator)
*
* @since 1.0.2
*/
public CategoryToolTipGenerator getToolTipGenerator() {
return this.toolTipGenerator;
}
/**
* Sets the tool tip generator for the plot and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param generator the generator (<code>null</code> permitted).
*
* @see #getToolTipGenerator()
*
* @since 1.0.2
*/
public void setToolTipGenerator(CategoryToolTipGenerator generator) {
this.toolTipGenerator = generator;
this.notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the URL generator for the plot.
*
* @return The URL generator (possibly <code>null</code>).
*
* @see #setURLGenerator(CategoryURLGenerator)
*
* @since 1.0.2
*/
public CategoryURLGenerator getURLGenerator() {
return this.urlGenerator;
}
/**
* Sets the URL generator for the plot and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param generator the generator (<code>null</code> permitted).
*
* @see #getURLGenerator()
*
* @since 1.0.2
*/
public void setURLGenerator(CategoryURLGenerator generator) {
this.urlGenerator = generator;
this.notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns a collection of legend items for the radar chart.
*
* @return The legend items.
*/
public LegendItemCollection getLegendItems() {
LegendItemCollection result = new LegendItemCollection();
List keys = null;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
keys = this.dataset.getRowKeys();
}
else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
keys = this.dataset.getColumnKeys();
}
if (keys != null) {
int series = 0;
Iterator iterator = keys.iterator();
Shape shape = getLegendItemShape();
while (iterator.hasNext()) {
String label = iterator.next().toString();
String description = label;
Paint paint = getSeriesPaint(series);
Paint outlinePaint = getSeriesOutlinePaint(series);
Stroke stroke = getSeriesOutlineStroke(series);
LegendItem item = new LegendItem(label, description,
null, null, shape, paint, stroke, outlinePaint);
item.setDataset(getDataset());
result.add(item);
series++;
}
}
return result;
}
/**
* Returns a cartesian point from a polar angle, length and bounding box
*
* @param bounds the area inside which the point needs to be.
* @param angle the polar angle, in degrees.
* @param length the relative length. Given in percent of maximum extend.
*
* @return The cartesian point.
*/
protected Point2D getWebPoint(Rectangle2D bounds,
double angle, double length) {
double angrad = Math.toRadians(angle);
double x = Math.cos(angrad) * length * bounds.getWidth() / 2;
double y = -Math.sin(angrad) * length * bounds.getHeight() / 2;
return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2,
bounds.getY() + y + bounds.getHeight() / 2);
}
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot, if there is one.
* @param info collects info about the drawing.
*/
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
PlotState parentState,
PlotRenderingInfo info)
{
// adjust for insets...
RectangleInsets insets = getInsets();
insets.trim(area);
if (info != null) {
info.setPlotArea(area);
info.setDataArea(area);
}
drawBackground(g2, area);
drawOutline(g2, area);
Shape savedClip = g2.getClip();
g2.clip(area);
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
int seriesCount = 0, catCount = 0;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
seriesCount = this.dataset.getRowCount();
catCount = this.dataset.getColumnCount();
}
else {
seriesCount = this.dataset.getColumnCount();
catCount = this.dataset.getRowCount();
}
// ensure we have a maximum value to use on the axes
if (this.maxValue == DEFAULT_MAX_VALUE)
calculateMaxValue(seriesCount, catCount);
// Next, setup the plot area
// adjust the plot area by the interior spacing value
double gapHorizontal = area.getWidth() * getInteriorGap();
double gapVertical = area.getHeight() * getInteriorGap();
double X = area.getX() + gapHorizontal / 2;
double Y = area.getY() + gapVertical / 2;
double W = area.getWidth() - gapHorizontal;
double H = area.getHeight() - gapVertical;
double headW = area.getWidth() * this.headPercent;
double headH = area.getHeight() * this.headPercent;
// make the chart area a square
double min = Math.min(W, H) / 2;
X = (X + X + W) / 2 - min;
Y = (Y + Y + H) / 2 - min;
W = 2 * min;
H = 2 * min;
Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);
// draw the axis and category label
for (int cat = 0; cat < catCount; cat++) {
double angle = getStartAngle()
+ (getDirection().getFactor() * cat * 360 / catCount);
Point2D endPoint = getWebPoint(radarArea, angle, 1);
// 1 = end of axis
Line2D line = new Line2D.Double(centre, endPoint);
g2.setPaint(this.axisLinePaint);
g2.setStroke(this.axisLineStroke);
g2.draw(line);
drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / catCount);
}
// Now actually plot each of the series polygons..
for (int series = 0; series < seriesCount; series++) {
drawRadarPoly(g2, radarArea, centre, info, series, catCount,
headH, headW);
}
}
else {
drawNoDataMessage(g2, area);
}
g2.setClip(savedClip);
g2.setComposite(originalComposite);
drawOutline(g2, area);
}
/**
* loop through each of the series to get the maximum value
* on each category axis
*
* @param seriesCount the number of series
* @param catCount the number of categories
*/
private void calculateMaxValue(int seriesCount, int catCount) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -