A combined category plot where the range axis is shared.
| Method from org.jfree.chart.plot.CombinedRangeCategoryPlot Detail: |
public void add(CategoryPlot subplot) {
// defer argument checking
add(subplot, 1);
}
Adds a subplot (with a default 'weight' of 1) and sends a
PlotChangeEvent to all registered listeners.
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(CategoryPlot 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));
subplot.setRangeAxis(null);
subplot.setOrientation(getOrientation());
subplot.addChangeListener(this);
this.subplots.add(subplot);
this.totalWeight += weight;
// configure the range axis...
ValueAxis axis = getRangeAxis();
if (axis != null) {
axis.configure();
}
fireChangeEvent();
}
Adds a subplot and sends a PlotChangeEvent to all registered
listeners.
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.subplotArea = 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++) {
CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
// calculate sub-plot area
if (orientation == PlotOrientation.VERTICAL) {
double w = usableSize * plot.getWeight() / this.totalWeight;
this.subplotArea[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.subplotArea[i] = new Rectangle2D.Double(x, y,
adjustedPlotArea.getWidth(), h);
y = y + h + this.gap;
}
AxisSpace subSpace = plot.calculateDomainAxisSpace(g2,
this.subplotArea[i], null);
space.ensureAtLeast(subSpace);
}
return space;
}
Calculates the space required for the axes. |
public Object clone() throws CloneNotSupportedException {
CombinedRangeCategoryPlot result
= (CombinedRangeCategoryPlot) 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);
// calculate the data area...
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
// set the width and height of non-shared axis of all sub-plots
setFixedDomainAxisSpaceForSubplots(space);
// draw the shared axis
ValueAxis axis = getRangeAxis();
RectangleEdge rangeEdge = getRangeAxisEdge();
double cursor = RectangleEdge.coordinate(dataArea, rangeEdge);
AxisState state = axis.draw(g2, cursor, area, dataArea, rangeEdge,
info);
if (parentState == null) {
parentState = new PlotState();
}
parentState.getSharedAxisStates().put(axis, state);
// draw all the charts
for (int i = 0; i < this.subplots.size(); i++) {
CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = null;
if (info != null) {
subplotInfo = new PlotRenderingInfo(info.getOwner());
info.addSubplotInfo(subplotInfo);
}
plot.draw(g2, this.subplotArea[i], null, parentState, subplotInfo);
}
if (info != null) {
info.setDataArea(dataArea);
}
}
Draws the plot on a Java 2D graphics device (such as the screen or a
printer). Will perform all the placement calculations for each
sub-plots and then tell these to draw themselves. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CombinedRangeCategoryPlot)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
CombinedRangeCategoryPlot that = (CombinedRangeCategoryPlot) 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 the plot for equality with an arbitrary object. |
public Range getDataRange(ValueAxis axis) {
Range result = null;
if (this.subplots != null) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
CategoryPlot subplot = (CategoryPlot) 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()) {
CategoryPlot plot = (CategoryPlot) iterator.next();
LegendItemCollection more = plot.getLegendItems();
result.addAll(more);
}
}
}
return result;
}
Returns a collection of legend items for the 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++) {
CategoryPlot subplot = (CategoryPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = info.getSubplotInfo(i);
subplot.handleClick(x, y, subplotInfo);
}
}
}
Handles a 'click' on the plot by updating the anchor value. |
public void plotChanged(PlotChangeEvent event) {
notifyListeners(event);
}
|
public void remove(CategoryPlot 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 range = getRangeAxis();
if (range != null) {
range.configure();
}
ValueAxis range2 = getRangeAxis(1);
if (range2 != null) {
range2.configure();
}
fireChangeEvent();
}
}
Removes a subplot from the combined chart. |
protected void setFixedDomainAxisSpaceForSubplots(AxisSpace space) {
Iterator iterator = this.subplots.iterator();
while (iterator.hasNext()) {
CategoryPlot plot = (CategoryPlot) iterator.next();
plot.setFixedDomainAxisSpace(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()) {
CategoryPlot plot = (CategoryPlot) iterator.next();
plot.setOrientation(orientation);
}
}
Sets the orientation for the plot (and all the subplots). |