📄 xydifferencerenderer.java
字号:
// draw the item label if there is one...
if (isItemLabelVisible(x_series, x_item)) {
drawItemLabel(x_graphics, l_orientation, x_dataset, x_series,
x_item, l_x1, l_y1, (l_y1 < 0.0));
}
int l_domainAxisIndex = x_plot.getDomainAxisIndex(x_domainAxis);
int l_rangeAxisIndex = x_plot.getRangeAxisIndex(x_rangeAxis);
updateCrosshairValues(x_crosshairState, l_x0, l_y0, l_domainAxisIndex,
l_rangeAxisIndex, l_x1, l_y1, l_orientation);
if (0 == x_item) {
return;
}
double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series,
(x_item - 1)), x_dataArea, l_domainAxisLocation);
double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series,
(x_item - 1)), x_dataArea, l_rangeAxisLocation);
Line2D l_line = null;
if (PlotOrientation.HORIZONTAL == l_orientation) {
l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
}
else if (PlotOrientation.VERTICAL == l_orientation) {
l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
}
if ((null != l_line) && l_line.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item));
x_graphics.setStroke(getItemStroke(x_series, x_item));
x_graphics.draw(l_line);
}
}
/**
* Determines if a dataset is degenerate. A degenerate dataset is a
* dataset where either series has less than two (2) points.
*
* @param x_dataset the dataset.
* @param x_impliedZeroSubtrahend if false, do not check the subtrahend
*
* @return true if the dataset is degenerate.
*/
private boolean isEitherSeriesDegenerate(XYDataset x_dataset,
boolean x_impliedZeroSubtrahend) {
if (x_impliedZeroSubtrahend) {
return (x_dataset.getItemCount(0) < 2);
}
return ((x_dataset.getItemCount(0) < 2)
|| (x_dataset.getItemCount(1) < 2));
}
/**
* Determines if the two (2) series are disjoint.
* Disjoint series do not overlap in the domain space.
*
* @param x_dataset the dataset.
*
* @return true if the dataset is degenerate.
*/
private boolean areSeriesDisjoint(XYDataset x_dataset) {
int l_minuendItemCount = x_dataset.getItemCount(0);
double l_minuendFirst = x_dataset.getXValue(0, 0);
double l_minuendLast = x_dataset.getXValue(0, l_minuendItemCount - 1);
int l_subtrahendItemCount = x_dataset.getItemCount(1);
double l_subtrahendFirst = x_dataset.getXValue(1, 0);
double l_subtrahendLast = x_dataset.getXValue(1,
l_subtrahendItemCount - 1);
return ((l_minuendLast < l_subtrahendFirst)
|| (l_subtrahendLast < l_minuendFirst));
}
/**
* Draws the visual representation of a polygon
*
* @param x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_positive indicates if the polygon is positive (true) or
* negative (false).
* @param x_xValues a linked list of the x values (expects values to be
* of type Double).
* @param x_yValues a linked list of the y values (expects values to be
* of type Double).
*/
private void createPolygon (Graphics2D x_graphics,
Rectangle2D x_dataArea,
XYPlot x_plot,
ValueAxis x_domainAxis,
ValueAxis x_rangeAxis,
boolean x_positive,
LinkedList x_xValues,
LinkedList x_yValues) {
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
Object[] l_xValues = x_xValues.toArray();
Object[] l_yValues = x_yValues.toArray();
GeneralPath l_path = new GeneralPath();
if (PlotOrientation.VERTICAL == l_orientation) {
double l_x = x_domainAxis.valueToJava2D((
(Double) l_xValues[0]).doubleValue(), x_dataArea,
l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D((
(Double) l_yValues[0]).doubleValue(), x_dataArea,
l_rangeAxisLocation);
l_path.moveTo((float) l_x, (float) l_y);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D((
(Double) l_xValues[i]).doubleValue(), x_dataArea,
l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D((
(Double) l_yValues[i]).doubleValue(), x_dataArea,
l_rangeAxisLocation);
l_path.lineTo((float) l_x, (float) l_y);
}
l_path.closePath();
}
else {
double l_x = x_domainAxis.valueToJava2D((
(Double) l_xValues[0]).doubleValue(), x_dataArea,
l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D((
(Double) l_yValues[0]).doubleValue(), x_dataArea,
l_rangeAxisLocation);
l_path.moveTo((float) l_y, (float) l_x);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D((
(Double) l_xValues[i]).doubleValue(), x_dataArea,
l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D((
(Double) l_yValues[i]).doubleValue(), x_dataArea,
l_rangeAxisLocation);
l_path.lineTo((float) l_y, (float) l_x);
}
l_path.closePath();
}
if (l_path.intersects(x_dataArea)) {
x_graphics.setPaint(x_positive ? getPositivePaint()
: getNegativePaint());
x_graphics.fill(l_path);
}
}
/**
* Returns a default legend item for the specified series. Subclasses
* should override this method to generate customised items.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return A legend item for the series.
*/
public LegendItem getLegendItem(int datasetIndex, int series) {
LegendItem result = null;
XYPlot p = getPlot();
if (p != null) {
XYDataset dataset = p.getDataset(datasetIndex);
if (dataset != null) {
if (getItemVisible(series, 0)) {
String label = getLegendItemLabelGenerator().generateLabel(
dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText
= getLegendItemToolTipGenerator().generateLabel(
dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(
dataset, series);
}
Paint paint = lookupSeriesPaint(series);
Stroke stroke = lookupSeriesStroke(series);
// TODO: the following hard-coded line needs generalising
Line2D line = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);
result = new LegendItem(label, description,
toolTipText, urlText, line, stroke, paint);
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getSeriesKey(series));
result.setSeriesIndex(series);
}
}
}
return result;
}
/**
* Tests this renderer 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 XYDifferenceRenderer)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
XYDifferenceRenderer that = (XYDifferenceRenderer) obj;
if (!PaintUtilities.equal(this.positivePaint, that.positivePaint)) {
return false;
}
if (!PaintUtilities.equal(this.negativePaint, that.negativePaint)) {
return false;
}
if (this.shapesVisible != that.shapesVisible) {
return false;
}
if (!ShapeUtilities.equal(this.legendLine, that.legendLine)) {
return false;
}
if (this.roundXCoordinates != that.roundXCoordinates) {
return false;
}
return true;
}
/**
* Returns a clone of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the renderer cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
XYDifferenceRenderer clone = (XYDifferenceRenderer) super.clone();
clone.legendLine = ShapeUtilities.clone(this.legendLine);
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.writePaint(this.positivePaint, stream);
SerialUtilities.writePaint(this.negativePaint, stream);
SerialUtilities.writeShape(this.legendLine, 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.positivePaint = SerialUtilities.readPaint(stream);
this.negativePaint = SerialUtilities.readPaint(stream);
this.legendLine = SerialUtilities.readShape(stream);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -