📄 xydifferencerenderer.java
字号:
int item,
CrosshairState crosshairState,
int pass) {
if (pass == 0) {
drawItemPass0(g2, dataArea, info, plot, domainAxis, rangeAxis,
dataset, series, item, crosshairState);
}
else if (pass == 1) {
drawItemPass1(g2, dataArea, info, plot, domainAxis, rangeAxis,
dataset, series, item, crosshairState);
}
}
/**
* Draws the visual representation of a single data item, first pass.
*
* @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 dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot
* (<code>null</code> permitted).
*/
protected void drawItemPass0(Graphics2D g2,
Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState) {
if (series == 0) {
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
double y0 = dataset.getYValue(0, item);
double x1 = dataset.getXValue(1, item);
double y1 = dataset.getYValue(1, item);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea,
rangeAxisLocation);
double transX1 = domainAxis.valueToJava2D(x1, dataArea,
domainAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
rangeAxisLocation);
if (item > 0) {
double prevx0 = dataset.getXValue(0, item - 1);
double prevy0 = dataset.getYValue(0, item - 1);
double prevy1 = dataset.getYValue(1, item - 1);
double prevtransX0 = domainAxis.valueToJava2D(prevx0, dataArea,
domainAxisLocation);
double prevtransY0 = rangeAxis.valueToJava2D(prevy0, dataArea,
rangeAxisLocation);
double prevtransY1 = rangeAxis.valueToJava2D(prevy1, dataArea,
rangeAxisLocation);
Shape positive = getPositiveArea((float) prevtransX0,
(float) prevtransY0, (float) prevtransY1,
(float) transX1, (float) transY0, (float) transY1,
orientation);
if (positive != null) {
g2.setPaint(getPositivePaint());
g2.fill(positive);
}
Shape negative = getNegativeArea((float) prevtransX0,
(float) prevtransY0, (float) prevtransY1,
(float) transX1, (float) transY0, (float) transY1,
orientation);
if (negative != null) {
g2.setPaint(getNegativePaint());
g2.fill(negative);
}
}
}
}
/**
* Draws the visual representation of a single data item, second pass. In
* the second pass, the renderer draws the lines and shapes for the
* individual points in the two series.
*
* @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 dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot
* (<code>null</code> permitted).
*/
protected void drawItemPass1(Graphics2D g2,
Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState) {
Shape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
Paint seriesPaint = getItemPaint(series, item);
Stroke seriesStroke = getItemStroke(series, item);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
if (series == 0) {
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
double x0 = dataset.getXValue(0, item);
double y0 = dataset.getYValue(0, item);
double x1 = dataset.getXValue(1, item);
double y1 = dataset.getYValue(1, item);
double transX0 = domainAxis.valueToJava2D(x0, dataArea,
domainAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea,
rangeAxisLocation);
double transX1 = domainAxis.valueToJava2D(x1, dataArea,
domainAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
rangeAxisLocation);
if (item > 0) {
// get the previous data points...
double prevx0 = dataset.getXValue(0, item - 1);
double prevy0 = dataset.getYValue(0, item - 1);
double prevx1 = dataset.getXValue(1, item - 1);
double prevy1 = dataset.getYValue(1, item - 1);
double prevtransX0 = domainAxis.valueToJava2D(prevx0, dataArea,
domainAxisLocation);
double prevtransY0 = rangeAxis.valueToJava2D(prevy0, dataArea,
rangeAxisLocation);
double prevtransX1 = domainAxis.valueToJava2D(prevx1, dataArea,
domainAxisLocation);
double prevtransY1 = rangeAxis.valueToJava2D(prevy1, dataArea,
rangeAxisLocation);
Line2D line0 = null;
Line2D line1 = null;
if (orientation == PlotOrientation.HORIZONTAL) {
line0 = new Line2D.Double(transY0, transX0, prevtransY0,
prevtransX0);
line1 = new Line2D.Double(transY1, transX1, prevtransY1,
prevtransX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
line0 = new Line2D.Double(transX0, transY0, prevtransX0,
prevtransY0);
line1 = new Line2D.Double(transX1, transY1, prevtransX1,
prevtransY1);
}
if (line0 != null && line0.intersects(dataArea)) {
g2.setPaint(getItemPaint(series, item));
g2.setStroke(getItemStroke(series, item));
g2.draw(line0);
}
if (line1 != null && line1.intersects(dataArea)) {
g2.setPaint(getItemPaint(1, item));
g2.setStroke(getItemStroke(1, item));
g2.draw(line1);
}
}
if (getShapesVisible()) {
Shape shape0 = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape0 = ShapeUtilities.createTranslatedShape(shape0,
transY0, transX0);
}
else { // vertical
shape0 = ShapeUtilities.createTranslatedShape(shape0,
transX0, transY0);
}
if (shape0.intersects(dataArea)) {
g2.setPaint(getItemPaint(series, item));
g2.fill(shape0);
}
entityArea = shape0;
// add an entity for the item...
if (entities != null) {
if (entityArea == null) {
entityArea = new Rectangle2D.Double(transX0 - 2,
transY0 - 2, 4, 4);
}
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series,
item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series,
item);
}
XYItemEntity entity = new XYItemEntity(entityArea, dataset,
series, item, tip, url);
entities.add(entity);
}
Shape shape1 = getItemShape(series + 1, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape1 = ShapeUtilities.createTranslatedShape(shape1,
transY1, transX1);
}
else { // vertical
shape1 = ShapeUtilities.createTranslatedShape(shape1,
transX1, transY1);
}
if (shape1.intersects(dataArea)) {
g2.setPaint(getItemPaint(series + 1, item));
g2.fill(shape1);
}
entityArea = shape1;
// add an entity for the item...
if (entities != null) {
if (entityArea == null) {
entityArea = new Rectangle2D.Double(transX1 - 2,
transY1 - 2, 4, 4);
}
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series,
item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series + 1,
item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset,
series + 1, item);
}
XYItemEntity entity = new XYItemEntity(entityArea, dataset,
series + 1, item, tip, url);
entities.add(entity);
}
}
updateCrosshairValues(crosshairState, x1, y1, transX1, transY1,
orientation);
}
}
/**
* Returns the positive area for a crossover point.
*
* @param x0 x coordinate.
* @param y0A y coordinate A.
* @param y0B y coordinate B.
* @param x1 x coordinate.
* @param y1A y coordinate A.
* @param y1B y coordinate B.
* @param orientation the plot orientation.
*
* @return The positive area.
*/
protected Shape getPositiveArea(float x0, float y0A, float y0B,
float x1, float y1A, float y1B,
PlotOrientation orientation) {
Shape result = null;
boolean startsNegative = (y0A >= y0B);
boolean endsNegative = (y1A >= y1B);
if (orientation == PlotOrientation.HORIZONTAL) {
startsNegative = (y0B >= y0A);
endsNegative = (y1B >= y1A);
}
if (startsNegative) { // starts negative
if (endsNegative) {
// all negative - return null
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -