📄 contourplot.java
字号:
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the range axis for the plot.
*
* @return The range axis.
*/
public ValueAxis getRangeAxis() {
ValueAxis result = this.rangeAxis;
return result;
}
/**
* Sets the range axis for the plot.
* <P>
* An exception is thrown if the new axis and the plot are not mutually
* compatible.
*
* @param axis The new axis (null permitted).
*/
public void setRangeAxis(ValueAxis axis) {
if (axis != null) {
axis.setPlot(this);
axis.addChangeListener(this);
}
// plot is likely registered as a listener with the existing axis...
if (this.rangeAxis != null) {
this.rangeAxis.removeChangeListener(this);
}
this.rangeAxis = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Sets the colorbar for the plot.
*
* @param axis The new axis (null permitted).
*/
public void setColorBarAxis(ColorBar axis) {
this.colorBar = axis;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the data area ratio.
*
* @return The ratio.
*/
public double getDataAreaRatio() {
return this.dataAreaRatio;
}
/**
* Sets the data area ratio.
*
* @param ratio the ratio.
*/
public void setDataAreaRatio(double ratio) {
this.dataAreaRatio = ratio;
}
/**
* Adds a marker for the domain axis.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to the range axis, however this is entirely up to the renderer.
*
* @param marker the marker.
*/
public void addDomainMarker(Marker marker) {
if (this.domainMarkers == null) {
this.domainMarkers = new java.util.ArrayList();
}
this.domainMarkers.add(marker);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the domain markers.
*/
public void clearDomainMarkers() {
if (this.domainMarkers != null) {
this.domainMarkers.clear();
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Adds a marker for the range axis.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to the range axis, however this is entirely up to the renderer.
*
* @param marker The marker.
*/
public void addRangeMarker(Marker marker) {
if (this.rangeMarkers == null) {
this.rangeMarkers = new java.util.ArrayList();
}
this.rangeMarkers.add(marker);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the range markers.
*/
public void clearRangeMarkers() {
if (this.rangeMarkers != null) {
this.rangeMarkers.clear();
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Adds an annotation to the plot.
*
* @param annotation the annotation.
*/
public void addAnnotation(XYAnnotation annotation) {
if (this.annotations == null) {
this.annotations = new java.util.ArrayList();
}
this.annotations.add(annotation);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the annotations.
*/
public void clearAnnotations() {
if (this.annotations != null) {
this.annotations.clear();
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Checks the compatibility of a domain axis, returning true if the axis is
* compatible with the plot, and false otherwise.
*
* @param axis The proposed axis.
*
* @return <code>true</code> if the axis is compatible with the plot.
*/
public boolean isCompatibleDomainAxis(ValueAxis axis) {
return true;
}
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
* <P>
* The optional <code>info</code> argument collects information about the
* rendering of the plot (dimensions, tooltip information etc). Just pass
* in <code>null</code> if you do not need this information.
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axis labels)
* 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 chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
PlotState parentState,
PlotRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
AxisSpace space = new AxisSpace();
space = this.domainAxis.reserveSpace(g2, this, area,
RectangleEdge.BOTTOM, space);
space = this.rangeAxis.reserveSpace(g2, this, area,
RectangleEdge.LEFT, space);
Rectangle2D estimatedDataArea = space.shrink(area, null);
AxisSpace space2 = new AxisSpace();
space2 = this.colorBar.reserveSpace(g2, this, area, estimatedDataArea,
this.colorBarLocation, space2);
Rectangle2D adjustedPlotArea = space2.shrink(area, null);
Rectangle2D dataArea = space.shrink(adjustedPlotArea, null);
Rectangle2D colorBarArea = space2.reserved(area, this.colorBarLocation);
// additional dataArea modifications
if (getDataAreaRatio() != 0.0) { //check whether modification is
double ratio = getDataAreaRatio();
Rectangle2D tmpDataArea = (Rectangle2D) dataArea.clone();
double h = tmpDataArea.getHeight();
double w = tmpDataArea.getWidth();
if (ratio > 0) { // ratio represents pixels
if (w * ratio <= h) {
h = ratio * w;
}
else {
w = h / ratio;
}
}
else { // ratio represents axis units
ratio *= -1.0;
double xLength = getDomainAxis().getRange().getLength();
double yLength = getRangeAxis().getRange().getLength();
double unitRatio = yLength / xLength;
ratio = unitRatio * ratio;
if (w * ratio <= h) {
h = ratio * w;
}
else {
w = h / ratio;
}
}
dataArea.setRect(tmpDataArea.getX() + tmpDataArea.getWidth() / 2
- w / 2, tmpDataArea.getY(), w, h);
}
if (info != null) {
info.setDataArea(dataArea);
}
CrosshairState crosshairState = new CrosshairState();
crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
// draw the plot background...
drawBackground(g2, dataArea);
double cursor = dataArea.getMaxY();
if (this.domainAxis != null) {
this.domainAxis.draw(g2, cursor, adjustedPlotArea, dataArea,
RectangleEdge.BOTTOM, info);
}
if (this.rangeAxis != null) {
cursor = dataArea.getMinX();
this.rangeAxis.draw(g2, cursor, adjustedPlotArea, dataArea,
RectangleEdge.LEFT, info);
}
if (this.colorBar != null) {
cursor = 0.0;
cursor = this.colorBar.draw(g2, cursor, adjustedPlotArea, dataArea,
colorBarArea, this.colorBarLocation);
}
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
getForegroundAlpha()));
render(g2, dataArea, info, crosshairState);
if (this.domainMarkers != null) {
Iterator iterator = this.domainMarkers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
drawDomainMarker(g2, this, getDomainAxis(), marker, dataArea);
}
}
if (this.rangeMarkers != null) {
Iterator iterator = this.rangeMarkers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
drawRangeMarker(g2, this, getRangeAxis(), marker, dataArea);
}
}
// TO DO: these annotations only work with XYPlot, see if it is possible to
// make ContourPlot a subclass of XYPlot (DG);
// // draw the annotations...
// if (this.annotations != null) {
// Iterator iterator = this.annotations.iterator();
// while (iterator.hasNext()) {
// Annotation annotation = (Annotation) iterator.next();
// if (annotation instanceof XYAnnotation) {
// XYAnnotation xya = (XYAnnotation) annotation;
// // get the annotation to draw itself...
// xya.draw(g2, this, dataArea, getDomainAxis(),
// getRangeAxis());
// }
// }
// }
g2.setClip(originalClip);
g2.setComposite(originalComposite);
drawOutline(g2, dataArea);
}
/**
* Draws a representation of the data within the dataArea region, using the
* current renderer.
* <P>
* The <code>info</code> and <code>crosshairState</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 crosshairState an optional object for collecting crosshair info.
*/
public void render(Graphics2D g2, Rectangle2D dataArea,
PlotRenderingInfo info, CrosshairState crosshairState) {
// now get the data and plot it (the visual representation will depend
// on the renderer that has been set)...
ContourDataset data = getDataset();
if (data != null) {
ColorBar zAxis = getColorBar();
if (this.clipPath != null) {
GeneralPath clipper = getClipPath().draw(g2, dataArea,
this.domainAxis, this.rangeAxis);
if (this.clipPath.isClip()) {
g2.clip(clipper);
}
}
if (this.renderAsPoints) {
pointRenderer(g2, dataArea, info, this, this.domainAxis,
this.rangeAxis, zAxis, data, crosshairState);
}
else {
contourRenderer(g2, dataArea, info, this, this.domainAxis,
this.rangeAxis, zAxis, data, crosshairState);
}
// draw vertical crosshair if required...
setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -