use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class CombinedRangeXYPlot method calculateAxisSpace.
/**
* Calculates the space required for the axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
*
* @return The space required for the axes.
*/
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
AxisSpace space = new AxisSpace();
PlotOrientation orientation = getOrientation();
// work out the space required by the domain axis...
AxisSpace fixed = getFixedRangeAxisSpace();
if (fixed != null) {
if (orientation == PlotOrientation.VERTICAL) {
space.setLeft(fixed.getLeft());
space.setRight(fixed.getRight());
} else if (orientation == PlotOrientation.HORIZONTAL) {
space.setTop(fixed.getTop());
space.setBottom(fixed.getBottom());
}
} else {
ValueAxis valueAxis = getRangeAxis();
RectangleEdge valueEdge = Plot.resolveRangeAxisLocation(getRangeAxisLocation(), orientation);
if (valueAxis != null) {
space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge, space);
}
}
Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
// work out the maximum height or width of the non-shared axes...
int n = this.subplots.size();
int totalWeight = 0;
for (int i = 0; i < n; i++) {
XYPlot sub = (XYPlot) this.subplots.get(i);
totalWeight += sub.getWeight();
}
// calculate plotAreas of all sub-plots, maximum vertical/horizontal
// axis width/height
this.subplotAreas = new Rectangle2D[n];
double x = adjustedPlotArea.getX();
double y = adjustedPlotArea.getY();
double usableSize = 0.0;
if (orientation == PlotOrientation.VERTICAL) {
usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
}
for (int i = 0; i < n; i++) {
XYPlot plot = (XYPlot) this.subplots.get(i);
// calculate sub-plot area
if (orientation == PlotOrientation.VERTICAL) {
double w = usableSize * plot.getWeight() / totalWeight;
this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
x = x + w + this.gap;
} else if (orientation == PlotOrientation.HORIZONTAL) {
double h = usableSize * plot.getWeight() / totalWeight;
this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
y = y + h + this.gap;
}
AxisSpace subSpace = plot.calculateDomainAxisSpace(g2, this.subplotAreas[i], null);
space.ensureAtLeast(subSpace);
}
return space;
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class CombinedRangeXYPlot method draw.
/**
* Draws the plot within the specified area on a graphics device.
*
* @param g2 the graphics device.
* @param area the plot area (in Java2D space).
* @param anchor an anchor point in Java2D space (<code>null</code>
* permitted).
* @param parentState the state from the parent plot, if there is one
* (<code>null</code> permitted).
* @param info collects chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// set up info collection...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
// this.axisOffset.trim(dataArea);
// set the width and height of non-shared axis of all sub-plots
setFixedDomainAxisSpaceForSubplots(space);
// draw the shared axis
ValueAxis axis = getRangeAxis();
RectangleEdge edge = getRangeAxisEdge();
double cursor = RectangleEdge.coordinate(dataArea, edge);
AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
if (parentState == null) {
parentState = new PlotState();
}
parentState.getSharedAxisStates().put(axis, axisState);
// draw all the charts
for (int i = 0; i < this.subplots.size(); i++) {
XYPlot plot = (XYPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = null;
if (info != null) {
subplotInfo = new PlotRenderingInfo(info.getOwner());
info.addSubplotInfo(subplotInfo);
}
plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo);
}
if (info != null) {
info.setDataArea(dataArea);
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method calculateDomainAxisSpace.
/**
* Calculates the space required for the domain axis/axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param space a carrier for the result (<code>null</code> permitted).
*
* @return The required space.
*/
protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the domain axis...
if (this.fixedDomainAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT);
} else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP);
space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM);
}
} else {
// reserve space for the domain axes...
for (int i = 0; i < this.domainAxes.size(); i++) {
Axis axis = (Axis) this.domainAxes.get(i);
if (axis != null) {
RectangleEdge edge = getDomainAxisEdge(i);
space = axis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method draw.
/**
* Draws the plot within the specified area on a graphics device.
*
* @param g2 the graphics device.
* @param area the plot area (in Java2D space).
* @param anchor an anchor point in Java2D space (<code>null</code>
* permitted).
* @param parentState the state from the parent plot, if there is one
* (<code>null</code> permitted).
* @param info collects chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
this.axisOffset.trim(dataArea);
dataArea = integerise(dataArea);
if (dataArea.isEmpty()) {
return;
}
createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null);
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
Map axisStateMap = drawAxes(g2, area, dataArea, info);
PlotOrientation orient = getOrientation();
// clicked - the crosshairs will be driven off this point...
if (anchor != null && !dataArea.contains(anchor)) {
anchor = null;
}
CrosshairState crosshairState = new CrosshairState();
crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
crosshairState.setAnchor(anchor);
crosshairState.setAnchorX(Double.NaN);
crosshairState.setAnchorY(Double.NaN);
if (anchor != null) {
ValueAxis domainAxis = getDomainAxis();
if (domainAxis != null) {
double x;
if (orient == PlotOrientation.VERTICAL) {
x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
} else {
x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge());
}
crosshairState.setAnchorX(x);
}
ValueAxis rangeAxis = getRangeAxis();
if (rangeAxis != null) {
double y;
if (orient == PlotOrientation.VERTICAL) {
y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
} else {
y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
}
crosshairState.setAnchorY(y);
}
}
crosshairState.setCrosshairX(getDomainCrosshairValue());
crosshairState.setCrosshairY(getRangeCrosshairValue());
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
AxisState domainAxisState = (AxisState) axisStateMap.get(getDomainAxis());
if (domainAxisState == null) {
if (parentState != null) {
domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());
}
}
AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
if (rangeAxisState == null) {
if (parentState != null) {
rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
}
}
if (domainAxisState != null) {
drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
}
if (rangeAxisState != null) {
drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
}
if (domainAxisState != null) {
drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
drawZeroDomainBaseline(g2, dataArea);
}
if (rangeAxisState != null) {
drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
drawZeroRangeBaseline(g2, dataArea);
}
Graphics2D savedG2 = g2;
Rectangle2D savedDataArea = dataArea;
BufferedImage dataImage = null;
if (this.shadowGenerator != null) {
dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
g2 = dataImage.createGraphics();
g2.setRenderingHints(savedG2.getRenderingHints());
dataArea = new Rectangle(0, 0, dataImage.getWidth(), dataImage.getHeight());
}
// draw the markers that are associated with a specific renderer...
for (int i = 0; i < this.renderers.size(); i++) {
drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
for (int i = 0; i < this.renderers.size(); i++) {
drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
// now draw annotations and render data items...
boolean foundData = false;
DatasetRenderingOrder order = getDatasetRenderingOrder();
if (order == DatasetRenderingOrder.FORWARD) {
// draw background annotations
int rendererCount = this.renderers.size();
for (int i = 0; i < rendererCount; i++) {
XYItemRenderer r = getRenderer(i);
if (r != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
}
}
// render data items...
for (int i = 0; i < getDatasetCount(); i++) {
foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
}
// draw foreground annotations
for (int i = 0; i < rendererCount; i++) {
XYItemRenderer r = getRenderer(i);
if (r != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
}
}
} else if (order == DatasetRenderingOrder.REVERSE) {
// draw background annotations
int rendererCount = this.renderers.size();
for (int i = rendererCount - 1; i >= 0; i--) {
XYItemRenderer r = getRenderer(i);
if (i >= getDatasetCount()) {
// a link to the axes
continue;
}
if (r != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
}
}
for (int i = getDatasetCount() - 1; i >= 0; i--) {
foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
}
// draw foreground annotations
for (int i = rendererCount - 1; i >= 0; i--) {
XYItemRenderer r = getRenderer(i);
if (i >= getDatasetCount()) {
// a link to the axes
continue;
}
if (r != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
}
}
}
// draw domain crosshair if required...
int xAxisIndex = crosshairState.getDomainAxisIndex();
ValueAxis xAxis = getDomainAxis(xAxisIndex);
RectangleEdge xAxisEdge = getDomainAxisEdge(xAxisIndex);
if (!this.domainCrosshairLockedOnData && anchor != null) {
double xx;
if (orient == PlotOrientation.VERTICAL) {
xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge);
} else {
xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge);
}
crosshairState.setCrosshairX(xx);
}
setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
if (isDomainCrosshairVisible()) {
double x = getDomainCrosshairValue();
Paint paint = getDomainCrosshairPaint();
Stroke stroke = getDomainCrosshairStroke();
drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint);
}
// draw range crosshair if required...
int yAxisIndex = crosshairState.getRangeAxisIndex();
ValueAxis yAxis = getRangeAxis(yAxisIndex);
RectangleEdge yAxisEdge = getRangeAxisEdge(yAxisIndex);
if (!this.rangeCrosshairLockedOnData && anchor != null) {
double yy;
if (orient == PlotOrientation.VERTICAL) {
yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
} else {
yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
}
crosshairState.setCrosshairY(yy);
}
setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
if (isRangeCrosshairVisible()) {
double y = getRangeCrosshairValue();
Paint paint = getRangeCrosshairPaint();
Stroke stroke = getRangeCrosshairStroke();
drawRangeCrosshair(g2, dataArea, orient, y, yAxis, stroke, paint);
}
if (!foundData) {
drawNoDataMessage(g2, dataArea);
}
for (int i = 0; i < this.renderers.size(); i++) {
drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
for (int i = 0; i < this.renderers.size(); i++) {
drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
drawAnnotations(g2, dataArea, info);
if (this.shadowGenerator != null) {
BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
g2 = savedG2;
dataArea = savedDataArea;
g2.drawImage(shadowImage, (int) savedDataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) savedDataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
g2.drawImage(dataImage, (int) savedDataArea.getX(), (int) savedDataArea.getY(), null);
}
g2.setClip(originalClip);
g2.setComposite(originalComposite);
drawOutline(g2, dataArea);
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYPlot method calculateRangeAxisSpace.
/**
* Calculates the space required for the range axis/axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param space a carrier for the result (<code>null</code> permitted).
*
* @return The required space.
*/
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the range axis...
if (this.fixedRangeAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
} else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
}
} else {
// reserve space for the range axes...
for (int i = 0; i < this.rangeAxes.size(); i++) {
Axis axis = (Axis) this.rangeAxes.get(i);
if (axis != null) {
RectangleEdge edge = getRangeAxisEdge(i);
space = axis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
Aggregations