From: <mu...@us...> - 2008-02-17 21:50:54
|
Revision: 736 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=736&view=rev Author: mungady Date: 2008-02-17 13:50:50 -0800 (Sun, 17 Feb 2008) Log Message: ----------- 2008-02-18 David Gilbert <dav...@ob...> Patch 1871902 by Martin Hoeller: * org/jfree/chart/plot/PolarPlot.java (DEFAULT_ANGLE_TICK_UNIT_SIZE): New field, (angleTickUnit): Likewise, (PolarPlot(XYDataset, ValueAxis, PolarItemRenderer)): Initialise angleTickUnit, (getAngleTickUnit): New method, (setAngleTickUnit): Likewise, (refreshAngleTicks): Likewise, (draw): Refresh angle tick list before drawing. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PolarPlotTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2008-02-15 03:29:37 UTC (rev 735) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2008-02-17 21:50:50 UTC (rev 736) @@ -1,3 +1,16 @@ +2008-02-18 David Gilbert <dav...@ob...> + + Patch 1871902 by Martin Hoeller: + * org/jfree/chart/plot/PolarPlot.java + (DEFAULT_ANGLE_TICK_UNIT_SIZE): New field, + (angleTickUnit): Likewise, + (PolarPlot(XYDataset, ValueAxis, PolarItemRenderer)): Initialise + angleTickUnit, + (getAngleTickUnit): New method, + (setAngleTickUnit): Likewise, + (refreshAngleTicks): Likewise, + (draw): Refresh angle tick list before drawing. + 2008-02-15 David Gilbert <dav...@ob...> * org/jfree/data/DefaultKeyedValue.java 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 2008-02-15 03:29:37 UTC (rev 735) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/PolarPlot.java 2008-02-17 21:50:50 UTC (rev 736) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,11 @@ * -------------- * PolarPlot.java * -------------- - * (C) Copyright 2004-2007, by Solution Engineering, Inc. and Contributors. + * (C) Copyright 2004-2008, by Solution Engineering, Inc. and Contributors. * * Original Author: Daniel Bridenbecker, Solution Engineering, Inc.; * Contributor(s): David Gilbert (for Object Refinery Limited); + * Martin Hoeller (patch 1871902); * * Changes * ------- @@ -43,12 +44,13 @@ * 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); + * 17-Feb-2007 : Added angle tick unit attribute (see patch 1871902 by + * Martin Hoeller) (DG); * */ package org.jfree.chart.plot; - import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; @@ -75,6 +77,8 @@ import org.jfree.chart.LegendItemCollection; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberTick; +import org.jfree.chart.axis.NumberTickUnit; +import org.jfree.chart.axis.TickUnit; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; @@ -92,7 +96,6 @@ import org.jfree.util.ObjectUtilities; import org.jfree.util.PaintUtilities; - /** * Plots data that is in (theta, radius) pairs where * theta equal to zero is due north and increases clockwise. @@ -109,6 +112,13 @@ /** The annotation margin. */ private static final double ANNOTATION_MARGIN = 7.0; + /** + * The default angle tick unit size. + * + * @since 1.0.10 + */ + public static final double DEFAULT_ANGLE_TICK_UNIT_SIZE = 45.0; + /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke( 0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, @@ -136,6 +146,13 @@ */ private PolarItemRenderer renderer; + /** + * The tick unit that controls the spacing between the angular grid lines. + * + * @since 1.0.10 + */ + private TickUnit angleTickUnit; + /** A flag that controls whether or not the angle labels are visible. */ private boolean angleLabelsVisible = true; @@ -190,24 +207,7 @@ if (this.dataset != null) { this.dataset.addChangeListener(this); } - - this.angleTicks = new java.util.ArrayList(); - this.angleTicks.add(new NumberTick(new Double(0.0), "0", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(45.0), "45", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(90.0), "90", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(135.0), "135", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(180.0), "180", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(225.0), "225", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(270.0), "270", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); - this.angleTicks.add(new NumberTick(new Double(315.0), "315", - TextAnchor.CENTER, TextAnchor.CENTER, 0.0)); + this.angleTickUnit = new NumberTickUnit(DEFAULT_ANGLE_TICK_UNIT_SIZE); this.axis = radiusAxis; if (this.axis != null) { @@ -393,6 +393,34 @@ } /** + * Returns the tick unit that controls the spacing of the angular grid + * lines. + * + * @return The tick unit (never <code>null</code>). + * + * @since 1.0.10 + */ + public TickUnit getAngleTickUnit() { + return this.angleTickUnit; + } + + /** + * Sets the tick unit that controls the spacing of the angular grid + * lines, and sends a {@link PlotChangeEvent} to all registered listeners. + * + * @param unit the tick unit (<code>null</code> not permitted). + * + * @since 1.0.10 + */ + public void setAngleTickUnit(TickUnit unit) { + if (unit == null) { + throw new IllegalArgumentException("Null 'unit' argument."); + } + this.angleTickUnit = unit; + notifyListeners(new PlotChangeEvent(this)); + } + + /** * Returns a flag that controls whether or not the angle labels are visible. * * @return A boolean. @@ -638,6 +666,25 @@ } /** + * Generates a list of tick values for the angular tick marks. + * + * @return A list of {@link NumberTick} instances. + * + * @since 1.0.10 + */ + protected List refreshAngleTicks() { + List ticks = new ArrayList(); + for (double currentTickVal = 0.0; currentTickVal < 360.0; + currentTickVal += this.angleTickUnit.getSize()) { + NumberTick tick = new NumberTick(Double.valueOf(currentTickVal), + this.angleTickUnit.valueToString(currentTickVal), + TextAnchor.CENTER, TextAnchor.CENTER, 0.0); + ticks.add(tick); + } + return ticks; + } + + /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * <P> @@ -698,7 +745,8 @@ g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, getForegroundAlpha())); - + + this.angleTicks = refreshAngleTicks(); drawGridlines(g2, dataArea, this.angleTicks, state.getTicks()); // draw... @@ -954,6 +1002,9 @@ if (!ObjectUtilities.equal(this.renderer, that.renderer)) { return false; } + if (!this.angleTickUnit.equals(that.angleTickUnit)) { + return false; + } if (this.angleGridlinesVisible != that.angleGridlinesVisible) { return false; } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PolarPlotTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PolarPlotTests.java 2008-02-15 03:29:37 UTC (rev 735) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/plot/junit/PolarPlotTests.java 2008-02-17 21:50:50 UTC (rev 736) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------- * PolarPlotTests.java * ------------------- - * (C) Copyright 2005, 2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,6 +37,7 @@ * 23-Feb-2005 : Version 1 (DG); * 08-Jun-2005 : Extended testEquals() (DG); * 07-Feb-2007 : Extended testEquals() and testCloning() (DG); + * 17-Feb-2008 : Tests for new angleTickUnit field (DG); * */ @@ -59,6 +60,7 @@ import junit.framework.TestSuite; import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.plot.PolarPlot; import org.jfree.chart.renderer.DefaultPolarItemRenderer; import org.jfree.data.xy.DefaultXYDataset; @@ -108,6 +110,11 @@ plot2.setAngleGridlineStroke(s); assertTrue(plot1.equals(plot2)); + plot1.setAngleTickUnit(new NumberTickUnit(11.0)); + assertFalse(plot1.equals(plot2)); + plot2.setAngleTickUnit(new NumberTickUnit(11.0)); + assertTrue(plot1.equals(plot2)); + plot1.setAngleGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setAngleGridlinesVisible(false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |