📄 xydifferencerenderer.java
字号:
l_subtrahendNextX = new Double(l_x4);
l_subtrahendNextY = new Double(l_y4);
}
// deassert b_*FastForward (only matters for 1st time through loop)
b_minuendFastForward = false;
b_subtrahendFastForward = false;
Double l_intersectX = null;
Double l_intersectY = null;
boolean b_intersect = false;
b_minuendAtIntersect = false;
b_subtrahendAtIntersect = false;
// check for intersect
if ((l_x2 == l_x4) && (l_y2 == l_y4)) {
// check if line segments are colinear
if ((l_x1 == l_x3) && (l_y1 == l_y3)) {
b_colinear = true;
}
else {
// the intersect is at the next point for both the minuend
// and subtrahend
l_intersectX = new Double(l_x2);
l_intersectY = new Double(l_y2);
b_intersect = true;
b_minuendAtIntersect = true;
b_subtrahendAtIntersect = true;
}
}
else {
// compute common denominator
double l_denominator = ((l_y4 - l_y3) * (l_x2 - l_x1))
- ((l_x4 - l_x3) * (l_y2 - l_y1));
// compute common deltas
double l_deltaY = l_y1 - l_y3;
double l_deltaX = l_x1 - l_x3;
// compute numerators
double l_numeratorA = ((l_x4 - l_x3) * l_deltaY)
- ((l_y4 - l_y3) * l_deltaX);
double l_numeratorB = ((l_x2 - l_x1) * l_deltaY)
- ((l_y2 - l_y1) * l_deltaX);
// check if line segments are colinear
if ((0 == l_numeratorA) && (0 == l_numeratorB)
&& (0 == l_denominator)) {
b_colinear = true;
}
else {
// check if previously colinear
if (b_colinear) {
// clear colinear points and flag
l_minuendXs.clear();
l_minuendYs.clear();
l_subtrahendXs.clear();
l_subtrahendYs.clear();
l_polygonXs.clear();
l_polygonYs.clear();
b_colinear = false;
// set new starting point for the polygon
boolean b_useMinuend = ((l_x3 <= l_x1)
&& (l_x1 <= l_x4));
l_polygonXs.add(b_useMinuend ? l_minuendCurX
: l_subtrahendCurX);
l_polygonYs.add(b_useMinuend ? l_minuendCurY
: l_subtrahendCurY);
}
// compute slope components
double l_slopeA = l_numeratorA / l_denominator;
double l_slopeB = l_numeratorB / l_denominator;
// check if the line segments intersect
if ((0 < l_slopeA) && (l_slopeA <= 1) && (0 < l_slopeB)
&& (l_slopeB <= 1)) {
// compute the point of intersection
double l_xi = l_x1 + (l_slopeA * (l_x2 - l_x1));
double l_yi = l_y1 + (l_slopeA * (l_y2 - l_y1));
l_intersectX = new Double(l_xi);
l_intersectY = new Double(l_yi);
b_intersect = true;
b_minuendAtIntersect = ((l_xi == l_x2)
&& (l_yi == l_y2));
b_subtrahendAtIntersect = ((l_xi == l_x4)
&& (l_yi == l_y4));
// advance minuend and subtrahend to intesect
l_minuendCurX = l_intersectX;
l_minuendCurY = l_intersectY;
l_subtrahendCurX = l_intersectX;
l_subtrahendCurY = l_intersectY;
}
}
}
if (b_intersect) {
// create the polygon
// add the minuend's points to polygon
l_polygonXs.addAll(l_minuendXs);
l_polygonYs.addAll(l_minuendYs);
// add intersection point to the polygon
l_polygonXs.add(l_intersectX);
l_polygonYs.add(l_intersectY);
// add the subtrahend's points to the polygon in reverse
Collections.reverse(l_subtrahendXs);
Collections.reverse(l_subtrahendYs);
l_polygonXs.addAll(l_subtrahendXs);
l_polygonYs.addAll(l_subtrahendYs);
// create an actual polygon
b_positive = (l_subtrahendMaxY <= l_minuendMaxY)
&& (l_subtrahendMinY <= l_minuendMinY);
createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis,
x_rangeAxis, b_positive, l_polygonXs, l_polygonYs);
// clear the point vectors
l_minuendXs.clear();
l_minuendYs.clear();
l_subtrahendXs.clear();
l_subtrahendYs.clear();
l_polygonXs.clear();
l_polygonYs.clear();
// set the maxY and minY values to intersect y-value
double l_y = l_intersectY.doubleValue();
l_minuendMaxY = l_y;
l_subtrahendMaxY = l_y;
l_minuendMinY = l_y;
l_subtrahendMinY = l_y;
// add interection point to new polygon
l_polygonXs.add(l_intersectX);
l_polygonYs.add(l_intersectY);
}
// advance the minuend if needed
if (l_x2 <= l_x4) {
l_minuendItem++;
b_minuendAdvanced = true;
}
else {
b_minuendAdvanced = false;
}
// advance the subtrahend if needed
if (l_x4 <= l_x2) {
l_subtrahendItem++;
b_subtrahendAdvanced = true;
}
else {
b_subtrahendAdvanced = false;
}
b_minuendDone = (l_minuendItem == (l_minuendItemCount - 1));
b_subtrahendDone = (l_subtrahendItem == (l_subtrahendItemCount
- 1));
}
// check if the final polygon needs to be clipped
if (b_minuendDone && (l_x3 < l_x2) && (l_x2 < l_x4)) {
// project onto subtrahend
double l_slope = (l_y4 - l_y3) / (l_x4 - l_x3);
l_subtrahendNextX = l_minuendNextX;
l_subtrahendNextY = new Double((l_slope * l_x2)
+ (l_y3 - (l_slope * l_x3)));
}
if (b_subtrahendDone && (l_x1 < l_x4) && (l_x4 < l_x2)) {
// project onto minuend
double l_slope = (l_y2 - l_y1) / (l_x2 - l_x1);
l_minuendNextX = l_subtrahendNextX;
l_minuendNextY = new Double((l_slope * l_x4)
+ (l_y1 - (l_slope * l_x1)));
}
// consider last point of minuend and subtrahend for determining
// positivity
l_minuendMaxY = Math.max(l_minuendMaxY,
l_minuendNextY.doubleValue());
l_subtrahendMaxY = Math.max(l_subtrahendMaxY,
l_subtrahendNextY.doubleValue());
l_minuendMinY = Math.min(l_minuendMinY,
l_minuendNextY.doubleValue());
l_subtrahendMinY = Math.min(l_subtrahendMinY,
l_subtrahendNextY.doubleValue());
// add the last point of the minuned and subtrahend
l_minuendXs.add(l_minuendNextX);
l_minuendYs.add(l_minuendNextY);
l_subtrahendXs.add(l_subtrahendNextX);
l_subtrahendYs.add(l_subtrahendNextY);
// create the polygon
// add the minuend's points to polygon
l_polygonXs.addAll(l_minuendXs);
l_polygonYs.addAll(l_minuendYs);
// add the subtrahend's points to the polygon in reverse
Collections.reverse(l_subtrahendXs);
Collections.reverse(l_subtrahendYs);
l_polygonXs.addAll(l_subtrahendXs);
l_polygonYs.addAll(l_subtrahendYs);
// create an actual polygon
b_positive = (l_subtrahendMaxY <= l_minuendMaxY)
&& (l_subtrahendMinY <= l_minuendMinY);
createPolygon(x_graphics, x_dataArea, x_plot, x_domainAxis,
x_rangeAxis, b_positive, l_polygonXs, l_polygonYs);
}
/**
* 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 x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_info collects information about the drawing.
* @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_dataset the dataset.
* @param x_series the series index (zero-based).
* @param x_item the item index (zero-based).
* @param x_crosshairState crosshair information for the plot
* (<code>null</code> permitted).
*/
protected void drawItemPass1(Graphics2D x_graphics,
Rectangle2D x_dataArea,
PlotRenderingInfo x_info,
XYPlot x_plot,
ValueAxis x_domainAxis,
ValueAxis x_rangeAxis,
XYDataset x_dataset,
int x_series,
int x_item,
CrosshairState x_crosshairState) {
Shape l_entityArea = null;
EntityCollection l_entities = null;
if (null != x_info) {
l_entities = x_info.getOwner().getEntityCollection();
}
Paint l_seriesPaint = getItemPaint(x_series, x_item);
Stroke l_seriesStroke = getItemStroke(x_series, x_item);
x_graphics.setPaint(l_seriesPaint);
x_graphics.setStroke(l_seriesStroke);
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
double l_x0 = x_dataset.getXValue(x_series, x_item);
double l_y0 = x_dataset.getYValue(x_series, x_item);
double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea,
l_domainAxisLocation);
double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea,
l_rangeAxisLocation);
if (getShapesVisible()) {
Shape l_shape = getItemShape(x_series, x_item);
if (l_orientation == PlotOrientation.HORIZONTAL) {
l_shape = ShapeUtilities.createTranslatedShape(l_shape,
l_y1, l_x1);
}
else {
l_shape = ShapeUtilities.createTranslatedShape(l_shape,
l_x1, l_y1);
}
if (l_shape.intersects(x_dataArea)) {
x_graphics.setPaint(getItemPaint(x_series, x_item));
x_graphics.fill(l_shape);
}
l_entityArea = l_shape;
}
// add an entity for the item...
if (null != l_entities) {
if (null == l_entityArea) {
l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2),
4, 4);
}
String l_tip = null;
XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series,
x_item);
if (null != l_tipGenerator) {
l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series,
x_item);
}
String l_url = null;
XYURLGenerator l_urlGenerator = getURLGenerator();
if (null != l_urlGenerator) {
l_url = l_urlGenerator.generateURL(x_dataset, x_series,
x_item);
}
XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset,
x_series, x_item, l_tip, l_url);
l_entities.add(l_entity);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -