From cf33448ca961d98a55dfc31787f81f91bc4c631e Mon Sep 17 00:00:00 2001 From: Lindsay Bradford Date: Thu, 1 May 2014 21:57:14 +1000 Subject: [PATCH] Upgrading to Gral 0.10. Fixing piechart labelling bug. --- .classpath | 2 +- build.gradle | 2 +- .../view/budget/AbstractBudgetPieChart.java | 47 ++++++++++++------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.classpath b/.classpath index 22bf7f0..691932d 100644 --- a/.classpath +++ b/.classpath @@ -5,10 +5,10 @@ - + diff --git a/build.gradle b/build.gradle index a8f8136..4258fde 100755 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ List testLibs = [ List libsToMerge = [ 'com.jtattoo:JTattoo:1.6.10', 'com.cedarsoftware:json-io:2.5.2', - 'de.erichseifert.gral:gral-core:0.9' + 'de.erichseifert.gral:gral-core:0.10' ] List libsToShip = [ diff --git a/src/main/java/blacksmyth/personalfinancier/view/budget/AbstractBudgetPieChart.java b/src/main/java/blacksmyth/personalfinancier/view/budget/AbstractBudgetPieChart.java index aa13b41..a228c1c 100644 --- a/src/main/java/blacksmyth/personalfinancier/view/budget/AbstractBudgetPieChart.java +++ b/src/main/java/blacksmyth/personalfinancier/view/budget/AbstractBudgetPieChart.java @@ -12,6 +12,7 @@ import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Font; import java.awt.LinearGradientPaint; import java.awt.Shape; import java.util.Observable; @@ -22,14 +23,11 @@ import de.erichseifert.gral.data.DataTable; import de.erichseifert.gral.graphics.Drawable; import de.erichseifert.gral.plots.PiePlot; -import de.erichseifert.gral.plots.PlotArea; import de.erichseifert.gral.plots.PiePlot.PieSliceRenderer; import de.erichseifert.gral.plots.points.PointData; -import de.erichseifert.gral.plots.points.PointRenderer; import de.erichseifert.gral.ui.InteractivePanel; import de.erichseifert.gral.util.Insets2D; import de.erichseifert.gral.util.Location; - import blacksmyth.personalfinancier.control.budget.IBudgetObserver; import blacksmyth.personalfinancier.model.budget.BudgetModel; @@ -92,14 +90,14 @@ protected void displayPiePlot(PiePlot plot) { BorderLayout.CENTER ); - this.validate(); // need to force a redraw +// this.validate(); // need to force a redraw } private PiePlot createPiePlot(String title, DataTable cashFlowData) { PiePlot plot = new PiePlot(cashFlowData); - + configurePiePlot(plot, title); - + plot.setPointRenderer( cashFlowData, new DualSliceRenderer( @@ -113,12 +111,15 @@ private PiePlot createPiePlot(String title, DataTable cashFlowData) { } private void configurePiePlot(PiePlot plot, String title) { - plot.setSetting(PiePlot.TITLE, title); - plot.getPlotArea().setSetting(PlotArea.BORDER,null); + //TODO: email info@erichseifert.de asking about small slices. + plot.getTitle().setText(title); - plot.setInsets(new Insets2D.Double(1.0, 1.0, 1.0, 1.0)); + plot.getPlotArea().setBorderStroke(null); + plot.setRadius(0.6); + plot.setStart(180); //black on top + plot.setInsets(new Insets2D.Double(1.0, 1.0, 1.0, 1.0)); } /** @@ -151,22 +152,21 @@ public DualSliceRenderer(PiePlot plot, Color positiveRenderColor, */ private PieSliceRenderer createPieSliceRenderer(Color color) { PieSliceRenderer renderer = new PieSliceRenderer(plot); - renderer.setSetting(PieSliceRenderer.GAP, 0.1); + renderer.setGap(0.1); - renderer.setSetting( - PointRenderer.COLOR, + renderer.setColor( new LinearGradientPaint( 0f,0f, 0f,1f, new float[] { 0.0f, 1.0f }, new Color[] { color, Color.GRAY } ) ); - - renderer.setSetting(PointRenderer.VALUE_DISPLAYED, true); - renderer.setSetting(PointRenderer.VALUE_LOCATION, Location.NORTH); - - renderer.setSetting(PointRenderer.VALUE_COLUMN, LABEL_COLUMN); - renderer.setSetting(PointRenderer.VALUE_COLOR, color); + renderer.setValueVisible(true); + renderer.setValueLocation(Location.NORTH); + renderer.setValueDistance(1.2); + renderer.setValueColumn(LABEL_COLUMN); + renderer.setValueColor(color); + renderer.setValueFont(Font.decode(null).deriveFont(Font.BOLD)); return renderer; } @@ -187,6 +187,15 @@ public Shape getPointShape(PointData data) { } return positiveSliceRenderer.getPointShape(data); } + + @Override + public Drawable getValue(PointData data, + java.awt.Shape shape) { + if (valueIsNegative(data)) { + return negativeSliceRenderer.getValue(data, shape); + } + return positiveSliceRenderer.getValue(data, shape); + } /** * Interrogates the current plot's data value @@ -201,5 +210,7 @@ private boolean valueIsNegative(PointData data) { data.row.getIndex() ); } + + } }