Skip to content

Commit

Permalink
Upgrading to Gral 0.10. Fixing piechart labelling bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
LindsayBradford committed May 1, 2014
1 parent 23b9d8c commit cf33448
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<classpathentry kind="src" path="src/test/java"/>
<classpathentry exported="true" kind="lib" path="libs/json-io-2.5.2.jar"/>
<classpathentry exported="true" kind="lib" path="libs/bcprov-jdk15on-1.50.jar"/>
<classpathentry exported="true" kind="lib" path="libs/gral-core-0.9.jar"/>
<classpathentry exported="true" kind="lib" path="libs/JTattoo-1.6.10.jar"/>
<classpathentry exported="true" kind="lib" path="libs/junit-4.11.jar"/>
<classpathentry exported="true" kind="lib" path="libs/mockito-all-1.9.5.jar"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="libs/gral-core-0.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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 [email protected] 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));
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -201,5 +210,7 @@ private boolean valueIsNegative(PointData data) {
data.row.getIndex()
);
}


}
}

0 comments on commit cf33448

Please sign in to comment.