From 8a4701185dc26e684d67295442ea2e12a5e4946b Mon Sep 17 00:00:00 2001
From: Simon Legner <Simon.Legner@gmail.com>
Date: Wed, 5 Feb 2014 10:38:13 +0100
Subject: [PATCH] Make CombinedDomainXYPlot more flexible

- allow domain axis to be displayed at each plot separately
- possibility to use with `null` domain axis
- separate method `drawSharedAxis` to allow subclasses
  to change implementation
- protected fields (instead of private fields)
---
 .../org/jfree/chart/plot/CombinedDomainXYPlot.java | 51 +++++++++++++++++-----
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/source/org/jfree/chart/plot/CombinedDomainXYPlot.java b/source/org/jfree/chart/plot/CombinedDomainXYPlot.java
index d0aa945..33f3195 100644
--- a/source/org/jfree/chart/plot/CombinedDomainXYPlot.java
+++ b/source/org/jfree/chart/plot/CombinedDomainXYPlot.java
@@ -127,19 +127,22 @@ public class CombinedDomainXYPlot extends XYPlot
         implements PlotChangeListener {
 
     /** For serialization. */
-    private static final long serialVersionUID = -7765545541261907383L;
+    private static final long serialVersionUID = -9176885086341201928L;
 
     /** Storage for the subplot references. */
-    private List subplots;
+    protected List subplots;
 
     /** The gap between subplots. */
-    private double gap = 5.0;
+    protected double gap = 5.0;
 
     /** Temporary storage for the subplot areas. */
-    private transient Rectangle2D[] subplotAreas;
+    protected transient Rectangle2D[] subplotAreas;
     // TODO:  the subplot areas needs to be moved out of the plot into the plot
     //        state
 
+    /** Whether the domain axis should be displayed at each plot separately */
+    protected final boolean domainAxisForEachSubplot;
+
     /**
      * Default constructor.
      */
@@ -154,6 +157,20 @@ public class CombinedDomainXYPlot extends XYPlot
      * @param domainAxis  the shared axis.
      */
     public CombinedDomainXYPlot(ValueAxis domainAxis) {
+        this(domainAxis, false);
+    }
+
+    /**
+     * Creates a new combined plot that shares a domain axis among multiple
+     * subplots.
+     *
+     * @param domainAxis  the shared axis.
+     * @param domainAxisForEachSubplot Whether the domain axis should
+     *        be displayed at each plot separately
+     *        instead of one axis at the end of the plot.
+     */
+    public CombinedDomainXYPlot(ValueAxis domainAxis,
+                                boolean domainAxisForEachSubplot) {
 
         super(null,        // no data in the parent plot
               domainAxis,
@@ -161,6 +178,7 @@ public class CombinedDomainXYPlot extends XYPlot
               null);       // no renderer
 
         this.subplots = new java.util.ArrayList();
+        this.domainAxisForEachSubplot = domainAxisForEachSubplot;
 
     }
 
@@ -294,7 +312,7 @@ public class CombinedDomainXYPlot extends XYPlot
         subplot.setParent(this);
         subplot.setWeight(weight);
         subplot.setInsets(RectangleInsets.ZERO_INSETS, false);
-        subplot.setDomainAxis(null);
+        subplot.setDomainAxis(domainAxisForEachSubplot ? getDomainAxis() : null);
         subplot.addChangeListener(this);
         this.subplots.add(subplot);
 
@@ -376,7 +394,7 @@ public class CombinedDomainXYPlot extends XYPlot
                 space.setBottom(fixed.getBottom());
             }
         }
-        else {
+        else if (!this.domainAxisForEachSubplot) {
             ValueAxis xAxis = getDomainAxis();
             RectangleEdge xEdge = Plot.resolveDomainAxisLocation(
                     getDomainAxisLocation(), orientation);
@@ -463,15 +481,13 @@ public class CombinedDomainXYPlot extends XYPlot
         // 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);
+
+        if (!this.domainAxisForEachSubplot) {
+            this.drawSharedAxis(g2, area, parentState, info, dataArea);
+        }
 
         // draw all the subplots
         for (int i = 0; i < this.subplots.size(); i++) {
@@ -491,6 +507,17 @@ public class CombinedDomainXYPlot extends XYPlot
 
     }
 
+    protected void drawSharedAxis(Graphics2D g2, Rectangle2D area,
+            PlotState parentState, PlotRenderingInfo info, Rectangle2D dataArea) {
+        final ValueAxis axis = getDomainAxis();
+        final RectangleEdge edge = getDomainAxisEdge();
+        if (axis != null && edge != null) {
+            final double cursor = RectangleEdge.coordinate(dataArea, edge);
+            final AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
+            parentState.getSharedAxisStates().put(axis, axisState);
+        }
+    }
+
     /**
      * Returns a collection of legend items for the plot.
      *
-- 
1.8.5.3

