?? contourplot.java
字號:
if (getToolTipGenerator() != null) {
tip = toolTipGenerator.generateToolTip(data, k);
}
// Shape s = g2.getClip();
// if (s.contains(rect) || s.intersects(rect)) {
String url = null;
// if (getURLGenerator() != null) { //dmo: look at this later
// url = getURLGenerator().generateURL(data, series, item);
// }
// Unlike XYItemRenderer, we need to clone entityArea since it reused.
ContourEntity entity = new ContourEntity((Rectangle2D.Double) entityArea.clone(),
tip, url);
entity.setIndex(k);
entities.addEntity(entity);
// }
}
// do we need to update the crosshair values?
if (plot.isDomainCrosshairLockedOnData()) {
if (plot.isRangeCrosshairLockedOnData()) {
// both axes
crosshairInfo.updateCrosshairPoint(transX, transY);
}
else {
// just the horizontal axis...
crosshairInfo.updateCrosshairX(transX);
}
}
else {
if (plot.isRangeCrosshairLockedOnData()) {
// just the vertical axis...
crosshairInfo.updateCrosshairY(transY);
}
}
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias);
return;
}
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param dataArea the area within which the data is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color information etc).
* @param domainAxis the domain (horizontal) axis.
* @param rangeAxis the range (vertical) axis.
* @param colorBar the color bar axis.
* @param data the dataset.
* @param crosshairInfo information about crosshairs on a plot.
*/
public void pointRenderer(Graphics2D g2,
Rectangle2D dataArea,
ChartRenderingInfo info,
ContourPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
ColorBar colorBar,
ContourDataset data,
CrosshairInfo crosshairInfo) {
// setup for collecting optional entity info...
RectangularShape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getEntityCollection();
}
// Rectangle2D.Double rect = null;
// rect = new Rectangle2D.Double();
RectangularShape rect = new Ellipse2D.Double();
//turn off anti-aliasing when filling rectangles
Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
// if (tooltips!=null) tooltips.clearToolTips(); // reset collection
// get the data points
Number[] xNumber = data.getXValues();
Number[] yNumber = data.getYValues();
Number[] zNumber = data.getZValues();
double[] x = new double[xNumber.length];
double[] y = new double[yNumber.length];
// double[] z = new double[zNumber.length];
for (int i = 0; i < x.length; i++) {
x[i] = xNumber[i].doubleValue();
y[i] = yNumber[i].doubleValue();
// z[i] = zNumber[i].doubleValue();
}
// int[] xIndex = ((DefaultContourDataset) data).indexX();
// int[] indexX = ((DefaultContourDataset) data).getXIndices();
// boolean vertInverted = ((NumberAxis) verticalAxis).isInverted();
// boolean horizInverted = false;
// if (horizontalAxis instanceof NumberAxis)
// horizInverted = ((NumberAxis) horizontalAxis).isInverted();
double transX = 0.0;
double transDX = 0.0;
double transY = 0.0;
double transDY = 0.0;
double size = dataArea.getWidth() * ptSizePct;
for (int k = 0; k < x.length; k++) {
transX = domainAxis.translateValueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM)
- 0.5 * size;
transY = rangeAxis.translateValueToJava2D(y[k], dataArea, RectangleEdge.LEFT)
- 0.5 * size;
transDX = size;
transDY = size;
rect.setFrame(transX, transY, transDX, transDY);
if (zNumber[k] != null) {
g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue()));
g2.fill(rect);
}
else if (missingPaint != null) {
g2.setPaint(missingPaint);
g2.fill(rect);
}
entityArea = rect;
// add an entity for the item...
if (entities != null) {
String tip = null;
if (getToolTipGenerator() != null) {
tip = toolTipGenerator.generateToolTip(data, k);
}
String url = null;
// if (getURLGenerator() != null) { //dmo: look at this later
// url = getURLGenerator().generateURL(data, series, item);
// }
//Unlike XYItemRenderer, we need to clone entityArea since it reused.
ContourEntity entity = new ContourEntity((RectangularShape) entityArea.clone(),
tip, url);
entity.setIndex(k);
entities.addEntity(entity);
}
// do we need to update the crosshair values?
if (plot.isDomainCrosshairLockedOnData()) {
if (plot.isRangeCrosshairLockedOnData()) {
// both axes
crosshairInfo.updateCrosshairPoint(transX, transY);
}
else {
// just the horizontal axis...
crosshairInfo.updateCrosshairX(transX);
}
}
else {
if (plot.isRangeCrosshairLockedOnData()) {
// just the vertical axis...
crosshairInfo.updateCrosshairY(transY);
}
}
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias);
return;
}
/**
* Utility method for drawing a crosshair on the chart (if required).
*
* @param g2 The graphics device.
* @param dataArea The data area.
* @param value The coordinate, where to draw the line.
* @param stroke The stroke to use.
* @param paint The paint to use.
*/
protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
double value, Stroke stroke, Paint paint) {
double xx = getDomainAxis().translateValueToJava2D(value, dataArea, RectangleEdge.BOTTOM);
Line2D line = new Line2D.Double(xx, dataArea.getMinY(),
xx, dataArea.getMaxY());
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
* Utility method for drawing a crosshair on the chart (if required).
*
* @param g2 The graphics device.
* @param dataArea The data area.
* @param value The coordinate, where to draw the line.
* @param stroke The stroke to use.
* @param paint The paint to use.
*/
protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea,
double value, Stroke stroke, Paint paint) {
double yy = getRangeAxis().translateValueToJava2D(value, dataArea, RectangleEdge.LEFT);
Line2D line = new Line2D.Double(dataArea.getMinX(), yy,
dataArea.getMaxX(), yy);
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
/**
* Handles a 'click' on the plot by updating the anchor values...
*
* @param x x-coordinate, where the click occured.
* @param y y-coordinate, where the click occured.
* @param info An object for collection dimension information.
*/
public void handleClick(int x, int y, ChartRenderingInfo info) {
/* // set the anchor value for the horizontal axis...
ValueAxis hva = getDomainAxis();
if (hva != null) {
double hvalue = hva.translateJava2DtoValue((float) x, info.getDataArea());
hva.setAnchorValue(hvalue);
setDomainCrosshairValue(hvalue);
}
// set the anchor value for the vertical axis...
ValueAxis vva = this.getRangeAxis();
if (vva != null) {
double vvalue = vva.translateJava2DtoValue((float) y, info.getDataArea());
vva.setAnchorValue(vvalue);
setRangeCrosshairValue(vvalue);
}
*/
}
/**
* Zooms the axis ranges by the specified percentage about the anchor point.
*
* @param percent The amount of the zoom.
*/
public void zoom(double percent) {
if (percent > 0) {
double range = this.domainAxis.getRange().getLength();
double scaledRange = range * percent;
// domainAxis.setAnchoredRange(scaledRange);
range = this.rangeAxis.getRange().getLength();
scaledRange = range * percent;
// rangeAxis.setAnchoredRange(scaledRange);
}
else {
getRangeAxis().setAutoRange(true);
getDomainAxis().setAutoRange(true);
}
}
/**
* Returns the plot type as a string.
*
* @return A short string describing the type of plot.
*/
public String getPlotType() {
return localizationResources.getString("Contour_Plot");
}
/**
* Returns the range for an axis.
*
* @param axis the axis.
*
* @return The range for an axis.
*/
public Range getDataRange(ValueAxis axis) {
if (this.dataset == null) {
return null;
}
Range result = null;
if (axis == getDomainAxis()) {
result = DatasetUtilities.getDomainExtent(dataset);
}
else if (axis == getRangeAxis()) {
result = DatasetUtilities.getRangeExtent(dataset);
}
return result;
}
/**
* Returns the range for the Contours.
*
* @return The range for the Contours (z-axis).
*/
public Range getContourDataRange() {
Range result = null;
ContourDataset data = (ContourDataset) getDataset();
if (data != null) {
Range h = getDomainAxis().getRange();
Range v = getRangeAxis().getRange();
result = this.visibleRange(data, h, v);
}
return result;
}
/**
* Notifies all registered listeners of a property change.
* <P>
* One source of property change events is the plot's renderer.
*
* @param event Information about the property change.
*/
public void propertyChange(PropertyChangeEvent event) {
this.notifyListeners(new PlotChangeEvent(this));
}
/**
* Receives notification of a change to the plot's dataset.
* <P>
* The chart reacts by passing on a chart change event to all registered
* listeners.
*
* @param event Information about the event (not used here).
*/
public void datasetChanged(DatasetChangeEvent event) {
if (this.domainAxis != null) {
this.domainAxis.configure();
}
if (this.rangeAxis != null) {
this.rangeAxis.configure();
}
if (this.colorBar != null) {
this.colorBar.configure(this);
}
PlotChangeEvent e = new PlotChangeEvent(this);
notifyListeners(e);
}
/**
* Returns the colorbar.
*
* @return The colorbar.
*/
public ColorBar getColorBar() {
return colorBar;
}
/**
* Returns a flag indicating whether or not the domain crosshair is visible.
*
* @return the flag.
*/
public boolean isDomainCrosshairVisible() {
return this.domainCrosshairVisible;
}
/**
* Sets the flag indicating whether or not the domain crosshair is visible.
*
* @param flag the new value of the flag.
*/
public void setDomainCrosshairVisible(boolean flag) {
if (this.domainCrosshairVisible != flag) {
this.domainCrosshairVisible = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag indicating whether or not the crosshair should "lock-on"
* to actual data values.
*
* @return the flag.
*/
public boolean isDomainCrosshairLockedOnData() {
return this.domainCrosshairLockedOnData;
}
/**
* Sets the flag indicating whether or not the domain crosshair should "lock-on"
* to actual data values.
*
* @param flag the flag.
*/
public void setDomainCrosshairLockedOnData(boolean flag) {
if (this.domainCrosshairLockedOnData != flag) {
this.domainCrosshairLockedOnData = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the domain crosshair value.
*
* @return The value.
*/
public double getDomainCrosshairValue() {
return this.domainCrosshairValue;
}
/**
* Sets the domain crosshair value.
* <P>
* Registered listeners are notified that the plot has been modified, but
* only if the crosshair is visible.
*
* @param value the new value.
*/
public void setDomainCrosshairValue(double value) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -