📄 xylineandshaperenderer.java
字号:
* Sets the flag that controls whether outlines are drawn for
* shapes, and sends a {@link RendererChangeEvent} to all registered
* listeners.
* <P>
* In some cases, shapes look better if they do NOT have an outline, but
* this flag allows you to set your own preference.
*
* @param flag the flag.
*
* @see #getDrawOutlines()
*/
public void setDrawOutlines(boolean flag) {
this.drawOutlines = flag;
fireChangeEvent();
}
/**
* Returns <code>true</code> if the renderer should use the fill paint
* setting to fill shapes, and <code>false</code> if it should just
* use the regular paint.
* <p>
* Refer to <code>XYLineAndShapeRendererDemo2.java</code> to see the
* effect of this flag.
*
* @return A boolean.
*
* @see #setUseFillPaint(boolean)
* @see #getUseOutlinePaint()
*/
public boolean getUseFillPaint() {
return this.useFillPaint;
}
/**
* Sets the flag that controls whether the fill paint is used to fill
* shapes, and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param flag the flag.
*
* @see #getUseFillPaint()
*/
public void setUseFillPaint(boolean flag) {
this.useFillPaint = flag;
fireChangeEvent();
}
/**
* Returns <code>true</code> if the renderer should use the outline paint
* setting to draw shape outlines, and <code>false</code> if it should just
* use the regular paint.
*
* @return A boolean.
*
* @see #setUseOutlinePaint(boolean)
* @see #getUseFillPaint()
*/
public boolean getUseOutlinePaint() {
return this.useOutlinePaint;
}
/**
* Sets the flag that controls whether the outline paint is used to draw
* shape outlines, and sends a {@link RendererChangeEvent} to all
* registered listeners.
* <p>
* Refer to <code>XYLineAndShapeRendererDemo2.java</code> to see the
* effect of this flag.
*
* @param flag the flag.
*
* @see #getUseOutlinePaint()
*/
public void setUseOutlinePaint(boolean flag) {
this.useOutlinePaint = flag;
fireChangeEvent();
}
/**
* Records the state for the renderer. This is used to preserve state
* information between calls to the drawItem() method for a single chart
* drawing.
*/
public static class State extends XYItemRendererState {
/** The path for the current series. */
public GeneralPath seriesPath;
/**
* A flag that indicates if the last (x, y) point was 'good'
* (non-null).
*/
private boolean lastPointGood;
/**
* Creates a new state instance.
*
* @param info the plot rendering info.
*/
public State(PlotRenderingInfo info) {
super(info);
}
/**
* Returns a flag that indicates if the last point drawn (in the
* current series) was 'good' (non-null).
*
* @return A boolean.
*/
public boolean isLastPointGood() {
return this.lastPointGood;
}
/**
* Sets a flag that indicates if the last point drawn (in the current
* series) was 'good' (non-null).
*
* @param good the flag.
*/
public void setLastPointGood(boolean good) {
this.lastPointGood = good;
}
}
/**
* Initialises the renderer.
* <P>
* This method will be called before the first item is rendered, giving the
* renderer an opportunity to initialise any state information it wants to
* maintain. The renderer can do nothing if it chooses.
*
* @param g2 the graphics device.
* @param dataArea the area inside the axes.
* @param plot the plot.
* @param data the data.
* @param info an optional info collection object to return data back to
* the caller.
*
* @return The renderer state.
*/
public XYItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
XYPlot plot,
XYDataset data,
PlotRenderingInfo info) {
State state = new State(info);
state.seriesPath = new GeneralPath();
return state;
}
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @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 axis.
* @param rangeAxis the range 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).
* @param pass the pass index.
*/
public void drawItem(Graphics2D g2,
XYItemRendererState state,
Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState,
int pass) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
// first pass draws the background (lines, for instance)
if (isLinePass(pass)) {
if (item == 0) {
if (this.drawSeriesLineAsPath) {
State s = (State) state;
s.seriesPath.reset();
s.lastPointGood = false;
}
}
if (getItemLineVisible(series, item)) {
if (this.drawSeriesLineAsPath) {
drawPrimaryLineAsPath(state, g2, plot, dataset, pass,
series, item, domainAxis, rangeAxis, dataArea);
}
else {
drawPrimaryLine(state, g2, plot, dataset, pass, series,
item, domainAxis, rangeAxis, dataArea);
}
}
}
// second pass adds shapes where the items are ..
else if (isItemPass(pass)) {
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
drawSecondaryPass(g2, plot, dataset, pass, series, item,
domainAxis, dataArea, rangeAxis, crosshairState, entities);
}
}
/**
* Returns <code>true</code> if the specified pass is the one for drawing
* lines.
*
* @param pass the pass.
*
* @return A boolean.
*/
protected boolean isLinePass(int pass) {
return pass == 0;
}
/**
* Returns <code>true</code> if the specified pass is the one for drawing
* items.
*
* @param pass the pass.
*
* @return A boolean.
*/
protected boolean isItemPass(int pass) {
return pass == 1;
}
/**
* Draws the item (first pass). This method draws the lines
* connecting the items.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the data is being drawn.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param pass the pass.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*/
protected void drawPrimaryLine(XYItemRendererState state,
Graphics2D g2,
XYPlot plot,
XYDataset dataset,
int pass,
int series,
int item,
ValueAxis domainAxis,
ValueAxis rangeAxis,
Rectangle2D dataArea) {
if (item == 0) {
return;
}
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
if (Double.isNaN(y0) || Double.isNaN(x0)) {
return;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0)
|| Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
state.workingLine.setLine(transY0, transX0, transY1, transX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
state.workingLine.setLine(transX0, transY0, transX1, transY1);
}
if (state.workingLine.intersects(dataArea)) {
drawFirstPassShape(g2, pass, series, item, state.workingLine);
}
}
/**
* Draws the first pass shape.
*
* @param g2 the graphics device.
* @param pass the pass.
* @param series the series index.
* @param item the item index.
* @param shape the shape.
*/
protected void drawFirstPassShape(Graphics2D g2, int pass, int series,
int item, Shape shape) {
g2.setStroke(getItemStroke(series, item));
g2.setPaint(getItemPaint(series, item));
g2.draw(shape);
}
/**
* Draws the item (first pass). This method draws the lines
* connecting the items. Instead of drawing separate lines,
* a GeneralPath is constructed and drawn at the end of
* the series painting.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param plot the plot (can be used to obtain standard color information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -