📄 xyplot.java
字号:
*
* @param g2 the graphics device.
* @param plotArea the area within which the plot (including axes and labels) should be drawn.
* @param info collects chart drawing information (<code>null</code> permitted).
*/
public void draw(Graphics2D g2, Rectangle2D plotArea, ChartRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(plotArea);
}
// adjust the drawing area for the plot insets (if any)...
Insets insets = getInsets();
if (insets != null) {
plotArea.setRect(plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom);
}
AxisSpace space = calculateAxisSpace(g2, plotArea);
Rectangle2D dataArea = space.shrink(plotArea, null);
this.axisOffset.trim(dataArea);
if (info != null) {
info.setDataArea(dataArea);
}
CrosshairInfo crosshairInfo = new CrosshairInfo();
crosshairInfo.setCrosshairDistance(Double.POSITIVE_INFINITY);
crosshairInfo.setAnchorX(getAnchorX());
crosshairInfo.setAnchorY(getAnchorY());
// draw the plot background and axes...
drawBackground(g2, dataArea);
drawAxes(g2, plotArea, dataArea);
if (this.renderer != null) {
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
drawDomainTickBands(g2, dataArea);
drawRangeTickBands(g2, dataArea);
drawGridlines(g2, dataArea);
if (this.domainMarkers != null) {
Iterator iterator = this.domainMarkers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
renderer.drawDomainMarker(g2, this, getDomainAxis(), marker, dataArea);
}
}
if (this.rangeMarkers != null) {
Iterator iterator = this.rangeMarkers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
renderer.drawRangeMarker(g2, this, getRangeAxis(), marker, dataArea);
}
}
if (this.secondaryRangeMarkers != null) {
Iterator iterator = this.secondaryRangeMarkers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
renderer.drawRangeMarker(g2, this, getSecondaryRangeAxis(0), marker, dataArea);
}
}
// draw...
render(g2, dataArea, info, crosshairInfo);
render2(g2, dataArea, info, crosshairInfo);
drawAnnotations(g2, dataArea, info);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
}
drawOutline(g2, dataArea);
}
/**
* Draws the domain tick bands, if any.
*
* @param g2 the graphics device.
* @param dataArea the data area.
*/
public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea) {
// draw the domain tick bands, if any...
Paint bandPaint = getDomainTickBandPaint();
if (bandPaint != null) {
boolean fillBand = false;
final ValueAxis xAxis = getDomainAxis();
double previous = xAxis.getMinimumAxisValue();
Iterator iterator = xAxis.getTicks().iterator();
while (iterator.hasNext()) {
Tick tick = (Tick) iterator.next();
double current = tick.getNumericalValue();
if (fillBand) {
this.renderer.fillDomainGridBand(g2, this, xAxis, dataArea, previous, current);
}
previous = current;
fillBand = !fillBand;
}
double end = xAxis.getMaximumAxisValue();
if (fillBand) {
this.renderer.fillDomainGridBand(g2, this, xAxis, dataArea, previous, end);
}
}
}
/**
* Draws the range tick bands, if any.
*
* @param g2 the graphics device.
* @param dataArea the data area.
*/
public void drawRangeTickBands(Graphics2D g2, Rectangle2D dataArea) {
// draw the range tick bands, if any...
Paint bandPaint = getRangeTickBandPaint();
if (bandPaint != null) {
boolean fillBand = false;
final ValueAxis rangeAxis = getRangeAxis();
double previous = rangeAxis.getMinimumAxisValue();
Iterator iterator = rangeAxis.getTicks().iterator();
while (iterator.hasNext()) {
Tick tick = (Tick) iterator.next();
double current = tick.getNumericalValue();
if (fillBand) {
renderer.fillRangeGridBand(g2, this, rangeAxis, dataArea, previous, current);
}
previous = current;
fillBand = !fillBand;
}
double end = rangeAxis.getMaximumAxisValue();
if (fillBand) {
renderer.fillRangeGridBand(g2, this, rangeAxis, dataArea, previous, end);
}
}
}
/**
* A utility method for drawing the axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param dataArea the data area.
*/
protected void drawAxes(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea) {
this.axesAtTop.clear();
this.axesAtBottom.clear();
this.axesAtLeft.clear();
this.axesAtRight.clear();
// add each axis to the appropriate list...
if (this.domainAxis != null) {
addAxisToList(this.domainAxis, getDomainAxisEdge());
}
if (this.rangeAxis != null) {
addAxisToList(this.rangeAxis, getRangeAxisEdge());
}
// add secondary domain axes to lists...
for (int index = 0; index < this.secondaryDomainAxes.size(); index++) {
ValueAxis secondaryAxis = (ValueAxis) this.secondaryDomainAxes.get(index);
if (secondaryAxis != null) {
addAxisToList(secondaryAxis, getSecondaryDomainAxisEdge(index));
}
}
// add secondary range axes to lists...
for (int index = 0; index < this.secondaryRangeAxes.size(); index++) {
ValueAxis secondaryAxis = (ValueAxis) this.secondaryRangeAxes.get(index);
if (secondaryAxis != null) {
addAxisToList(secondaryAxis, getSecondaryRangeAxisEdge(index));
}
}
// draw the top axes
double cursor = dataArea.getMinY() - this.axisOffset.getTopSpace(dataArea.getHeight());
Iterator iterator = this.axesAtTop.iterator();
while (iterator.hasNext()) {
ValueAxis axis = (ValueAxis) iterator.next();
double used = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.TOP);
cursor = cursor - used;
}
// draw the bottom axes
cursor = dataArea.getMaxY() + this.axisOffset.getBottomSpace(dataArea.getHeight());
iterator = this.axesAtBottom.iterator();
while (iterator.hasNext()) {
ValueAxis axis = (ValueAxis) iterator.next();
double used = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM);
cursor = cursor + used;
}
// draw the left axes
cursor = dataArea.getMinX() - this.axisOffset.getLeftSpace(dataArea.getWidth());
iterator = this.axesAtLeft.iterator();
while (iterator.hasNext()) {
ValueAxis axis = (ValueAxis) iterator.next();
double used = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT);
cursor = cursor - used;
}
// draw the right axes
cursor = dataArea.getMaxX() + this.axisOffset.getRightSpace(dataArea.getWidth());
iterator = this.axesAtRight.iterator();
while (iterator.hasNext()) {
ValueAxis axis = (ValueAxis) iterator.next();
double used = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.RIGHT);
cursor = cursor + used;
}
}
/**
* Draws a representation of the data within the dataArea region, using the
* current renderer.
* <P>
* The <code>info</code> and <code>crosshairInfo</code> arguments may be <code>null</code>.
*
* @param g2 the graphics device.
* @param dataArea the region in which the data is to be drawn.
* @param info an optional object for collection dimension information.
* @param crosshairInfo an optional object for collecting crosshair info.
*/
public void render(Graphics2D g2, Rectangle2D dataArea,
ChartRenderingInfo info, CrosshairInfo crosshairInfo) {
// now get the data and plot it (the visual representation will depend
// on the renderer that has been set)...
XYDataset data = getDataset();
if (!DatasetUtilities.isEmptyOrNull(data)) {
int passCount = this.renderer.initialise(g2, dataArea, this, data, info);
ValueAxis xAxis = getDomainAxis();
ValueAxis yAxis = getRangeAxis();
for (int pass = 0; pass < passCount; pass++) {
int seriesCount = data.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
int itemCount = data.getItemCount(series);
for (int item = 0; item < itemCount; item++) {
renderer.drawItem(g2, dataArea, info, this,
xAxis, yAxis,
data, series, item,
crosshairInfo, pass);
}
}
}
// draw vertical crosshair if required...
setDomainCrosshairValue(crosshairInfo.getCrosshairX(), false);
if (isDomainCrosshairVisible()) {
drawVerticalLine(g2, dataArea,
getDomainCrosshairValue(),
getDomainCrosshairStroke(),
getDomainCrosshairPaint());
}
// draw horizontal crosshair if required...
setRangeCrosshairValue(crosshairInfo.getCrosshairY(), false);
if (isRangeCrosshairVisible()) {
drawHorizontalLine(g2, dataArea,
getRangeCrosshairValue(),
getRangeCrosshairStroke(),
getRangeCrosshairPaint());
}
}
else {
drawNoDataMessage(g2, dataArea);
}
}
/**
* Draws a representation of the data within the dataArea region, using the
* current renderer.
* <P>
* The <code>info</code> and <code>crosshairInfo</code> arguments may be <code>null</code>.
*
* @param g2 the graphics device.
* @param dataArea the region in which the data is to be drawn.
* @param info an optional object for collection dimension information.
* @param crosshairInfo an optional object for collecting crosshair info.
*/
public void render2(Graphics2D g2, Rectangle2D dataArea,
ChartRenderingInfo info, CrosshairInfo crosshairInfo) {
for (int i = 0; i < getSecondaryDatasetCount(); i++) {
XYDataset dataset2 = getSecondaryDataset(i);
if (!DatasetUtilities.isEmptyOrNull(dataset2)) {
ValueAxis xAxis = getDomainAxis();
Integer key = (Integer) this.secondaryDatasetDomainAxisMap.get(i);
if (key != null) {
ValueAxis axis = getSecondaryDomainAxis(key.intValue());
if (axis != null) {
xAxis = axis;
}
}
ValueAxis yAxis = getRangeAxis();
Integer key2 = (Integer) this.secondaryDatasetRangeAxisMap.get(i);
if (key2 != null) {
ValueAxis axis = getSecondaryRangeAxis(key2.intValue());
if (axis != null) {
yAxis = axis;
}
}
XYItemRenderer renderer = getSecondaryRenderer(i);
if (renderer == null) {
renderer = getRenderer();
}
int passCount = renderer.initialise(g2, dataArea, this, dataset2, info);
for (int pass = 0; pass < passCount; pass++) {
int seriesCount = dataset2.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
int itemCount = dataset2.getItemCount(series);
for (int item = 0; item < itemCount; item++) {
renderer.drawItem(g2, dataArea, info, this,
xAxis, yAxis,
dataset2, series, item,
crosshairInfo, pass);
}
}
}
}
}
}
/**
* Draws the gridlines for the plot, if they are visible.
*
* @param g2 the graphics device.
* @param dataArea the data area.
*/
protected void drawGridlines(Graphics2D g2, Rectangle2D dataArea) {
// no renderer, no gridlines...
if (this.renderer == null) {
return;
}
// draw the domain grid lines, if any...
if (isDomainGridlinesVisible()) {
Stroke gridStroke = getDomainGridlineStroke();
Paint gridPaint = getDomainGridlinePaint();
if ((gridStroke != null) && (gridPaint != null)) {
Iterator iterator = getDomainAxis().getTicks().iterator();
while (iterator.hasNext()) {
Tick tick = (Tick) iterator.next();
this.renderer.draw
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -