that contains multiple subplots that share a
common domain axis.
| Method from org.jfree.chart.plot.CombinedDomainXYPlot Detail: |
public void add(XYPlot subplot) {
// defer argument checking
add(subplot, 1);
}
Adds a subplot (with a default 'weight' of 1) and sends a
PlotChangeEvent to all registered listeners.
The domain axis for the subplot will be set to null. You
must ensure that the subplot has a non-null range axis. |
public void add(XYPlot subplot,
int weight) {
if (subplot == null) {
throw new IllegalArgumentException("Null 'subplot' argument.");
}
if (weight < = 0) {
throw new IllegalArgumentException("Require weight >= 1.");
}
// store the plot and its weight
subplot.setParent(this);
subplot.setWeight(weight);
subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false);
subplot.setDomainAxis(null);
subplot.addChangeListener(this);
this.subplots.add(subplot);
// keep track of total weights
this.totalWeight += weight;
ValueAxis axis = getDomainAxis();
if (axis != null) {
axis.configure();
}
fireChangeEvent();
}
Adds a subplot with the specified weight and sends a
PlotChangeEvent to all registered listeners. The weight
determines how much space is allocated to the subplot relative to all
the other subplots.
The domain axis for the subplot will be set to null. You
must ensure that the subplot has a non-null range axis. |
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 = getFixedDomainAxisSpace();
if (fixed != null) {
if (orientation == PlotOrientation.HORIZONTAL) {
space.setLeft(fixed.getLeft());
space.setRight(fixed.getRight());
}
else if (orientation == PlotOrientation.VERTICAL) {
space.setTop(fixed.getTop());
space.setBottom(fixed.getBottom());
}
}
else {
ValueAxis xAxis = getDomainAxis();
RectangleEdge xEdge = Plot.resolveDomainAxisLocation(
getDomainAxisLocation(), orientation);
if (xAxis != null) {
space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
}
}
Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
// work out the maximum height or width of the non-shared axes...
int n = this.subplots.size();
this.subplotAreas = new Rectangle2D[n];
double x = adjustedPlotArea.getX();
double y = adjustedPlotArea.getY();
double usableSize = 0.0;
if (orientation == PlotOrientation.HORIZONTAL) {
usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
}
else if (orientation == PlotOrientation.VERTICAL) {
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.HORIZONTAL) {
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.VERTICAL) {
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.calculateRangeAxisSpace(g2,
this.subplotAreas[i], null);
space.ensureAtLeast(subSpace);
}
return space;
}
Calculates the axis space required. |
public Object clone() throws CloneNotSupportedException {
CombinedDomainXYPlot result = (CombinedDomainXYPlot) 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 domain axis may need
// reconfiguring
ValueAxis domainAxis = result.getDomainAxis();
if (domainAxis != null) {
domainAxis.configure();
}
return result;
}
Returns a clone of the annotation. |
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);
setFixedRangeAxisSpaceForSubplots(null);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
// set the width and height of non-shared axis of all sub-plots
setFixedRangeAxisSpaceForSubplots(space);
// draw the shared axis
ValueAxis axis = getDomainAxis();
RectangleEdge edge = getDomainAxisEdge();
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 subplots
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 == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof CombinedDomainXYPlot)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
CombinedDomainXYPlot p = (CombinedDomainXYPlot) obj;
if (this.totalWeight != p.totalWeight) {
return false;
}
if (this.gap != p.gap) {
return false;
}
if (!ObjectUtilities.equal(this.subplots, p.subplots)) {
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 domain axis is shared between subplots, the JFreeChart code
will only call this method for the domain values (although this is not
checked/enforced). |
public double getGap() {
return this.gap;
}
Returns the gap between subplots, measured in Java2D units. |
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 "Combined_Domain_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();
ValueAxis domain = getDomainAxis();
if (domain != null) {
domain.configure();
}
fireChangeEvent();
}
}
Removes a subplot from the combined chart and sends a
PlotChangeEvent to all registered listeners. |
public void setFixedRangeAxisSpace(AxisSpace space) {
super.setFixedRangeAxisSpace(space);
setFixedRangeAxisSpaceForSubplots(space);
fireChangeEvent();
}
Sets the fixed range axis space and sends a PlotChangeEvent to
all registered listeners. |
protected void setFixedRangeAxisSpaceForSubplots(AxisSpace space) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
XYPlot plot = (XYPlot) iterator.next();
plot.setFixedRangeAxisSpace(space, false);
}
}
Sets the size (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;
fireChangeEvent();
}
Sets the amount of space between subplots and sends a
PlotChangeEvent to all registered listeners. |
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 (also changes the orientation for all
the subplots to match). |
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 zoomRangeAxes(double factor,
PlotRenderingInfo info,
Point2D source) {
zoomRangeAxes(factor, info, source, false);
}
Multiplies the range on the range axis/axes by the specified factor. |
public void zoomRangeAxes(double factor,
PlotRenderingInfo state,
Point2D source,
boolean useAnchor) {
// delegate 'state' and 'source' argument checks...
XYPlot subplot = findSubplot(state, source);
if (subplot != null) {
subplot.zoomRangeAxes(factor, state, 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.zoomRangeAxes(factor, state, source, useAnchor);
}
}
}
Multiplies the range on the range axis/axes by the specified factor. |
public void zoomRangeAxes(double lowerPercent,
double upperPercent,
PlotRenderingInfo info,
Point2D source) {
// delegate 'info' and 'source' argument checks...
XYPlot subplot = findSubplot(info, source);
if (subplot != null) {
subplot.zoomRangeAxes(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.zoomRangeAxes(lowerPercent, upperPercent, info, source);
}
}
}
Zooms in on the range axes. |