📄 stackedarearenderer.java
字号:
left.lineTo((float) xx1, transStack1);
left.lineTo((float) xxLeft, transStackLeft);
left.lineTo((float) xxLeft, transYLeft);
left.closePath();
}
float transStackRight = (float) rangeAxis.valueToJava2D(
adjStackRight[0], dataArea, edge1);
// RIGHT POLYGON
if (y2 >= 0.0) {
right.moveTo((float) xx1, transStack1);
right.lineTo((float) xx1, transY1);
right.lineTo((float) xxRight, transStackRight);
right.closePath();
}
else {
double yright = (y1 + y2) / 2.0 + stackRight[0];
float transYRight = (float) rangeAxis.valueToJava2D(yright,
dataArea, edge1);
right.moveTo((float) xx1, transStack1);
right.lineTo((float) xx1, transY1);
right.lineTo((float) xxRight, transYRight);
right.lineTo((float) xxRight, transStackRight);
right.closePath();
}
}
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
// Get series Paint and Stroke
Paint itemPaint = getItemPaint(row, column);
if (pass == 0) {
g2.setPaint(itemPaint);
g2.fill(left);
g2.fill(right);
}
// add an entity for the item...
if (entities != null) {
GeneralPath gp = new GeneralPath(left);
gp.append(right, false);
entityArea = gp;
addItemEntity(entities, dataset, row, column, entityArea);
}
}
// /**
// * Draw a single data item.
// *
// * @param g2 the graphics device.
// * @param state the renderer state.
// * @param dataArea the data plot area.
// * @param plot the plot.
// * @param domainAxis the domain axis.
// * @param rangeAxis the range axis.
// * @param dataset the data.
// * @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) {
//
// // plot non-null values...
// Number dataValue = dataset.getValue(row, column);
// if (dataValue == null) {
// return;
// }
//
// double value = dataValue.doubleValue();
// double total = 0.0; // only needed if calculating percentages
// if (this.renderAsPercentages) {
// total = DataUtilities.calculateColumnTotal(dataset, column);
// value = value / total;
// }
//
// // leave the y values (y1, y0) untranslated as it is going to be be
// // stacked up later by previous series values, after this it will be
// // translated.
// double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
// dataArea, plot.getDomainAxisEdge());
//
// double previousHeightx1 = getPreviousHeight(dataset, row, column);
// double y1 = value + previousHeightx1;
// RectangleEdge location = plot.getRangeAxisEdge();
// double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);
//
// g2.setPaint(getItemPaint(row, column));
// g2.setStroke(getItemStroke(row, column));
//
// // in column zero, the only job to do is draw any visible item labels
// // and this is done in the second pass...
// if (column == 0) {
// if (pass == 1) {
// // draw item labels, if visible
// if (isItemLabelVisible(row, column)) {
// drawItemLabel(g2, plot.getOrientation(), dataset, row, column,
// xx1, yy1, (y1 < 0.0));
// }
// }
// }
// else {
// Number previousValue = dataset.getValue(row, column - 1);
// if (previousValue != null) {
//
// double xx0 = domainAxis.getCategoryMiddle(column - 1,
// getColumnCount(), dataArea, plot.getDomainAxisEdge());
// double y0 = previousValue.doubleValue();
// if (this.renderAsPercentages) {
// total = DataUtilities.calculateColumnTotal(dataset,
// column - 1);
// y0 = y0 / total;
// }
//
//
// // Get the previous height, but this will be different for both
// // y0 and y1 as the previous series values could differ.
// double previousHeightx0 = getPreviousHeight(dataset, row,
// column - 1);
//
// // Now stack the current y values on top of the previous values.
// y0 += previousHeightx0;
//
// // Now translate the previous heights
// double previousHeightxx0 = rangeAxis.valueToJava2D(
// previousHeightx0, dataArea, location);
// double previousHeightxx1 = rangeAxis.valueToJava2D(
// previousHeightx1, dataArea, location);
//
// // Now translate the current y values.
// double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
//
// if (pass == 0) {
// // FIXME: this doesn't handle negative values properly
// Polygon p = null;
// PlotOrientation orientation = plot.getOrientation();
// if (orientation == PlotOrientation.HORIZONTAL) {
// p = new Polygon();
// p.addPoint((int) yy0, (int) xx0);
// p.addPoint((int) yy1, (int) xx1);
// p.addPoint((int) previousHeightxx1, (int) xx1);
// p.addPoint((int) previousHeightxx0, (int) xx0);
// }
// else if (orientation == PlotOrientation.VERTICAL) {
// p = new Polygon();
// p.addPoint((int) xx0, (int) yy0);
// p.addPoint((int) xx1, (int) yy1);
// p.addPoint((int) xx1, (int) previousHeightxx1);
// p.addPoint((int) xx0, (int) previousHeightxx0);
// }
// g2.setPaint(getItemPaint(row, column));
// g2.setStroke(getItemStroke(row, column));
// g2.fill(p);
//
// // add an item entity, if this information is being
// // collected...
// EntityCollection entities = state.getEntityCollection();
// if (entities != null) {
// addItemEntity(entities, dataset, row, column, p);
// }
//
// }
// else {
// if (isItemLabelVisible(row, column)) {
// drawItemLabel(g2, plot.getOrientation(), dataset, row,
// column, xx1, yy1, (y1 < 0.0));
// }
// }
// }
//
//
// }
//
// }
/**
* Calculates the stacked value of the all series up to, but not including
* <code>series</code> for the specified category, <code>category</code>.
* It returns 0.0 if <code>series</code> is the first series, i.e. 0.
*
* @param dataset the dataset (<code>null</code> not permitted).
* @param series the series.
* @param category the category.
*
* @return double returns a cumulative value for all series' values up to
* but excluding <code>series</code> for Object
* <code>category</code>.
*/
protected double getPreviousHeight(CategoryDataset dataset,
int series, int category) {
double result = 0.0;
Number n;
double total = 0.0;
if (this.renderAsPercentages) {
total = DataUtilities.calculateColumnTotal(dataset, category);
}
for (int i = 0; i < series; i++) {
n = dataset.getValue(i, category);
if (n != null) {
double v = n.doubleValue();
if (this.renderAsPercentages) {
v = v / total;
}
result += v;
}
}
return result;
}
/**
* Calculates the stacked values (one positive and one negative) of all
* series up to, but not including, <code>series</code> for the specified
* item. It returns [0.0, 0.0] if <code>series</code> is the first series.
*
* @param dataset the dataset (<code>null</code> not permitted).
* @param series the series index.
* @param index the item index.
*
* @return An array containing the cumulative negative and positive values
* for all series values up to but excluding <code>series</code>
* for <code>index</code>.
*/
protected double[] getStackValues(CategoryDataset dataset,
int series, int index) {
double[] result = new double[2];
for (int i = 0; i < series; i++) {
if (isSeriesVisible(i)) {
double v = 0.0;
Number n = dataset.getValue(i, index);
if (n != null) {
v = n.doubleValue();
}
if (!Double.isNaN(v)) {
if (v >= 0.0) {
result[1] += v;
}
else {
result[0] += v;
}
}
}
}
return result;
}
/**
* Returns a pair of "stack" values calculated as the mean of the two
* specified stack value pairs.
*
* @param stack1 the first stack pair.
* @param stack2 the second stack pair.
*
* @return A pair of average stack values.
*/
private double[] averageStackValues(double[] stack1, double[] stack2) {
double[] result = new double[2];
result[0] = (stack1[0] + stack2[0]) / 2.0;
result[1] = (stack1[1] + stack2[1]) / 2.0;
return result;
}
/**
* Calculates adjusted stack values from the supplied values. The value is
* the mean of the supplied values, unless either of the supplied values
* is zero, in which case the adjusted value is zero also.
*
* @param stack1 the first stack pair.
* @param stack2 the second stack pair.
*
* @return A pair of average stack values.
*/
private double[] adjustedStackValues(double[] stack1, double[] stack2) {
double[] result = new double[2];
if (stack1[0] == 0.0 || stack2[0] == 0.0) {
result[0] = 0.0;
}
else {
result[0] = (stack1[0] + stack2[0]) / 2.0;
}
if (stack1[1] == 0.0 || stack2[1] == 0.0) {
result[1] = 0.0;
}
else {
result[1] = (stack1[1] + stack2[1]) / 2.0;
}
return result;
}
/**
* Checks this instance for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> not permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (! (obj instanceof StackedAreaRenderer)) {
return false;
}
StackedAreaRenderer that = (StackedAreaRenderer) obj;
if (this.renderAsPercentages != that.renderAsPercentages) {
return false;
}
return super.equals(obj);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -