📄 barrenderer.java
字号:
Paint paint = getItemLabelPaint(row, column);
g2.setPaint(paint);
String label = generator.generateItemLabel(dataset, row, column);
// get the label anchor..
ItemLabelAnchor labelAnchor = getItemLabelAnchor(row, column);
TextAnchor textAnchor = getItemLabelTextAnchor(row, column);
TextAnchor rotationAnchor = getItemLabelRotationAnchor(row, column);
if (transY2 > transY1) {
labelAnchor = ItemLabelAnchor.getVerticalOpposite(labelAnchor);
textAnchor = TextAnchor.getVerticalOpposite(textAnchor);
rotationAnchor = TextAnchor.getVerticalOpposite(rotationAnchor);
}
double angle = getItemLabelAngle(row, column).doubleValue();
// work out the label anchor point...
Point2D anchorPoint = calculateLabelAnchorPoint(labelAnchor, bar,
PlotOrientation.VERTICAL);
RefineryUtilities.drawRotatedString(label, g2,
(float) anchorPoint.getX(),
(float) anchorPoint.getY(),
textAnchor, rotationAnchor, angle);
}
// collect entity and tool tip information...
if (getInfo() != null) {
EntityCollection entities = getInfo().getEntityCollection();
if (entities != null) {
String tip = null;
if (generator != null) {
tip = generator.generateToolTip(dataset, row, column);
}
String url = null;
if (getItemURLGenerator(row, column) != null) {
url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
}
CategoryItemEntity entity = new CategoryItemEntity(
bar, tip, url, dataset, row, dataset.getColumnKey(column), column
);
entities.addEntity(entity);
}
}
}
/**
* Calculates the item label anchor point.
*
* @param anchor the anchor.
* @param bar the bar.
* @param orientation the plot orientation.
*
* @return The anchor point.
*/
private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor,
Rectangle2D bar, PlotOrientation orientation) {
Point2D result = null;
if (orientation == PlotOrientation.HORIZONTAL) {
result = getHorizontalLabelAnchorPoint(anchor, bar);
}
else if (orientation == PlotOrientation.VERTICAL) {
result = getVerticalLabelAnchorPoint(anchor, bar);
}
return result;
}
/**
* Returns the label anchor point for a horizontal bar.
*
* @param anchor the label anchor.
* @param bar the bar area.
*
* @return The anchor point.
*/
private Point2D getHorizontalLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar) {
Point2D result = null;
double x0 = bar.getX() - this.itemLabelAnchorOffset;
double x1 = bar.getX();
double x2 = bar.getX() + this.itemLabelAnchorOffset;
double x3 = bar.getCenterX();
double x4 = bar.getMaxX() - this.itemLabelAnchorOffset;
double x5 = bar.getMaxX();
double x6 = bar.getMaxX() + this.itemLabelAnchorOffset;
double y0 = bar.getMaxY() + this.itemLabelAnchorOffset;
double y1 = bar.getMaxY();
double y2 = bar.getMaxY() - this.itemLabelAnchorOffset;
double y3 = bar.getCenterY();
double y4 = bar.getMinY() + this.itemLabelAnchorOffset;
double y5 = bar.getMinY();
double y6 = bar.getMinY() - this.itemLabelAnchorOffset;
if (anchor == ItemLabelAnchor.CENTER) {
result = new Point2D.Double(x3, y3);
}
else if (anchor == ItemLabelAnchor.INSIDE1) {
result = new Point2D.Double(x4, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE2) {
result = new Point2D.Double(x4, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE3) {
result = new Point2D.Double(x3, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE4) {
result = new Point2D.Double(x2, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE5) {
result = new Point2D.Double(x2, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE6) {
result = new Point2D.Double(x2, y3);
}
else if (anchor == ItemLabelAnchor.INSIDE7) {
result = new Point2D.Double(x2, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE8) {
result = new Point2D.Double(x2, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE9) {
result = new Point2D.Double(x3, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE10) {
result = new Point2D.Double(x4, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE11) {
result = new Point2D.Double(x4, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE12) {
result = new Point2D.Double(x4, y3);
}
else if (anchor == ItemLabelAnchor.OUTSIDE1) {
result = new Point2D.Double(x6, y1);
}
else if (anchor == ItemLabelAnchor.OUTSIDE2) {
result = new Point2D.Double(x5, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE3) {
result = new Point2D.Double(x3, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE4) {
result = new Point2D.Double(x1, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE5) {
result = new Point2D.Double(x0, y1);
}
else if (anchor == ItemLabelAnchor.OUTSIDE6) {
result = new Point2D.Double(x0, y3);
}
else if (anchor == ItemLabelAnchor.OUTSIDE7) {
result = new Point2D.Double(x0, y5);
}
else if (anchor == ItemLabelAnchor.OUTSIDE8) {
result = new Point2D.Double(x1, y6);
}
else if (anchor == ItemLabelAnchor.OUTSIDE9) {
result = new Point2D.Double(x3, y6);
}
else if (anchor == ItemLabelAnchor.OUTSIDE10) {
result = new Point2D.Double(x5, y6);
}
else if (anchor == ItemLabelAnchor.OUTSIDE11) {
result = new Point2D.Double(x6, y5);
}
else if (anchor == ItemLabelAnchor.OUTSIDE12) {
result = new Point2D.Double(x6, y3);
}
return result;
}
/**
* Returns the label anchor point for a vertical bar.
*
* @param anchor the label anchor.
* @param bar the bar area.
*
* @return The anchor point.
*/
private Point2D getVerticalLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar) {
Point2D result = null;
double x0 = bar.getX() - this.itemLabelAnchorOffset;
double x1 = bar.getX();
double x2 = bar.getX() + this.itemLabelAnchorOffset;
double x3 = bar.getCenterX();
double x4 = bar.getMaxX() - this.itemLabelAnchorOffset;
double x5 = bar.getMaxX();
double x6 = bar.getMaxX() + this.itemLabelAnchorOffset;
double y0 = bar.getMaxY() + this.itemLabelAnchorOffset;
double y1 = bar.getMaxY();
double y2 = bar.getMaxY() - this.itemLabelAnchorOffset;
double y3 = bar.getCenterY();
double y4 = bar.getMinY() + this.itemLabelAnchorOffset;
double y5 = bar.getMinY();
double y6 = bar.getMinY() - this.itemLabelAnchorOffset;
if (anchor == ItemLabelAnchor.CENTER) {
result = new Point2D.Double(x3, y3);
}
else if (anchor == ItemLabelAnchor.INSIDE1) {
result = new Point2D.Double(x4, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE2) {
result = new Point2D.Double(x4, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE3) {
result = new Point2D.Double(x4, y3);
}
else if (anchor == ItemLabelAnchor.INSIDE4) {
result = new Point2D.Double(x4, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE5) {
result = new Point2D.Double(x4, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE6) {
result = new Point2D.Double(x3, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE7) {
result = new Point2D.Double(x2, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE8) {
result = new Point2D.Double(x2, y2);
}
else if (anchor == ItemLabelAnchor.INSIDE9) {
result = new Point2D.Double(x2, y3);
}
else if (anchor == ItemLabelAnchor.INSIDE10) {
result = new Point2D.Double(x2, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE11) {
result = new Point2D.Double(x2, y4);
}
else if (anchor == ItemLabelAnchor.INSIDE12) {
result = new Point2D.Double(x3, y4);
}
else if (anchor == ItemLabelAnchor.OUTSIDE1) {
result = new Point2D.Double(x5, y6);
}
else if (anchor == ItemLabelAnchor.OUTSIDE2) {
result = new Point2D.Double(x6, y5);
}
else if (anchor == ItemLabelAnchor.OUTSIDE3) {
result = new Point2D.Double(x6, y3);
}
else if (anchor == ItemLabelAnchor.OUTSIDE4) {
result = new Point2D.Double(x6, y1);
}
else if (anchor == ItemLabelAnchor.OUTSIDE5) {
result = new Point2D.Double(x5, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE6) {
result = new Point2D.Double(x3, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE7) {
result = new Point2D.Double(x1, y0);
}
else if (anchor == ItemLabelAnchor.OUTSIDE8) {
result = new Point2D.Double(x0, y1);
}
else if (anchor == ItemLabelAnchor.OUTSIDE9) {
result = new Point2D.Double(x0, y3);
}
else if (anchor == ItemLabelAnchor.OUTSIDE10) {
result = new Point2D.Double(x0, y5);
}
else if (anchor == ItemLabelAnchor.OUTSIDE11) {
result = new Point2D.Double(x1, y6);
}
else if (anchor == ItemLabelAnchor.OUTSIDE12) {
result = new Point2D.Double(x3, y6);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -