1 /* =========================================================== 2 * JFreeChart : a free chart library for the Java(tm) platform 3 * =========================================================== 4 * 5 * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. 6 * 7 * Project Info: http://www.jfree.org/jfreechart/index.html 8 * 9 * This library is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU Lesser General Public License as published by 11 * the Free Software Foundation; either version 2.1 of the License, or 12 * (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 * License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 * USA. 23 * 24 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 25 * Other names may be trademarks of their respective owners.] 26 * 27 * ------------------- 28 * CombinedXYPlot.java 29 * ------------------- 30 * (C) Copyright 2008, by Richard West and Contributors. 31 * 32 * Original Author: Richard West, Advanced Micro Devices, Inc.; 33 * Contributor(s): David Gilbert (for Object Refinery Limited); 34 * 35 * Changes 36 * ------- 37 * 05-May-2008 : Version 1, contributed by Richard West - see 38 * patch 1924543 (DG); 39 * 40 */ 41 42 package org.jfree.experimental.chart.plot; 43 44 import java.util.Iterator; 45 46 import org.jfree.chart.axis.ValueAxis; 47 import org.jfree.chart.plot.CombinedDomainCategoryPlot; 48 import org.jfree.chart.plot.CombinedDomainXYPlot; 49 import org.jfree.chart.plot.XYPlot; 50 import org.jfree.data.Range; 51 52 /** 53 * A specialised form of {@link CombinedDomainCategoryPlot} where the 54 * subplots share not only the same x-axis, but also the same y-axis. 55 */ 56 public class CombinedXYPlot extends CombinedDomainXYPlot { 57 58 /** 59 * Creates a new instance with the specified axes. 60 * 61 * @param domainAxis the x-axis. 62 * @param rangeAxis the y-axis. 63 */ CombinedXYPlot(ValueAxis domainAxis, ValueAxis rangeAxis)64 public CombinedXYPlot(ValueAxis domainAxis, ValueAxis rangeAxis) { 65 super(domainAxis); 66 super.setGap(10.0); 67 super.setRangeAxis(rangeAxis); 68 } 69 70 /** 71 * Adds a new subplot with weight <code>1</code>. 72 * 73 * @param subplot the subplot. 74 */ add(XYPlot subplot)75 public void add(XYPlot subplot) { 76 this.add(subplot, 1); 77 } 78 79 /** 80 * Adds a new subplot with the specified weight. 81 * 82 * @param subplot the subplot. 83 * @param weight the weight for the subplot. 84 */ add(XYPlot subplot, int weight)85 public void add(XYPlot subplot, int weight) { 86 super.add(subplot, weight); 87 88 ValueAxis l_range = super.getRangeAxis(); 89 subplot.setRangeAxis(0, l_range, false); 90 91 super.setRangeAxis(l_range); 92 if (null == l_range) { 93 return; 94 } 95 96 l_range.configure(); 97 } 98 99 /** 100 * Returns the bounds of the data values that will be plotted against 101 * the specified axis. 102 * 103 * @param axis the axis. 104 * 105 * @return The bounds. 106 */ getDataRange(ValueAxis axis)107 public Range getDataRange(ValueAxis axis) { 108 Range l_result = null; 109 Iterator l_itr = getSubplots().iterator(); 110 while (l_itr.hasNext()) { 111 XYPlot l_subplot = (XYPlot) l_itr.next(); 112 113 l_result = Range.combine(l_result, l_subplot.getDataRange(axis)); 114 } 115 return l_result; 116 } 117 118 /** 119 * Sets the range axis that is shared by all the subplots. 120 * 121 * @param axis the axis. 122 */ setRangeAxis(ValueAxis axis)123 public void setRangeAxis(ValueAxis axis) { 124 Iterator l_itr = getSubplots().iterator(); 125 while (l_itr.hasNext()) { 126 XYPlot l_subplot = (XYPlot) l_itr.next(); 127 l_subplot.setRangeAxis(0, axis, false); 128 } 129 130 super.setRangeAxis(axis); 131 if (null == axis) { 132 return; 133 } 134 135 axis.configure(); 136 } 137 138 } 139 140