📄 spiderwebplot.java
字号:
double v = 0;
Number nV = null;
for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {
for (int catIndex = 0; catIndex < catCount; catIndex++) {
nV = getPlotValue(seriesIndex, catIndex);
if (nV != null) {
v = nV.doubleValue();
if (v > this.maxValue) {
this.maxValue = v;
}
}
}
}
}
/**
* Draws a radar plot polygon.
*
* @param g2 the graphics device.
* @param plotArea the area we are plotting in (already adjusted).
* @param centre the centre point of the radar axes
* @param info chart rendering info.
* @param series the series within the dataset we are plotting
* @param catCount the number of categories per radar plot
* @param headH the data point height
* @param headW the data point width
*/
protected void drawRadarPoly(Graphics2D g2,
Rectangle2D plotArea,
Point2D centre,
PlotRenderingInfo info,
int series, int catCount,
double headH, double headW) {
Polygon polygon = new Polygon();
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
// plot the data...
for (int cat = 0; cat < catCount; cat++) {
Number dataValue = getPlotValue(series, cat);
if (dataValue != null) {
double value = dataValue.doubleValue();
if (value >= 0) { // draw the polygon series...
// Finds our starting angle from the centre for this axis
double angle = getStartAngle()
+ (getDirection().getFactor() * cat * 360 / catCount);
// The following angle calc will ensure there isn't a top
// vertical axis - this may be useful if you don't want any
// given criteria to 'appear' move important than the
// others..
// + (getDirection().getFactor()
// * (cat + 0.5) * 360 / catCount);
// find the point at the appropriate distance end point
// along the axis/angle identified above and add it to the
// polygon
Point2D point = getWebPoint(plotArea, angle,
value / this.maxValue);
polygon.addPoint((int) point.getX(), (int) point.getY());
// put an elipse at the point being plotted..
Paint paint = getSeriesPaint(series);
Paint outlinePaint = getSeriesOutlinePaint(series);
Stroke outlineStroke = getSeriesOutlineStroke(series);
Ellipse2D head = new Ellipse2D.Double(point.getX()
- headW / 2, point.getY() - headH / 2, headW,
headH);
g2.setPaint(paint);
g2.fill(head);
g2.setStroke(outlineStroke);
g2.setPaint(outlinePaint);
g2.draw(head);
if (entities != null) {
String tip = null;
if (this.toolTipGenerator != null) {
tip = this.toolTipGenerator.generateToolTip(
this.dataset, series, cat);
}
String url = null;
if (this.urlGenerator != null) {
url = this.urlGenerator.generateURL(this.dataset,
series, cat);
}
Shape area = new Rectangle((int) (point.getX() - headW),
(int) (point.getY() - headH),
(int) (headW * 2), (int) (headH * 2));
CategoryItemEntity entity = new CategoryItemEntity(
area, tip, url, this.dataset,
this.dataset.getRowKey(series),
this.dataset.getColumnKey(cat));
entities.add(entity);
}
}
}
}
// Plot the polygon
Paint paint = getSeriesPaint(series);
g2.setPaint(paint);
g2.setStroke(getSeriesOutlineStroke(series));
g2.draw(polygon);
// Lastly, fill the web polygon if this is required
if (this.webFilled) {
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.1f));
g2.fill(polygon);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
}
}
/**
* Returns the value to be plotted at the interseries of the
* series and the category. This allows us to plot
* <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just
* reversing the definition of the categories and data series being
* plotted.
*
* @param series the series to be plotted.
* @param cat the category within the series to be plotted.
*
* @return The value to be plotted (possibly <code>null</code>).
*
* @see #getDataExtractOrder()
*/
protected Number getPlotValue(int series, int cat) {
Number value = null;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
value = this.dataset.getValue(series, cat);
}
else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
value = this.dataset.getValue(cat, series);
}
return value;
}
/**
* Draws the label for one axis.
*
* @param g2 the graphics device.
* @param plotArea the plot area
* @param value the value of the label (ignored).
* @param cat the category (zero-based index).
* @param startAngle the starting angle.
* @param extent the extent of the arc.
*/
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
int cat, double startAngle, double extent) {
FontRenderContext frc = g2.getFontRenderContext();
String label = null;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
// if series are in rows, then the categories are the column keys
label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
}
else {
// if series are in columns, then the categories are the row keys
label = this.labelGenerator.generateRowLabel(this.dataset, cat);
}
Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
double ascent = lm.getAscent();
Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
plotArea, startAngle);
Composite saveComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1.0f));
g2.setPaint(getLabelPaint());
g2.setFont(getLabelFont());
g2.drawString(label, (float) labelLocation.getX(),
(float) labelLocation.getY());
g2.setComposite(saveComposite);
}
/**
* Returns the location for a label
*
* @param labelBounds the label bounds.
* @param ascent the ascent (height of font).
* @param plotArea the plot area
* @param startAngle the start angle for the pie series.
*
* @return The location for a label.
*/
protected Point2D calculateLabelLocation(Rectangle2D labelBounds,
double ascent,
Rectangle2D plotArea,
double startAngle)
{
Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
Point2D point1 = arc1.getEndPoint();
double deltaX = -(point1.getX() - plotArea.getCenterX())
* this.axisLabelGap;
double deltaY = -(point1.getY() - plotArea.getCenterY())
* this.axisLabelGap;
double labelX = point1.getX() - deltaX;
double labelY = point1.getY() - deltaY;
if (labelX < plotArea.getCenterX()) {
labelX -= labelBounds.getWidth();
}
if (labelX == plotArea.getCenterX()) {
labelX -= labelBounds.getWidth() / 2;
}
if (labelY > plotArea.getCenterY()) {
labelY += ascent;
}
return new Point2D.Double(labelX, labelY);
}
/**
* Tests this plot for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof SpiderWebPlot)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
SpiderWebPlot that = (SpiderWebPlot) obj;
if (!this.dataExtractOrder.equals(that.dataExtractOrder)) {
return false;
}
if (this.headPercent != that.headPercent) {
return false;
}
if (this.interiorGap != that.interiorGap) {
return false;
}
if (this.startAngle != that.startAngle) {
return false;
}
if (!this.direction.equals(that.direction)) {
return false;
}
if (this.maxValue != that.maxValue) {
return false;
}
if (this.webFilled != that.webFilled) {
return false;
}
if (this.axisLabelGap != that.axisLabelGap) {
return false;
}
if (!PaintUtilities.equal(this.axisLinePaint, that.axisLinePaint)) {
return false;
}
if (!this.axisLineStroke.equals(that.axisLineStroke)) {
return false;
}
if (!ShapeUtilities.equal(this.legendItemShape, that.legendItemShape)) {
return false;
}
if (!PaintUtilities.equal(this.seriesPaint, that.seriesPaint)) {
return false;
}
if (!this.seriesPaintList.equals(that.seriesPaintList)) {
return false;
}
if (!PaintUtilities.equal(this.baseSeriesPaint, that.baseSeriesPaint)) {
return false;
}
if (!PaintUtilities.equal(this.seriesOutlinePaint,
that.seriesOutlinePaint)) {
return false;
}
if (!this.seriesOutlinePaintList.equals(that.seriesOutlinePaintList)) {
return false;
}
if (!PaintUtilities.equal(this.baseSeriesOutlinePaint,
that.baseSeriesOutlinePaint)) {
return false;
}
if (!ObjectUtilities.equal(this.seriesOutlineStroke,
that.seriesOutlineStroke)) {
return false;
}
if (!this.seriesOutlineStrokeList.equals(
that.seriesOutlineStrokeList)) {
return false;
}
if (!this.baseSeriesOutlineStroke.equals(
that.baseSeriesOutlineStroke)) {
return false;
}
if (!this.labelFont.equals(that.labelFont)) {
return false;
}
if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) {
return false;
}
if (!this.labelGenerator.equals(that.labelGenerator)) {
return false;
}
if (!ObjectUtilities.equal(this.toolTipGenerator,
that.toolTipGenerator)) {
return false;
}
if (!ObjectUtilities.equal(this.urlGenerator,
that.urlGenerator)) {
return false;
}
return true;
}
/**
* Returns a clone of this plot.
*
* @return A clone of this plot.
*
* @throws CloneNotSupportedException if the plot cannot be cloned for
* any reason.
*/
public Object clone() throws CloneNotSupportedException {
SpiderWebPlot clone = (SpiderWebPlot) super.clone();
clone.legendItemShape = ShapeUtilities.clone(this.legendItemShape);
clone.seriesPaintList = (PaintList) this.seriesPaintList.clone();
clone.seriesOutlinePaintList
= (PaintList) this.seriesOutlinePaintList.clone();
clone.seriesOutlineStrokeList
= (StrokeList) this.seriesOutlineStrokeList.clone();
return clone;
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtilities.writeShape(this.legendItemShape, stream);
SerialUtilities.writePaint(this.seriesPaint, stream);
SerialUtilities.writePaint(this.baseSeriesPaint, stream);
SerialUtilities.writePaint(this.seriesOutlinePaint, stream);
SerialUtilities.writePaint(this.baseSeriesOutlinePaint, stream);
SerialUtilities.writeStroke(this.seriesOutlineStroke, stream);
SerialUtilities.writeStroke(this.baseSeriesOutlineStroke, stream);
SerialUtilities.writePaint(this.labelPaint, stream);
SerialUtilities.writePaint(this.axisLinePaint, stream);
SerialUtilities.writeStroke(this.axisLineStroke, stream);
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream) throws IOException,
ClassNotFoundException {
stream.defaultReadObject();
this.legendItemShape = SerialUtilities.readShape(stream);
this.seriesPaint = SerialUtilities.readPaint(stream);
this.baseSeriesPaint = SerialUtilities.readPaint(stream);
this.seriesOutlinePaint = SerialUtilities.readPaint(stream);
this.baseSeriesOutlinePaint = SerialUtilities.readPaint(stream);
this.seriesOutlineStroke = SerialUtilities.readStroke(stream);
this.baseSeriesOutlineStroke = SerialUtilities.readStroke(stream);
this.labelPaint = SerialUtilities.readPaint(stream);
this.axisLinePaint = SerialUtilities.readPaint(stream);
this.axisLineStroke = SerialUtilities.readStroke(stream);
if (this.dataset != null) {
this.dataset.addChangeListener(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -