📄 lineandshaperenderer.java
字号:
* shapes, and sends a {@link RendererChangeEvent} to all
* registered listeners.
*
* @param flag the flag.
*
* @see #getUseFillPaint()
*/
public void setUseFillPaint(boolean flag) {
this.useFillPaint = flag;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the flag that controls whether or not the x-position for each
* data item is offset within the category according to the series.
*
* @return A boolean.
*
* @see #setUseSeriesOffset(boolean)
*
* @since 1.0.7
*/
public boolean getUseSeriesOffset() {
return this.useSeriesOffset;
}
/**
* Sets the flag that controls whether or not the x-position for each
* data item is offset within its category according to the series, and
* sends a {@link RendererChangeEvent} to all registered listeners.
*
* @param offset the offset.
*
* @see #getUseSeriesOffset()
*
* @since 1.0.7
*/
public void setUseSeriesOffset(boolean offset) {
this.useSeriesOffset = offset;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns the item margin, which is the gap between items within a
* category (expressed as a percentage of the overall category width).
* This can be used to match the offset alignment with the bars drawn by
* a {@link BarRenderer}).
*
* @return The item margin.
*
* @see #setItemMargin(double)
* @see #getUseSeriesOffset()
*
* @since 1.0.7
*/
public double getItemMargin() {
return this.itemMargin;
}
/**
* Sets the item margin, which is the gap between items within a category
* (expressed as a percentage of the overall category width), and sends
* a {@link RendererChangeEvent} to all registered listeners.
*
* @param margin the margin (0.0 <= margin < 1.0).
*
* @see #getItemMargin()
* @see #getUseSeriesOffset()
*
* @since 1.0.7
*/
public void setItemMargin(double margin) {
if (margin < 0.0 || margin >= 1.0) {
throw new IllegalArgumentException("Requires 0.0 <= margin < 1.0.");
}
this.itemMargin = margin;
notifyListeners(new RendererChangeEvent(this));
}
/**
* Returns a legend item for a series.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return The legend item.
*/
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot cp = getPlot();
if (cp == null) {
return null;
}
if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
CategoryDataset dataset = cp.getDataset(datasetIndex);
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);
}
Shape shape = lookupSeriesShape(series);
Paint paint = lookupSeriesPaint(series);
Paint fillPaint = (this.useFillPaint
? getItemFillPaint(series, 0) : paint);
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint
? getItemOutlinePaint(series, 0) : paint);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
boolean shapeVisible = getItemShapeVisible(series, 0);
LegendItem result = new LegendItem(label, description, toolTipText,
urlText, shapeVisible, shape, getItemShapeFilled(series, 0),
fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke,
lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0),
getItemStroke(series, 0), getItemPaint(series, 0));
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getRowKey(series));
result.setSeriesIndex(series);
return result;
}
return null;
}
/**
* This renderer uses two passes to draw the data.
*
* @return The pass count (<code>2</code> for this renderer).
*/
public int getPassCount() {
return 2;
}
/**
* Draw a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area in which the data is drawn.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param pass the pass index.
*/
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
int pass) {
// do nothing if item is not visible
if (!getItemVisible(row, column)) {
return;
}
// do nothing if both the line and shape are not visible
if (!getItemLineVisible(row, column)
&& !getItemShapeVisible(row, column)) {
return;
}
// nothing is drawn for null...
Number v = dataset.getValue(row, column);
if (v == null) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// current data point...
double x1;
if (this.useSeriesOffset) {
x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(
column), dataset.getRowKey(row), dataset, this.itemMargin,
dataArea, plot.getDomainAxisEdge());
}
else {
x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
dataArea, plot.getDomainAxisEdge());
}
double value = v.doubleValue();
double y1 = rangeAxis.valueToJava2D(value, dataArea,
plot.getRangeAxisEdge());
if (pass == 0 && getItemLineVisible(row, column)) {
if (column != 0) {
Number previousValue = dataset.getValue(row, column - 1);
if (previousValue != null) {
// previous data point...
double previous = previousValue.doubleValue();
double x0;
if (this.useSeriesOffset) {
x0 = domainAxis.getCategorySeriesMiddle(
dataset.getColumnKey(column - 1),
dataset.getRowKey(row), dataset,
this.itemMargin, dataArea,
plot.getDomainAxisEdge());
}
else {
x0 = domainAxis.getCategoryMiddle(column - 1,
getColumnCount(), dataArea,
plot.getDomainAxisEdge());
}
double y0 = rangeAxis.valueToJava2D(previous, dataArea,
plot.getRangeAxisEdge());
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(y0, x0, y1, x1);
}
else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(x0, y0, x1, y1);
}
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
g2.draw(line);
}
}
}
if (pass == 1) {
Shape shape = getItemShape(row, column);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
}
else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
}
if (getItemShapeVisible(row, column)) {
if (getItemShapeFilled(row, column)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(row, column));
}
else {
g2.setPaint(getItemPaint(row, column));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (this.useOutlinePaint) {
g2.setPaint(getItemOutlinePaint(row, column));
}
else {
g2.setPaint(getItemPaint(row, column));
}
g2.setStroke(getItemOutlineStroke(row, column));
g2.draw(shape);
}
}
// draw the item label if there is one...
if (isItemLabelVisible(row, column)) {
if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, row, column, y1,
x1, (value < 0.0));
}
else if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, row, column, x1,
y1, (value < 0.0));
}
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, shape);
}
}
}
/**
* 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 LineAndShapeRenderer)) {
return false;
}
LineAndShapeRenderer that = (LineAndShapeRenderer) obj;
if (this.baseLinesVisible != that.baseLinesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.seriesLinesVisible,
that.seriesLinesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.linesVisible, that.linesVisible)) {
return false;
}
if (this.baseShapesVisible != that.baseShapesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.seriesShapesVisible,
that.seriesShapesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.shapesVisible, that.shapesVisible)) {
return false;
}
if (!ObjectUtilities.equal(this.shapesFilled, that.shapesFilled)) {
return false;
}
if (!ObjectUtilities.equal(this.seriesShapesFilled,
that.seriesShapesFilled)) {
return false;
}
if (this.baseShapesFilled != that.baseShapesFilled) {
return false;
}
if (this.useOutlinePaint != that.useOutlinePaint) {
return false;
}
if (this.useSeriesOffset != that.useSeriesOffset) {
return false;
}
if (this.itemMargin != that.itemMargin) {
return false;
}
return super.equals(obj);
}
/**
* Returns an independent copy of the renderer.
*
* @return A clone.
*
* @throws CloneNotSupportedException should not happen.
*/
public Object clone() throws CloneNotSupportedException {
LineAndShapeRenderer clone = (LineAndShapeRenderer) super.clone();
clone.seriesLinesVisible
= (BooleanList) this.seriesLinesVisible.clone();
clone.seriesShapesVisible
= (BooleanList) this.seriesShapesVisible.clone();
clone.seriesShapesFilled
= (BooleanList) this.seriesShapesFilled.clone();
return clone;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -