From: <mu...@us...> - 2007-07-10 09:30:21
|
Revision: 109 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=109&view=rev Author: mungady Date: 2007-07-10 02:30:17 -0700 (Tue, 10 Jul 2007) Log Message: ----------- 2007-06-10 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/CategoryPlot.java (getRangeAxisIndex): New method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-06 15:14:34 UTC (rev 108) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 09:30:17 UTC (rev 109) @@ -1,3 +1,10 @@ +2007-06-10 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/CategoryPlot.java + (getRangeAxisIndex): New method. + +---------- JFREECHART 1.0.6 RELEASED ------------------------ + 2007-06-15 David Gilbert <dav...@ob...> * swt/org/jfree/experimental/swt/SWTGraphics2D.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java 2007-07-06 15:14:34 UTC (rev 108) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java 2007-07-10 09:30:17 UTC (rev 109) @@ -146,8 +146,9 @@ * ignored) (DG); * 13-Mar-2007 : Added null argument checks for setRangeCrosshairPaint() and * setRangeCrosshairStroke(), fixed clipping for - * anntotations (DG); + * annotations (DG); * 07-Jun-2007 : Override drawBackground() for new GradientPaint handling (DG); + * 10-Jul-2007 : Added getRangeAxisIndex(ValueAxis) method (DG); * */ @@ -695,6 +696,30 @@ public int getDomainAxisIndex(CategoryAxis axis) { return this.domainAxes.indexOf(axis); } + + /** + * Returns the index of the specified axis, or <code>-1</code> if the axis + * is not assigned to the plot. + * + * @param axis the axis. + * + * @return The axis index. + * + * @see #getDomainAxisIndex(CategoryAxis) + * + * @since 1.0.7 + */ + public int getRangeAxisIndex(ValueAxis axis) { + int result = this.rangeAxes.indexOf(axis); + if (result < 0) { // try the parent plot + Plot parent = getParent(); + if (parent instanceof CategoryPlot) { + CategoryPlot p = (CategoryPlot) parent; + result = p.getRangeAxisIndex(axis); + } + } + return result; + } /** * Returns the domain axis location for the primary domain axis. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-10 09:53:18
|
Revision: 111 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=111&view=rev Author: mungady Date: 2007-07-10 02:53:17 -0700 (Tue, 10 Jul 2007) Log Message: ----------- 2007-07-10 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/SimpleHistogramDataset.java (SimpleHistogramDataset): Check for null argument. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 09:33:45 UTC (rev 110) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 09:53:17 UTC (rev 111) @@ -1,5 +1,10 @@ -2007-06-10 David Gilbert <dav...@ob...> +2007-07-10 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/SimpleHistogramDataset.java + (SimpleHistogramDataset): Check for null argument. + +2007-07-10 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/CategoryPlot.java (getRangeAxisIndex): New method. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java 2007-07-10 09:33:45 UTC (rev 110) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java 2007-07-10 09:53:17 UTC (rev 111) @@ -38,7 +38,8 @@ * ------- * 10-Jan-2005 : Version 1 (DG); * 21-May-2007 : Added clearObservations() and removeAllBins() (SI); - * + * 10-Jul-2007 : Added null argument check to constructor (DG); + * */ package org.jfree.data.statistics; @@ -84,9 +85,12 @@ /** * Creates a new histogram dataset. * - * @param key the series key. + * @param key the series key (<code>null</code> not permitted). */ public SimpleHistogramDataset(Comparable key) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } this.key = key; this.bins = new ArrayList(); this.adjustForBinSize = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-10 14:26:33
|
Revision: 113 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=113&view=rev Author: mungady Date: 2007-07-10 07:26:29 -0700 (Tue, 10 Jul 2007) Log Message: ----------- 2007-07-10 David Gilbert <dav...@ob...> * tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java (EPSILON): New field, (testFindDomainBounds): Fixed compile errors, * tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java (EPSILON): New field, (testGetDomainBoundsWithoutInterval): Fixed compile errors, (testGetDomainBoundsWithInterval): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 09:56:11 UTC (rev 112) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 14:26:29 UTC (rev 113) @@ -1,5 +1,15 @@ 2007-07-10 David Gilbert <dav...@ob...> + * tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java + (EPSILON): New field, + (testFindDomainBounds): Fixed compile errors, + * tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java + (EPSILON): New field, + (testGetDomainBoundsWithoutInterval): Fixed compile errors, + (testGetDomainBoundsWithInterval): Likewise. + +2007-07-10 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/SimpleHistogramDataset.java (SimpleHistogramDataset): Check for null argument. Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java 2007-07-10 09:56:11 UTC (rev 112) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java 2007-07-10 14:26:29 UTC (rev 113) @@ -38,7 +38,7 @@ * ------- * 25-Mar-2003 : Version 1 (DG); * 22-Oct-2003 : Added hashCode test (DG); - * + * 10-Jul-2007 : Fixed compile errors (DG); */ package org.jfree.chart.renderer.xy.junit; @@ -56,7 +56,6 @@ import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; import org.jfree.chart.renderer.xy.ClusteredXYBarRenderer; -import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.DefaultIntervalXYDataset; import org.jfree.data.xy.XYDataset; @@ -159,6 +158,8 @@ } + private static final double EPSILON = 0.0000000001; + /** * Some checks for the findDomainBounds() method (which requires special * handling when the centerBarAtStartValue flag is set to true). @@ -167,13 +168,13 @@ AbstractXYItemRenderer renderer = new ClusteredXYBarRenderer(); XYDataset dataset = createSampleDataset1(); Range r = renderer.findDomainBounds(dataset); - assertEquals(0.9, r.getLowerBound()); - assertEquals(13.1, r.getUpperBound()); + assertEquals(0.9, r.getLowerBound(), EPSILON); + assertEquals(13.1, r.getUpperBound(), EPSILON); renderer = new ClusteredXYBarRenderer(0.0, true); r = renderer.findDomainBounds(dataset); - assertEquals(0.8, r.getLowerBound()); - assertEquals(13.0, r.getUpperBound()); + assertEquals(0.8, r.getLowerBound(), EPSILON); + assertEquals(13.0, r.getUpperBound(), EPSILON); // check that a null dataset returns null bounds assertTrue(renderer.findDomainBounds(null) == null); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java 2007-07-10 09:56:11 UTC (rev 112) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java 2007-07-10 14:26:29 UTC (rev 113) @@ -39,6 +39,7 @@ * 11-Mar-2005 : Version 1 (DG); * 08-Mar-2007 : Added testGetSeries() (DG); * 11-Jun-2007 : Added tests for getDomainBounds() (DG); + * 10-Jul-2007 : Fixed compile errors (DG); * */ @@ -192,6 +193,8 @@ assertTrue(pass); } + private static final double EPSILON = 0.0000000001; + /** * Some checks for the getDomainBounds() method. */ @@ -207,14 +210,14 @@ s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0); dataset.addSeries(s1); r = dataset.getDomainBounds(false); - assertEquals(1500.0, r.getLowerBound()); - assertEquals(1500.0, r.getUpperBound()); + assertEquals(1500.0, r.getLowerBound(), EPSILON); + assertEquals(1500.0, r.getUpperBound(), EPSILON); // check dataset with two time periods s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0); r = dataset.getDomainBounds(false); - assertEquals(1500.0, r.getLowerBound()); - assertEquals(2250.0, r.getUpperBound()); + assertEquals(1500.0, r.getLowerBound(), EPSILON); + assertEquals(2250.0, r.getUpperBound(), EPSILON); } /** @@ -233,13 +236,13 @@ s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0); dataset.addSeries(s1); r = dataset.getDomainBounds(true); - assertEquals(1000.0, r.getLowerBound()); - assertEquals(2000.0, r.getUpperBound()); + assertEquals(1000.0, r.getLowerBound(), EPSILON); + assertEquals(2000.0, r.getUpperBound(), EPSILON); // check dataset with two time periods s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0); r = dataset.getDomainBounds(true); - assertEquals(1000.0, r.getLowerBound()); - assertEquals(3000.0, r.getUpperBound()); + assertEquals(1000.0, r.getLowerBound(), EPSILON); + assertEquals(3000.0, r.getUpperBound(), EPSILON); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-10 14:37:09
|
Revision: 115 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=115&view=rev Author: mungady Date: 2007-07-10 07:37:03 -0700 (Tue, 10 Jul 2007) Log Message: ----------- 2007-07-10 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartFactory.java (createPieChart(String, PieDataset, boolean, boolean, Locale)): New method, (createPieChart(String, PieDataset, PieDataset, int, boolean, boolean, boolean, Locale, boolean, boolean)) : Likewise, (createRingChart(String, PieDataset, boolean, boolean, Locale)): Likewise, (createPieChart3D(String, PieDataset, boolean, boolean, Locale)): Likewise, * source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java (StandardPieSectionLabelGenerator(Locale)): New constructor, (StandardPieSectionLabelGenerator(String labelFormat, Locale)): Likewise, * source/org/jfree/chart/labels/StandardPieToolTipGenerator.java (StandardPieToolTipGenerator): Delegate, (StandardPieToolTipGenerator(Locale)): New constructor, (StandardPieToolTipGenerator(String)): Delegate, (StandardPieToolTipGenerator(String labelFormat, Locale)): New constructor. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartFactory.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 14:28:24 UTC (rev 114) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 14:37:03 UTC (rev 115) @@ -1,5 +1,22 @@ 2007-07-10 David Gilbert <dav...@ob...> + * source/org/jfree/chart/ChartFactory.java + (createPieChart(String, PieDataset, boolean, boolean, Locale)): New method, + (createPieChart(String, PieDataset, PieDataset, int, boolean, boolean, + boolean, Locale, boolean, boolean)) : Likewise, + (createRingChart(String, PieDataset, boolean, boolean, Locale)): Likewise, + (createPieChart3D(String, PieDataset, boolean, boolean, Locale)): Likewise, + * source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java + (StandardPieSectionLabelGenerator(Locale)): New constructor, + (StandardPieSectionLabelGenerator(String labelFormat, Locale)): Likewise, + * source/org/jfree/chart/labels/StandardPieToolTipGenerator.java + (StandardPieToolTipGenerator): Delegate, + (StandardPieToolTipGenerator(Locale)): New constructor, + (StandardPieToolTipGenerator(String)): Delegate, + (StandardPieToolTipGenerator(String labelFormat, Locale)): New constructor. + +2007-07-10 David Gilbert <dav...@ob...> + * tests/org/jfree/chart/renderer/xy/junit/ClusteredXYBarRendererTests.java (EPSILON): New field, (testFindDomainBounds): Fixed compile errors, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartFactory.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartFactory.java 2007-07-10 14:28:24 UTC (rev 114) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartFactory.java 2007-07-10 14:37:03 UTC (rev 115) @@ -115,6 +115,8 @@ * generator is a DateAxis is requested (DG); * 17-Jan-2007 : Added createBoxAndWhiskerChart() method from patch 1603937 * submitted by Darren Jung (DG); + * 10-Jul-2007 : Added new methods to create pie charts with locale for + * section label and tool tip formatting (DG); * */ @@ -126,6 +128,7 @@ import java.text.NumberFormat; import java.util.Iterator; import java.util.List; +import java.util.Locale; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryAxis3D; @@ -226,6 +229,36 @@ * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? + * @param locale the locale (<code>null</code> not permitted). + * + * @return A pie chart. + * + * @since 1.0.7 + */ + public static JFreeChart createPieChart(String title, PieDataset dataset, + boolean legend, boolean tooltips, Locale locale) { + + PiePlot plot = new PiePlot(dataset); + plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); + plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); + if (tooltips) { + plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); + } + return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, + legend); + + } + + /** + * Creates a pie chart with default settings. + * <P> + * The chart object returned by this method uses a {@link PiePlot} instance + * as the plot. + * + * @param title the chart title (<code>null</code> permitted). + * @param dataset the dataset for the chart (<code>null</code> permitted). + * @param legend a flag specifying whether or not a legend is required. + * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A pie chart. @@ -240,8 +273,7 @@ plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { - plot.setToolTipGenerator(new StandardPieToolTipGenerator( - StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT)); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); @@ -282,6 +314,125 @@ * displayed in green (decrease red) if true. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? + * @param locale the locale (<code>null</code> not permitted). + * @param subTitle displays a subtitle with colour scheme if true + * @param showDifference create a new dataset that will show the % + * difference between the two datasets. + * + * @return A pie chart. + * + * @since 1.0.7 + */ + public static JFreeChart createPieChart(String title, PieDataset dataset, + PieDataset previousDataset, int percentDiffForMaxScale, + boolean greenForIncrease, boolean legend, boolean tooltips, + Locale locale, boolean subTitle, boolean showDifference) { + + PiePlot plot = new PiePlot(dataset); + plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); + plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); + + if (tooltips) { + plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); + } + + List keys = dataset.getKeys(); + DefaultPieDataset series = null; + if (showDifference) { + series = new DefaultPieDataset(); + } + + double colorPerPercent = 255.0 / percentDiffForMaxScale; + for (Iterator it = keys.iterator(); it.hasNext();) { + Comparable key = (Comparable) it.next(); + Number newValue = dataset.getValue(key); + Number oldValue = previousDataset.getValue(key); + + if (oldValue == null) { + if (greenForIncrease) { + plot.setSectionPaint(key, Color.green); + } + else { + plot.setSectionPaint(key, Color.red); + } + if (showDifference) { + series.setValue(key + " (+100%)", newValue); + } + } + else { + double percentChange = (newValue.doubleValue() + / oldValue.doubleValue() - 1.0) * 100.0; + double shade + = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 + : Math.abs(percentChange) * colorPerPercent); + if (greenForIncrease + && newValue.doubleValue() > oldValue.doubleValue() + || !greenForIncrease && newValue.doubleValue() + < oldValue.doubleValue()) { + plot.setSectionPaint(key, new Color(0, (int) shade, 0)); + } + else { + plot.setSectionPaint(key, new Color((int) shade, 0, 0)); + } + if (showDifference) { + series.setValue(key + " (" + (percentChange >= 0 ? "+" : "") + + NumberFormat.getPercentInstance().format( + percentChange / 100.0) + ")", newValue); + } + } + } + + if (showDifference) { + plot.setDataset(series); + } + + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, legend); + + if (subTitle) { + TextTitle subtitle = null; + subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" + : "green") + "=change >=-" + percentDiffForMaxScale + + "%, Bright " + (!greenForIncrease ? "red" : "green") + + "=change >=+" + percentDiffForMaxScale + "%", + new Font("SansSerif", Font.PLAIN, 10)); + chart.addSubtitle(subtitle); + } + + return chart; + } + + /** + * Creates a pie chart with default settings that compares 2 datasets. + * The colour of each section will be determined by the move from the value + * for the same key in <code>previousDataset</code>. ie if value1 > value2 + * then the section will be in green (unless <code>greenForIncrease</code> + * is <code>false</code>, in which case it would be <code>red</code>). + * Each section can have a shade of red or green as the difference can be + * tailored between 0% (black) and percentDiffForMaxScale% (bright + * red/green). + * <p> + * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a + * difference of 5% will have a half shade of red/green, a difference of + * 10% or more will have a maximum shade/brightness of red/green. + * <P> + * The chart object returned by this method uses a {@link PiePlot} instance + * as the plot. + * <p> + * Written by <a href="mailto:ope...@ob...">Benoit + * Xhenseval</a>. + * + * @param title the chart title (<code>null</code> permitted). + * @param dataset the dataset for the chart (<code>null</code> permitted). + * @param previousDataset the dataset for the last run, this will be used + * to compare each key in the dataset + * @param percentDiffForMaxScale scale goes from bright red/green to black, + * percentDiffForMaxScale indicate the change + * required to reach top scale. + * @param greenForIncrease an increase since previousDataset will be + * displayed in green (decrease red) if true. + * @param legend a flag specifying whether or not a legend is required. + * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * @param subTitle displays a subtitle with colour scheme if true * @param showDifference create a new dataset that will show the % @@ -305,8 +456,7 @@ plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { - plot.setToolTipGenerator(new StandardPieToolTipGenerator( - StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT)); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); @@ -362,9 +512,8 @@ plot.setDataset(series); } - JFreeChart chart = new JFreeChart( - title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend - ); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; @@ -389,9 +538,39 @@ * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? + * @param locale the locale (<code>null</code> not permitted). + * + * @return A ring chart. + * + * @since 1.0.7 + */ + public static JFreeChart createRingChart(String title, PieDataset dataset, + boolean legend, boolean tooltips, Locale locale) { + + RingPlot plot = new RingPlot(dataset); + plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); + plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); + if (tooltips) { + plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); + } + return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, + legend); + + } + + /** + * Creates a ring chart with default settings. + * <P> + * The chart object returned by this method uses a {@link RingPlot} + * instance as the plot. + * + * @param title the chart title (<code>null</code> permitted). + * @param dataset the dataset for the chart (<code>null</code> permitted). + * @param legend a flag specifying whether or not a legend is required. + * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * - * @return A pie chart. + * @return A ring chart. */ public static JFreeChart createRingChart(String title, PieDataset dataset, @@ -403,8 +582,7 @@ plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { - plot.setToolTipGenerator(new StandardPieToolTipGenerator( - StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT)); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); @@ -473,6 +651,34 @@ * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? + * @param locale the locale (<code>null</code> not permitted). + * + * @return A pie chart. + * + * @since 1.0.7 + */ + public static JFreeChart createPieChart3D(String title, PieDataset dataset, + boolean legend, boolean tooltips, Locale locale) { + + PiePlot3D plot = new PiePlot3D(dataset); + plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); + if (tooltips) { + plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); + } + return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, + legend); + + } + + /** + * Creates a 3D pie chart using the specified dataset. The chart object + * returned by this method uses a {@link PiePlot3D} instance as the + * plot. + * + * @param title the chart title (<code>null</code> permitted). + * @param dataset the dataset for the chart (<code>null</code> permitted). + * @param legend a flag specifying whether or not a legend is required. + * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A pie chart. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java 2007-07-10 14:28:24 UTC (rev 114) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java 2007-07-10 14:37:03 UTC (rev 115) @@ -41,6 +41,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 03-May-2006 : Modified DEFAULT_SECTION_LABEL_FORMAT (DG); * 10-Jan-2007 : Include attributedLabels in equals() test (DG); + * 10-Jul-2007 : Added constructors with locale parameter (DG); * */ @@ -52,6 +53,7 @@ import java.io.Serializable; import java.text.AttributedString; import java.text.NumberFormat; +import java.util.Locale; import org.jfree.data.general.PieDataset; import org.jfree.util.ObjectList; @@ -66,8 +68,8 @@ * <code>apple = 120 (5%)</code>. */ public class StandardPieSectionLabelGenerator - extends AbstractPieItemLabelGenerator - implements PieSectionLabelGenerator, Cloneable, Serializable { + extends AbstractPieItemLabelGenerator + implements PieSectionLabelGenerator, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 3064190563760203668L; @@ -91,6 +93,17 @@ } /** + * Creates a new instance for the specified locale. + * + * @param locale the local (<code>null</code> not permitted). + * + * @since 1.0.7 + */ + public StandardPieSectionLabelGenerator(Locale locale) { + this(DEFAULT_SECTION_LABEL_FORMAT, locale); + } + + /** * Creates a new section label generator using the specified label format * string, and platform default number and percentage formatters. * @@ -102,6 +115,19 @@ } /** + * Creates a new instance for the specified locale. + * + * @param labelFormat the label format (<code>null</code> not permitted). + * @param locale the local (<code>null</code> not permitted). + * + * @since 1.0.7 + */ + public StandardPieSectionLabelGenerator(String labelFormat, Locale locale) { + this(labelFormat, NumberFormat.getNumberInstance(locale), + NumberFormat.getPercentInstance(locale)); + } + + /** * Creates an item label generator using the specified number formatters. * * @param labelFormat the label format string (<code>null</code> not @@ -112,12 +138,9 @@ * (<code>null</code> not permitted). */ public StandardPieSectionLabelGenerator(String labelFormat, - NumberFormat numberFormat, - NumberFormat percentFormat) { - + NumberFormat numberFormat, NumberFormat percentFormat) { super(labelFormat, numberFormat, percentFormat); this.attributedLabels = new ObjectList(); - } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java 2007-07-10 14:28:24 UTC (rev 114) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java 2007-07-10 14:37:03 UTC (rev 115) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------------- * StandardPieToolTipGenerator.java * -------------------------------- - * (C) Copyright 2001-2006, by Object Refinery Limited. + * (C) Copyright 2001-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Richard Atkinson; @@ -53,6 +53,7 @@ * 25-Nov-2004 : Moved some code into abstract super class (DG); * 29-Jul-2005 : Removed implementation of PieSectionLabelGenerator * interface (DG); + * 10-Jul-2007 : Added constructors with locale argument (DG); * */ @@ -60,6 +61,7 @@ import java.io.Serializable; import java.text.NumberFormat; +import java.util.Locale; import org.jfree.data.general.PieDataset; import org.jfree.util.PublicCloneable; @@ -85,28 +87,55 @@ /** The default tooltip format. */ public static final String DEFAULT_TOOLTIP_FORMAT = "{0}: ({1}, {2})"; - /** The default section label format. */ + /** + * The default section label format. + * + * @deprecated As of 1.0.7, use {@link #DEFAULT_TOOLTIP_FORMAT} instead. + */ public static final String DEFAULT_SECTION_LABEL_FORMAT = "{0} = {1}"; /** * Creates an item label generator using default number formatters. */ public StandardPieToolTipGenerator() { - this(DEFAULT_SECTION_LABEL_FORMAT, NumberFormat.getNumberInstance(), - NumberFormat.getPercentInstance()); + this(DEFAULT_TOOLTIP_FORMAT); } /** - * Creates an item label generator. + * Creates a pie tool tip generator for the specified locale, using the + * default format string. * - * @param labelFormat the label format. + * @param locale the locale (<code>null</code> not permitted). + * + * @since 1.0.7 */ + public StandardPieToolTipGenerator(Locale locale) { + this(DEFAULT_TOOLTIP_FORMAT, locale); + } + + /** + * Creates a pie tool tip generator for the default locale. + * + * @param labelFormat the label format (<code>null</code> not permitted). + */ public StandardPieToolTipGenerator(String labelFormat) { - this(labelFormat, NumberFormat.getNumberInstance(), - NumberFormat.getPercentInstance()); + this(labelFormat, Locale.getDefault()); } /** + * Creates a pie tool tip generator for the specified locale. + * + * @param labelFormat the label format (<code>null</code> not permitted). + * @param locale the locale (<code>null</code> not permitted). + * + * @since 1.0.7 + */ + public StandardPieToolTipGenerator(String labelFormat, Locale locale) { + this(labelFormat, NumberFormat.getNumberInstance(locale), + NumberFormat.getPercentInstance(locale)); + } + + /** * Creates an item label generator using the specified number formatters. * * @param labelFormat the label format string (<code>null</code> not This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-11 10:09:38
|
Revision: 117 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=117&view=rev Author: mungady Date: 2007-07-11 03:09:33 -0700 (Wed, 11 Jul 2007) Log Message: ----------- 2007-07-11 David Gilbert <dav...@ob...> * tests/org/jfree/data/time/junit/DayTests.java (testGetFirstMillisecond): Set/restore time zone, (testGetFirstMillisecondWithCalendar): Set time zone, (testGetLastMillisecond): Set/restore time zone, (testGetLastMillisecondWithCalendar): Set time zone, * tests/org/jfree/data/time/junit/HourTests.java: Likewise, * tests/org/jfree/data/time/junit/MillisecondTests.java: Likewise, * tests/org/jfree/data/time/junit/MinuteTests.java: (testGetFirstMillisecond): Set/restore time zone, (testGetFirstMillisecondWithCalendar): Set time zone, (testGetLastMillisecond): Set/restore time zone, (testGetLastMillisecondWithCalendar): Set time zone, (testGetStart): Set/restore time zone, (testGetEnd): Likewise, * tests/org/jfree/data/time/junit/MonthTests.java (testGetFirstMillisecond): Set/restore time zone, (testGetFirstMillisecondWithCalendar): Set time zone, (testGetLastMillisecond): Set/restore time zone, (testGetLastMillisecondWithCalendar): Set time zone, * tests/org/jfree/data/time/junit/QuarterTests.java: Likewise, * tests/org/jfree/data/time/junit/SecondTests.java: Likewise, * tests/org/jfree/data/time/junit/WeekTests.java: Likewise, * tests/org/jfree/data/time/junit/YearTests.java: Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DayTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/HourTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MillisecondTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MinuteTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MonthTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/QuarterTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/SecondTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/YearTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-11 10:09:33 UTC (rev 117) @@ -1,3 +1,29 @@ +2007-07-11 David Gilbert <dav...@ob...> + + * tests/org/jfree/data/time/junit/DayTests.java + (testGetFirstMillisecond): Set/restore time zone, + (testGetFirstMillisecondWithCalendar): Set time zone, + (testGetLastMillisecond): Set/restore time zone, + (testGetLastMillisecondWithCalendar): Set time zone, + * tests/org/jfree/data/time/junit/HourTests.java: Likewise, + * tests/org/jfree/data/time/junit/MillisecondTests.java: Likewise, + * tests/org/jfree/data/time/junit/MinuteTests.java: + (testGetFirstMillisecond): Set/restore time zone, + (testGetFirstMillisecondWithCalendar): Set time zone, + (testGetLastMillisecond): Set/restore time zone, + (testGetLastMillisecondWithCalendar): Set time zone, + (testGetStart): Set/restore time zone, + (testGetEnd): Likewise, + * tests/org/jfree/data/time/junit/MonthTests.java + (testGetFirstMillisecond): Set/restore time zone, + (testGetFirstMillisecondWithCalendar): Set time zone, + (testGetLastMillisecond): Set/restore time zone, + (testGetLastMillisecondWithCalendar): Set time zone, + * tests/org/jfree/data/time/junit/QuarterTests.java: Likewise, + * tests/org/jfree/data/time/junit/SecondTests.java: Likewise, + * tests/org/jfree/data/time/junit/WeekTests.java: Likewise, + * tests/org/jfree/data/time/junit/YearTests.java: Likewise. + 2007-07-10 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartFactory.java Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DayTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DayTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DayTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -45,6 +45,7 @@ * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 03-Oct-2006 : Added testGetSerialIndex() (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -56,6 +57,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -294,9 +296,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 3, 1970); assertEquals(5094000000L, d.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -324,6 +329,7 @@ public void testGetFirstMillisecondWithCalendar() { Day d = new Day(1, 12, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1007164800000L, d.getFirstMillisecond(calendar)); // try null calendar @@ -343,9 +349,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 1, 1970); assertEquals(82799999L, d.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -371,8 +380,10 @@ * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { + Day d = new Day(4, 5, 2001); - GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + Calendar calendar = Calendar.getInstance( + TimeZone.getTimeZone("Europe/London"), Locale.UK); assertEquals(989017199999L, d.getLastMillisecond(calendar)); // try null calendar Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/HourTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/HourTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/HourTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------- * HourTests.java * -------------- - * (C) Copyright 2002-2006 by Object Refinery Limited. + * (C) Copyright 2002-2007 by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -42,6 +42,7 @@ * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added new tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -263,9 +264,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(15, 1, 4, 2006); assertEquals(1143900000000L, h.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -293,7 +297,8 @@ public void testGetFirstMillisecondWithCalendar() { Hour h = new Hour(2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(955760400000L, h.getFirstMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(955764000000L, h.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; @@ -312,9 +317,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(1, 1, 1, 1970); assertEquals(3599999L, h.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -342,7 +350,8 @@ public void testGetLastMillisecondWithCalendar() { Hour h = new Hour(21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(987886799999L, h.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(987890399999L, h.getLastMillisecond(calendar)); // try null calendar boolean pass = false; Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MillisecondTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MillisecondTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MillisecondTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -42,6 +42,7 @@ * 29-Apr-2004 : Added test for getMiddleMillisecond() method (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added some tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -232,9 +233,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(500, 15, 43, 15, 1, 4, 2006); assertEquals(1143902595500L, m.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -262,7 +266,8 @@ public void testGetFirstMillisecondWithCalendar() { Millisecond m = new Millisecond(500, 55, 40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(955762855500L, m.getFirstMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(955766455500L, m.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; @@ -281,9 +286,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(750, 1, 1, 1, 1, 1, 1970); assertEquals(61750L, m.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -311,7 +319,8 @@ public void testGetLastMillisecondWithCalendar() { Millisecond m = new Millisecond(250, 50, 45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(987885950250L, m.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(987889550250L, m.getLastMillisecond(calendar)); // try null calendar boolean pass = false; Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MinuteTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MinuteTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MinuteTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------- * MinuteTests.java * ---------------- - * (C) Copyright 2002-2006 by Object Refinery Limited. + * (C) Copyright 2002-2007 by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -43,6 +43,7 @@ * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added new tests (DG); * 11-Dec-2006 : Added test1611872() (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -213,9 +214,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Minute m = new Minute(43, 15, 1, 4, 2006); assertEquals(1143902580000L, m.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -243,7 +247,8 @@ public void testGetFirstMillisecondWithCalendar() { Minute m = new Minute(40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(955762800000L, m.getFirstMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(955766400000L, m.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; @@ -262,9 +267,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Minute m = new Minute(1, 1, 1, 1, 1970); assertEquals(119999L, m.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -292,7 +300,8 @@ public void testGetLastMillisecondWithCalendar() { Minute m = new Minute(45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(987885959999L, m.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(987889559999L, m.getLastMillisecond(calendar)); // try null calendar boolean pass = false; @@ -336,12 +345,15 @@ public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); - Locale.setDefault(saved); + Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -350,12 +362,15 @@ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59); cal.set(Calendar.MILLISECOND, 999); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); - Locale.setDefault(saved); + Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MonthTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MonthTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/MonthTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -45,6 +45,7 @@ * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added non-clonability test (DG); * 05-Oct-2006 : Added some new tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -299,9 +300,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(5094000000L, m.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -329,6 +333,7 @@ public void testGetFirstMillisecondWithCalendar() { Month m = new Month(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, m.getFirstMillisecond(calendar)); // try null calendar @@ -348,9 +353,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(7772399999L, m.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -378,7 +386,8 @@ public void testGetLastMillisecondWithCalendar() { Month m = new Month(3, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(986079599999L, m.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(986083199999L, m.getLastMillisecond(calendar)); // try null calendar boolean pass = false; Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/QuarterTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/QuarterTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/QuarterTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -41,6 +41,7 @@ * 13-Mar-2003 : Added serialization test (DG); * 11-Jan-2005 : Added check for non-clonability (DG); * 05-Oct-2006 : Added some new tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -319,9 +320,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(15634800000L, q.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -349,6 +353,7 @@ public void testGetFirstMillisecondWithCalendar() { Quarter q = new Quarter(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, q.getFirstMillisecond(calendar)); // try null calendar @@ -368,9 +373,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(23583599999L, q.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -398,7 +406,8 @@ public void testGetLastMillisecondWithCalendar() { Quarter q = new Quarter(3, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(1001890799999L, q.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(1001894399999L, q.getLastMillisecond(calendar)); // try null calendar boolean pass = false; Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/SecondTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/SecondTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/SecondTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------- * SecondTests.java * ---------------- - * (C) Copyright 2002-2006, by Object Refinery Limited. + * (C) Copyright 2002-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -41,6 +41,7 @@ * 13-Oct-2003 : Added serialization test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 06-Oct-2006 : Added some new tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -213,9 +214,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Second s = new Second(15, 43, 15, 1, 4, 2006); assertEquals(1143902595000L, s.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -243,7 +247,8 @@ public void testGetFirstMillisecondWithCalendar() { Second s = new Second(55, 40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(955762855000L, s.getFirstMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(955766455000L, s.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; @@ -262,9 +267,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Second s = new Second(1, 1, 1, 1, 1, 1970); assertEquals(61999L, s.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -292,7 +300,8 @@ public void testGetLastMillisecondWithCalendar() { Second s = new Second(50, 45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); - assertEquals(987885950999L, s.getLastMillisecond(calendar)); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); + assertEquals(987889550999L, s.getLastMillisecond(calendar)); // try null calendar boolean pass = false; Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------- * WeekTests.java * -------------- - * (C) Copyright 2002-2006, by Object Refinery Limited. + * (C) Copyright 2002-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -43,6 +43,7 @@ * 21-Oct-2003 : Added hashCode test (DG); * 06-Apr-2006 : Added testBug1448828() method (DG); * 01-Jun-2006 : Added testBug1498805() method (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -312,9 +313,12 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Week w = new Week(3, 1970); assertEquals(946800000L, w.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -342,6 +346,7 @@ public void testGetFirstMillisecondWithCalendar() { Week w = new Week(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, w.getFirstMillisecond(calendar)); // try null calendar @@ -361,9 +366,12 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Week w = new Week(31, 1970); assertEquals(18485999999L, w.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -391,6 +399,7 @@ public void testGetLastMillisecondWithCalendar() { Week w = new Week(52, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1009756799999L, w.getLastMillisecond(calendar)); // try null calendar Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/YearTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/YearTests.java 2007-07-10 14:53:19 UTC (rev 116) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/YearTests.java 2007-07-11 10:09:33 UTC (rev 117) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------- * YearTests.java * -------------- - * (C) Copyright 2001-2006, by Object Refinery Limited. + * (C) Copyright 2001-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -43,6 +43,7 @@ * 13-Mar-2003 : Added serialization test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added some new tests (DG); + * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ @@ -281,10 +282,13 @@ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Year y = new Year(1970); // TODO: Check this result... assertEquals(-3600000L, y.getFirstMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -312,6 +316,7 @@ public void testGetFirstMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, y.getFirstMillisecond(calendar)); // try null calendar @@ -331,10 +336,13 @@ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Year y = new Year(1970); // TODO: Check this result... assertEquals(31532399999L, y.getLastMillisecond()); Locale.setDefault(saved); + TimeZone.setDefault(savedZone); } /** @@ -362,6 +370,7 @@ public void testGetLastMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); + calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1009843199999L, y.getLastMillisecond(calendar)); // try null calendar This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-11 10:27:59
|
Revision: 119 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=119&view=rev Author: mungady Date: 2007-07-11 03:27:57 -0700 (Wed, 11 Jul 2007) Log Message: ----------- 2007-07-11 David Gilbert <dav...@ob...> * source/org/jfree/chart/axis/SegmentedTimeline.java (FIRST_MONDAY_AFTER_1900): Deprecated, (NO_DST_TIME_ZONE): Likewise, (DEFAULT_TIME_ZONE): Likewise, (workingCalendarNoDST): Initialise in constructor, (SegmentedTimeline): Initialise workingCalendarNoDST, (firstMondayAfter1900): New method, (newMondayThroughFridayTimeline): Use new method for first monday, (newFifteenMinuteTimeline): Likewise, * tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java: Save and restore time zone in all tests. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SegmentedTimeline.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-11 10:23:41 UTC (rev 118) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-11 10:27:57 UTC (rev 119) @@ -1,5 +1,19 @@ 2007-07-11 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/SegmentedTimeline.java + (FIRST_MONDAY_AFTER_1900): Deprecated, + (NO_DST_TIME_ZONE): Likewise, + (DEFAULT_TIME_ZONE): Likewise, + (workingCalendarNoDST): Initialise in constructor, + (SegmentedTimeline): Initialise workingCalendarNoDST, + (firstMondayAfter1900): New method, + (newMondayThroughFridayTimeline): Use new method for first monday, + (newFifteenMinuteTimeline): Likewise, + * tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java: + Save and restore time zone in all tests. + +2007-07-11 David Gilbert <dav...@ob...> + * tests/org/jfree/data/time/junit/DayTests.java (testGetFirstMillisecond): Set/restore time zone, (testGetFirstMillisecondWithCalendar): Set time zone, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SegmentedTimeline.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SegmentedTimeline.java 2007-07-11 10:23:41 UTC (rev 118) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SegmentedTimeline.java 2007-07-11 10:27:57 UTC (rev 119) @@ -45,6 +45,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 14-Nov-2006 : Fix in toTimelineValue(long) to avoid stack overflow (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); + * 11-Jul-2007 : Fixed time zone bugs (DG); * */ @@ -58,6 +59,7 @@ import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.SimpleTimeZone; import java.util.TimeZone; @@ -193,6 +195,9 @@ * 1/1/1970. This should be used when creating a SegmentedTimeline for * Monday through Friday. See static block below for calculation of this * constant. + * + * @deprecated As of 1.0.7. This field doesn't take into account changes + * to the default time zone. */ public static long FIRST_MONDAY_AFTER_1900; @@ -200,6 +205,10 @@ * Utility TimeZone object that has no DST and an offset equal to the * default TimeZone. This allows easy arithmetic between days as each one * will have equal size. + * + * @deprecated As of 1.0.7. This field is initialised based on the + * default time zone, and doesn't take into account subsequent + * changes to the default. */ public static TimeZone NO_DST_TIME_ZONE; @@ -208,6 +217,9 @@ * getTime() below where we make use of certain transformations between * times in the default time zone and the no-dst time zone used for our * calculations. + * + * @deprecated As of 1.0.7. When the default time zone is required, + * just call <code>TimeZone.getDefault()</code>. */ public static TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault(); @@ -215,8 +227,7 @@ * This will be a utility calendar that has no DST but is shifted relative * to the default time zone's offset. */ - private Calendar workingCalendarNoDST - = new GregorianCalendar(NO_DST_TIME_ZONE); + private Calendar workingCalendarNoDST; /** * This will be a utility calendar that used the default time zone. @@ -327,10 +338,38 @@ this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize; this.segmentsGroupSize = this.segmentsIncludedSize + this.segmentsExcludedSize; - + int offset = TimeZone.getDefault().getRawOffset(); + TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset); + this.workingCalendarNoDST = new GregorianCalendar(z, + Locale.getDefault()); } /** + * Returns the milliseconds for midnight of the first Monday after + * 1-Jan-1900, ignoring daylight savings. + * + * @return The milliseconds. + * + * @since 1.0.7 + */ + public static long firstMondayAfter1900() { + int offset = TimeZone.getDefault().getRawOffset(); + TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset); + + // calculate midnight of first monday after 1/1/1900 relative to + // current locale + Calendar cal = new GregorianCalendar(z); + cal.set(1900, 0, 1, 0, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { + cal.add(Calendar.DATE, 1); + } + //return cal.getTimeInMillis(); + // preceding code won't work with JDK 1.3 + return cal.getTime().getTime(); + } + + /** * Factory method to create a Monday through Friday SegmentedTimeline. * <P> * The <code>startTime</code> of the resulting timeline will be midnight @@ -341,7 +380,7 @@ public static SegmentedTimeline newMondayThroughFridayTimeline() { SegmentedTimeline timeline = new SegmentedTimeline(DAY_SEGMENT_SIZE, 5, 2); - timeline.setStartTime(FIRST_MONDAY_AFTER_1900); + timeline.setStartTime(firstMondayAfter1900()); return timeline; } @@ -363,11 +402,10 @@ * @return A fully initialized SegmentedTimeline. */ public static SegmentedTimeline newFifteenMinuteTimeline() { - SegmentedTimeline timeline - = new SegmentedTimeline(FIFTEEN_MINUTE_SEGMENT_SIZE, 28, 68); - timeline.setStartTime( - FIRST_MONDAY_AFTER_1900 + 36 * timeline.getSegmentSize() - ); + SegmentedTimeline timeline = new SegmentedTimeline( + FIFTEEN_MINUTE_SEGMENT_SIZE, 28, 68); + timeline.setStartTime(firstMondayAfter1900() + 36 + * timeline.getSegmentSize()); timeline.setBaseTimeline(newMondayThroughFridayTimeline()); return timeline; } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java 2007-07-11 10:23:41 UTC (rev 118) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests2.java 2007-07-11 10:27:57 UTC (rev 119) @@ -46,6 +46,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import junit.framework.TestCase; @@ -68,7 +69,10 @@ * back again correctly. This is prior to Daylight Saving. */ public void test1() { - + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); + Locale savedLocale = Locale.getDefault(); + Locale.setDefault(Locale.UK); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -82,14 +86,13 @@ SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); - Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); - assertTrue("test1", value == (900000 * 34) && date.getTime() == reverted.getTime()); - + TimeZone.setDefault(savedZone); + Locale.setDefault(savedLocale); } /** @@ -97,6 +100,8 @@ * and back again correctly. This is prior to Daylight Saving. */ public void test2() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -118,6 +123,7 @@ "test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** @@ -125,6 +131,8 @@ * and back again correctly. This is prior to Daylight Saving. */ public void test3() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -146,6 +154,7 @@ "test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** @@ -154,6 +163,8 @@ * Saving. */ public void test4() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -174,6 +185,7 @@ "test4", value == (900000 * 34 + 900000 * 2 + 1) && date.getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** @@ -183,6 +195,8 @@ * Daylight Saving. */ public void test5() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -212,6 +226,7 @@ "test5", value == (900000 * 34) && expectedReverted.getTime().getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** @@ -221,6 +236,8 @@ * Monday 29 March 2004. This is during daylight saving. */ public void test6() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -251,6 +268,7 @@ "test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** @@ -258,6 +276,8 @@ * back again correctly. This is during Daylight Saving. */ public void test7() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -289,12 +309,15 @@ "test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** * Test 8. */ public void test8() { + TimeZone savedZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); @@ -337,6 +360,7 @@ "test8", value == (900000 * 34 * 2 + 900000 * (4 - 1)) && expectedReverted.getTime().getTime() == reverted.getTime() ); + TimeZone.setDefault(savedZone); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-12 09:46:07
|
Revision: 126 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=126&view=rev Author: mungady Date: 2007-07-12 02:14:32 -0700 (Thu, 12 Jul 2007) Log Message: ----------- 2007-07-11 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/axis/LogAxis.java (setSmallestValue): Added event notification, (zoomRange): New method override. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-12 08:41:36 UTC (rev 125) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-12 09:14:32 UTC (rev 126) @@ -1,5 +1,11 @@ 2007-07-11 David Gilbert <dav...@ob...> + * experimental/org/jfree/experimental/chart/axis/LogAxis.java + (setSmallestValue): Added event notification, + (zoomRange): New method override. + +2007-07-11 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/SegmentedTimeline.java (FIRST_MONDAY_AFTER_1900): Deprecated, (NO_DST_TIME_ZONE): Likewise, Modified: branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java 2007-07-12 08:41:36 UTC (rev 125) +++ branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java 2007-07-12 09:14:32 UTC (rev 126) @@ -38,7 +38,8 @@ * ------- * 24-Aug-2006 : Version 1 (DG); * 22-Mar-2007 : Use defaultAutoArrange attribute (DG); - * + * 12-Jul-2007 : Fixed zooming bug (DG); + * */ package org.jfree.experimental.chart.axis; @@ -121,6 +122,8 @@ * Returns the base for the logarithm calculation. * * @return The base for the logarithm calculation. + * + * @see #setBase(double) */ public double getBase() { return this.base; @@ -131,6 +134,8 @@ * {@link AxisChangeEvent} to all registered listeners. * * @param base the base value (must be > 1.0). + * + * @see #getBase() */ public void setBase(double base) { if (base <= 1.0) { @@ -145,27 +150,35 @@ * Returns the smallest value represented by the axis. * * @return The smallest value represented by the axis. + * + * @see #setSmallestValue(double) */ public double getSmallestValue() { return this.smallestValue; } /** - * Sets the smallest value represented by the axis. + * Sets the smallest value represented by the axis and sends an + * {@link AxisChangeEvent} to all registered listeners. * * @param value the value. + * + * @see #getSmallestValue() */ public void setSmallestValue(double value) { if (value <= 0.0) { throw new IllegalArgumentException("Requires 'value' > 0.0."); } this.smallestValue = value; + notifyListeners(new AxisChangeEvent(this)); } /** * Returns the current tick unit. * * @return The current tick unit. + * + * @see #setTickUnit(NumberTickUnit) */ public NumberTickUnit getTickUnit() { return this.tickUnit; @@ -179,6 +192,8 @@ * method). * * @param unit the new tick unit (<code>null</code> not permitted). + * + * @see #getTickUnit() */ public void setTickUnit(NumberTickUnit unit) { // defer argument checking... @@ -195,6 +210,8 @@ * @param unit the new tick unit (<code>null</code> not permitted). * @param notify notify listeners? * @param turnOffAutoSelect turn off the auto-tick selection? + * + * @see #getTickUnit() */ public void setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect) { @@ -217,6 +234,8 @@ * be used to format the numbers on the axis. * * @return The number formatter (possibly <code>null</code>). + * + * @see #setNumberFormatOverride(NumberFormat) */ public NumberFormat getNumberFormatOverride() { return this.numberFormatOverride; @@ -227,6 +246,8 @@ * used to format the numbers on the axis. * * @param formatter the number formatter (<code>null</code> permitted). + * + * @see #getNumberFormatOverride() */ public void setNumberFormatOverride(NumberFormat formatter) { this.numberFormatOverride = formatter; @@ -237,15 +258,20 @@ * Returns the number of minor tick marks to display. * * @return The number of minor tick marks to display. + * + * @see #setMinorTickCount(int) */ public int getMinorTickCount() { return this.minorTickCount; } /** - * Sets the number of minor tick marks to display. + * Sets the number of minor tick marks to display, and sends an + * {@link AxisChangeEvent} to all registered listeners. * * @param count the count. + * + * @see #getMinorTickCount() */ public void setMinorTickCount(int count) { if (count <= 0) { @@ -262,6 +288,7 @@ * * @return The log of the given value. * + * @see #calculateValue(double) * @see #getBase() */ public double calculateLog(double value) { @@ -274,6 +301,9 @@ * @param log the log value (must be > 0.0). * * @return The value with the given log. + * + * @see #calculateLog(double) + * @see #getBase() */ public double calculateValue(double log) { return Math.pow(this.base, log); @@ -545,6 +575,33 @@ } return ticks; } + + /** + * Zooms in on the current range. + * + * @param lowerPercent the new lower bound. + * @param upperPercent the new upper bound. + */ + public void zoomRange(double lowerPercent, double upperPercent) { + Range range = getRange(); + double start = range.getLowerBound(); + double end = range.getUpperBound(); + double log1 = calculateLog(start); + double log2 = calculateLog(end); + double length = log2 - log1; + Range adjusted = null; + if (isInverted()) { + double logA = log1 + length * (1 - upperPercent); + double logB = log1 + length * (1 - lowerPercent); + adjusted = new Range(calculateValue(logA), calculateValue(logB)); + } + else { + double logA = log1 + length * lowerPercent; + double logB = log1 + length * upperPercent; + adjusted = new Range(calculateValue(logA), calculateValue(logB)); + } + setRange(adjusted); + } /** * Creates a tick label for the specified value. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-18 08:56:23
|
Revision: 130 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=130&view=rev Author: mungady Date: 2007-07-18 01:56:20 -0700 (Wed, 18 Jul 2007) Log Message: ----------- 2007-07-18 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/CombinedRangeXYPlot.java (remove): Actually remove the subplot. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CombinedRangeXYPlot.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-16 14:50:21 UTC (rev 129) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-18 08:56:20 UTC (rev 130) @@ -1,3 +1,8 @@ +2007-07-18 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/CombinedRangeXYPlot.java + (remove): Actually remove the subplot. + 2007-07-11 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/axis/LogAxis.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CombinedRangeXYPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CombinedRangeXYPlot.java 2007-07-16 14:50:21 UTC (rev 129) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CombinedRangeXYPlot.java 2007-07-18 08:56:20 UTC (rev 130) @@ -86,7 +86,8 @@ * 06-Feb-2007 : Fixed bug 1606205, draw shared axis after subplots (DG); * 23-Mar-2007 : Reverted previous patch (DG); * 17-Apr-2007 : Added null argument checks to findSubplot() (DG); - * + * 18-Jul-2007 : Fixed bug in removeSubplot (DG); + * */ package org.jfree.chart.plot; @@ -253,6 +254,7 @@ i++; } if (position != -1) { + this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); this.totalWeight -= subplot.getWeight(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-18 14:01:23
|
Revision: 135 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=135&view=rev Author: mungady Date: 2007-07-18 07:01:19 -0700 (Wed, 18 Jul 2007) Log Message: ----------- 2007-07-18 David Gilbert <dav...@ob...> * source/org/jfree/chart/demo/PieChartDemo1.java (createChart): Modified settings, * source/org/jfree/chart/plot/PiePlot.java (DEFAULT_INTERIOR_GAP): Modified default, (DEFAULT_LABEL_SHADOW_PAINT): Likewise, (simpleLabels): New field, (labelPadding): Likewise, (simpleLabelOffset): Likewise, (PiePlot(PieDataset)): Initialise new fields, (getLabelPadding): New method, (setLabelPadding): Likewise, (getSimpleLabels): Likewise, (setSimpleLabels): Likewise, (getSimpleLabelOffset): Likewise, (setSimpleLabelOffset): Likewise, (drawPie): Added simple label handling, (drawSimpleLabels): New method, (drawLabels): Reformatting, (drawLeftLabels): Set label padding, (drawRightLabels): Likewise, (equals): Updated for new fields, * source/org/jfree/chart/plot/PiePlot3D.java (draw): Updated for simple labels. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/demo/PieChartDemo1.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-18 13:47:24 UTC (rev 134) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-18 14:01:19 UTC (rev 135) @@ -1,3 +1,29 @@ +2007-07-18 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/demo/PieChartDemo1.java + (createChart): Modified settings, + * source/org/jfree/chart/plot/PiePlot.java + (DEFAULT_INTERIOR_GAP): Modified default, + (DEFAULT_LABEL_SHADOW_PAINT): Likewise, + (simpleLabels): New field, + (labelPadding): Likewise, + (simpleLabelOffset): Likewise, + (PiePlot(PieDataset)): Initialise new fields, + (getLabelPadding): New method, + (setLabelPadding): Likewise, + (getSimpleLabels): Likewise, + (setSimpleLabels): Likewise, + (getSimpleLabelOffset): Likewise, + (setSimpleLabelOffset): Likewise, + (drawPie): Added simple label handling, + (drawSimpleLabels): New method, + (drawLabels): Reformatting, + (drawLeftLabels): Set label padding, + (drawRightLabels): Likewise, + (equals): Updated for new fields, + * source/org/jfree/chart/plot/PiePlot3D.java + (draw): Updated for simple labels. + 2007-07-18 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/CombinedRangeXYPlot.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/demo/PieChartDemo1.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/demo/PieChartDemo1.java 2007-07-18 13:47:24 UTC (rev 134) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/demo/PieChartDemo1.java 2007-07-18 14:01:19 UTC (rev 135) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------ * PieChartDemo1.java * ------------------ - * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): ; @@ -107,10 +107,9 @@ PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); - plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); + plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); plot.setNoDataMessage("No data available"); - plot.setCircular(false); - plot.setLabelGap(0.02); + plot.setSimpleLabels(true); return chart; } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot.java 2007-07-18 13:47:24 UTC (rev 134) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot.java 2007-07-18 14:01:19 UTC (rev 135) @@ -146,7 +146,8 @@ * 19-Apr-2007 : Deprecated override settings (DG); * 18-May-2007 : Set dataset for LegendItem (DG); * 14-Jun-2007 : Added label distributor attribute (DG); - * + * 18-Jul-2007 : Added simple label option (DG); + * */ package org.jfree.chart.plot; @@ -156,6 +157,7 @@ import java.awt.Color; import java.awt.Composite; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; @@ -197,11 +199,13 @@ import org.jfree.text.TextUtilities; import org.jfree.ui.RectangleAnchor; import org.jfree.ui.RectangleInsets; +import org.jfree.ui.TextAnchor; import org.jfree.util.ObjectUtilities; import org.jfree.util.PaintUtilities; import org.jfree.util.PublicCloneable; import org.jfree.util.Rotation; import org.jfree.util.ShapeUtilities; +import org.jfree.util.UnitType; /** * A plot that displays data in the form of a pie chart, using data from any @@ -225,7 +229,7 @@ private static final long serialVersionUID = -795612466005590431L; /** The default interior gap. */ - public static final double DEFAULT_INTERIOR_GAP = 0.25; + public static final double DEFAULT_INTERIOR_GAP = 0.1; /** The maximum interior gap (currently 40%). */ public static final double MAX_INTERIOR_GAP = 0.40; @@ -252,7 +256,8 @@ 0.5f); /** The default section label shadow paint. */ - public static final Paint DEFAULT_LABEL_SHADOW_PAINT = Color.lightGray; + public static final Paint DEFAULT_LABEL_SHADOW_PAINT = new Color(151, 151, + 151, 128); /** The default minimum arc angle to draw. */ public static final double DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW = 0.00001; @@ -350,7 +355,10 @@ /** The color used to draw the section labels. */ private transient Paint labelPaint; - /** The color used to draw the background of the section labels. */ + /** + * The color used to draw the background of the section labels. If this + * is <code>null</code>, the background is not filled. + */ private transient Paint labelBackgroundPaint; /** @@ -371,6 +379,28 @@ */ private transient Paint labelShadowPaint; + /** + * A flag that controls whether simple or extended labels are used. + * + * @since 1.0.7 + */ + private boolean simpleLabels = true; + + /** + * The padding between the labels and the label outlines. This is not + * allowed to be <code>null</code>. + * + * @since 1.0.7 + */ + private RectangleInsets labelPadding; + + /** + * The simple label offset. + * + * @since 1.0.7 + */ + private RectangleInsets simpleLabelOffset; + /** The maximum label width as a percentage of the plot width. */ private double maximumLabelWidth = 0.20; @@ -462,6 +492,7 @@ */ public PiePlot(PieDataset dataset) { super(); + setBackgroundPaint(new Color(230, 230, 230)); this.dataset = dataset; if (dataset != null) { dataset.addChangeListener(this); @@ -473,7 +504,7 @@ this.startAngle = DEFAULT_START_ANGLE; this.direction = Rotation.CLOCKWISE; this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW; - + this.sectionPaint = null; this.sectionPaintMap = new PaintMap(); this.baseSectionPaint = Color.gray; @@ -499,6 +530,11 @@ this.labelLinksVisible = true; this.labelDistributor = new PieLabelDistributor(0); + this.simpleLabels = false; + this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18, + 0.18, 0.18, 0.18); + this.labelPadding = new RectangleInsets(2, 2, 2, 2); + this.toolTipGenerator = null; this.urlGenerator = null; this.legendLabelGenerator = new StandardPieSectionLabelGenerator(); @@ -652,13 +688,11 @@ */ public void setInteriorGap(double percent) { - // check arguments... if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) { throw new IllegalArgumentException( "Invalid 'percent' (" + percent + ") argument."); } - // make the change... if (this.interiorGap != percent) { this.interiorGap = percent; notifyListeners(new PlotChangeEvent(this)); @@ -1807,8 +1841,96 @@ this.labelShadowPaint = paint; notifyListeners(new PlotChangeEvent(this)); } + + /** + * Returns the label padding. + * + * @return The label padding (never <code>null</code>). + * + * @since 1.0.7 + * + * @see #setLabelPadding(RectangleInsets) + */ + public RectangleInsets getLabelPadding() { + return this.labelPadding; + } + + /** + * Sets the padding between each label and its outline and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param padding the padding (<code>null</code> not permitted). + * + * @since 1.0.7 + * + * @see #getLabelPadding() + */ + public void setLabelPadding(RectangleInsets padding) { + if (padding == null) { + throw new IllegalArgumentException("Null 'padding' argument."); + } + this.labelPadding = padding; + notifyListeners(new PlotChangeEvent(this)); + } /** + * Returns the flag that controls whether simple or extended labels are + * displayed on the plot. + * + * @return A boolean. + * + * @since 1.0.7 + */ + public boolean getSimpleLabels() { + return this.simpleLabels; + } + + /** + * Sets the flag that controls whether simple or extended labels are + * displayed on the plot, and sends a {@link PlotChangeEvent} to all + * registered listeners. + * + * @param simple the new flag value. + * + * @since 1.0.7 + */ + public void setSimpleLabels(boolean simple) { + this.simpleLabels = simple; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the offset used for the simple labels, if they are displayed. + * + * @return The offset (never <code>null</code>). + * + * @since 1.0.7 + * + * @see #setSimpleLabelOffset(RectangleInsets) + */ + public RectangleInsets getSimpleLabelOffset() { + return this.simpleLabelOffset; + } + + /** + * Sets the offset for the simple labels and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param offset the offset (<code>null</code> not permitted). + * + * @since 1.0.7 + * + * @see #getSimpleLabelOffset() + */ + public void setSimpleLabelOffset(RectangleInsets offset) { + if (offset == null) { + throw new IllegalArgumentException("Null 'offset' argument."); + } + this.simpleLabelOffset = offset; + notifyListeners(new PlotChangeEvent(this)); + } + + /** * Returns the object responsible for the vertical layout of the pie * section labels. * @@ -2116,7 +2238,7 @@ // adjust the plot area for interior spacing and labels... double labelWidth = 0.0; - if (this.labelGenerator != null) { + if (this.labelGenerator != null && !this.simpleLabels) { labelWidth = this.labelGap + this.maximumLabelWidth + this.labelLinkMargin; } @@ -2147,8 +2269,12 @@ // the explode area defines the max circle/ellipse for the exploded // pie sections. it is defined by shrinking the linkArea by the // linkMargin factor. - double hh = linkArea.getWidth() * this.labelLinkMargin; - double vv = linkArea.getHeight() * this.labelLinkMargin; + double lm = 0.0; + if (!this.simpleLabels) { + lm = this.labelLinkMargin; + } + double hh = linkArea.getWidth() * lm; + double vv = linkArea.getHeight() * lm; Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv); @@ -2171,6 +2297,7 @@ state.setPieCenterY(pieArea.getCenterY()); state.setPieWRadius(pieArea.getWidth() / 2.0); state.setPieHRadius(pieArea.getHeight() / 2.0); + // plot the data (unless the dataset is null)... if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) { @@ -2192,8 +2319,13 @@ } } } - - drawLabels(g2, keys, totalValue, plotArea, linkArea, state); + if (this.simpleLabels) { + drawSimpleLabels(g2, keys, totalValue, plotArea, linkArea, + state); + } + else { + drawLabels(g2, keys, totalValue, plotArea, linkArea, state); + } } else { @@ -2295,6 +2427,100 @@ } /** + * Draws the pie section labels in the simple form. + * + * @param g2 the graphics device. + * @param keys the section keys. + * @param totalValue the total value for all sections in the pie. + * @param plotArea the plot area. + * @param pieArea the area containing the pie. + * @param state the plot state. + * + * @since 1.0.7 + */ + protected void drawSimpleLabels(Graphics2D g2, List keys, double totalValue, + Rectangle2D plotArea, Rectangle2D pieArea, PiePlotState state) { + + Composite originalComposite = g2.getComposite(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, + 1.0f)); + + RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, + 0.18, 0.18, 0.18, 0.18); + Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea); + double runningTotal = 0.0; + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); + boolean include = true; + double v = 0.0; + Number n = getDataset().getValue(key); + if (n == null) { + include = !getIgnoreNullValues(); + } + else { + v = n.doubleValue(); + include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0; + } + + if (include) { + runningTotal = runningTotal + v; + // work out the mid angle (0 - 90 and 270 - 360) = right, + // otherwise left + double mid = getStartAngle() + (getDirection().getFactor() + * ((runningTotal - v / 2.0) * 360) / totalValue); + + Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), + mid - getStartAngle(), Arc2D.OPEN); + int x = (int) arc.getEndPoint().getX(); + int y = (int) arc.getEndPoint().getY(); + + PieSectionLabelGenerator labelGenerator = getLabelGenerator(); + if (labelGenerator == null) { + continue; + } + String label = labelGenerator.generateSectionLabel( + this.dataset, key); + if (label == null) { + continue; + } + g2.setFont(this.labelFont); + FontMetrics fm = g2.getFontMetrics(); + Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm); + Rectangle2D out = this.labelPadding.createOutsetRectangle(bounds); + Shape bg = ShapeUtilities.createTranslatedShape(out, + x - bounds.getCenterX(), y - bounds.getCenterY()); + if (this.labelShadowPaint != null) { + Shape shadow = ShapeUtilities.createTranslatedShape(bg, + this.shadowXOffset, this.shadowYOffset); + g2.setPaint(this.labelShadowPaint); + g2.fill(shadow); + } + if (this.labelBackgroundPaint != null) { + g2.setPaint(this.labelBackgroundPaint); + g2.fill(bg); + } + if (this.labelOutlinePaint != null + && this.labelOutlineStroke != null) { + g2.setPaint(this.labelOutlinePaint); + g2.setStroke(this.labelOutlineStroke); + g2.draw(bg); + } + + g2.setPaint(this.labelPaint); + g2.setFont(this.labelFont); + TextUtilities.drawAlignedString(getLabelGenerator() + .generateSectionLabel(getDataset(), key), g2, x, y, + TextAnchor.CENTER); + + } + } + + g2.setComposite(originalComposite); + + } + + /** * Draws the labels for the pie sections. * * @param g2 the graphics device. @@ -2309,17 +2535,17 @@ PiePlotState state) { Composite originalComposite = g2.getComposite(); - g2.setComposite( - AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, + 1.0f)); // classify the keys according to which side the label will appear... DefaultKeyedValues leftKeys = new DefaultKeyedValues(); DefaultKeyedValues rightKeys = new DefaultKeyedValues(); - double runningTotal1 = 0.0; - Iterator iterator1 = keys.iterator(); - while (iterator1.hasNext()) { - Comparable key = (Comparable) iterator1.next(); + double runningTotal = 0.0; + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); boolean include = true; double v = 0.0; Number n = this.dataset.getValue(key); @@ -2332,11 +2558,11 @@ } if (include) { - runningTotal1 = runningTotal1 + v; + runningTotal = runningTotal + v; // work out the mid angle (0 - 90 and 270 - 360) = right, // otherwise left double mid = this.startAngle + (this.direction.getFactor() - * ((runningTotal1 - v / 2.0) * 360) / totalValue); + * ((runningTotal - v / 2.0) * 360) / totalValue); if (Math.cos(Math.toRadians(mid)) < 0.0) { leftKeys.addValue(key, new Double(mid)); } @@ -2347,8 +2573,8 @@ } g2.setFont(getLabelFont()); - float maxLabelWidth - = (float) (getMaximumLabelWidth() * plotArea.getWidth()); + float maxLabelWidth = (float) (getMaximumLabelWidth() + * plotArea.getWidth()); // draw the labels... if (this.labelGenerator != null) { @@ -2392,6 +2618,7 @@ labelBox.setOutlinePaint(this.labelOutlinePaint); labelBox.setOutlineStroke(this.labelOutlineStroke); labelBox.setShadowPaint(this.labelShadowPaint); + labelBox.setInteriorGap(this.labelPadding); double theta = Math.toRadians( leftKeys.getValue(i).doubleValue()); double baseY = state.getPieCenterY() - Math.sin(theta) @@ -2444,6 +2671,7 @@ labelBox.setOutlinePaint(this.labelOutlinePaint); labelBox.setOutlineStroke(this.labelOutlineStroke); labelBox.setShadowPaint(this.labelShadowPaint); + labelBox.setInteriorGap(this.labelPadding); double theta = Math.toRadians(keys.getValue(i).doubleValue()); double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius; @@ -2767,6 +2995,15 @@ that.labelShadowPaint)) { return false; } + if (this.simpleLabels != that.simpleLabels) { + return false; + } + if (!this.simpleLabelOffset.equals(that.simpleLabelOffset)) { + return false; + } + if (!this.labelPadding.equals(that.labelPadding)) { + return false; + } if (!(this.maximumLabelWidth == that.maximumLabelWidth)) { return false; } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java 2007-07-18 13:47:24 UTC (rev 134) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PiePlot3D.java 2007-07-18 14:01:19 UTC (rev 135) @@ -73,7 +73,8 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 27-Sep-2006 : Updated draw() method for new lookup methods (DG); * 22-Mar-2007 : Added equals() override (DG); - * + * 18-Jun-2007 : Added handling for simple label option (DG); + * */ package org.jfree.chart.plot; @@ -501,7 +502,14 @@ originalPlotArea.getX(), originalPlotArea.getY(), originalPlotArea.getWidth(), originalPlotArea.getHeight() - depth); - drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state); + if (getSimpleLabels()) { + drawSimpleLabels(g2, keys, totalValue, adjustedPlotArea, + linkArea, state); + } + else { + drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, + state); + } } g2.setClip(savedClip); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-25 10:16:56
|
Revision: 138 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=138&view=rev Author: mungady Date: 2007-07-25 03:16:42 -0700 (Wed, 25 Jul 2007) Log Message: ----------- 2007-07-25 David Gilbert <dav...@ob...> * source/org/jfree/chart/axis/SymbolAxis.java (DEFAULT_GRID_BAND_ALTERNATE_PAINT): New field, (gridBandAlternatePaint): New field, (SymbolAxis): Initialise new field, (getGridBandAlternatePaint): New method, (setGridBandAlternatePaint): Likewise, (equals): Test new field, (writeObject): Handle new field, (readObject): Likewise, * tests/org/jfree/chart/axis/junit/SymbolAxisTests.java (testEquals): Added check for new field. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SymbolAxis.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 09:37:14 UTC (rev 137) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 10:16:42 UTC (rev 138) @@ -1,3 +1,17 @@ +2007-07-25 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/axis/SymbolAxis.java + (DEFAULT_GRID_BAND_ALTERNATE_PAINT): New field, + (gridBandAlternatePaint): New field, + (SymbolAxis): Initialise new field, + (getGridBandAlternatePaint): New method, + (setGridBandAlternatePaint): Likewise, + (equals): Test new field, + (writeObject): Handle new field, + (readObject): Likewise, + * tests/org/jfree/chart/axis/junit/SymbolAxisTests.java + (testEquals): Added check for new field. + 2007-07-18 David Gilbert <dav...@ob...> * source/org/jfree/chart/demo/PieChartDemo1.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SymbolAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SymbolAxis.java 2007-07-25 09:37:14 UTC (rev 137) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/SymbolAxis.java 2007-07-25 10:16:42 UTC (rev 138) @@ -73,6 +73,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 28-Feb-2007 : Fixed bug 1669302 (tick label overlap) (DG); + * 25-Jul-2007 : Added new field for alternate grid band paint (DG); * */ @@ -118,15 +119,30 @@ public static final Paint DEFAULT_GRID_BAND_PAINT = new Color(232, 234, 232, 128); + /** + * The default paint for alternate grid bands. + * + * @since 1.0.7 + */ + public static final Paint DEFAULT_GRID_BAND_ALTERNATE_PAINT + = new Color(0, 0, 0, 0); // transparent + /** The list of symbols to display instead of the numeric values. */ private List symbols; + /** Flag that indicates whether or not grid bands are visible. */ + private boolean gridBandsVisible; + /** The paint used to color the grid bands (if the bands are visible). */ private transient Paint gridBandPaint; + + /** + * The paint used to fill the alternate grid bands. + * + * @since 1.0.7 + */ + private transient Paint gridBandAlternatePaint; - /** Flag that indicates whether or not grid bands are visible. */ - private boolean gridBandsVisible; - /** * Constructs a symbol axis, using default attribute values where * necessary. @@ -140,7 +156,7 @@ this.symbols = Arrays.asList(sv); this.gridBandsVisible = true; this.gridBandPaint = DEFAULT_GRID_BAND_PAINT; - + this.gridBandAlternatePaint = DEFAULT_GRID_BAND_ALTERNATE_PAINT; setAutoTickUnitSelection(false, false); setAutoRangeStickyZero(false); @@ -158,6 +174,34 @@ } /** + * Returns <code>true</code> if the grid bands are showing, and + * <code>false</code> otherwise. + * + * @return <code>true</code> if the grid bands are showing, and + * <code>false</code> otherwise. + * + * @see #setGridBandsVisible(boolean) + */ + public boolean isGridBandsVisible() { + return this.gridBandsVisible; + } + + /** + * Sets the visibility of the grid bands and notifies registered + * listeners that the axis has been modified. + * + * @param flag the new setting. + * + * @see #isGridBandsVisible() + */ + public void setGridBandsVisible(boolean flag) { + if (this.gridBandsVisible != flag) { + this.gridBandsVisible = flag; + notifyListeners(new AxisChangeEvent(this)); + } + } + + /** * Returns the paint used to color the grid bands. * * @return The grid band paint (never <code>null</code>). @@ -184,35 +228,40 @@ this.gridBandPaint = paint; notifyListeners(new AxisChangeEvent(this)); } - + /** - * Returns <code>true</code> if the grid bands are showing, and - * <code>false</code> otherwise. - * - * @return <code>true</code> if the grid bands are showing, and - * <code>false</code> otherwise. - * - * @see #setGridBandsVisible(boolean) + * Returns the paint used for alternate grid bands. + * + * @return The paint (never <code>null</code>). + * + * @see #setGridBandAlternatePaint(Paint) + * @see #getGridBandPaint() + * + * @since 1.0.7 */ - public boolean isGridBandsVisible() { - return this.gridBandsVisible; + public Paint getGridBandAlternatePaint() { + return this.gridBandAlternatePaint; } - + /** - * Sets the visibility of the grid bands and notifies registered - * listeners that the axis has been modified. - * - * @param flag the new setting. + * Sets the paint used for alternate grid bands and sends a + * {@link AxisChangeEvent} to all registered listeners. * - * @see #isGridBandsVisible() + * @param paint the paint (<code>null</code> not permitted). + * + * @see #getGridBandAlternatePaint() + * @see #setGridBandPaint(Paint) + * + * @since 1.0.7 */ - public void setGridBandsVisible(boolean flag) { - if (this.gridBandsVisible != flag) { - this.gridBandsVisible = flag; - notifyListeners(new AxisChangeEvent(this)); + public void setGridBandAlternatePaint(Paint paint) { + if (paint == null) { + throw new IllegalArgumentException("Null 'paint' argument."); } + this.gridBandAlternatePaint = paint; + notifyListeners(new AxisChangeEvent(this)); } - + /** * This operation is not supported by this axis. * @@ -733,6 +782,10 @@ if (!PaintUtilities.equal(this.gridBandPaint, that.gridBandPaint)) { return false; } + if (!PaintUtilities.equal(this.gridBandAlternatePaint, + that.gridBandAlternatePaint)) { + return false; + } return super.equals(obj); } @@ -746,6 +799,7 @@ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.gridBandPaint, stream); + SerialUtilities.writePaint(this.gridBandAlternatePaint, stream); } /** @@ -760,6 +814,7 @@ throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.gridBandPaint = SerialUtilities.readPaint(stream); + this.gridBandAlternatePaint = SerialUtilities.readPaint(stream); } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java 2007-07-25 09:37:14 UTC (rev 137) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java 2007-07-25 10:16:42 UTC (rev 138) @@ -37,7 +37,8 @@ * Changes * ------- * 26-Mar-2003 : Version 1 (DG); - * + * 25-Jul-2007 : Added new field in testEquals() (DG); + * */ package org.jfree.chart.axis.junit; @@ -142,14 +143,19 @@ a2 = new SymbolAxis("Axis 2", new String[] {"C", "B"}); assertTrue(a1.equals(a2)); + a1.setGridBandsVisible(false); + assertFalse(a1.equals(a2)); + a2.setGridBandsVisible(false); + assertTrue(a1.equals(a2)); + a1.setGridBandPaint(Color.black); assertFalse(a1.equals(a2)); a2.setGridBandPaint(Color.black); assertTrue(a1.equals(a2)); - a1.setGridBandsVisible(false); + a1.setGridBandAlternatePaint(Color.red); assertFalse(a1.equals(a2)); - a2.setGridBandsVisible(false); + a2.setGridBandAlternatePaint(Color.red); assertTrue(a1.equals(a2)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-25 11:46:29
|
Revision: 140 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=140&view=rev Author: mungady Date: 2007-07-25 04:46:26 -0700 (Wed, 25 Jul 2007) Log Message: ----------- 2007-07-25 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java: New file, contributed by Klaus Rheinwald. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/RendererXYPackageTests.java Added Paths: ----------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/XYSplineAndShapeRendererTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 10:25:10 UTC (rev 139) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 11:46:26 UTC (rev 140) @@ -1,5 +1,10 @@ 2007-07-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java: + New file, contributed by Klaus Rheinwald. + +2007-07-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/SymbolAxis.java (DEFAULT_GRID_BAND_ALTERNATE_PAINT): New field, (gridBandAlternatePaint): New field, Added: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java 2007-07-25 11:46:26 UTC (rev 140) @@ -0,0 +1,327 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * ----------------------------- + * XYSplineAndShapeRenderer.java + * ----------------------------- + * (C) Copyright 2007, by Klaus Rheinwald and Contributors. + * + * Original Author: Klaus Rheinwald; + * Contributor(s): Tobias von Petersdorff (tv...@ma..., + * http://www.wam.umd.edu/~petersd/); + * David Gilbert (for Object Refinery Limited); + * + * $Id: XYLineAndShapeRenderer.java,v 1.20.2.13 2007/06/08 13:29:38 mungady Exp $ + * + * Changes: + * -------- + * 25-Jul-2007 : Version 1, contributed by Klaus Rheinwald (DG); + * + */ + + +package org.jfree.chart.renderer.xy; + +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.util.Vector; + +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.event.RendererChangeEvent; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.PlotRenderingInfo; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleEdge; + + +/** + * A renderer that connects data points with natural cubic splines and/or + * draws shapes at each data point. This renderer is designed for use with + * the {@link XYPlot} class. + * + * @since 1.0.7 + */ +public class XYSplineAndShapeRenderer extends XYLineAndShapeRenderer { + + /** + * To collect data points for later splining. + */ + private Vector points; + + /** + * Resolution of splines (number of line segments between points) + */ + private int precision = 10; + + /** + * Creates a new instance with the 'precision' attribute defaulting to + * 10. + */ + public XYSplineAndShapeRenderer() { + super(); + this.precision = 10; + } + + /** + * Get the resolution of splines. + * + * @return Number of line segments between points. + * + * @see #setPrecision(int) + */ + public int getPrecision() { + return this.precision; + } + + /** + * Set the resolution of splines and sends a {@link RendererChangeEvent} + * to all registered listeners. + * + * @param p number of line segments between points (must be > 0). + * + * @see #getPrecision() + */ + public void setPrecision(int p) { + if (p <= 0) { + throw new IllegalArgumentException("Requires p > 0."); + } + this.precision = p; + notifyListeners(new RendererChangeEvent(this)); + } + + + /** + * Initialises the renderer. + * <P> + * This method will be called before the first item is rendered, giving the + * renderer an opportunity to initialise any state information it wants to + * maintain. The renderer can do nothing if it chooses. + * + * @param g2 the graphics device. + * @param dataArea the area inside the axes. + * @param plot the plot. + * @param data the data. + * @param info an optional info collection object to return data back to + * the caller. + * + * @return The renderer state. + */ + public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, + XYPlot plot, XYDataset data, PlotRenderingInfo info) { + + State state = (State) super.initialise(g2, dataArea, plot, data, info); + state.setProcessVisibleItemsOnly(false); + this.points = new Vector(); + setDrawSeriesLineAsPath(true); + return state; + } + + /** + * Draws the item (first pass). This method draws the lines + * connecting the items. Instead of drawing separate lines, + * a GeneralPath is constructed and drawn at the end of + * the series painting. + * + * @param g2 the graphics device. + * @param state the renderer state. + * @param plot the plot (can be used to obtain standard color information + * etc). + * @param dataset the dataset. + * @param pass the pass. + * @param series the series index (zero-based). + * @param item the item index (zero-based). + * @param domainAxis the domain axis. + * @param rangeAxis the range axis. + * @param dataArea the area within which the data is being drawn. + */ + protected void drawPrimaryLineAsPath(XYItemRendererState state, + Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, + int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, + Rectangle2D dataArea) { + + RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); + RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); + + // get the data points + double x1 = dataset.getXValue(series, item); + double y1 = dataset.getYValue(series, item); + double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); + double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); + + // collect points + if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { + this.points.add(new ControlPoint(plot.getOrientation() + == PlotOrientation.HORIZONTAL ? (float) transY1 + : (float) transX1, plot.getOrientation() + == PlotOrientation.HORIZONTAL ? (float) transX1 + : (float) transY1)); + } + if (item == dataset.getItemCount(series) - 1) { + State s = (State) state; + // construct path + if (this.points.size() > 1) { + // we need at least two points to draw something + ControlPoint cp0 = (ControlPoint) this.points.get(0); + s.seriesPath.moveTo(cp0.x, cp0.y); + if (this.points.size() == 2) { + // we need at least 3 points to spline. Draw simple line for two points + ControlPoint cp1 = (ControlPoint) this.points.get(1); + s.seriesPath.lineTo(cp1.x, cp1.y); + } + else { + // construct spline + int np = this.points.size(); // number of points + float[] d = new float[np]; // Newton form coefficients + float[] x = new float[np]; // x-coordinates of nodes + float y; + float t; + float oldy = 0; + float oldt = 0; + + float[] a = new float[np]; + float t1; + float t2; + float[] h = new float[np]; + + for (int i = 0; i < np; i++) { + ControlPoint cpi = (ControlPoint) this.points.get(i); + x[i] = cpi.x; + d[i] = cpi.y; + } + + for (int i = 1; i <= np - 1; i++) { + h[i] = x[i] - x[i - 1]; + } + float[] sub = new float[np - 1]; + float[] diag = new float[np - 1]; + float[] sup = new float[np - 1]; + + for (int i = 1; i <= np - 2; i++) { + diag[i] = (h[i] + h[i + 1]) / 3; + sup[i] = h[i + 1] / 6; + sub[i] = h[i] / 6; + a[i] = (d[i + 1] - d[i]) / h[i + 1] + - (d[i] - d[i - 1]) / h[i]; + } + solveTridiag(sub, diag, sup, a, np - 2); + + // note that a[0]=a[np-1]=0 + // draw + oldt = x[0]; + oldy = d[0]; + s.seriesPath.moveTo(oldt, oldy); + for (int i = 1; i <= np - 1; i++) { + // loop over intervals between nodes + for (int j = 1; j <= this.precision; j++) { + t1 = (h[i] * j) / this.precision; + t2 = h[i] - t1; + y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) + * t2 + (-a[i] / 6 * (t1 + h[i]) * t2 + + d[i]) * t1) / h[i]; + t = x[i - 1] + t1; + s.seriesPath.lineTo(t, y); + oldt = t; + oldy = y; + } + } + } + // draw path + drawFirstPassShape(g2, pass, series, item, s.seriesPath); + } + + // reset points vector + this.points = new Vector(); + } + } + + private void solveTridiag(float[] sub, float[] diag, float[] sup, + float[] b, int n) { +/* solve linear system with tridiagonal n by n matrix a + using Gaussian elimination *without* pivoting + where a(i,i-1) = sub[i] for 2<=i<=n + a(i,i) = diag[i] for 1<=i<=n + a(i,i+1) = sup[i] for 1<=i<=n-1 + (the values sub[1], sup[n] are ignored) + right hand side vector b[1:n] is overwritten with solution + NOTE: 1...n is used in all arrays, 0 is unused */ + int i; +/* factorization and forward substitution */ + for (i = 2; i <= n; i++) { + sub[i] = sub[i] / diag[i - 1]; + diag[i] = diag[i] - sub[i] * sup[i - 1]; + b[i] = b[i] - sub[i] * b[i - 1]; + } + b[n] = b[n] / diag[n]; + for (i = n - 1; i >= 1; i--) { + b[i] = (b[i] - sup[i] * b[i + 1]) / diag[i]; + } + } + + /** + * Tests this renderer for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof XYSplineAndShapeRenderer)) { + return false; + } + XYSplineAndShapeRenderer that = (XYSplineAndShapeRenderer) obj; + if (this.precision != that.precision) { + return false; + } + return super.equals(obj); + } + + /** + * Represents a control point. + */ + class ControlPoint { + + /** The x-coordinate. */ + public float x; + + /** The y-coordinate. */ + public float y; + + /** + * Creates a new control point. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + */ + public ControlPoint(float x, float y) { + this.x = x; + this.y = y; + } + } +} Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/RendererXYPackageTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/RendererXYPackageTests.java 2007-07-25 10:25:10 UTC (rev 139) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/RendererXYPackageTests.java 2007-07-25 11:46:26 UTC (rev 140) @@ -45,6 +45,7 @@ * 26-Feb-2007 : Added DeviationRendererTests (DG); * 30-Apr-2007 : Added XYLine3DRendererTests (DG); * 25-May-2007 : Added VectorRendererTests (DG); + * 25-Jul-2007 : Added XYSplineAndRendererTests (DG); * */ Added: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/XYSplineAndShapeRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/XYSplineAndShapeRendererTests.java (rev 0) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/xy/junit/XYSplineAndShapeRendererTests.java 2007-07-25 11:46:26 UTC (rev 140) @@ -0,0 +1,154 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * ---------------------------------- + * XYSplineAndShapeRendererTests.java + * ---------------------------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * $Id: XYLineAndShapeRendererTests.java,v 1.1.2.4 2007/05/17 16:23:31 mungady Exp $ + * + * Changes + * ------- + * 25-Jul-2007 : Version 1 (DG); + * + */ + +package org.jfree.chart.renderer.xy.junit; + +import java.awt.geom.Rectangle2D; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.renderer.xy.XYSplineAndShapeRenderer; + +/** + * Tests for the {@link XYSplineAndShapeRenderer} class. + */ +public class XYSplineAndShapeRendererTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(XYSplineAndShapeRendererTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public XYSplineAndShapeRendererTests(String name) { + super(name); + } + + /** + * Test that the equals() method distinguishes all fields. + */ + public void testEquals() { + + XYSplineAndShapeRenderer r1 = new XYSplineAndShapeRenderer(); + XYSplineAndShapeRenderer r2 = new XYSplineAndShapeRenderer(); + assertEquals(r1, r2); + assertEquals(r2, r1); + + r1.setPrecision(9); + assertFalse(r1.equals(r2)); + r2.setPrecision(9); + assertTrue(r1.equals(r2)); + } + + /** + * Two objects that are equal are required to return the same hashCode. + */ + public void testHashcode() { + XYSplineAndShapeRenderer r1 = new XYSplineAndShapeRenderer(); + XYSplineAndShapeRenderer r2 = new XYSplineAndShapeRenderer(); + assertTrue(r1.equals(r2)); + int h1 = r1.hashCode(); + int h2 = r2.hashCode(); + assertEquals(h1, h2); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + Rectangle2D legendShape = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0); + XYSplineAndShapeRenderer r1 = new XYSplineAndShapeRenderer(); + r1.setLegendLine(legendShape); + XYSplineAndShapeRenderer r2 = null; + try { + r2 = (XYSplineAndShapeRenderer) r1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(r1 != r2); + assertTrue(r1.getClass() == r2.getClass()); + assertTrue(r1.equals(r2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + XYSplineAndShapeRenderer r1 = new XYSplineAndShapeRenderer(); + XYSplineAndShapeRenderer r2 = null; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(r1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + r2 = (XYSplineAndShapeRenderer) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(r1, r2); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-25 14:02:47
|
Revision: 142 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=142&view=rev Author: mungady Date: 2007-07-25 07:02:45 -0700 (Wed, 25 Jul 2007) Log Message: ----------- 2007-07-25 David Gilbert <dav...@ob...> Patch 1752205: * source/org/jfree/data/time/TimeTableXYDataset.java (clear): New method, * tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java (testClear): New method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/TimeTableXYDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 11:52:15 UTC (rev 141) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-25 14:02:45 UTC (rev 142) @@ -1,5 +1,13 @@ 2007-07-25 David Gilbert <dav...@ob...> + Patch 1752205: + * source/org/jfree/data/time/TimeTableXYDataset.java + (clear): New method, + * tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java + (testClear): New method. + +2007-07-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java: New file, contributed by Klaus Rheinwald. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/TimeTableXYDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/TimeTableXYDataset.java 2007-07-25 11:52:15 UTC (rev 141) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/TimeTableXYDataset.java 2007-07-25 14:02:45 UTC (rev 142) @@ -31,6 +31,7 @@ * * Original Author: Andreas Schroeder; * Contributor(s): David Gilbert (for Object Refinery Limited); + * Rob Eden; * * $Id: TimeTableXYDataset.java,v 1.10.2.3 2007/03/09 15:43:09 mungady Exp $ * @@ -48,6 +49,7 @@ * release (DG); * 27-Jan-2005 : Modified to use TimePeriod rather than RegularTimePeriod (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); + * 25-Jul-2007 : Added clear() method by Rob Eden, see patch 1752205 (DG); * */ @@ -251,6 +253,19 @@ } /** + * Removes all data items from the dataset and sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @since 1.0.7 + */ + public void clear() { + if (this.values.getRowCount() > 0) { + this.values.clear(); + fireDatasetChanged(); + } + } + + /** * Returns the time period for the specified item. Bear in mind that all * series share the same set of time periods. * Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java 2007-07-25 11:52:15 UTC (rev 141) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java 2007-07-25 14:02:45 UTC (rev 142) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,17 @@ * ---------------------------- * TimeTableXYDatasetTests.java * ---------------------------- - * (C) Copyright 2004, by Object Refinery Limited. + * (C) Copyright 2004, 2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; + * Contributor(s): Rob Eden; * * $Id: TimeTableXYDatasetTests.java,v 1.1.2.1 2006/10/03 15:41:39 mungady Exp $ * * Changes * ------- * 15-Sep-2004 : Version 1 (DG); + * 25-Jul-2007 : Added test for clear() method, by Rob Eden (DG); * */ @@ -132,9 +133,8 @@ assertTrue(d1.equals(d2)); d1 = new TimeTableXYDataset(TimeZone.getTimeZone("GMT")); - d2 = new TimeTableXYDataset( - TimeZone.getTimeZone("America/Los_Angeles") - ); + d2 = new TimeTableXYDataset(TimeZone.getTimeZone( + "America/Los_Angeles")); assertFalse(d1.equals(d2)); } @@ -175,17 +175,32 @@ out.writeObject(d1); out.close(); - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); d2 = (TimeTableXYDataset) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertTrue(d1.equals(d2)); } + + /** + * Test clearing data. + */ + public void testClear() { + TimeTableXYDataset d = new TimeTableXYDataset(); + d.add(new Year(1999), 1.0, "Series 1"); + assertEquals(d.getItemCount(), 1); + assertEquals(d.getSeriesCount(), 1); + d.add(new Year(2000), 2.0, "Series 2"); + d.clear(); + // Make sure there's nothing left + assertEquals(0, d.getItemCount()); + assertEquals(0, d.getSeriesCount()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-31 14:06:04
|
Revision: 145 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=145&view=rev Author: mungady Date: 2007-07-31 07:06:00 -0700 (Tue, 31 Jul 2007) Log Message: ----------- 2007-07-31 David Gilbert <dav...@ob...> Bug 1763413: * source/org/jfree/chart/axis/PeriodAxis.java (drawTickLabels): Calculate tick label width correctly for inverted axis. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/PeriodAxis.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-31 10:49:50 UTC (rev 144) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-07-31 14:06:00 UTC (rev 145) @@ -1,3 +1,9 @@ +2007-07-31 David Gilbert <dav...@ob...> + + Bug 1763413: + * source/org/jfree/chart/axis/PeriodAxis.java + (drawTickLabels): Calculate tick label width correctly for inverted axis. + 2007-07-25 David Gilbert <dav...@ob...> Patch 1752205: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/PeriodAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/PeriodAxis.java 2007-07-31 10:49:50 UTC (rev 144) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/PeriodAxis.java 2007-07-31 14:06:00 UTC (rev 145) @@ -50,6 +50,7 @@ * 06-Oct-2006 : Updated for deprecations in RegularTimePeriod and * subclasses (DG); * 22-Mar-2007 : Use new defaultAutoRange attribute (DG); + * 31-Jul-2007 : Fix for inverted axis labelling (see bug 1763413) (DG); * */ @@ -808,7 +809,13 @@ g2.getFontMetrics()); double w = Math.max(b1.getWidth(), b2.getWidth()); long ww = Math.round(java2DToValue(dataArea.getX() + w + 5.0, - dataArea, edge)) - axisMin; + dataArea, edge)); + if (isInverted()) { + ww = axisMax - ww; + } + else { + ww = ww - axisMin; + } long length = p1.getLastMillisecond(this.calendar) - p1.getFirstMillisecond(this.calendar); int periods = (int) (ww / length) + 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-02 10:20:11
|
Revision: 150 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=150&view=rev Author: mungady Date: 2007-08-02 03:20:09 -0700 (Thu, 02 Aug 2007) Log Message: ----------- 2007-08-02 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/axis/LogAxis.java (LogAxis(String)): Leave tick marks visible, (autoAdjustRange): Apply margins to log scale, and don't allow auto-range to go below minimum value, (refreshTicksHorizontal): Improved handling of ticks and labels, (refreshTicksVertical): Likewise, (selectAutoTickUnit): New method, (selectHorizontalAutoTickUnit): Likewise, (selectVerticalAutoTickUnit): Likewise, (exponentLengthToJava2D): Likewise, (estimateMaximumTickLabelHeight): Likewise, (estimateMaximumTickLabelWidth): Likewise, (equals): New method override, (hashCode): Likewise, (createLogTickUnits): New method, and moved to source/org/jfree/chart/axis/, * source/org/jfree/chart/axis/NumberTick.java (NumberTick(TickType, double, String, TextAnchor, TextAnchor, double)): New constructor, * source/org/jfree/chart/axis/NumberTickUnit.java (NumberTickUnit(double, NumberFormat, int)): New constructor, (toString): New method override, * source/org/jfree/chart/axis/TickType.java: New file, * source/org/jfree/chart/axis/TickUnit.java (minorTickCount): New field, (TickUnit(double, int)): New constructor, (getMinorTickCount): New method, (equals): Updated for new field, * source/org/jfree/chart/axis/TickUnits.java: Reformatting only, * source/org/jfree/chart/axis/ValueAxis.java (drawTickMarksAndLabels): Check for major tick before writing label, * source/org/jfree/chart/axis/ValueTick.java: (tickType): New field, (ValueTick(TickType, double, String, TextAnchor, TextAnchor, double)): New constructor, (getTickType): New method, (equals): Updated for new field, * source/org/jfree/chart/util/LogFormat.java: New file, * tests/org/jfree/chart/axis/junit/AxisPackageTests.java (suite): Added LogAxisTests and TickUnitsTests, * tests/org/jfree/chart/axis/junit/LogAxisTests.java: New file, * tests/org/jfree/chart/axis/junit/TickUnitsTests.java: Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTick.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTickUnit.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnit.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnits.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueTick.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/AxisPackageTests.java Added Paths: ----------- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/LogAxis.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickType.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/LogFormat.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/LogAxisTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/TickUnitsTests.java Copied: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/LogAxis.java (from rev 129, branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java) =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/LogAxis.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/LogAxis.java 2007-08-02 10:20:09 UTC (rev 150) @@ -0,0 +1,928 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * ------------ + * LogAxis.java + * ------------ + * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * $Id: LogAxis.java,v 1.1.2.2 2007/03/22 16:39:18 mungady Exp $ + * + * Changes + * ------- + * 24-Aug-2006 : Version 1 (DG); + * 22-Mar-2007 : Use defaultAutoArrange attribute (DG); + * 02-Aug-2007 : Fixed zooming bug, added support for margins (DG); + * + */ + +package org.jfree.chart.axis; + +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.awt.geom.Rectangle2D; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.jfree.chart.event.AxisChangeEvent; +import org.jfree.chart.plot.Plot; +import org.jfree.chart.plot.PlotRenderingInfo; +import org.jfree.chart.plot.ValueAxisPlot; +import org.jfree.data.Range; +import org.jfree.ui.RectangleEdge; +import org.jfree.ui.RectangleInsets; +import org.jfree.ui.TextAnchor; + +/** + * A numerical axis that uses a logarithmic scale. The plan is for this class + * to replace the {@link LogarithmicAxis} class. + * + * WARNING: THIS CLASS IS NOT PART OF THE STANDARD JFREECHART API AND IS + * SUBJECT TO ALTERATION OR REMOVAL. DO NOT RELY ON THIS CLASS FOR + * PRODUCTION USE. Please experiment with this code and provide feedback. + */ + +public class LogAxis extends ValueAxis { + + /** The logarithm base. */ + private double base = 10.0; + + /** The logarithm of the base value - cached for performance. */ + private double baseLog = Math.log(10.0); + + /** The smallest value permitted on the axis. */ + private double smallestValue = 1E-100; + + /** The current tick unit. */ + private NumberTickUnit tickUnit; + + /** The override number format. */ + private NumberFormat numberFormatOverride; + + /** The number of minor ticks per major tick unit. */ + private int minorTickCount; + + /** + * Creates a new <code>LogAxis</code> with no label. + */ + public LogAxis() { + this(null); + } + + /** + * Creates a new <code>LogAxis</code> with the given label. + * + * @param label the axis label (<code>null</code> permitted). + */ + public LogAxis(String label) { + super(label, createLogTickUnits(Locale.getDefault())); + setDefaultAutoRange(new Range(0.01, 1.0)); + this.tickUnit = new NumberTickUnit(1.0, new DecimalFormat("0.#")); + this.minorTickCount = 10; + } + + /** + * Returns the base for the logarithm calculation. + * + * @return The base for the logarithm calculation. + * + * @see #setBase(double) + */ + public double getBase() { + return this.base; + } + + /** + * Sets the base for the logarithm calculation and sends an + * {@link AxisChangeEvent} to all registered listeners. + * + * @param base the base value (must be > 1.0). + * + * @see #getBase() + */ + public void setBase(double base) { + if (base <= 1.0) { + throw new IllegalArgumentException("Requires 'base' > 1.0."); + } + this.base = base; + this.baseLog = Math.log(base); + notifyListeners(new AxisChangeEvent(this)); + } + + /** + * Returns the smallest value represented by the axis. + * + * @return The smallest value represented by the axis. + * + * @see #setSmallestValue(double) + */ + public double getSmallestValue() { + return this.smallestValue; + } + + /** + * Sets the smallest value represented by the axis and sends an + * {@link AxisChangeEvent} to all registered listeners. + * + * @param value the value. + * + * @see #getSmallestValue() + */ + public void setSmallestValue(double value) { + if (value <= 0.0) { + throw new IllegalArgumentException("Requires 'value' > 0.0."); + } + this.smallestValue = value; + notifyListeners(new AxisChangeEvent(this)); + } + + /** + * Returns the current tick unit. + * + * @return The current tick unit. + * + * @see #setTickUnit(NumberTickUnit) + */ + public NumberTickUnit getTickUnit() { + return this.tickUnit; + } + + /** + * Sets the tick unit for the axis and sends an {@link AxisChangeEvent} to + * all registered listeners. A side effect of calling this method is that + * the "auto-select" feature for tick units is switched off (you can + * restore it using the {@link ValueAxis#setAutoTickUnitSelection(boolean)} + * method). + * + * @param unit the new tick unit (<code>null</code> not permitted). + * + * @see #getTickUnit() + */ + public void setTickUnit(NumberTickUnit unit) { + // defer argument checking... + setTickUnit(unit, true, true); + } + + /** + * Sets the tick unit for the axis and, if requested, sends an + * {@link AxisChangeEvent} to all registered listeners. In addition, an + * option is provided to turn off the "auto-select" feature for tick units + * (you can restore it using the + * {@link ValueAxis#setAutoTickUnitSelection(boolean)} method). + * + * @param unit the new tick unit (<code>null</code> not permitted). + * @param notify notify listeners? + * @param turnOffAutoSelect turn off the auto-tick selection? + * + * @see #getTickUnit() + */ + public void setTickUnit(NumberTickUnit unit, boolean notify, + boolean turnOffAutoSelect) { + + if (unit == null) { + throw new IllegalArgumentException("Null 'unit' argument."); + } + this.tickUnit = unit; + if (turnOffAutoSelect) { + setAutoTickUnitSelection(false, false); + } + if (notify) { + notifyListeners(new AxisChangeEvent(this)); + } + + } + + /** + * Returns the number format override. If this is non-null, then it will + * be used to format the numbers on the axis. + * + * @return The number formatter (possibly <code>null</code>). + * + * @see #setNumberFormatOverride(NumberFormat) + */ + public NumberFormat getNumberFormatOverride() { + return this.numberFormatOverride; + } + + /** + * Sets the number format override. If this is non-null, then it will be + * used to format the numbers on the axis. + * + * @param formatter the number formatter (<code>null</code> permitted). + * + * @see #getNumberFormatOverride() + */ + public void setNumberFormatOverride(NumberFormat formatter) { + this.numberFormatOverride = formatter; + notifyListeners(new AxisChangeEvent(this)); + } + + /** + * Returns the number of minor tick marks to display. + * + * @return The number of minor tick marks to display. + * + * @see #setMinorTickCount(int) + */ + public int getMinorTickCount() { + return this.minorTickCount; + } + + /** + * Sets the number of minor tick marks to display, and sends an + * {@link AxisChangeEvent} to all registered listeners. + * + * @param count the count. + * + * @see #getMinorTickCount() + */ + public void setMinorTickCount(int count) { + if (count <= 0) { + throw new IllegalArgumentException("Requires 'count' > 0."); + } + this.minorTickCount = count; + notifyListeners(new AxisChangeEvent(this)); + } + + /** + * Calculates the log of the given value, using the current base. + * + * @param value the value. + * + * @return The log of the given value. + * + * @see #calculateValue(double) + * @see #getBase() + */ + public double calculateLog(double value) { + return Math.log(value) / this.baseLog; + } + + /** + * Calculates the value from a given log. + * + * @param log the log value (must be > 0.0). + * + * @return The value with the given log. + * + * @see #calculateLog(double) + * @see #getBase() + */ + public double calculateValue(double log) { + return Math.pow(this.base, log); + } + + /** + * Converts a Java2D coordinate to an axis value, assuming that the + * axis covers the specified <code>edge</code> of the <code>area</code>. + * + * @param java2DValue the Java2D coordinate. + * @param area the area. + * @param edge the edge that the axis belongs to. + * + * @return A value along the axis scale. + */ + public double java2DToValue(double java2DValue, Rectangle2D area, + RectangleEdge edge) { + + Range range = getRange(); + double axisMin = calculateLog(range.getLowerBound()); + double axisMax = calculateLog(range.getUpperBound()); + + double min = 0.0; + double max = 0.0; + if (RectangleEdge.isTopOrBottom(edge)) { + min = area.getX(); + max = area.getMaxX(); + } + else if (RectangleEdge.isLeftOrRight(edge)) { + min = area.getMaxY(); + max = area.getY(); + } + double log = 0.0; + if (isInverted()) { + log = axisMax - (java2DValue - min) / (max - min) + * (axisMax - axisMin); + } + else { + log = axisMin + (java2DValue - min) / (max - min) + * (axisMax - axisMin); + } + return calculateValue(log); + } + + /** + * Converts a value on the axis scale to a Java2D coordinate relative to + * the given <code>area</code>, based on the axis running along the + * specified <code>edge</code>. + * + * @param value the data value. + * @param area the area. + * @param edge the edge. + * + * @return The Java2D coordinate corresponding to <code>value</code>. + */ + public double valueToJava2D(double value, Rectangle2D area, + RectangleEdge edge) { + + Range range = getRange(); + double axisMin = calculateLog(range.getLowerBound()); + double axisMax = calculateLog(range.getUpperBound()); + value = calculateLog(value); + + double min = 0.0; + double max = 0.0; + if (RectangleEdge.isTopOrBottom(edge)) { + min = area.getX(); + max = area.getMaxX(); + } + else if (RectangleEdge.isLeftOrRight(edge)) { + max = area.getMinY(); + min = area.getMaxY(); + } + if (isInverted()) { + return max + - ((value - axisMin) / (axisMax - axisMin)) * (max - min); + } + else { + return min + + ((value - axisMin) / (axisMax - axisMin)) * (max - min); + } + } + + /** + * Configures the axis. This method is typically called when an axis + * is assigned to a new plot. + */ + public void configure() { + if (isAutoRange()) { + autoAdjustRange(); + } + } + + /** + * Adjusts the axis range to match the data range that the axis is + * required to display. + */ + protected void autoAdjustRange() { + Plot plot = getPlot(); + if (plot == null) { + return; // no plot, no data + } + + if (plot instanceof ValueAxisPlot) { + ValueAxisPlot vap = (ValueAxisPlot) plot; + + Range r = vap.getDataRange(this); + if (r == null) { + r = getDefaultAutoRange(); + } + + double upper = r.getUpperBound(); + double lower = Math.max(r.getLowerBound(), this.smallestValue); + double range = upper - lower; + + // if fixed auto range, then derive lower bound... + double fixedAutoRange = getFixedAutoRange(); + if (fixedAutoRange > 0.0) { + lower = Math.max(upper - fixedAutoRange, this.smallestValue); + } + else { + // ensure the autorange is at least <minRange> in size... + double minRange = getAutoRangeMinimumSize(); + if (range < minRange) { + double expand = (minRange - range) / 2; + upper = upper + expand; + lower = lower - expand; + } + + // apply the margins - these should apply to the exponent range + double logUpper = calculateLog(upper); + double logLower = calculateLog(lower); + double logRange = logUpper - logLower; + logUpper = logUpper + getUpperMargin() * logRange; + logLower = logLower - getLowerMargin() * logRange; + upper = calculateValue(logUpper); + lower = calculateValue(logLower); + } + + setRange(new Range(lower, upper), false, false); + } + + } + + /** + * Draws the axis on a Java 2D graphics device (such as the screen or a + * printer). + * + * @param g2 the graphics device (<code>null</code> not permitted). + * @param cursor the cursor location (determines where to draw the axis). + * @param plotArea the area within which the axes and plot should be drawn. + * @param dataArea the area within which the data should be drawn. + * @param edge the axis location (<code>null</code> not permitted). + * @param plotState collects information about the plot + * (<code>null</code> permitted). + * + * @return The axis state (never <code>null</code>). + */ + public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, + Rectangle2D dataArea, RectangleEdge edge, + PlotRenderingInfo plotState) { + + AxisState state = null; + // if the axis is not visible, don't draw it... + if (!isVisible()) { + state = new AxisState(cursor); + // even though the axis is not visible, we need ticks for the + // gridlines... + List ticks = refreshTicks(g2, state, dataArea, edge); + state.setTicks(ticks); + return state; + } + state = drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge); + state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state); + return state; + } + + /** + * Calculates the positions of the tick labels for the axis, storing the + * results in the tick label list (ready for drawing). + * + * @param g2 the graphics device. + * @param state the axis state. + * @param dataArea the area in which the plot should be drawn. + * @param edge the location of the axis. + * + * @return A list of ticks. + * + */ + public List refreshTicks(Graphics2D g2, AxisState state, + Rectangle2D dataArea, RectangleEdge edge) { + + List result = new java.util.ArrayList(); + if (RectangleEdge.isTopOrBottom(edge)) { + result = refreshTicksHorizontal(g2, dataArea, edge); + } + else if (RectangleEdge.isLeftOrRight(edge)) { + result = refreshTicksVertical(g2, dataArea, edge); + } + return result; + + } + + /** + * Returns a list of ticks for an axis at the top or bottom of the chart. + * + * @param g2 the graphics device. + * @param dataArea the data area. + * @param edge the edge. + * + * @return A list of ticks. + */ + protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, + RectangleEdge edge) { + + Range range = getRange(); + List ticks = new ArrayList(); + Font tickLabelFont = getTickLabelFont(); + g2.setFont(tickLabelFont); + + if (isAutoTickUnitSelection()) { + selectAutoTickUnit(g2, dataArea, edge); + } + double start = Math.floor(calculateLog(getLowerBound())); + double end = Math.ceil(calculateLog(getUpperBound())); + double current = start; + while (current <= end) { + double v = calculateValue(current); + if (range.contains(v)) { + ticks.add(new NumberTick(TickType.MAJOR, v, createTickLabel(v), + TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); + } + // add minor ticks (for gridlines) + double next = Math.pow(this.base, current + + this.tickUnit.getSize()); + for (int i = 1; i < this.minorTickCount; i++) { + double minorV = v + i * ((next - v) / this.minorTickCount); + if (range.contains(minorV)) { + ticks.add(new NumberTick(TickType.MINOR, minorV, + "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); + } + } + current = current + this.tickUnit.getSize(); + } + return ticks; + } + + /** + * Returns a list of ticks for an axis at the left or right of the chart. + * + * @param g2 the graphics device. + * @param dataArea the data area. + * @param edge the edge. + * + * @return A list of ticks. + */ + protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, + RectangleEdge edge) { + + Range range = getRange(); + List ticks = new ArrayList(); + Font tickLabelFont = getTickLabelFont(); + g2.setFont(tickLabelFont); + + if (isAutoTickUnitSelection()) { + selectAutoTickUnit(g2, dataArea, edge); + } + double start = Math.floor(calculateLog(getLowerBound())); + double end = Math.ceil(calculateLog(getUpperBound())); + double current = start; + while (current <= end) { + double v = calculateValue(current); + if (range.contains(v)) { + ticks.add(new NumberTick(TickType.MINOR, v, createTickLabel(v), + TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); + } + // add minor ticks (for gridlines) + double next = Math.pow(this.base, current + + this.tickUnit.getSize()); + for (int i = 1; i < this.minorTickCount; i++) { + double minorV = v + i * ((next - v) / this.minorTickCount); + if (range.contains(minorV)) { + ticks.add(new NumberTick(TickType.MINOR, minorV, "", + TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); + } + } + current = current + this.tickUnit.getSize(); + } + return ticks; + } + + /** + * Selects an appropriate tick value for the axis. The strategy is to + * display as many ticks as possible (selected from an array of 'standard' + * tick units) without the labels overlapping. + * + * @param g2 the graphics device. + * @param dataArea the area defined by the axes. + * @param edge the axis location. + * + * @since 1.0.7 + */ + protected void selectAutoTickUnit(Graphics2D g2, Rectangle2D dataArea, + RectangleEdge edge) { + + if (RectangleEdge.isTopOrBottom(edge)) { + selectHorizontalAutoTickUnit(g2, dataArea, edge); + } + else if (RectangleEdge.isLeftOrRight(edge)) { + selectVerticalAutoTickUnit(g2, dataArea, edge); + } + + } + + /** + * Selects an appropriate tick value for the axis. The strategy is to + * display as many ticks as possible (selected from an array of 'standard' + * tick units) without the labels overlapping. + * + * @param g2 the graphics device. + * @param dataArea the area defined by the axes. + * @param edge the axis location. + * + * @since 1.0.7 + */ + protected void selectHorizontalAutoTickUnit(Graphics2D g2, + Rectangle2D dataArea, RectangleEdge edge) { + + double tickLabelWidth = estimateMaximumTickLabelWidth(g2, + getTickUnit()); + + // start with the current tick unit... + TickUnitSource tickUnits = getStandardTickUnits(); + TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); + double unit1Width = exponentLengthToJava2D(unit1.getSize(), dataArea, edge); + + // then extrapolate... + double guess = (tickLabelWidth / unit1Width) * unit1.getSize(); + + NumberTickUnit unit2 = (NumberTickUnit) + tickUnits.getCeilingTickUnit(guess); + double unit2Width = exponentLengthToJava2D(unit2.getSize(), dataArea, edge); + + tickLabelWidth = estimateMaximumTickLabelWidth(g2, unit2); + if (tickLabelWidth > unit2Width) { + unit2 = (NumberTickUnit) tickUnits.getLargerTickUnit(unit2); + } + + setTickUnit(unit2, false, false); + + } + + /** + * Converts a length in data coordinates into the corresponding length in + * Java2D coordinates. + * + * @param length the length. + * @param area the plot area. + * @param edge the edge along which the axis lies. + * + * @return The length in Java2D coordinates. + * + * @since 1.0.7 + */ + public double exponentLengthToJava2D(double length, Rectangle2D area, + RectangleEdge edge) { + double one = valueToJava2D(calculateValue(1.0), area, edge); + double l = valueToJava2D(calculateValue(length + 1.0), area, edge); + return Math.abs(l - one); + } + + /** + * Selects an appropriate tick value for the axis. The strategy is to + * display as many ticks as possible (selected from an array of 'standard' + * tick units) without the labels overlapping. + * + * @param g2 the graphics device. + * @param dataArea the area in which the plot should be drawn. + * @param edge the axis location. + * + * @since 1.0.7 + */ + protected void selectVerticalAutoTickUnit(Graphics2D g2, + Rectangle2D dataArea, + RectangleEdge edge) { + + double tickLabelHeight = estimateMaximumTickLabelHeight(g2); + + // start with the current tick unit... + TickUnitSource tickUnits = getStandardTickUnits(); + TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); + double unitHeight = exponentLengthToJava2D(unit1.getSize(), dataArea, + edge); + + // then extrapolate... + double guess = (tickLabelHeight / unitHeight) * unit1.getSize(); + + NumberTickUnit unit2 = (NumberTickUnit) + tickUnits.getCeilingTickUnit(guess); + double unit2Height = exponentLengthToJava2D(unit2.getSize(), dataArea, + edge); + + tickLabelHeight = estimateMaximumTickLabelHeight(g2); + if (tickLabelHeight > unit2Height) { + unit2 = (NumberTickUnit) tickUnits.getLargerTickUnit(unit2); + } + + setTickUnit(unit2, false, false); + + } + + /** + * Estimates the maximum tick label height. + * + * @param g2 the graphics device. + * + * @return The maximum height. + * + * @since 1.0.7 + */ + protected double estimateMaximumTickLabelHeight(Graphics2D g2) { + + RectangleInsets tickLabelInsets = getTickLabelInsets(); + double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom(); + + Font tickLabelFont = getTickLabelFont(); + FontRenderContext frc = g2.getFontRenderContext(); + result += tickLabelFont.getLineMetrics("123", frc).getHeight(); + return result; + + } + + /** + * Estimates the maximum width of the tick labels, assuming the specified + * tick unit is used. + * <P> + * Rather than computing the string bounds of every tick on the axis, we + * just look at two values: the lower bound and the upper bound for the + * axis. These two values will usually be representative. + * + * @param g2 the graphics device. + * @param unit the tick unit to use for calculation. + * + * @return The estimated maximum width of the tick labels. + * + * @since 1.0.7 + */ + protected double estimateMaximumTickLabelWidth(Graphics2D g2, + TickUnit unit) { + + RectangleInsets tickLabelInsets = getTickLabelInsets(); + double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight(); + + if (isVerticalTickLabels()) { + // all tick labels have the same width (equal to the height of the + // font)... + FontRenderContext frc = g2.getFontRenderContext(); + LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc); + result += lm.getHeight(); + } + else { + // look at lower and upper bounds... + FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); + Range range = getRange(); + double lower = range.getLowerBound(); + double upper = range.getUpperBound(); + String lowerStr = ""; + String upperStr = ""; + NumberFormat formatter = getNumberFormatOverride(); + if (formatter != null) { + lowerStr = formatter.format(lower); + upperStr = formatter.format(upper); + } + else { + lowerStr = unit.valueToString(lower); + upperStr = unit.valueToString(upper); + } + double w1 = fm.stringWidth(lowerStr); + double w2 = fm.stringWidth(upperStr); + result += Math.max(w1, w2); + } + + return result; + + } + + /** + * Zooms in on the current range. + * + * @param lowerPercent the new lower bound. + * @param upperPercent the new upper bound. + */ + public void zoomRange(double lowerPercent, double upperPercent) { + Range range = getRange(); + double start = range.getLowerBound(); + double end = range.getUpperBound(); + double log1 = calculateLog(start); + double log2 = calculateLog(end); + double length = log2 - log1; + Range adjusted = null; + if (isInverted()) { + double logA = log1 + length * (1 - upperPercent); + double logB = log1 + length * (1 - lowerPercent); + adjusted = new Range(calculateValue(logA), calculateValue(logB)); + } + else { + double logA = log1 + length * lowerPercent; + double logB = log1 + length * upperPercent; + adjusted = new Range(calculateValue(logA), calculateValue(logB)); + } + setRange(adjusted); + } + + /** + * Creates a tick label for the specified value. + * + * @param value the value. + * + * @return The label. + */ + private String createTickLabel(double value) { + if (this.numberFormatOverride != null) { + return this.numberFormatOverride.format(value); + } + else { + return this.tickUnit.valueToString(value); + } + } + + /** + * Tests this axis for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof LogAxis)) { + return false; + } + LogAxis that = (LogAxis) obj; + if (this.base != that.base) { + return false; + } + if (this.smallestValue != that.smallestValue) { + return false; + } + if (this.minorTickCount != that.minorTickCount) { + return false; + } + return super.equals(obj); + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 193; + long temp = Double.doubleToLongBits(this.base); + result = 37 * result + (int) (temp ^ (temp >>> 32)); + result = 37 * result + this.minorTickCount; + temp = Double.doubleToLongBits(this.smallestValue); + result = 37 * result + (int) (temp ^ (temp >>> 32)); + if (this.numberFormatOverride != null) { + result = 37 * result + this.numberFormatOverride.hashCode(); + } + result = 37 * result + this.tickUnit.hashCode(); + return result; + } + + /** + * Returns a collection of tick units for log (base 10) values. + * Uses a given Locale to create the DecimalFormats. + * + * @param locale the locale to use to represent Numbers. + * + * @return A collection of tick units for integer values. + * + * @since 1.0.7 + */ + public static TickUnitSource createLogTickUnits(Locale locale) { + + TickUnits units = new TickUnits(); + + NumberFormat numberFormat = NumberFormat.getNumberInstance(locale); + + units.add(new NumberTickUnit(1, numberFormat)); + units.add(new NumberTickUnit(2, numberFormat)); + units.add(new NumberTickUnit(5, numberFormat)); + units.add(new NumberTickUnit(10, numberFormat)); + units.add(new NumberTickUnit(20, numberFormat)); + units.add(new NumberTickUnit(50, numberFormat)); + units.add(new NumberTickUnit(100, numberFormat)); + units.add(new NumberTickUnit(200, numberFormat)); + units.add(new NumberTickUnit(500, numberFormat)); + units.add(new NumberTickUnit(1000, numberFormat)); + units.add(new NumberTickUnit(2000, numberFormat)); + units.add(new NumberTickUnit(5000, numberFormat)); + units.add(new NumberTickUnit(10000, numberFormat)); + units.add(new NumberTickUnit(20000, numberFormat)); + units.add(new NumberTickUnit(50000, numberFormat)); + units.add(new NumberTickUnit(100000, numberFormat)); + units.add(new NumberTickUnit(200000, numberFormat)); + units.add(new NumberTickUnit(500000, numberFormat)); + units.add(new NumberTickUnit(1000000, numberFormat)); + units.add(new NumberTickUnit(2000000, numberFormat)); + units.add(new NumberTickUnit(5000000, numberFormat)); + units.add(new NumberTickUnit(10000000, numberFormat)); + units.add(new NumberTickUnit(20000000, numberFormat)); + units.add(new NumberTickUnit(50000000, numberFormat)); + units.add(new NumberTickUnit(100000000, numberFormat)); + units.add(new NumberTickUnit(200000000, numberFormat)); + units.add(new NumberTickUnit(500000000, numberFormat)); + units.add(new NumberTickUnit(1000000000, numberFormat)); + units.add(new NumberTickUnit(2000000000, numberFormat)); + units.add(new NumberTickUnit(5000000000.0, numberFormat)); + units.add(new NumberTickUnit(10000000000.0, numberFormat)); + + return units; + + } +} Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTick.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTick.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTick.java 2007-08-02 10:20:09 UTC (rev 150) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------- * NumberTick.java * --------------- - * (C) Copyright 2003, 2004, by Object Refinery Limited. + * (C) Copyright 2003-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,7 +37,8 @@ * Changes * ------- * 07-Nov-2003 : Version 1 (DG); - * + * 02-Aug-2007 : Added new constructor with tick type (DG); + * */ package org.jfree.chart.axis; @@ -55,7 +56,7 @@ /** * Creates a new tick. * - * @param number the number. + * @param number the number (<code>null</code> not permitted). * @param label the label. * @param textAnchor the part of the label that is aligned with the anchor * point. @@ -72,6 +73,28 @@ } /** + * Creates a new tick. + * + * @param tickType the tick type. + * @param value the value. + * @param label the label. + * @param textAnchor the part of the label that is aligned with the anchor + * point. + * @param rotationAnchor defines the rotation point relative to the text. + * @param angle the rotation angle (in radians). + * + * @since 1.0.7 + */ + public NumberTick(TickType tickType, double value, String label, + TextAnchor textAnchor, + TextAnchor rotationAnchor, double angle) { + + super(tickType, value, label, textAnchor, rotationAnchor, angle); + this.number = new Double(value); + + } + + /** * Returns the number. * * @return The number. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTickUnit.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTickUnit.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/NumberTickUnit.java 2007-08-02 10:20:09 UTC (rev 150) @@ -44,6 +44,7 @@ * 26-Mar-2003 : Implemented Serializable (DG); * 05-Jul-2005 : Added equals() implementation (DG); * 05-Sep-2005 : Implemented hashCode(), thanks to Thomas Morgner (DG); + * 02-Aug-2007 : Added new constructor with minorTickCount (DG); * */ @@ -88,6 +89,25 @@ } /** + * Creates a new number tick unit. + * + * @param size the size of the tick unit. + * @param formatter a number formatter for the tick unit (<code>null</code> + * not permitted). + * @param minorTickCount the number of minor ticks. + * + * @since 1.0.7 + */ + public NumberTickUnit(double size, NumberFormat formatter, + int minorTickCount) { + super(size, minorTickCount); + if (formatter == null) { + throw new IllegalArgumentException("Null 'formatter' argument."); + } + this.formatter = formatter; + } + + /** * Converts a value to a string. * * @param value the value. @@ -121,6 +141,15 @@ } return true; } + + /** + * Returns a string representing this unit. + * + * @return A string. + */ + public String toString() { + return "[size=" + this.valueToString(this.getSize()) + "]"; + } /** * Returns a hash code for this instance. Added: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickType.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickType.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickType.java 2007-08-02 10:20:09 UTC (rev 150) @@ -0,0 +1,123 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * ------------- + * TickType.java + * ------------- + * (C) Copyright 2007, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * $Id: $ + * + * Changes: + * -------- + * 02-Aug-2007 : Version 1 (DG); + * + */ + +package org.jfree.chart.axis; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +/** + * Used to indicate the tick type (MAJOR or MINOR). + * + * @since 1.0.7 + */ +public final class TickType implements Serializable { + + /** Major tick. */ + public static final TickType MAJOR = new TickType("MAJOR"); + + /** Minor tick. */ + public static final TickType MINOR = new TickType("MINOR"); + + /** The name. */ + private String name; + + /** + * Private constructor. + * + * @param name the name. + */ + private TickType(String name) { + this.name = name; + } + + /** + * Returns a string representing the object. + * + * @return The string. + */ + public String toString() { + return this.name; + } + + /** + * Returns <code>true</code> if this object is equal to the specified + * object, and <code>false</code> otherwise. + * + * @param obj the other object. + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof TickType)) { + return false; + } + + TickType that = (TickType) obj; + if (!this.name.equals(that.name)) { + return false; + } + return true; + } + + /** + * Ensures that serialization returns the unique instances. + * + * @return The object. + * + * @throws ObjectStreamException if there is a problem. + */ + private Object readResolve() throws ObjectStreamException { + Object result = null; + if (this.equals(TickType.MAJOR)) { + result = TickType.MAJOR; + } + else if (this.equals(TickType.MINOR)) { + result = TickType.MINOR; + } + return result; + } + +} Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnit.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnit.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnit.java 2007-08-02 10:20:09 UTC (rev 150) @@ -27,7 +27,7 @@ * ------------- * TickUnit.java * ------------- - * (C) Copyright 2001-2005, by Object Refinery Limited. + * (C) Copyright 2001-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -42,6 +42,7 @@ * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 05-Sep-2005 : Implemented hashCode(), thanks to Thomas Morgner (DG); + * 02-Aug-2007 : Added minorTickCount attribute (DG); * */ @@ -70,6 +71,13 @@ private double size; /** + * The number of minor ticks. + * + * @since 1.0.7 + */ + private int minorTickCount; + + /** * Constructs a new tick unit. * * @param size the tick unit size. @@ -77,6 +85,19 @@ public TickUnit(double size) { this.size = size; } + + /** + * Constructs a new tick unit. + * + * @param size the tick unit size. + * @param minorTickCount the minor tick count. + * + * @since 1.0.7 + */ + public TickUnit(double size, int minorTickCount) { + this.size = size; + this.minorTickCount = minorTickCount; + } /** * Returns the size of the tick unit. @@ -86,6 +107,17 @@ public double getSize() { return this.size; } + + /** + * Returns the minor tick count. + * + * @return The minor tick count. + * + * @since 1.0.7 + */ + public int getMinorTickCount() { + return this.minorTickCount; + } /** * Converts the supplied value to a string. @@ -137,19 +169,20 @@ * @return <code>true</code> or <code>false</code>. */ public boolean equals(Object obj) { - - if (obj == null) { - return false; - } if (obj == this) { return true; } - if (obj instanceof TickUnit) { - TickUnit tu = (TickUnit) obj; - return this.size == tu.size; + if (!(obj instanceof TickUnit)) { + return false; } - return false; - + TickUnit that = (TickUnit) obj; + if (this.size != that.size) { + return false; + } + if (this.minorTickCount != that.minorTickCount) { + return false; + } + return true; } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnits.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnits.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/TickUnits.java 2007-08-02 10:20:09 UTC (rev 150) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------- * TickUnits.java * -------------- - * (C) Copyright 2001-2005, by Object Refinery Limited. + * (C) Copyright 2001-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -83,20 +83,17 @@ } /** - * Adds a tick unit to the collection. - * <P> - * The tick units are maintained in ascending order. + * Adds a tick unit to the collection. The tick units are maintained in + * ascending order. * - * @param unit the tick unit to add. + * @param unit the tick unit to add (<code>null</code> not permitted). */ public void add(TickUnit unit) { - if (unit == null) { throw new NullPointerException("Null 'unit' argument."); } this.tickUnits.add(unit); Collections.sort(this.tickUnits); - } /** @@ -140,9 +137,8 @@ index = -index; } - return (TickUnit) this.tickUnits.get( - Math.min(index, this.tickUnits.size() - 1) - ); + return (TickUnit) this.tickUnits.get(Math.min(index, + this.tickUnits.size() - 1)); } @@ -162,9 +158,8 @@ } else { index = -(index + 1); - return (TickUnit) this.tickUnits.get( - Math.min(index, this.tickUnits.size() - 1) - ); + return (TickUnit) this.tickUnits.get(Math.min(index, + this.tickUnits.size() - 1)); } } @@ -199,22 +194,19 @@ /** * Tests an object for equality with this instance. * - * @param object the object to test. + * @param obj the object to test (<code>null</code> permitted). * * @return A boolean. */ - public boolean equals(Object object) { - if (object == null) { - return false; - } - if (object == this) { + public boolean equals(Object obj) { + if (obj == this) { return true; } - if (object instanceof TickUnits) { - TickUnits tu = (TickUnits) object; - return tu.tickUnits.equals(this.tickUnits); + if (!(obj instanceof TickUnits)) { + return false; } - return false; + TickUnits that = (TickUnits) obj; + return that.tickUnits.equals(this.tickUnits); } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java 2007-08-02 10:20:09 UTC (rev 150) @@ -97,6 +97,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 10-Oct-2006 : Source reformatting (DG); * 22-Mar-2007 : Added new defaultAutoRange attribute (DG); + * 02-Aug-2007 : Check for major tick when drawing label (DG); * */ @@ -697,7 +698,7 @@ tick.getAngle(), tick.getRotationAnchor()); } - if (isTickMarksVisible()) { + if (isTickMarksVisible() && tick.getTickType().equals(TickType.MAJOR)) { float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge); Line2D mark = null; Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueTick.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueTick.java 2007-08-01 10:56:13 UTC (rev 149) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueTick.java 2007-08-02 10:20:09 UTC (rev 150) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------- * ValueTick.java * -------------- - * (C) Copyright 2003, 2004, by Object Refinery Limited. + * (C) Copyright 2003-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,8 +37,10 @@ * Changes * ------- * 07-Nov-2003 : Version 1 (DG); - * + * 02-Aug-2007 : Added tick type attribute (DG); + * */ + package org.jfree.chart.axis; import org.jfree.ui.TextAnchor; @@ -51,6 +53,13 @@ /** The value. */ private double value; + /** + * The tick type (major or minor). + * + * @since 1.0.7 + */ + private TickType tickType; + /** * Creates a new value tick. * @@ -65,10 +74,32 @@ TextAnchor textAnchor, TextAnchor rotationAnchor, double angle) { - super(label, textAnchor, rotationAnchor, angle); + this(TickType.MAJOR, value, label, textAnchor, rotationAnchor, angle); this.value = value; } + + /** + * Creates a new value tick. + * + * @param tickType the tick type (major or minor). + * @param value the value. + * @param label the label. + * @param textAnchor the part of the label that is aligned to the anchor + * point. + * @param rotationAnchor defines the rotation point relative to the label. + * @param angle the rotation angle (in radians). + * + * @since 1.0.7 + */ + public ValueTick(TickType tickType, double value, String label, + TextAnchor textAnchor, TextAnchor rotationAnchor, + double angle) { + + super(label, textAnchor, rotationAnchor, angle); + this.value = value; + this.tickType = tickType; + } /** * Returns the value. @@ -80,6 +111,17 @@ } /** + * Returns the tick type (major or minor). + * + * @return The tick type. + * + * @since 1.0.7 + */ + public TickType getTickType() { + return this.tickType; + } + + /** * Tests this tick for equality with an arbitrary object. * * @param obj the object to test (<code>null</code> permitted). @@ -90,14 +132,17 @@ if (obj == this) { return true; } - if (obj instanceof ValueTick && super.equals(obj)) { - ValueTick vt = (ValueTick) obj; - if (!(this.value == vt.value)) { - return false; - } - return true; + if (!(obj instanceof ValueTick)) { + return false; } - return false; + ValueTick that = (ValueTick) obj; + if (this.value != that.value) { + return false; + } + if (!this.tickType.equals(that.tickType)) { + return false; + } + return super.equals(obj); } } Added: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/LogFormat.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/LogFormat.java (rev 0) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/util/LogFormat.java 2007-08-02 10:20:09 UTC (rev 150) @@ -0,0 +1,153 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * -------------- + * LogFormat.java + * -------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * $Id: LogAxis.java,v 1.1.2.2 2007/03/22 16:39:18 mungady Exp $ + * + * Changes + * ------- + * 02-Aug-2007 : Version 1 (DG); + * + */ + +package org.jfree.chart.util; + +import java.text.DecimalFormat; +import java.text.FieldPosition; +import java.text.NumberFormat; +import java.text.ParsePosition; + +/** + * A number formatter for logarithmic values. This formatter does not support + * parsing. + * + * @since 1.0.7 + */ +public class LogFormat extends NumberFormat { + + /** The log base value. */ + private double base; + + /** The natural logarithm of the base value. */ + private double baseLog; + + /** The label for the log base (for example, "e"). */ + private String baseLabel; + + /** A flag that controls whether or not the base is shown. */ + private boolean showBase; + + /** The number formatter for the exponent. */ + private NumberFormat formatter = new DecimalFormat("0.0"); + + /** + * Creates a new instance. + * + * @param base the base. + * @param baseLabel the base label. + * @param showBase a flag that controls whether or not the base value is + * shown. + */ + public LogFormat(double base, String baseLabel, boolean showBase) { + this.base = base; + this.baseLog = Math.log(this.base); + this.baseLabel = baseLabel; + this.showBase = showBase; + } + + /** + * Calculates the log of a given value. + * + * @param value the value. + * + * @return The log of the value. + */ + private double calculateLog(double value) { + return Math.log(value) / this.baseLog; + } + + /** + * Returns a formatted representation of the specified number. + * + * @param number the number. + * @param toAppendTo the string buffer to append to. + * @param pos the position. + * + * @return A string buffer containing the formatted value. + */ + public StringBuffer format(double number, StringBuffer toAppendTo, + FieldPosition pos) { + StringBuffer result = new StringBuffer(); + if (this.showBase) { + result.append(this.baseLabel); + result.append("^"); + } + result.append(this.formatter.format(calculateLog(number))); + return result; + } + + /** + * Formats the specified number as a hexadecimal string. The decimal + * fraction is ignored. + * + * @param number the number to format. + * @param toAppendTo the buffer to append to (ignored here). + * @param pos the field position (ignored here). + * + * @return The string buffer. + */ + public StringBuffer format(long number, StringBuffer toAppendTo, + FieldPosition pos) { + StringBuffer result = new StringBuffer(); + if (this.showBase) { + result.append(this.baseLabel); + result.append("^"); + } + result.append(this.formatter.format(calculateLog(number))); + return result; + } + + /** + * Parsing is not implemented, so this method always returns + * <code>null</code>. + * + * @param source ignored. + * @param parsePos... [truncated message content] |
From: <mu...@us...> - 2007-08-03 09:30:39
|
Revision: 153 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=153&view=rev Author: mungady Date: 2007-08-03 02:30:36 -0700 (Fri, 03 Aug 2007) Log Message: ----------- Updates previously missed. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog Removed Paths: ------------- branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-02 11:06:07 UTC (rev 152) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 09:30:36 UTC (rev 153) @@ -1,3 +1,49 @@ +2007-08-02 David Gilbert <dav...@ob...> + + * experimental/org/jfree/experimental/chart/axis/LogAxis.java + (LogAxis(String)): Leave tick marks visible, + (autoAdjustRange): Apply margins to log scale, and don't allow auto-range + to go below minimum value, + (refreshTicksHorizontal): Improved handling of ticks and labels, + (refreshTicksVertical): Likewise, + (selectAutoTickUnit): New method, + (selectHorizontalAutoTickUnit): Likewise, + (selectVerticalAutoTickUnit): Likewise, + (exponentLengthToJava2D): Likewise, + (estimateMaximumTickLabelHeight): Likewise, + (estimateMaximumTickLabelWidth): Likewise, + (equals): New method override, + (hashCode): Likewise, + (createLogTickUnits): New method, + and moved to source/org/jfree/chart/axis/, + * source/org/jfree/chart/axis/NumberTick.java + (NumberTick(TickType, double, String, TextAnchor, TextAnchor, double)): + New constructor, + * source/org/jfree/chart/axis/NumberTickUnit.java + (NumberTickUnit(double, NumberFormat, int)): New constructor, + (toString): New method override, + * source/org/jfree/chart/axis/TickType.java: New file, + * source/org/jfree/chart/axis/TickUnit.java + (minorTickCount): New field, + (TickUnit(double, int)): New constructor, + (getMinorTickCount): New method, + (equals): Updated for new field, + * source/org/jfree/chart/axis/TickUnits.java: Reformatting only, + * source/org/jfree/chart/axis/ValueAxis.java + (drawTickMarksAndLabels): Check for major tick before writing label, + * source/org/jfree/chart/axis/ValueTick.java: + (tickType): New field, + (ValueTick(TickType, double, String, TextAnchor, TextAnchor, double)): + New constructor, + (getTickType): New method, + (equals): Updated for new field, + * source/org/jfree/chart/util/LogFormat.java: New file, + * tests/org/jfree/chart/axis/junit/AxisPackageTests.java + (suite): Added LogAxisTests and TickUnitsTests, + * tests/org/jfree/chart/axis/junit/LogAxisTests.java: + New file, + * tests/org/jfree/chart/axis/junit/TickUnitsTests.java: Likewise. + 2007-07-31 David Gilbert <dav...@ob...> Bug 1763413: Deleted: branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java 2007-08-02 11:06:07 UTC (rev 152) +++ branches/jfreechart-1.0.x-branch/experimental/org/jfree/experimental/chart/axis/LogAxis.java 2007-08-03 09:30:36 UTC (rev 153) @@ -1,622 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ------------ - * LogAxis.java - * ------------ - * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * $Id: LogAxis.java,v 1.1.2.2 2007/03/22 16:39:18 mungady Exp $ - * - * Changes - * ------- - * 24-Aug-2006 : Version 1 (DG); - * 22-Mar-2007 : Use defaultAutoArrange attribute (DG); - * 12-Jul-2007 : Fixed zooming bug (DG); - * - */ - -package org.jfree.experimental.chart.axis; - -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.List; - -import org.jfree.chart.axis.AxisState; -import org.jfree.chart.axis.LogarithmicAxis; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.NumberTick; -import org.jfree.chart.axis.NumberTickUnit; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.event.AxisChangeEvent; -import org.jfree.chart.plot.Plot; -import org.jfree.chart.plot.PlotRenderingInfo; -import org.jfree.chart.plot.ValueAxisPlot; -import org.jfree.data.Range; -import org.jfree.ui.RectangleEdge; -import org.jfree.ui.TextAnchor; - -/** - * A numerical axis that uses a logarithmic scale. The plan is for this class - * to replace the {@link LogarithmicAxis} class. - * - * WARNING: THIS CLASS IS NOT PART OF THE STANDARD JFREECHART API AND IS - * SUBJECT TO ALTERATION OR REMOVAL. DO NOT RELY ON THIS CLASS FOR - * PRODUCTION USE. Please experiment with this code and provide feedback. - */ - -// TODO: support for margins that get inherited from ValueAxis -// TODO: add auto tick unit selection -// TODO: number formatting options -// TODO: write JUnit tests - -public class LogAxis extends ValueAxis { - - /** The logarithm base. */ - private double base = 10.0; - - /** The logarithm of the base value - cached for performance. */ - private double baseLog = Math.log(10.0); - - /** The smallest value permitted on the axis. */ - private double smallestValue = 1E-100; - - /** The current tick unit. */ - private NumberTickUnit tickUnit; - - /** The override number format. */ - private NumberFormat numberFormatOverride; - - /** The number of minor ticks per major tick unit. */ - private int minorTickCount; - - /** - * Creates a new <code>LogAxis</code> with no label. - */ - public LogAxis() { - this(null); - } - - /** - * Creates a new <code>LogAxis</code> with the given label. - * - * @param label the axis label (<code>null</code> permitted). - */ - public LogAxis(String label) { - super(label, NumberAxis.createIntegerTickUnits()); - setDefaultAutoRange(new Range(0.01, 1.0)); - this.tickUnit = new NumberTickUnit(1.0); - this.minorTickCount = 10; - this.setTickMarksVisible(false); - } - - /** - * Returns the base for the logarithm calculation. - * - * @return The base for the logarithm calculation. - * - * @see #setBase(double) - */ - public double getBase() { - return this.base; - } - - /** - * Sets the base for the logarithm calculation and sends an - * {@link AxisChangeEvent} to all registered listeners. - * - * @param base the base value (must be > 1.0). - * - * @see #getBase() - */ - public void setBase(double base) { - if (base <= 1.0) { - throw new IllegalArgumentException("Requires 'base' > 1.0."); - } - this.base = base; - this.baseLog = Math.log(base); - notifyListeners(new AxisChangeEvent(this)); - } - - /** - * Returns the smallest value represented by the axis. - * - * @return The smallest value represented by the axis. - * - * @see #setSmallestValue(double) - */ - public double getSmallestValue() { - return this.smallestValue; - } - - /** - * Sets the smallest value represented by the axis and sends an - * {@link AxisChangeEvent} to all registered listeners. - * - * @param value the value. - * - * @see #getSmallestValue() - */ - public void setSmallestValue(double value) { - if (value <= 0.0) { - throw new IllegalArgumentException("Requires 'value' > 0.0."); - } - this.smallestValue = value; - notifyListeners(new AxisChangeEvent(this)); - } - - /** - * Returns the current tick unit. - * - * @return The current tick unit. - * - * @see #setTickUnit(NumberTickUnit) - */ - public NumberTickUnit getTickUnit() { - return this.tickUnit; - } - - /** - * Sets the tick unit for the axis and sends an {@link AxisChangeEvent} to - * all registered listeners. A side effect of calling this method is that - * the "auto-select" feature for tick units is switched off (you can - * restore it using the {@link ValueAxis#setAutoTickUnitSelection(boolean)} - * method). - * - * @param unit the new tick unit (<code>null</code> not permitted). - * - * @see #getTickUnit() - */ - public void setTickUnit(NumberTickUnit unit) { - // defer argument checking... - setTickUnit(unit, true, true); - } - - /** - * Sets the tick unit for the axis and, if requested, sends an - * {@link AxisChangeEvent} to all registered listeners. In addition, an - * option is provided to turn off the "auto-select" feature for tick units - * (you can restore it using the - * {@link ValueAxis#setAutoTickUnitSelection(boolean)} method). - * - * @param unit the new tick unit (<code>null</code> not permitted). - * @param notify notify listeners? - * @param turnOffAutoSelect turn off the auto-tick selection? - * - * @see #getTickUnit() - */ - public void setTickUnit(NumberTickUnit unit, boolean notify, - boolean turnOffAutoSelect) { - - if (unit == null) { - throw new IllegalArgumentException("Null 'unit' argument."); - } - this.tickUnit = unit; - if (turnOffAutoSelect) { - setAutoTickUnitSelection(false, false); - } - if (notify) { - notifyListeners(new AxisChangeEvent(this)); - } - - } - - /** - * Returns the number format override. If this is non-null, then it will - * be used to format the numbers on the axis. - * - * @return The number formatter (possibly <code>null</code>). - * - * @see #setNumberFormatOverride(NumberFormat) - */ - public NumberFormat getNumberFormatOverride() { - return this.numberFormatOverride; - } - - /** - * Sets the number format override. If this is non-null, then it will be - * used to format the numbers on the axis. - * - * @param formatter the number formatter (<code>null</code> permitted). - * - * @see #getNumberFormatOverride() - */ - public void setNumberFormatOverride(NumberFormat formatter) { - this.numberFormatOverride = formatter; - notifyListeners(new AxisChangeEvent(this)); - } - - /** - * Returns the number of minor tick marks to display. - * - * @return The number of minor tick marks to display. - * - * @see #setMinorTickCount(int) - */ - public int getMinorTickCount() { - return this.minorTickCount; - } - - /** - * Sets the number of minor tick marks to display, and sends an - * {@link AxisChangeEvent} to all registered listeners. - * - * @param count the count. - * - * @see #getMinorTickCount() - */ - public void setMinorTickCount(int count) { - if (count <= 0) { - throw new IllegalArgumentException("Requires 'count' > 0."); - } - this.minorTickCount = count; - notifyListeners(new AxisChangeEvent(this)); - } - - /** - * Calculates the log of the given value, using the current base. - * - * @param value the value. - * - * @return The log of the given value. - * - * @see #calculateValue(double) - * @see #getBase() - */ - public double calculateLog(double value) { - return Math.log(value) / this.baseLog; - } - - /** - * Calculates the value from a given log. - * - * @param log the log value (must be > 0.0). - * - * @return The value with the given log. - * - * @see #calculateLog(double) - * @see #getBase() - */ - public double calculateValue(double log) { - return Math.pow(this.base, log); - } - - /** - * Converts a Java2D coordinate to an axis value, assuming that the - * axis covers the specified <code>edge</code> of the <code>area</code>. - * - * @param java2DValue the Java2D coordinate. - * @param area the area. - * @param edge the edge that the axis belongs to. - * - * @return A value along the axis scale. - */ - public double java2DToValue(double java2DValue, Rectangle2D area, - RectangleEdge edge) { - - Range range = getRange(); - double axisMin = calculateLog(range.getLowerBound()); - double axisMax = calculateLog(range.getUpperBound()); - - double min = 0.0; - double max = 0.0; - if (RectangleEdge.isTopOrBottom(edge)) { - min = area.getX(); - max = area.getMaxX(); - } - else if (RectangleEdge.isLeftOrRight(edge)) { - min = area.getMaxY(); - max = area.getY(); - } - double log = 0.0; - if (isInverted()) { - log = axisMax - (java2DValue - min) / (max - min) - * (axisMax - axisMin); - } - else { - log = axisMin + (java2DValue - min) / (max - min) - * (axisMax - axisMin); - } - return calculateValue(log); - } - - /** - * Converts a value on the axis scale to a Java2D coordinate relative to - * the given <code>area</code>, based on the axis running along the - * specified <code>edge</code>. - * - * @param value the data value. - * @param area the area. - * @param edge the edge. - * - * @return The Java2D coordinate corresponding to <code>value</code>. - */ - public double valueToJava2D(double value, Rectangle2D area, - RectangleEdge edge) { - - Range range = getRange(); - double axisMin = calculateLog(range.getLowerBound()); - double axisMax = calculateLog(range.getUpperBound()); - value = calculateLog(value); - - double min = 0.0; - double max = 0.0; - if (RectangleEdge.isTopOrBottom(edge)) { - min = area.getX(); - max = area.getMaxX(); - } - else if (RectangleEdge.isLeftOrRight(edge)) { - max = area.getMinY(); - min = area.getMaxY(); - } - if (isInverted()) { - return max - - ((value - axisMin) / (axisMax - axisMin)) * (max - min); - } - else { - return min - + ((value - axisMin) / (axisMax - axisMin)) * (max - min); - } - } - - /** - * Configures the axis. This method is typically called when an axis - * is assigned to a new plot. - */ - public void configure() { - if (isAutoRange()) { - autoAdjustRange(); - } - } - - /** - * Adjusts the axis range to match the data range that the axis is - * required to display. - */ - protected void autoAdjustRange() { - Plot plot = getPlot(); - if (plot == null) { - return; // no plot, no data - } - - if (plot instanceof ValueAxisPlot) { - ValueAxisPlot vap = (ValueAxisPlot) plot; - - Range r = vap.getDataRange(this); - if (r == null) { - r = getDefaultAutoRange(); - } - - double upper = r.getUpperBound(); - double lower = r.getLowerBound(); - double range = upper - lower; - - // if fixed auto range, then derive lower bound... - double fixedAutoRange = getFixedAutoRange(); - if (fixedAutoRange > 0.0) { - lower = Math.max(upper - fixedAutoRange, this.smallestValue); - } - else { - // ensure the autorange is at least <minRange> in size... - double minRange = getAutoRangeMinimumSize(); - if (range < minRange) { - double expand = (minRange - range) / 2; - upper = upper + expand; - lower = lower - expand; - } - - // apply the margins - these should apply to the exponent range -// upper = upper + getUpperMargin() * range; -// lower = lower - getLowerMargin() * range; - } - - setRange(new Range(lower, upper), false, false); - } - - } - - /** - * Draws the axis on a Java 2D graphics device (such as the screen or a - * printer). - * - * @param g2 the graphics device (<code>null</code> not permitted). - * @param cursor the cursor location (determines where to draw the axis). - * @param plotArea the area within which the axes and plot should be drawn. - * @param dataArea the area within which the data should be drawn. - * @param edge the axis location (<code>null</code> not permitted). - * @param plotState collects information about the plot - * (<code>null</code> permitted). - * - * @return The axis state (never <code>null</code>). - */ - public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, - Rectangle2D dataArea, RectangleEdge edge, - PlotRenderingInfo plotState) { - - AxisState state = null; - // if the axis is not visible, don't draw it... - if (!isVisible()) { - state = new AxisState(cursor); - // even though the axis is not visible, we need ticks for the - // gridlines... - List ticks = refreshTicks(g2, state, dataArea, edge); - state.setTicks(ticks); - return state; - } - state = drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge); - state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state); - return state; - } - - /** - * Calculates the positions of the tick labels for the axis, storing the - * results in the tick label list (ready for drawing). - * - * @param g2 the graphics device. - * @param state the axis state. - * @param dataArea the area in which the plot should be drawn. - * @param edge the location of the axis. - * - * @return A list of ticks. - * - */ - public List refreshTicks(Graphics2D g2, AxisState state, - Rectangle2D dataArea, RectangleEdge edge) { - - List result = new java.util.ArrayList(); - if (RectangleEdge.isTopOrBottom(edge)) { - result = refreshTicksHorizontal(g2, dataArea, edge); - } - else if (RectangleEdge.isLeftOrRight(edge)) { - result = refreshTicksVertical(g2, dataArea, edge); - } - return result; - - } - - /** - * Returns a list of ticks for an axis at the top or bottom of the chart. - * - * @param g2 the graphics device. - * @param dataArea the data area. - * @param edge the edge. - * - * @return A list of ticks. - */ - protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, - RectangleEdge edge) { - Range range = getRange(); - List ticks = new ArrayList(); - double start = Math.floor(calculateLog(getLowerBound())); - double end = Math.ceil(calculateLog(getUpperBound())); - double current = start; - while (current <= end) { - double v = calculateValue(current); - if (range.contains(v)) { - ticks.add(new NumberTick(new Double(v), createTickLabel(v), - TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); - } - // add minor ticks (for gridlines) - double next = Math.pow(this.base, current - + this.tickUnit.getSize()); - for (int i = 1; i < this.minorTickCount; i++) { - double minorV = v + i * ((next - v) / this.minorTickCount); - if (range.contains(minorV)) { - ticks.add(new NumberTick(new Double(minorV), - "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0)); - } - } - current = current + this.tickUnit.getSize(); - } - return ticks; - } - - /** - * Returns a list of ticks for an axis at the left or right of the chart. - * - * @param g2 the graphics device. - * @param dataArea the data area. - * @param edge the edge. - * - * @return A list of ticks. - */ - protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, - RectangleEdge edge) { - Range range = getRange(); - List ticks = new ArrayList(); - double start = Math.floor(calculateLog(getLowerBound())); - double end = Math.ceil(calculateLog(getUpperBound())); - double current = start; - while (current <= end) { - double v = calculateValue(current); - if (range.contains(v)) { - ticks.add(new NumberTick(new Double(v), createTickLabel(v), - TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); - } - // add minor ticks (for gridlines) - double next = Math.pow(this.base, current - + this.tickUnit.getSize()); - for (int i = 1; i < this.minorTickCount; i++) { - double minorV = v + i * ((next - v) / this.minorTickCount); - if (range.contains(minorV)) { - ticks.add(new NumberTick(new Double(minorV), "", - TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0.0)); - } - } - current = current + this.tickUnit.getSize(); - } - return ticks; - } - - /** - * Zooms in on the current range. - * - * @param lowerPercent the new lower bound. - * @param upperPercent the new upper bound. - */ - public void zoomRange(double lowerPercent, double upperPercent) { - Range range = getRange(); - double start = range.getLowerBound(); - double end = range.getUpperBound(); - double log1 = calculateLog(start); - double log2 = calculateLog(end); - double length = log2 - log1; - Range adjusted = null; - if (isInverted()) { - double logA = log1 + length * (1 - upperPercent); - double logB = log1 + length * (1 - lowerPercent); - adjusted = new Range(calculateValue(logA), calculateValue(logB)); - } - else { - double logA = log1 + length * lowerPercent; - double logB = log1 + length * upperPercent; - adjusted = new Range(calculateValue(logA), calculateValue(logB)); - } - setRange(adjusted); - } - - /** - * Creates a tick label for the specified value. - * - * @param value the value. - * - * @return The label. - */ - private String createTickLabel(double value) { - if (this.numberFormatOverride != null) { - return this.numberFormatOverride.format(value); - } - else { - return this.tickUnit.valueToString(value); - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-03 09:36:40
|
Revision: 154 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=154&view=rev Author: mungady Date: 2007-08-03 02:36:39 -0700 (Fri, 03 Aug 2007) Log Message: ----------- 2007-08-03 David Gilbert <dav...@ob...> * source/org/jfree/chart/LegendItem.java (LegendItem): Initialise GradientPaintTransformer. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/LegendItem.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 09:30:36 UTC (rev 153) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 09:36:39 UTC (rev 154) @@ -1,3 +1,8 @@ +2007-08-03 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/LegendItem.java + (LegendItem): Initialise GradientPaintTransformer. + 2007-08-02 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/axis/LogAxis.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/LegendItem.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/LegendItem.java 2007-08-03 09:30:36 UTC (rev 153) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/LegendItem.java 2007-08-03 09:36:39 UTC (rev 154) @@ -55,6 +55,7 @@ * 20-Jul-2006 : Added dataset and series index fields (DG); * 13-Dec-2006 : Added fillPaintTransformer attribute (DG); * 18-May-2007 : Added dataset and seriesKey fields (DG); + * 03-Aug-2007 : Fixed null pointer exception (DG); * */ @@ -457,6 +458,7 @@ this.shape = shape; this.shapeFilled = shapeFilled; this.fillPaint = fillPaint; + this.fillPaintTransformer = new StandardGradientPaintTransformer(); this.shapeOutlineVisible = shapeOutlineVisible; this.outlinePaint = outlinePaint; this.outlineStroke = outlineStroke; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-03 10:00:44
|
Revision: 156 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=156&view=rev Author: mungady Date: 2007-08-03 03:00:43 -0700 (Fri, 03 Aug 2007) Log Message: ----------- 2007-08-03 David Gilbert <dav...@ob...> Fix for bug 1766646: * source/org/jfree/chart/renderer/xy/XYBlockRenderer.java (findDomainBounds): Check for null, (findRangeBounds): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 09:41:48 UTC (rev 155) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 10:00:43 UTC (rev 156) @@ -1,5 +1,12 @@ 2007-08-03 David Gilbert <dav...@ob...> + Fix for bug 1766646: + * source/org/jfree/chart/renderer/xy/XYBlockRenderer.java + (findDomainBounds): Check for null, + (findRangeBounds): Likewise. + +2007-08-03 David Gilbert <dav...@ob...> + * source/org/jfree/chart/LegendItem.java (LegendItem): Initialise GradientPaintTransformer. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java 2007-08-03 09:41:48 UTC (rev 155) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java 2007-08-03 10:00:43 UTC (rev 156) @@ -39,6 +39,7 @@ * 05-Jul-2006 : Version 1 (DG); * 02-Feb-2007 : Added getPaintScale() method (DG); * 09-Mar-2007 : Fixed cloning (DG); + * 03-Aug-2007 : Fix for bug 1766646 (DG); * */ @@ -276,12 +277,19 @@ * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). + * + * @see #findRangeBounds(XYDataset) */ public Range findDomainBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findDomainBounds(dataset, false); - return new Range(r.getLowerBound() + this.xOffset, - r.getUpperBound() + this.blockWidth + this.xOffset); + if (r == null) { + return null; + } + else { + return new Range(r.getLowerBound() + this.xOffset, + r.getUpperBound() + this.blockWidth + this.xOffset); + } } else { return null; @@ -296,12 +304,19 @@ * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). + * + * @see #findDomainBounds(XYDataset) */ public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findRangeBounds(dataset, false); - return new Range(r.getLowerBound() + this.yOffset, - r.getUpperBound() + this.blockHeight + this.yOffset); + if (r == null) { + return null; + } + else { + return new Range(r.getLowerBound() + this.yOffset, + r.getUpperBound() + this.blockHeight + this.yOffset); + } } else { return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-03 10:37:10
|
Revision: 160 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=160&view=rev Author: mungady Date: 2007-08-03 03:37:04 -0700 (Fri, 03 Aug 2007) Log Message: ----------- 2007-08-03 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java (precision): Initialise in constructor, (XYSplineAndShapeRenderer()): Change default precision to 5, (XYSplineAndShapeRenderer(int)): New constructor. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 10:05:04 UTC (rev 159) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-03 10:37:04 UTC (rev 160) @@ -1,5 +1,13 @@ + 2007-08-03 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java + (precision): Initialise in constructor, + (XYSplineAndShapeRenderer()): Change default precision to 5, + (XYSplineAndShapeRenderer(int)): New constructor. + +2007-08-03 David Gilbert <dav...@ob...> + Fix for bug 1766646: * source/org/jfree/chart/renderer/xy/XYBlockRenderer.java (findDomainBounds): Check for null, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java 2007-08-03 10:05:04 UTC (rev 159) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java 2007-08-03 10:37:04 UTC (rev 160) @@ -34,11 +34,10 @@ * http://www.wam.umd.edu/~petersd/); * David Gilbert (for Object Refinery Limited); * - * $Id: XYLineAndShapeRenderer.java,v 1.20.2.13 2007/06/08 13:29:38 mungady Exp $ - * * Changes: * -------- * 25-Jul-2007 : Version 1, contributed by Klaus Rheinwald (DG); + * 03-Aug-2007 : Added new constructor (KR); * */ @@ -75,16 +74,28 @@ /** * Resolution of splines (number of line segments between points) */ - private int precision = 10; + private int precision; /** * Creates a new instance with the 'precision' attribute defaulting to - * 10. + * 5. */ public XYSplineAndShapeRenderer() { + this(5); + } + + /** + * Creates a new renderer with the specified precision. + * + * @param precision the number of points between data items. + */ + public XYSplineAndShapeRenderer(int precision) { super(); - this.precision = 10; - } + if (precision <= 0) { + throw new IllegalArgumentException("Requires precision > 0."); + } + this.precision = precision; + } /** * Get the resolution of splines. @@ -113,7 +124,6 @@ notifyListeners(new RendererChangeEvent(this)); } - /** * Initialises the renderer. * <P> @@ -188,7 +198,8 @@ ControlPoint cp0 = (ControlPoint) this.points.get(0); s.seriesPath.moveTo(cp0.x, cp0.y); if (this.points.size() == 2) { - // we need at least 3 points to spline. Draw simple line for two points + // we need at least 3 points to spline. Draw simple line + // for two points ControlPoint cp1 = (ControlPoint) this.points.get(1); s.seriesPath.lineTo(cp1.x, cp1.y); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-28 11:31:36
|
Revision: 163 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=163&view=rev Author: mungady Date: 2007-08-28 04:31:32 -0700 (Tue, 28 Aug 2007) Log Message: ----------- 2007-08-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java (drawHorizontalItem): Check for null data items, (drawVerticalItem): Likewise, * tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java (testDrawWithNullMeanVertical): New test method, (testDrawWithNullMeanHorizontal): Likewise, (testDrawWithNullDeviationVertical): Likewise, (testDrawWithNullDeviationHorizontal): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-27 10:36:34 UTC (rev 162) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-28 11:31:32 UTC (rev 163) @@ -1,4 +1,14 @@ +2007-08-28 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java + (drawHorizontalItem): Check for null data items, + (drawVerticalItem): Likewise, + * tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java + (testDrawWithNullMeanVertical): New test method, + (testDrawWithNullMeanHorizontal): Likewise, + (testDrawWithNullDeviationVertical): Likewise, + (testDrawWithNullDeviationHorizontal): Likewise. + 2007-08-03 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java 2007-08-27 10:36:34 UTC (rev 162) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java 2007-08-28 11:31:32 UTC (rev 163) @@ -51,7 +51,8 @@ * 19-May-2006 : Added support for tooltips and URLs (DG); * 12-Jul-2006 : Added support for item labels (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); - * + * 28-Aug-2007 : Fixed NullPointerException - see bug 1779941 (DG); + * */ package org.jfree.chart.renderer.category; @@ -108,6 +109,8 @@ * * @return The paint used for the error indicators (possibly * <code>null</code>). + * + * @see #setErrorIndicatorPaint(Paint) */ public Paint getErrorIndicatorPaint() { return this.errorIndicatorPaint; @@ -118,6 +121,8 @@ * the item outline paint is used instead) * * @param paint the paint (<code>null</code> permitted). + * + * @see #getErrorIndicatorPaint() */ public void setErrorIndicatorPaint(Paint paint) { this.errorIndicatorPaint = paint; @@ -210,7 +215,9 @@ // BAR X Number meanValue = dataset.getMeanValue(row, column); - + if (meanValue == null) { + return; + } double value = meanValue.doubleValue(); double base = 0.0; double lclip = getLowerClip(); @@ -266,34 +273,37 @@ } // standard deviation lines - double valueDelta = dataset.getStdDevValue(row, column).doubleValue(); - double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - + valueDelta, dataArea, yAxisLocation); - double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - - valueDelta, dataArea, yAxisLocation); + Number n = dataset.getStdDevValue(row, column); + if (n != null) { + double valueDelta = n.doubleValue(); + double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + + valueDelta, dataArea, yAxisLocation); + double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + - valueDelta, dataArea, yAxisLocation); - if (this.errorIndicatorPaint != null) { - g2.setPaint(this.errorIndicatorPaint); + if (this.errorIndicatorPaint != null) { + g2.setPaint(this.errorIndicatorPaint); + } + else { + g2.setPaint(getItemOutlinePaint(row, column)); + } + Line2D line = null; + line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, + highVal, rectY + rectHeight / 2.0d); + g2.draw(line); + line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, + highVal, rectY + rectHeight * 0.75); + g2.draw(line); + line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, + lowVal, rectY + rectHeight * 0.75); + g2.draw(line); } - else { - g2.setPaint(getItemOutlinePaint(row, column)); - } - Line2D line = null; - line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, - highVal, rectY + rectHeight / 2.0d); - g2.draw(line); - line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, - highVal, rectY + rectHeight * 0.75); - g2.draw(line); - line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, - lowVal, rectY + rectHeight * 0.75); - g2.draw(line); CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, - (value < 0.0)); + (value < 0.0)); } // add an item entity, if this information is being collected @@ -347,6 +357,9 @@ // BAR Y Number meanValue = dataset.getMeanValue(row, column); + if (meanValue == null) { + return; + } double value = meanValue.doubleValue(); double base = 0.0; @@ -403,34 +416,37 @@ } // standard deviation lines - double valueDelta = dataset.getStdDevValue(row, column).doubleValue(); - double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - + valueDelta, dataArea, yAxisLocation); - double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - - valueDelta, dataArea, yAxisLocation); + Number n = dataset.getStdDevValue(row, column); + if (n != null) { + double valueDelta = n.doubleValue(); + double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + + valueDelta, dataArea, yAxisLocation); + double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + - valueDelta, dataArea, yAxisLocation); - if (this.errorIndicatorPaint != null) { - g2.setPaint(this.errorIndicatorPaint); + if (this.errorIndicatorPaint != null) { + g2.setPaint(this.errorIndicatorPaint); + } + else { + g2.setPaint(getItemOutlinePaint(row, column)); + } + Line2D line = null; + line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, + rectX + rectWidth / 2.0d, highVal); + g2.draw(line); + line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, + rectX + rectWidth / 2.0d + 5.0d, highVal); + g2.draw(line); + line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, + rectX + rectWidth / 2.0d + 5.0d, lowVal); + g2.draw(line); } - else { - g2.setPaint(getItemOutlinePaint(row, column)); - } - Line2D line = null; - line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, - rectX + rectWidth / 2.0d, highVal); - g2.draw(line); - line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, - rectX + rectWidth / 2.0d + 5.0d, highVal); - g2.draw(line); - line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, - rectX + rectWidth / 2.0d + 5.0d, lowVal); - g2.draw(line); CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, - (value < 0.0)); + (value < 0.0)); } // add an item entity, if this information is being collected Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java 2007-08-27 10:36:34 UTC (rev 162) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/category/junit/StatisticalBarRendererTests.java 2007-08-28 11:31:32 UTC (rev 163) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------------- * StatisticalBarRendererTests.java * -------------------------------- - * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,6 +37,7 @@ * Changes * ------- * 25-Mar-2003 : Version 1 (DG); + * 28-Aug-2007 : Added tests for bug 1779941 (DG); * */ @@ -58,6 +59,7 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.StatisticalBarRenderer; import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; @@ -120,7 +122,7 @@ r2 = (StatisticalBarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { - System.err.println("Failed to clone."); + e.printStackTrace(); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); @@ -141,14 +143,13 @@ out.writeObject(r1); out.close(); - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); r2 = (StatisticalBarRenderer) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(r1, r2); @@ -162,7 +163,7 @@ boolean success = false; try { DefaultStatisticalCategoryDataset dataset - = new DefaultStatisticalCategoryDataset(); + = new DefaultStatisticalCategoryDataset(); dataset.add(1.0, 2.0, "S1", "C1"); dataset.add(3.0, 4.0, "S1", "C2"); CategoryPlot plot = new CategoryPlot(dataset, @@ -180,4 +181,114 @@ assertTrue(success); } + /** + * Draws the chart with a <code>null</code> mean value to make sure that + * no exceptions are thrown (particularly by code in the renderer). See + * bug report 1779941. + */ + public void testDrawWithNullMeanVertical() { + boolean success = false; + try { + DefaultStatisticalCategoryDataset dataset + = new DefaultStatisticalCategoryDataset(); + dataset.add(1.0, 2.0, "S1", "C1"); + dataset.add(null, new Double(4.0), "S1", "C2"); + CategoryPlot plot = new CategoryPlot(dataset, + new CategoryAxis("Category"), new NumberAxis("Value"), + new StatisticalBarRenderer()); + JFreeChart chart = new JFreeChart(plot); + /* BufferedImage image = */ chart.createBufferedImage(300, 200, + null); + success = true; + } + catch (NullPointerException e) { + e.printStackTrace(); + success = false; + } + assertTrue(success); + } + + /** + * Draws the chart with a <code>null</code> mean value to make sure that + * no exceptions are thrown (particularly by code in the renderer). See + * bug report 1779941. + */ + public void testDrawWithNullMeanHorizontal() { + boolean success = false; + try { + DefaultStatisticalCategoryDataset dataset + = new DefaultStatisticalCategoryDataset(); + dataset.add(1.0, 2.0, "S1", "C1"); + dataset.add(null, new Double(4.0), "S1", "C2"); + CategoryPlot plot = new CategoryPlot(dataset, + new CategoryAxis("Category"), new NumberAxis("Value"), + new StatisticalBarRenderer()); + plot.setOrientation(PlotOrientation.HORIZONTAL); + JFreeChart chart = new JFreeChart(plot); + /* BufferedImage image = */ chart.createBufferedImage(300, 200, + null); + success = true; + } + catch (NullPointerException e) { + e.printStackTrace(); + success = false; + } + assertTrue(success); + } + + /** + * Draws the chart with a <code>null</code> standard deviation to make sure + * that no exceptions are thrown (particularly by code in the renderer). + * See bug report 1779941. + */ + public void testDrawWithNullDeviationVertical() { + boolean success = false; + try { + DefaultStatisticalCategoryDataset dataset + = new DefaultStatisticalCategoryDataset(); + dataset.add(1.0, 2.0, "S1", "C1"); + dataset.add(new Double(4.0), null, "S1", "C2"); + CategoryPlot plot = new CategoryPlot(dataset, + new CategoryAxis("Category"), new NumberAxis("Value"), + new StatisticalBarRenderer()); + JFreeChart chart = new JFreeChart(plot); + /* BufferedImage image = */ chart.createBufferedImage(300, 200, + null); + success = true; + } + catch (NullPointerException e) { + e.printStackTrace(); + success = false; + } + assertTrue(success); + } + + /** + * Draws the chart with a <code>null</code> standard deviation to make sure + * that no exceptions are thrown (particularly by code in the renderer). + * See bug report 1779941. + */ + public void testDrawWithNullDeviationHorizontal() { + boolean success = false; + try { + DefaultStatisticalCategoryDataset dataset + = new DefaultStatisticalCategoryDataset(); + dataset.add(1.0, 2.0, "S1", "C1"); + dataset.add(new Double(4.0), null, "S1", "C2"); + CategoryPlot plot = new CategoryPlot(dataset, + new CategoryAxis("Category"), new NumberAxis("Value"), + new StatisticalBarRenderer()); + plot.setOrientation(PlotOrientation.HORIZONTAL); + JFreeChart chart = new JFreeChart(plot); + /* BufferedImage image = */ chart.createBufferedImage(300, 200, + null); + success = true; + } + catch (NullPointerException e) { + e.printStackTrace(); + success = false; + } + assertTrue(success); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-28 21:18:22
|
Revision: 165 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=165&view=rev Author: mungady Date: 2007-08-28 08:55:23 -0700 (Tue, 28 Aug 2007) Log Message: ----------- 2007-08-28 David Gilbert <dav...@ob...> * source/org/jfree/data/time/Week.java (Week(Date, TimeZone)): Deprecated, (Week(Date, TimeZone, Locale)): New constructor, * tests/org/jfree/data/time/junit/WeekTests.java (testConstructor): New test. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-28 15:55:23 UTC (rev 165) @@ -1,5 +1,13 @@ 2007-08-28 David Gilbert <dav...@ob...> + * source/org/jfree/data/time/Week.java + (Week(Date, TimeZone)): Deprecated, + (Week(Date, TimeZone, Locale)): New constructor, + * tests/org/jfree/data/time/junit/WeekTests.java + (testConstructor): New test. + +2007-08-28 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java (drawHorizontalItem): Check for null data items, (drawVerticalItem): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java 2007-08-28 15:55:23 UTC (rev 165) @@ -65,6 +65,8 @@ * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 09-Jan-2007 : Fixed bug in next() (DG); + * 28-Aug-2007 : Added new constructor to avoid problem in creating new + * instances (DG); * */ @@ -73,6 +75,7 @@ import java.io.Serializable; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; /** @@ -156,7 +159,7 @@ */ public Week(Date time) { // defer argument checking... - this(time, RegularTimePeriod.DEFAULT_TIME_ZONE); + this(time, RegularTimePeriod.DEFAULT_TIME_ZONE, Locale.getDefault()); } /** @@ -165,15 +168,35 @@ * * @param time the date/time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). + * + * @deprecated As of 1.0.7, use {@link #Week(Date, TimeZone, Locale)}. */ public Week(Date time, TimeZone zone) { + // defer argument checking... + this(time, RegularTimePeriod.DEFAULT_TIME_ZONE, Locale.getDefault()); + } + + /** + * Creates a time period for the week in which the specified date/time + * falls, calculated relative to the specified time zone. + * + * @param time the date/time (<code>null</code> not permitted). + * @param zone the time zone (<code>null</code> not permitted). + * @param locale the locale (<code>null</code> not permitted). + * + * @since 1.0.7 + */ + public Week(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } - Calendar calendar = Calendar.getInstance(zone); + if (locale == null) { + throw new IllegalArgumentException("Null 'locale' argument."); + } + Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); // sometimes the last few days of the year are considered to fall in @@ -197,7 +220,6 @@ this.year = (short) yyyy; } peg(calendar); - } /** @@ -522,8 +544,7 @@ w = Week.stringToWeek(s2); if (w == -1) { throw new TimePeriodFormatException( - "Can't evaluate the week." - ); + "Can't evaluate the week."); } result = new Week(w, y); } @@ -533,23 +554,20 @@ w = Week.stringToWeek(s1); if (w == -1) { throw new TimePeriodFormatException( - "Can't evaluate the week." - ); + "Can't evaluate the week."); } result = new Week(w, y); } else { throw new TimePeriodFormatException( - "Can't evaluate the year." - ); + "Can't evaluate the year."); } } } else { throw new TimePeriodFormatException( - "Could not find separator." - ); + "Could not find separator."); } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-08-28 15:55:23 UTC (rev 165) @@ -44,6 +44,7 @@ * 06-Apr-2006 : Added testBug1448828() method (DG); * 01-Jun-2006 : Added testBug1498805() method (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); + * 28-Aug-2007 : Added test for constructor problem (DG); * */ @@ -185,7 +186,7 @@ in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(w1, w2); @@ -463,4 +464,42 @@ Locale.setDefault(saved); } + /** + * A test for a problem in constructing a new Week instance. + */ + public void testConstructor() { + Locale savedLocale = Locale.getDefault(); + TimeZone savedZone = TimeZone.getDefault(); + Locale.setDefault(new Locale("da", "DK")); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); + GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance( + TimeZone.getDefault(), Locale.getDefault()); + + // first day of week is monday + assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); + cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + Date t = cal.getTime(); + Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); + assertEquals(34, w.getWeek()); + + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); + cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); + // first day of week is Sunday + assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); + cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + + t = cal.getTime(); + w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); + assertEquals(35, w.getWeek()); + w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), + new Locale("da", "DK")); + assertEquals(34, w.getWeek()); + + Locale.setDefault(savedLocale); + TimeZone.setDefault(savedZone); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-21 09:50:32
|
Revision: 168 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=168&view=rev Author: mungady Date: 2007-09-21 02:50:30 -0700 (Fri, 21 Sep 2007) Log Message: ----------- 2007-09-21 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/SimpleHistogramDataset.java: API doc updates. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-11 17:48:41 UTC (rev 167) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-21 09:50:30 UTC (rev 168) @@ -1,3 +1,8 @@ +2007-09-21 David Gilbert <dav...@ob...> + + * source/org/jfree/data/statistics/SimpleHistogramDataset.java: + API doc updates. + 2007-08-28 David Gilbert <dav...@ob...> * source/org/jfree/data/time/Week.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java 2007-09-11 17:48:41 UTC (rev 167) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/SimpleHistogramDataset.java 2007-09-21 09:50:30 UTC (rev 168) @@ -83,7 +83,8 @@ private boolean adjustForBinSize; /** - * Creates a new histogram dataset. + * Creates a new histogram dataset. Note that the + * <code>adjustForBinSize</code> flag defaults to <code>true</code>. * * @param key the series key (<code>null</code> not permitted). */ @@ -101,6 +102,8 @@ * the bin size in the {@link #getXValue(int, int)} method. * * @return A boolean. + * + * @see #setAdjustForBinSize(boolean) */ public boolean getAdjustForBinSize() { return this.adjustForBinSize; @@ -108,9 +111,12 @@ /** * Sets the flag that controls whether or not the bin count is divided by - * the bin size in the {@link #getXValue(int, int)} method. + * the bin size in the {@link #getYValue(int, int)} method, and sends a + * {@link DatasetChangeEvent} to all registered listeners. * * @param adjust the flag. + * + * @see #getAdjustForBinSize() */ public void setAdjustForBinSize(boolean adjust) { this.adjustForBinSize = adjust; @@ -127,7 +133,8 @@ } /** - * Returns the key for a series. + * Returns the key for a series. Since this dataset only stores a single + * series, the <code>series</code> argument is ignored. * * @param series the series (zero-based index, ignored in this dataset). * @@ -147,7 +154,8 @@ } /** - * Returns the number of items in a series. + * Returns the number of items in a series. Since this dataset only stores + * a single series, the <code>series</code> argument is ignored. * * @param series the series index (zero-based, ignored in this dataset). * @@ -162,13 +170,15 @@ * with any existing bin in the dataset. * * @param bin the bin (<code>null</code> not permitted). + * + * @see #removeAllBins() */ public void addBin(SimpleHistogramBin bin) { // check that the new bin doesn't overlap with any existing bin Iterator iterator = this.bins.iterator(); while (iterator.hasNext()) { SimpleHistogramBin existingBin - = (SimpleHistogramBin) iterator.next(); + = (SimpleHistogramBin) iterator.next(); if (bin.overlapsWith(existingBin)) { throw new RuntimeException("Overlapping bin"); } @@ -215,9 +225,12 @@ } /** - * Adds a set of values to the dataset. + * Adds a set of values to the dataset and sends a + * {@link DatasetChangeEvent} to all registered listeners. * * @param values the values (<code>null</code> not permitted). + * + * @see #clearObservations() */ public void addObservations(double[] values) { for (int i = 0; i < values.length; i++) { @@ -231,6 +244,9 @@ * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.6 + * + * @see #addObservations(double[]) + * @see #removeAllBins() */ public void clearObservations() { Iterator iterator = this.bins.iterator(); @@ -246,6 +262,8 @@ * registered listeners. * * @since 1.0.6 + * + * @see #addBin(SimpleHistogramBin) */ public void removeAllBins() { this.bins = new ArrayList(); @@ -298,6 +316,8 @@ * @param item the item index (zero-based). * * @return The y-value. + * + * @see #getAdjustForBinSize() */ public double getYValue(int series, int item) { SimpleHistogramBin bin = (SimpleHistogramBin) this.bins.get(item); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-24 12:41:12
|
Revision: 171 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=171&view=rev Author: mungady Date: 2007-09-24 05:41:09 -0700 (Mon, 24 Sep 2007) Log Message: ----------- 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartPanel.java (zoomAroundAnchor): New field, (getZoomAroundAnchor): New method, (setZoomAroundAnchor): Likewise, (zoomInDomain): Use zoomAroundAnchor flag, (zoomInRange): Likewise, (zoomOutDomain): Likewise, (zoomOutRange): Likewise, * source/org/jfree/chart/plot/CategoryPlot.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D)): Delegate to new method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, * source/org/jfree/chart/plot/FastScatterPlot.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, * source/org/jfree/chart/PolarPlot.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, * source/org/jfree/chart/ThermometerPlot.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, * source/org/jfree/chart/XYPlot.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomDomainAxes(double, PlotRenderingInfo, Point2D)): Delegate to new method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D)): Delegate to new method, * source/org/jfree/chart/plot/Zoomable.java (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/FastScatterPlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Zoomable.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 12:41:09 UTC (rev 171) @@ -1,3 +1,36 @@ +2007-09-24 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/ChartPanel.java + (zoomAroundAnchor): New field, + (getZoomAroundAnchor): New method, + (setZoomAroundAnchor): Likewise, + (zoomInDomain): Use zoomAroundAnchor flag, + (zoomInRange): Likewise, + (zoomOutDomain): Likewise, + (zoomOutRange): Likewise, + * source/org/jfree/chart/plot/CategoryPlot.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D)): Delegate to new method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + * source/org/jfree/chart/plot/FastScatterPlot.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, + * source/org/jfree/chart/PolarPlot.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, + * source/org/jfree/chart/ThermometerPlot.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise, + * source/org/jfree/chart/XYPlot.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomDomainAxes(double, PlotRenderingInfo, Point2D)): Delegate to new + method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D)): Delegate to new method, + * source/org/jfree/chart/plot/Zoomable.java + (zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)): New method, + (zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean)): Likewise. + 2007-09-21 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/SimpleHistogramDataset.java: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2007-09-24 12:41:09 UTC (rev 171) @@ -134,6 +134,7 @@ * 24-May-2007 : When the look-and-feel changes, update the popup menu if there * is one (DG); * 06-Jun-2007 : Fixed coordinates for drawing buffer image (DG); + * 24-Sep-2007 : Added zoomAroundAnchor flag (DG); * */ @@ -422,6 +423,14 @@ /** The factor used to zoom out on an axis range. */ private double zoomOutFactor = 2.0; + /** + * A flag that controls whether zoom operations are centred on the + * current anchor point, or the centre point of the relevant axis. + * + * @since 1.0.7 + */ + private boolean zoomAroundAnchor; + /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle"); @@ -587,6 +596,7 @@ this.ownToolTipDismissDelay = ttm.getDismissDelay(); this.ownToolTipReshowDelay = ttm.getReshowDelay(); + this.zoomAroundAnchor = false; } /** @@ -1018,6 +1028,34 @@ public void setEnforceFileExtensions(boolean enforce) { this.enforceFileExtensions = enforce; } + + /** + * Returns the flag that controls whether or not zoom operations are + * centered around the current anchor point. + * + * @return A boolean. + * + * @since 1.0.7 + * + * @see #setZoomAroundAnchor(boolean) + */ + public boolean getZoomAroundAnchor() { + return this.zoomAroundAnchor; + } + + /** + * Sets the flag that controls whether or not zoom operations are + * centered around the current anchor point. + * + * @param zoomAroundAnchor the new flag value. + * + * @since 1.0.7 + * + * @see #getZoomAroundAnchor() + */ + public void setZoomAroundAnchor(boolean zoomAroundAnchor) { + this.zoomAroundAnchor = zoomAroundAnchor; + } /** * Switches the display of tooltips for the panel on or off. Note that @@ -1077,9 +1115,10 @@ } /** - * Translates a screen location to a Java2D point. + * Translates a panel (component) location to a Java2D point. * - * @param screenPoint the screen location. + * @param screenPoint the screen location (<code>null</code> not + * permitted). * * @return The Java2D coordinates. */ @@ -1711,7 +1750,8 @@ if (p instanceof Zoomable) { Zoomable plot = (Zoomable) p; plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(), - translateScreenToJava2D(new Point((int) x, (int) y))); + translateScreenToJava2D(new Point((int) x, (int) y)), + this.zoomAroundAnchor); } } @@ -1728,7 +1768,8 @@ if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(), - translateScreenToJava2D(new Point((int) x, (int) y))); + translateScreenToJava2D(new Point((int) x, (int) y)), + this.zoomAroundAnchor); } } @@ -1756,7 +1797,8 @@ if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(), - translateScreenToJava2D(new Point((int) x, (int) y))); + translateScreenToJava2D(new Point((int) x, (int) y)), + this.zoomAroundAnchor); } } @@ -1773,7 +1815,8 @@ if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(), - translateScreenToJava2D(new Point((int) x, (int) y))); + translateScreenToJava2D(new Point((int) x, (int) y)), + this.zoomAroundAnchor); } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/axis/ValueAxis.java 2007-09-24 12:41:09 UTC (rev 171) @@ -1485,6 +1485,8 @@ * To halve the length of the axis range, use 50% (0.5). * * @param percent the resize factor. + * + * @see #resizeRange(double, double) */ public void resizeRange(double percent) { resizeRange(percent, this.range.getCentralValue()); @@ -1500,6 +1502,8 @@ * * @param percent the resize factor. * @param anchorValue the new central value after the resize. + * + * @see #resizeRange(double) */ public void resizeRange(double percent, double anchorValue) { if (percent > 0.0) { Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/CategoryPlot.java 2007-09-24 12:41:09 UTC (rev 171) @@ -149,6 +149,7 @@ * annotations (DG); * 07-Jun-2007 : Override drawBackground() for new GradientPaint handling (DG); * 10-Jul-2007 : Added getRangeAxisIndex(ValueAxis) method (DG); + * 24-Sep-2007 : Implemented new zoom methods (DG); * */ @@ -217,11 +218,9 @@ * A general plotting class that uses data from a {@link CategoryDataset} and * renders each data item using a {@link CategoryItemRenderer}. */ -public class CategoryPlot extends Plot - implements ValueAxisPlot, - Zoomable, - RendererChangeListener, - Cloneable, PublicCloneable, Serializable { +public class CategoryPlot extends Plot implements ValueAxisPlot, + Zoomable, RendererChangeListener, Cloneable, PublicCloneable, + Serializable { /** For serialization. */ private static final long serialVersionUID = -3537691700434728188L; @@ -240,18 +239,15 @@ /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_BEVEL, - 0.0f, - new float[] {2.0f, 2.0f}, - 0.0f); + BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] + {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.lightGray; /** The default value label font. */ - public static final Font DEFAULT_VALUE_LABEL_FONT - = new Font("SansSerif", Font.PLAIN, 10); + public static final Font DEFAULT_VALUE_LABEL_FONT = new Font("SansSerif", + Font.PLAIN, 10); /** * The default crosshair visibility. @@ -277,7 +273,8 @@ /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources - = ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle"); + = ResourceBundle.getBundle( + "org.jfree.chart.plot.LocalizationBundle"); /** The plot orientation. */ private PlotOrientation orientation; @@ -3365,6 +3362,24 @@ PlotRenderingInfo state, Point2D source) { // can't zoom domain axis } + + /** + * This method does nothing, because <code>CategoryPlot</code> doesn't + * support zooming on the domain. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point (in Java2D space). + * @param useAnchor use source point as zoom anchor? + * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + // can't zoom domain axis + } /** * Multiplies the range on the range axis/axes by the specified factor. @@ -3375,10 +3390,44 @@ */ public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source) { + // delegate to other method + zoomRangeAxes(factor, state, source, false); + } + + /** + * Multiplies the range on the range axis/axes by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point. + * @param useAnchor a flag that controls whether or not the source point + * is used for the zoom anchor. + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + // perform the zoom on each range axis for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = (ValueAxis) this.rangeAxes.get(i); if (rangeAxis != null) { - rangeAxis.resizeRange(factor); + if (useAnchor) { + // get the relevant source coordinate given the plot + // orientation + double sourceY = source.getY(); + if (this.orientation == PlotOrientation.HORIZONTAL) { + sourceY = source.getX(); + } + double anchorY = rangeAxis.java2DToValue(sourceY, + info.getDataArea(), getRangeAxisEdge()); + rangeAxis.resizeRange(factor, anchorY); + } + else { + rangeAxis.resizeRange(factor); + } } } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/FastScatterPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/FastScatterPlot.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/FastScatterPlot.java 2007-09-24 12:41:09 UTC (rev 171) @@ -56,6 +56,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 10-Nov-2006 : Fixed bug 1593150, by not allowing null axes, and added * setDomainAxis() and setRangeAxis() methods (DG); + * 24-Sep-2007 : Implemented new zooming methods (DG); * */ @@ -98,19 +99,15 @@ * A fast scatter plot. */ public class FastScatterPlot extends Plot implements ValueAxisPlot, - Zoomable, - Cloneable, Serializable { + Zoomable, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 7871545897358563521L; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_BEVEL, - 0.0f, - new float[] {2.0f, 2.0f}, - 0.0f); + BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] + {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.lightGray; @@ -153,7 +150,8 @@ /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = - ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle"); + ResourceBundle.getBundle( + "org.jfree.chart.plot.LocalizationBundle"); /** * Creates a new instance of <code>FastScatterPlot</code> with default @@ -752,7 +750,7 @@ } /** - * Multiplies the range on the domain axis/axes by the specified factor. + * Multiplies the range on the domain axis by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. @@ -762,6 +760,35 @@ Point2D source) { this.domainAxis.resizeRange(factor); } + + /** + * Multiplies the range on the domain axis by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point (in Java2D space). + * @param useAnchor use source point as zoom anchor? + * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + if (useAnchor) { + // get the source coordinate - this plot has always a VERTICAL + // orientation + double sourceX = source.getX(); + double anchorX = this.domainAxis.java2DToValue(sourceX, + info.getDataArea(), RectangleEdge.BOTTOM); + this.domainAxis.resizeRange(factor, anchorX); + } + else { + this.domainAxis.resizeRange(factor); + } + + } /** * Zooms in on the domain axes. @@ -791,6 +818,35 @@ } /** + * Multiplies the range on the range axis by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point (in Java2D space). + * @param useAnchor use source point as zoom anchor? + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + if (useAnchor) { + // get the source coordinate - this plot has always a VERTICAL + // orientation + double sourceX = source.getX(); + double anchorX = this.rangeAxis.java2DToValue(sourceX, + info.getDataArea(), RectangleEdge.LEFT); + this.rangeAxis.resizeRange(factor, anchorX); + } + else { + this.rangeAxis.resizeRange(factor); + } + + } + + /** * Zooms in on the range axes. * * @param lowerPercent the new lower bound as a percentage of the current Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java 2007-09-24 12:41:09 UTC (rev 171) @@ -44,6 +44,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 07-Feb-2007 : Fixed bug 1599761, data value less than axis minimum (DG); * 21-Mar-2007 : Fixed serialization bug (DG); + * 24-Sep-2007 : Implemented new zooming methods (DG); * */ @@ -98,11 +99,8 @@ * Plots data that is in (theta, radius) pairs where * theta equal to zero is due north and increases clockwise. */ -public class PolarPlot extends Plot implements ValueAxisPlot, - Zoomable, - RendererChangeListener, - Cloneable, - Serializable { +public class PolarPlot extends Plot implements ValueAxisPlot, Zoomable, + RendererChangeListener, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 3794383185924179525L; @@ -1087,7 +1085,23 @@ /** * This method is required by the {@link Zoomable} interface, but since * the plot does not have any domain axes, it does nothing. + * + * @param factor the zoom factor. + * @param state the plot state. + * @param source the source point (in Java2D coordinates). + * @param useAnchor use source point as zoom anchor? * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo state, + Point2D source, boolean useAnchor) { + // do nothing + } + + /** + * This method is required by the {@link Zoomable} interface, but since + * the plot does not have any domain axes, it does nothing. + * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. @@ -1097,7 +1111,7 @@ PlotRenderingInfo state, Point2D source) { // do nothing } - + /** * Multiplies the range on the range axis/axes by the specified factor. * @@ -1111,6 +1125,35 @@ } /** + * Multiplies the range on the range axis by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point (in Java2D space). + * @param useAnchor use source point as zoom anchor? + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + if (useAnchor) { + // get the source coordinate - this plot has always a VERTICAL + // orientation + double sourceX = source.getX(); + double anchorX = this.axis.java2DToValue(sourceX, + info.getDataArea(), RectangleEdge.BOTTOM); + this.axis.resizeRange(factor, anchorX); + } + else { + axis.resizeRange(factor); + } + + } + + /** * Zooms in on the range axes. * * @param lowerPercent the new lower bound. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/ThermometerPlot.java 2007-09-24 12:41:09 UTC (rev 171) @@ -81,6 +81,7 @@ * deprecated get/setShowValueLines(), deprecated * getMinimum/MaximumVerticalDataValue(), and fixed serialization * bug (DG); + * 24-Sep-2007 : Implemented new methods in Zoomable interface (DG); * */ @@ -1530,6 +1531,22 @@ } /** + * Multiplies the range on the domain axis/axes by the specified factor. + * + * @param factor the zoom factor. + * @param state the plot state. + * @param source the source point. + * @param useAnchor a flag that controls whether or not the source point + * is used for the zoom anchor. + * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo state, + Point2D source, boolean useAnchor) { + // no domain axis to zoom + } + + /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. @@ -1542,6 +1559,24 @@ } /** + * Multiplies the range on the range axis/axes by the specified factor. + * + * @param factor the zoom factor. + * @param state the plot state. + * @param source the source point. + * @param useAnchor a flag that controls whether or not the source point + * is used for the zoom anchor. + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo state, + Point2D source, boolean useAnchor) { + double anchorY = this.getRangeAxis().java2DToValue(source.getY(), + state.getDataArea(), RectangleEdge.LEFT); + this.rangeAxis.resizeRange(factor, anchorY); + } + + /** * This method does nothing. * * @param lowerPercent the lower percent. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/XYPlot.java 2007-09-24 12:41:09 UTC (rev 171) @@ -187,6 +187,7 @@ * 24-May-2007 : Fixed bug in render method for an empty series (DG); * 07-Jun-2007 : Modified drawBackground() to pass orientation to * fillBackground() for handling GradientPaint (DG); + * 24-Sep-2007 : Added new zoom methods (DG); * */ @@ -4172,14 +4173,49 @@ * * @param factor the zoom factor. * @param info the plot rendering info. - * @param source the source point. + * @param source the source point (in Java2D space). + * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source) { + // delegate to other method + zoomDomainAxes(factor, info, source, false); + } + + /** + * Multiplies the range on the domain axis/axes by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point (in Java2D space). + * @param useAnchor use source point as zoom anchor? + * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + // perform the zoom on each domain axis for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis domainAxis = (ValueAxis) this.domainAxes.get(i); if (domainAxis != null) { - domainAxis.resizeRange(factor); + if (useAnchor) { + // get the relevant source coordinate given the plot + // orientation + double sourceX = source.getX(); + if (this.orientation == PlotOrientation.HORIZONTAL) { + sourceX = source.getY(); + } + double anchorX = domainAxis.java2DToValue(sourceX, + info.getDataArea(), getDomainAxisEdge()); + domainAxis.resizeRange(factor, anchorX); + } + else { + domainAxis.resizeRange(factor); + } } } } @@ -4194,7 +4230,9 @@ * @param upperPercent a percentage that determines the new upper bound * for the axis (e.g. 0.80 is eighty percent). * @param info the plot rendering info. - * @param source the source point. + * @param source the source point (ignored). + * + * @see #zoomRangeAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { @@ -4212,13 +4250,49 @@ * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) */ public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source) { + // delegate to other method + zoomRangeAxes(factor, info, source, false); + } + + /** + * Multiplies the range on the range axis/axes by the specified factor. + * + * @param factor the zoom factor. + * @param info the plot rendering info. + * @param source the source point. + * @param useAnchor a flag that controls whether or not the source point + * is used for the zoom anchor. + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo info, + Point2D source, boolean useAnchor) { + + // perform the zoom on each range axis for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = (ValueAxis) this.rangeAxes.get(i); if (rangeAxis != null) { - rangeAxis.resizeRange(factor); + if (useAnchor) { + // get the relevant source coordinate given the plot + // orientation + double sourceY = source.getY(); + if (this.orientation == PlotOrientation.HORIZONTAL) { + sourceY = source.getX(); + } + double anchorY = rangeAxis.java2DToValue(sourceY, + info.getDataArea(), getRangeAxisEdge()); + rangeAxis.resizeRange(factor, anchorY); + } + else { + rangeAxis.resizeRange(factor); + } } } } @@ -4230,6 +4304,8 @@ * @param upperPercent the upper bound. * @param info the plot rendering info. * @param source the source point. + * + * @see #zoomDomainAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { @@ -4358,9 +4434,6 @@ if (!(obj instanceof XYPlot)) { return false; } - if (!super.equals(obj)) { - return false; - } XYPlot that = (XYPlot) obj; if (this.weight != that.weight) { @@ -4519,7 +4592,7 @@ return false; } } - return true; + return super.equals(obj); } /** @@ -4543,8 +4616,8 @@ clonedAxis.addChangeListener(clone); } } - clone.domainAxisLocations - = (ObjectList) this.domainAxisLocations.clone(); + clone.domainAxisLocations = (ObjectList) + this.domainAxisLocations.clone(); clone.rangeAxes = (ObjectList) ObjectUtilities.clone(this.rangeAxes); for (int i = 0; i < this.rangeAxes.size(); i++) { @@ -4556,8 +4629,8 @@ clonedAxis.addChangeListener(clone); } } - clone.rangeAxisLocations - = (ObjectList) ObjectUtilities.clone(this.rangeAxisLocations); + clone.rangeAxisLocations = (ObjectList) ObjectUtilities.clone( + this.rangeAxisLocations); // the datasets are not cloned, but listeners need to be added... clone.datasets = (ObjectList) ObjectUtilities.clone(this.datasets); Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Zoomable.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Zoomable.java 2007-09-24 11:04:28 UTC (rev 170) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Zoomable.java 2007-09-24 12:41:09 UTC (rev 171) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -28,7 +28,7 @@ * Zoomable.java * ------------- * - * (C) Copyright 2004, 2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2004-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Rune Fauske; @@ -38,6 +38,9 @@ * 12-Nov-2004 : Version 1 (DG); * 26-Jan-2004 : Added getOrientation() method (DG); * 04-Sep-2006 : Added credit for Rune Fauske, see patch 1050659 (DG); + * 21-Sep-2007 : Added new zooming methods with 'useAnchor' flag. This breaks + * the API, but is the cleanest way I can think of to fix a + * long-standing bug (DG); * */ @@ -58,6 +61,8 @@ * <code>false</code> otherwise. * * @return A boolean. + * + * @see #isRangeZoomable() */ public boolean isDomainZoomable(); @@ -66,6 +71,8 @@ * <code>false</code> otherwise. * * @return A boolean. + * + * @see #isDomainZoomable() */ public boolean isRangeZoomable(); @@ -78,42 +85,94 @@ /** * Multiplies the range on the domain axis/axes by the specified factor. + * The <code>source</code> point can be used in some cases to identify a + * subplot, or to determine the center of zooming (refer to the + * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). + * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source); /** - * Zooms in on the domain axes. + * Multiplies the range on the domain axis/axes by the specified factor. + * The <code>source</code> point can be used in some cases to identify a + * subplot, or to determine the center of zooming (refer to the + * documentation of the implementing class for details). + * + * @param factor the zoom factor. + * @param state the plot state. + * @param source the source point (in Java2D coordinates). + * @param useAnchor use source point as zoom anchor? * + * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) + * + * @since 1.0.7 + */ + public void zoomDomainAxes(double factor, PlotRenderingInfo state, + Point2D source, boolean useAnchor); + + /** + * Zooms in on the domain axes. The <code>source</code> point can be used + * in some cases to identify a subplot for zooming. + * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). + * + * @see #zoomRangeAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source); /** * Multiplies the range on the range axis/axes by the specified factor. + * The <code>source</code> point can be used in some cases to identify a + * subplot, or to determine the center of zooming (refer to the + * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). + * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D) */ public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source); /** - * Zooms in on the range axes. + * Multiplies the range on the range axis/axes by the specified factor. + * The <code>source</code> point can be used in some cases to identify a + * subplot, or to determine the center of zooming (refer to the + * documentation of the implementing class for details). + * + * @param factor the zoom factor. + * @param state the plot state. + * @param source the source point (in Java2D coordinates). + * @param useAnchor use source point as zoom anchor? * + * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D) + * + * @since 1.0.7 + */ + public void zoomRangeAxes(double factor, PlotRenderingInfo state, + Point2D source, boolean useAnchor); + + /** + * Zooms in on the range axes. The <code>source</code> point can be used + * in some cases to identify a subplot for zooming. + * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). + * + * @see #zoomDomainAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-24 15:16:27
|
Revision: 174 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=174&view=rev Author: mungady Date: 2007-09-24 08:16:25 -0700 (Mon, 24 Sep 2007) Log Message: ----------- 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartPanel.java (paintComponent): Clear chart buffer before refreshing. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 13:38:45 UTC (rev 173) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 15:16:25 UTC (rev 174) @@ -1,6 +1,11 @@ 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartPanel.java + (paintComponent): Clear chart buffer before refreshing. + +2007-09-24 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/ChartPanel.java (zoomAroundAnchor): New field, (getZoomAroundAnchor): New method, (setZoomAroundAnchor): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2007-09-24 13:38:45 UTC (rev 173) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2007-09-24 15:16:25 UTC (rev 174) @@ -134,7 +134,8 @@ * 24-May-2007 : When the look-and-feel changes, update the popup menu if there * is one (DG); * 06-Jun-2007 : Fixed coordinates for drawing buffer image (DG); - * 24-Sep-2007 : Added zoomAroundAnchor flag (DG); + * 24-Sep-2007 : Added zoomAroundAnchor flag, and handle clearing of chart + * buffer (DG); * */ @@ -1249,20 +1250,24 @@ // are we using the chart buffer? if (this.useBuffer) { + // if buffer is being refreshed, it needs clearing unless it is + // new - use the following flag to track this... + boolean clearBuffer = true; + // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) - || (this.chartBufferHeight != available.getHeight()) - ) { + || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); - this.chartBuffer = createImage( - this.chartBufferWidth, this.chartBufferHeight); + this.chartBuffer = createImage(this.chartBufferWidth, + this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; + clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? @@ -1271,8 +1276,12 @@ Rectangle2D bufferArea = new Rectangle2D.Double( 0, 0, this.chartBufferWidth, this.chartBufferHeight); - Graphics2D bufferG2 - = (Graphics2D) this.chartBuffer.getGraphics(); + Graphics2D bufferG2 = (Graphics2D) + this.chartBuffer.getGraphics(); + if (clearBuffer) { + bufferG2.clearRect(0, 0, this.chartBufferWidth, + this.chartBufferHeight); + } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-24 15:55:32
|
Revision: 176 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=176&view=rev Author: mungady Date: 2007-09-24 08:55:26 -0700 (Mon, 24 Sep 2007) Log Message: ----------- 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java (linesVisible): Deprecated, (shapesVisible): Likewise, (shapesFilled): Likewise, (getLinesVisible): Likewise, (setLinesVisible(Boolean)): Likewise, (setLinesVisible(boolean)): Likewise, (getShapesVisible): Likewise, (setShapesVisible(Boolean)): Likewise, (setShapesVisible(boolean)): Likewise, (setUseOutlinePaint): Fire change event, (getShapesFilled): Deprecated, (setShapesFilled(Boolean)): Likewise, (setShapesFilled(boolean)): Likewise, (setSeriesShapesFilled): Fire change event, (setBaseShapesFilled): Likewise, (equals): Minor tidy up. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 15:20:10 UTC (rev 175) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 15:55:26 UTC (rev 176) @@ -1,5 +1,25 @@ 2007-09-24 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java + (linesVisible): Deprecated, + (shapesVisible): Likewise, + (shapesFilled): Likewise, + (getLinesVisible): Likewise, + (setLinesVisible(Boolean)): Likewise, + (setLinesVisible(boolean)): Likewise, + (getShapesVisible): Likewise, + (setShapesVisible(Boolean)): Likewise, + (setShapesVisible(boolean)): Likewise, + (setUseOutlinePaint): Fire change event, + (getShapesFilled): Deprecated, + (setShapesFilled(Boolean)): Likewise, + (setShapesFilled(boolean)): Likewise, + (setSeriesShapesFilled): Fire change event, + (setBaseShapesFilled): Likewise, + (equals): Minor tidy up. + +2007-09-24 David Gilbert <dav...@ob...> + * source/org/jfree/chart/ChartPanel.java (paintComponent): Clear chart buffer before refreshing. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java 2007-09-24 15:20:10 UTC (rev 175) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java 2007-09-24 15:55:26 UTC (rev 176) @@ -85,7 +85,8 @@ * 20-Apr-2007 : Updated getLegendItem() for renderer change (DG); * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG); * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); - * + * 24-Sep-2007 : Deprecated redundant fields/methods (DG); + * */ package org.jfree.chart.renderer.category; @@ -123,7 +124,11 @@ /** For serialization. */ private static final long serialVersionUID = -197749519869226398L; - /** A flag that controls whether or not lines are visible for ALL series. */ + /** + * A flag that controls whether or not lines are visible for ALL series. + * + * @deprecated As of 1.0.7 (this override flag is unnecessary). + */ private Boolean linesVisible; /** @@ -139,7 +144,9 @@ private boolean baseLinesVisible; /** - * A flag that controls whether or not shapes are visible for ALL series. + * A flag that controls whether or not shapes are visible for ALL series. + * + * @deprecated As of 1.0.7 (this override flag is unnecessary). */ private Boolean shapesVisible; @@ -152,7 +159,11 @@ /** The default value returned by the getShapeVisible() method. */ private boolean baseShapesVisible; - /** A flag that controls whether or not shapes are filled for ALL series. */ + /** + * A flag that controls whether or not shapes are filled for ALL series. + * + * @deprecated As of 1.0.7 (this override flag is unnecessary). + */ private Boolean shapesFilled; /** @@ -238,6 +249,11 @@ * settings will apply. * * @return A flag (possibly <code>null</code>). + * + * @see #setLinesVisible(Boolean) + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public Boolean getLinesVisible() { return this.linesVisible; @@ -250,6 +266,11 @@ * want the "per series" settings to apply. * * @param visible the flag (<code>null</code> permitted). + * + * @see #getLinesVisible() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setLinesVisible(Boolean visible) { this.linesVisible = visible; @@ -262,6 +283,11 @@ * registered listeners. * * @param visible the flag. + * + * @see #getLinesVisible() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setLinesVisible(boolean visible) { setLinesVisible(BooleanUtilities.valueOf(visible)); @@ -274,16 +300,21 @@ * @param series the series index (zero-based). * * @return The flag (possibly <code>null</code>). + * + * @see #setSeriesLinesVisible(int, Boolean) */ public Boolean getSeriesLinesVisible(int series) { return this.seriesLinesVisible.getBoolean(series); } /** - * Sets the 'lines visible' flag for a series. + * Sets the 'lines visible' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param flag the flag (<code>null</code> permitted). + * + * @see #getSeriesLinesVisible(int) */ public void setSeriesLinesVisible(int series, Boolean flag) { this.seriesLinesVisible.setBoolean(series, flag); @@ -291,10 +322,13 @@ } /** - * Sets the 'lines visible' flag for a series. + * Sets the 'lines visible' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param visible the flag. + * + * @see #getSeriesLinesVisible(int) */ public void setSeriesLinesVisible(int series, boolean visible) { setSeriesLinesVisible(series, BooleanUtilities.valueOf(visible)); @@ -304,15 +338,20 @@ * Returns the base 'lines visible' attribute. * * @return The base flag. + * + * @see #getBaseLinesVisible() */ public boolean getBaseLinesVisible() { return this.baseLinesVisible; } /** - * Sets the base 'lines visible' flag. + * Sets the base 'lines visible' flag and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param flag the flag. + * + * @see #getBaseLinesVisible() */ public void setBaseLinesVisible(boolean flag) { this.baseLinesVisible = flag; @@ -348,6 +387,11 @@ * items in ALL series. * * @return The flag (possibly <code>null</code>). + * + * @see #setShapesVisible(Boolean) + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public Boolean getShapesVisible() { return this.shapesVisible; @@ -358,6 +402,11 @@ * {@link RendererChangeEvent} to all registered listeners. * * @param visible the flag (<code>null</code> permitted). + * + * @see #getShapesVisible() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setShapesVisible(Boolean visible) { this.shapesVisible = visible; @@ -369,6 +418,11 @@ * {@link RendererChangeEvent} to all registered listeners. * * @param visible the flag. + * + * @see #getShapesVisible() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setShapesVisible(boolean visible) { setShapesVisible(BooleanUtilities.valueOf(visible)); @@ -381,6 +435,8 @@ * @param series the series index (zero-based). * * @return A boolean. + * + * @see #setSeriesShapesVisible(int, Boolean) */ public Boolean getSeriesShapesVisible(int series) { return this.seriesShapesVisible.getBoolean(series); @@ -392,6 +448,8 @@ * * @param series the series index (zero-based). * @param visible the flag. + * + * @see #getSeriesShapesVisible(int) */ public void setSeriesShapesVisible(int series, boolean visible) { setSeriesShapesVisible(series, BooleanUtilities.valueOf(visible)); @@ -403,6 +461,8 @@ * * @param series the series index (zero-based). * @param flag the flag. + * + * @see #getSeriesShapesVisible(int) */ public void setSeriesShapesVisible(int series, Boolean flag) { this.seriesShapesVisible.setBoolean(series, flag); @@ -413,15 +473,20 @@ * Returns the base 'shape visible' attribute. * * @return The base flag. + * + * @see #setBaseShapesVisible(boolean) */ public boolean getBaseShapesVisible() { return this.baseShapesVisible; } /** - * Sets the base 'shapes visible' flag. + * Sets the base 'shapes visible' flag and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param flag the flag. + * + * @see #getBaseShapesVisible() */ public void setBaseShapesVisible(boolean flag) { this.baseShapesVisible = flag; @@ -433,6 +498,8 @@ * <code>false</code> otherwise. * * @return A boolean. + * + * @see #setDrawOutlines(boolean) */ public boolean getDrawOutlines() { return this.drawOutlines; @@ -447,6 +514,8 @@ * this flag allows you to set your own preference. * * @param flag the flag. + * + * @see #getDrawOutlines() */ public void setDrawOutlines(boolean flag) { this.drawOutlines = flag; @@ -458,6 +527,8 @@ * shape outlines. If not, the regular series paint is used. * * @return A boolean. + * + * @see #setUseOutlinePaint(boolean) */ public boolean getUseOutlinePaint() { return this.useOutlinePaint; @@ -465,12 +536,16 @@ /** * Sets the flag that controls whether the outline paint is used for shape - * outlines. + * outlines, and sends a {@link RendererChangeEvent} to all registered + * listeners. * * @param use the flag. + * + * @see #getUseOutlinePaint() */ public void setUseOutlinePaint(boolean use) { this.useOutlinePaint = use; + notifyListeners(new RendererChangeEvent(this)); } // SHAPES FILLED @@ -521,15 +596,26 @@ * ALL series. * * @return A Boolean. + * + * @see #setShapesFilled(Boolean) + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public Boolean getShapesFilled() { return this.shapesFilled; } /** - * Sets the 'shapes filled' for ALL series. + * Sets the 'shapes filled' for ALL series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param filled the flag. + * + * @see #getShapesFilled() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setShapesFilled(boolean filled) { if (filled) { @@ -541,52 +627,71 @@ } /** - * Sets the 'shapes filled' for ALL series. + * Sets the 'shapes filled' for ALL series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param filled the flag (<code>null</code> permitted). + * + * @see #getShapesFilled() + * + * @deprecated As of 1.0.7 (the override facility is unnecessary, just + * use the per-series and base (default) settings). */ public void setShapesFilled(Boolean filled) { this.shapesFilled = filled; + notifyListeners(new RendererChangeEvent(this)); } /** - * Sets the 'shapes filled' flag for a series. + * Sets the 'shapes filled' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param filled the flag. + * + * @see #getSeriesShapesFilled(int) */ public void setSeriesShapesFilled(int series, Boolean filled) { this.seriesShapesFilled.setBoolean(series, filled); + notifyListeners(new RendererChangeEvent(this)); } /** - * Sets the 'shapes filled' flag for a series. + * Sets the 'shapes filled' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param filled the flag. + * + * @see #getSeriesShapesFilled(int) */ public void setSeriesShapesFilled(int series, boolean filled) { - this.seriesShapesFilled.setBoolean( - series, BooleanUtilities.valueOf(filled) - ); + // delegate + setSeriesShapesFilled(series, BooleanUtilities.valueOf(filled)); } /** * Returns the base 'shape filled' attribute. * * @return The base flag. + * + * @see #setBaseShapesFilled(boolean) */ public boolean getBaseShapesFilled() { return this.baseShapesFilled; } /** - * Sets the base 'shapes filled' flag. + * Sets the base 'shapes filled' flag and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param flag the flag. + * + * @see #getBaseShapesFilled() */ public void setBaseShapesFilled(boolean flag) { this.baseShapesFilled = flag; + notifyListeners(new RendererChangeEvent(this)); } /** @@ -595,6 +700,8 @@ * use the regular paint. * * @return A boolean. + * + * @see #setUseFillPaint(boolean) */ public boolean getUseFillPaint() { return this.useFillPaint; @@ -606,6 +713,8 @@ * registered listeners. * * @param flag the flag. + * + * @see #getUseFillPaint() */ public void setUseFillPaint(boolean flag) { this.useFillPaint = flag; @@ -849,10 +958,7 @@ if (this.useOutlinePaint != that.useOutlinePaint) { return false; } - if (!super.equals(obj)) { - return false; - } - return true; + return super.equals(obj); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 09:42:59
|
Revision: 178 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=178&view=rev Author: mungady Date: 2007-09-26 02:42:52 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/Marker.java (readObject): Initialise listener list, * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java (test1802195): New test method. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Marker.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-24 16:06:58 UTC (rev 177) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-09-26 09:42:52 UTC (rev 178) @@ -1,3 +1,10 @@ +2007-09-26 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/Marker.java + (readObject): Initialise listener list, + * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java + (test1802195): New test method. + 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Marker.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Marker.java 2007-09-24 16:06:58 UTC (rev 177) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Marker.java 2007-09-26 09:42:52 UTC (rev 178) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ----------- * Marker.java * ----------- - * (C) Copyright 2002-2006, by Object Refinery Limited. + * (C) Copyright 2002-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu; @@ -54,8 +54,9 @@ * applied to the domain or range axis as appropriate (DG); * 06-Jun-2005 : Fix equals() method to handle GradientPaint (DG); * 19-Aug-2005 : Changed constructor from public --> protected (DG); - * ------------- JFREECHART 1.0.0 --------------------------------------------- + * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added MarkerChangeListener support (DG); + * 26-Sep-2007 : Fix for serialization bug 1802195 (DG); * */ @@ -526,6 +527,8 @@ * * @param listener the object to be registered. * + * @see #removeChangeListener(MarkerChangeListener) + * * @since 1.0.3 */ public void addChangeListener(MarkerChangeListener listener) { @@ -537,6 +540,8 @@ * * @param listener the object to be unregistered. * + * @see #addChangeListener(MarkerChangeListener) + * * @since 1.0.3 */ public void removeChangeListener(MarkerChangeListener listener) { @@ -671,6 +676,7 @@ this.outlinePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); this.labelPaint = SerialUtilities.readPaint(stream); + this.listenerList = new EventListenerList(); } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java 2007-09-24 16:06:58 UTC (rev 177) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/ValueMarkerTests.java 2007-09-26 09:42:52 UTC (rev 178) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------------- * ValueMarkerTests.java * --------------------- - * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -40,6 +40,7 @@ * 14-Jun-2004 : Renamed MarkerTests --> ValueMarkerTests (DG); * 01-Jun-2005 : Strengthened equals() test (DG); * 05-Sep-2006 : Added checks for MarkerChangeEvent generation (DG); + * 26-Sep-2007 : Added test1802195() method (DG); * */ @@ -245,4 +246,40 @@ this.lastEvent = event; } + /** + * A test for bug 1802195. + */ + public void test1802195() { + + ValueMarker m1 = new ValueMarker(25.0); + ValueMarker m2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(m1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + m2 = (ValueMarker) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + boolean b = m1.equals(m2); + assertTrue(b); + + boolean pass = true; + try { + m2.setValue(-10.0); + } + catch (NullPointerException e) { + pass = false; + } + assertTrue(pass); + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |