that contains multiple subplots that share a
common range axis.
| Method from org.jfree.chart.plot.CombinedRangeXYPlot Detail: |
public void add(XYPlot subplot) {
add(subplot, 1);
}
Adds a subplot, with a default 'weight' of 1.
You must ensure that the subplot has a non-null domain axis. The range
axis for the subplot will be set to null. |
public void add(XYPlot subplot,
int weight) {
// verify valid weight
if (weight < = 0) {
String msg = "The 'weight' must be positive.";
throw new IllegalArgumentException(msg);
}
// store the plot and its weight
subplot.setParent(this);
subplot.setWeight(weight);
subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
subplot.setRangeAxis(null);
subplot.addChangeListener(this);
this.subplots.add(subplot);
// keep track of total weights
this.totalWeight += weight;
configureRangeAxes();
fireChangeEvent();
}
Adds a subplot with a particular weight (greater than or equal to one).
The weight determines how much space is allocated to the subplot
relative to all the other subplots.
You must ensure that the subplot has a non-null domain axis. The range
axis for the subplot will be set to null. |
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();
// 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() / this.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() / this.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;
}
Calculates the space required for the axes. |
public Object clone() throws CloneNotSupportedException {
CombinedRangeXYPlot result = (CombinedRangeXYPlot) super.clone();
result.subplots = (List) ObjectUtilities.deepClone(this.subplots);
for (Iterator it = result.subplots.iterator(); it.hasNext();) {
Plot child = (Plot) it.next();
child.setParent(result);
}
// after setting up all the subplots, the shared range axis may need
// reconfiguring
ValueAxis rangeAxis = result.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.configure();
}
return result;
}
Returns a clone of the plot. |
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);
}
}
Draws the plot within the specified area on a graphics device. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CombinedRangeXYPlot)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
CombinedRangeXYPlot that = (CombinedRangeXYPlot) obj;
if (!ObjectUtilities.equal(this.subplots, that.subplots)) {
return false;
}
if (this.totalWeight != that.totalWeight) {
return false;
}
if (this.gap != that.gap) {
return false;
}
return true;
}
Tests this plot for equality with another object. |
public XYPlot findSubplot(PlotRenderingInfo info,
Point2D source) {
if (info == null) {
throw new IllegalArgumentException("Null 'info' argument.");
}
if (source == null) {
throw new IllegalArgumentException("Null 'source' argument.");
}
XYPlot result = null;
int subplotIndex = info.getSubplotIndex(source);
if (subplotIndex >= 0) {
result = (XYPlot) this.subplots.get(subplotIndex);
}
return result;
}
Returns the subplot (if any) that contains the (x, y) point (specified
in Java2D space). |
public Range getDataRange(ValueAxis axis) {
Range result = null;
if (this.subplots != null) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot subplot = (XYPlot) iterator.next();
result = Range.combine(result, subplot.getDataRange(axis));
}
}
return result;
}
Returns a range representing the extent of the data values in this plot
(obtained from the subplots) that will be rendered against the specified
axis. NOTE: This method is intended for internal JFreeChart use, and
is public only so that code in the axis classes can call it. Since
only the range axis is shared between subplots, the JFreeChart code
will only call this method for the range values (although this is not
checked/enforced). |
public double getGap() {
return this.gap;
}
Returns the space between subplots. |
public LegendItemCollection getLegendItems() {
LegendItemCollection result = getFixedLegendItems();
if (result == null) {
result = new LegendItemCollection();
if (this.subplots != null) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot plot = (XYPlot) iterator.next();
LegendItemCollection more = plot.getLegendItems();
result.addAll(more);
}
}
}
return result;
}
Returns a collection of legend items for the plot. |
public String getPlotType() {
return localizationResources.getString("Combined_Range_XYPlot");
}
Returns a string describing the type of plot. |
public List getSubplots() {
if (this.subplots != null) {
return Collections.unmodifiableList(this.subplots);
}
else {
return Collections.EMPTY_LIST;
}
}
Returns the list of subplots. The returned list may be empty, but is
never null. |
public void handleClick(int x,
int y,
PlotRenderingInfo info) {
Rectangle2D dataArea = info.getDataArea();
if (dataArea.contains(x, y)) {
for (int i = 0; i < this.subplots.size(); i++) {
XYPlot subplot = (XYPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = info.getSubplotInfo(i);
subplot.handleClick(x, y, subplotInfo);
}
}
}
Handles a 'click' on the plot by updating the anchor values... |
public void plotChanged(PlotChangeEvent event) {
notifyListeners(event);
}
|
public void remove(XYPlot subplot) {
if (subplot == null) {
throw new IllegalArgumentException(" Null 'subplot' argument.");
}
int position = -1;
int size = this.subplots.size();
int i = 0;
while (position == -1 && i < size) {
if (this.subplots.get(i) == subplot) {
position = i;
}
i++;
}
if (position != -1) {
this.subplots.remove(position);
subplot.setParent(null);
subplot.removeChangeListener(this);
this.totalWeight -= subplot.getWeight();
configureRangeAxes();
fireChangeEvent();
}
}
Removes a subplot from the combined chart. |
protected void setFixedDomainAxisSpaceForSubplots(AxisSpace space) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot plot = (XYPlot) iterator.next();
plot.setFixedDomainAxisSpace(space, false);
}
}
Sets the space (width or height, depending on the orientation of the
plot) for the domain axis of each subplot. |
public void setGap(double gap) {
this.gap = gap;
}
Sets the amount of space between subplots. |
public void setOrientation(PlotOrientation orientation) {
super.setOrientation(orientation);
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot plot = (XYPlot) iterator.next();
plot.setOrientation(orientation);
}
}
Sets the orientation for the plot (and all its subplots). |
public void setRenderer(XYItemRenderer renderer) {
super.setRenderer(renderer); // not strictly necessary, since the
// renderer set for the
// parent plot is not used
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot plot = (XYPlot) iterator.next();
plot.setRenderer(renderer);
}
}
Sets the item renderer FOR ALL SUBPLOTS. Registered listeners are
notified that the plot has been modified.
Note: usually you will want to set the renderer independently for each
subplot, which is NOT what this method does. |
public void zoomDomainAxes(double factor,
PlotRenderingInfo info,
Point2D source) {
zoomDomainAxes(factor, info, source, false);
}
Multiplies the range on the domain axis/axes by the specified factor. |
public void zoomDomainAxes(double factor,
PlotRenderingInfo info,
Point2D source,
boolean useAnchor) {
// delegate 'info' and 'source' argument checks...
XYPlot subplot = findSubplot(info, source);
if (subplot != null) {
subplot.zoomDomainAxes(factor, info, source, useAnchor);
}
else {
// if the source point doesn't fall within a subplot, we do the
// zoom on all subplots...
Iterator iterator = getSubplots().iterator();
while (iterator.hasNext()) {
subplot = (XYPlot) iterator.next();
subplot.zoomDomainAxes(factor, info, source, useAnchor);
}
}
}
Multiplies the range on the domain axis/axes by the specified factor. |
public void zoomDomainAxes(double lowerPercent,
double upperPercent,
PlotRenderingInfo info,
Point2D source) {
// delegate 'info' and 'source' argument checks...
XYPlot subplot = findSubplot(info, source);
if (subplot != null) {
subplot.zoomDomainAxes(lowerPercent, upperPercent, info, source);
}
else {
// if the source point doesn't fall within a subplot, we do the
// zoom on all subplots...
Iterator iterator = getSubplots().iterator();
while (iterator.hasNext()) {
subplot = (XYPlot) iterator.next();
subplot.zoomDomainAxes(lowerPercent, upperPercent, info,
source);
}
}
}
Zooms in on the domain axes. |