use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYImageAnnotation method draw.
/**
* Draws the annotation. This method is called by the drawing code in the
* {@link XYPlot} class, you don't normally need to call this method
* directly.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param rendererIndex the renderer index.
* @param info if supplied, this info object will be populated with
* entity information.
*/
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
PlotOrientation orientation = plot.getOrientation();
AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
float xx = 0.0f;
float yy = 0.0f;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = j2DY;
yy = j2DX;
} else if (orientation == PlotOrientation.VERTICAL) {
xx = j2DX;
yy = j2DY;
}
int w = this.image.getWidth(null);
int h = this.image.getHeight(null);
Rectangle2D imageRect = new Rectangle2D.Double(0, 0, w, h);
Point2D anchorPoint = RectangleAnchor.coordinates(imageRect, this.anchor);
xx = xx - (float) anchorPoint.getX();
yy = yy - (float) anchorPoint.getY();
g2.drawImage(this.image, (int) xx, (int) yy, null);
String toolTip = getToolTipText();
String url = getURL();
if (toolTip != null || url != null) {
addEntity(info, new Rectangle2D.Float(xx, yy, w, h), rendererIndex, toolTip, url);
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method convertToDataSpace.
/**
* Converts a path from Java2D space to data space.
*
* @param path the path (<code>null</code> not permitted).
* @param dataArea the data area.
* @param dataset the dataset which can be used to find the appropriate
* axes.
*
* @return A path in data space.
*/
private GeneralPath convertToDataSpace(GeneralPath path, Rectangle2D dataArea, XYDataset dataset) {
GeneralPath result = new GeneralPath(path.getWindingRule());
int datasetIndex = indexOf(dataset);
ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
RectangleEdge xAxisEdge = getDomainAxisEdge();
RectangleEdge yAxisEdge = getRangeAxisEdge();
double[] coords = new double[6];
PathIterator iterator = path.getPathIterator(null);
while (!iterator.isDone()) {
int segType = iterator.currentSegment(coords);
double xx = xAxis.java2DToValue(coords[0], dataArea, xAxisEdge);
double yy = yAxis.java2DToValue(coords[1], dataArea, yAxisEdge);
if (segType == PathIterator.SEG_MOVETO) {
result.moveTo((float) xx, (float) yy);
} else if (segType == PathIterator.SEG_LINETO) {
result.lineTo((float) xx, (float) yy);
} else if (segType == PathIterator.SEG_CLOSE) {
result.closePath();
}
iterator.next();
}
return result;
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method getDomainAxisEdge.
/**
* Returns the edge for a domain axis.
*
* @param index the axis index.
*
* @return The edge.
*
* @see #getRangeAxisEdge(int)
*/
public RectangleEdge getDomainAxisEdge(int index) {
AxisLocation location = getDomainAxisLocation(index);
RectangleEdge result = Plot.resolveDomainAxisLocation(location, this.orientation);
if (result == null) {
result = RectangleEdge.opposite(getDomainAxisEdge());
}
return result;
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method getRangeAxisEdge.
/**
* Returns the edge for a range axis.
*
* @param index the axis index.
*
* @return The edge.
*
* @see #getRangeAxisLocation(int)
* @see #getOrientation()
*/
public RectangleEdge getRangeAxisEdge(int index) {
AxisLocation location = getRangeAxisLocation(index);
RectangleEdge result = Plot.resolveRangeAxisLocation(location, this.orientation);
if (result == null) {
result = RectangleEdge.opposite(getRangeAxisEdge());
}
return result;
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class BarRenderer method createHotSpotBounds.
public Rectangle2D createHotSpotBounds(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, boolean selected, CategoryItemRendererState state, Rectangle2D result) {
// nothing is drawn if the row index is not included in the list with
// the indices of the visible rows...
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return null;
}
if (!this.getItemVisible(row, column)) {
return null;
}
// nothing is drawn for null values...
Number dataValue = dataset.getValue(row, column);
if (dataValue == null) {
return null;
}
final double value = dataValue.doubleValue();
PlotOrientation orientation = plot.getOrientation();
double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
double[] barL0L1 = calculateBarL0L1(value, rangeAxis.getLowerBound(), rangeAxis.getUpperBound());
if (barL0L1 == null) {
// the bar is not visible
return null;
}
RectangleEdge edge = plot.getRangeAxisEdge();
double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);
double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);
// in the following code, barL0 is (in Java2D coordinates) the LEFT
// end of the bar for a horizontal bar chart, and the TOP end of the
// bar for a vertical bar chart. Whether this is the BASE of the bar
// or not depends also on (a) whether the data value is 'negative'
// relative to the base value and (b) whether or not the range axis is
// inverted. This only matters if/when we apply the minimumBarLength
// attribute, because we should extend the non-base end of the bar
boolean positive = (value >= this.base);
boolean inverted = rangeAxis.isInverted();
double barL0 = Math.min(transL0, transL1);
double barLength = Math.abs(transL1 - transL0);
double barLengthAdj = 0.0;
if (barLength > 0.0 && barLength < getMinimumBarLength()) {
barLengthAdj = getMinimumBarLength() - barLength;
}
double barL0Adj = 0.0;
RectangleEdge barBase;
if (orientation == PlotOrientation.HORIZONTAL) {
if (positive && inverted || !positive && !inverted) {
barL0Adj = barLengthAdj;
barBase = RectangleEdge.RIGHT;
} else {
barBase = RectangleEdge.LEFT;
}
} else {
if (positive && !inverted || !positive && inverted) {
barL0Adj = barLengthAdj;
barBase = RectangleEdge.BOTTOM;
} else {
barBase = RectangleEdge.TOP;
}
}
// draw the bar...
Rectangle2D bar = null;
if (orientation == PlotOrientation.HORIZONTAL) {
bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth());
} else {
bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj);
}
return bar;
}
Aggregations