Skip to content
Snippets Groups Projects
Commit 0bf7b8df authored by Thomas Neidhart's avatar Thomas Neidhart
Browse files

Proposal to fix issue 36: area stack glitch.

parent 121d4c2a
No related branches found
No related tags found
No related merge requests found
...@@ -107,6 +107,9 @@ public class PlotContentLineChart extends PlotContent { ...@@ -107,6 +107,9 @@ public class PlotContentLineChart extends PlotContent {
if (errorBars != null) { if (errorBars != null) {
ebItr = errorBars.iterator(); ebItr = errorBars.iterator();
} }
Path2D.Double path = null;
while (xItr.hasNext()) { while (xItr.hasNext()) {
BigDecimal x = null; BigDecimal x = null;
...@@ -124,6 +127,9 @@ public class PlotContentLineChart extends PlotContent { ...@@ -124,6 +127,9 @@ public class PlotContentLineChart extends PlotContent {
Number next = yItr.next(); Number next = yItr.next();
if (next == null) { if (next == null) {
closePath(g, path, previousX, bounds, yTopMargin);
path = null;
previousX = Integer.MIN_VALUE; previousX = Integer.MIN_VALUE;
previousY = Integer.MIN_VALUE; previousY = Integer.MIN_VALUE;
continue; continue;
...@@ -178,13 +184,19 @@ public class PlotContentLineChart extends PlotContent { ...@@ -178,13 +184,19 @@ public class PlotContentLineChart extends PlotContent {
g.setColor(series.getStrokeColor()); g.setColor(series.getStrokeColor());
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin + 1; double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin + 1;
Path2D.Double path = new Path2D.Double(); // if the new x value is smaller than the previous one, close the current path
path.moveTo(previousX, previousY); if (xOffset < previousX) {
closePath(g, path, previousX, bounds, yTopMargin);
path = null;
}
if (path == null) {
path = new Path2D.Double();
path.moveTo(previousX, yBottomOfArea);
path.lineTo(previousX, previousY);
}
path.lineTo(xOffset, yOffset); path.lineTo(xOffset, yOffset);
path.lineTo(xOffset, yBottomOfArea);
path.lineTo(previousX, yBottomOfArea);
path.closePath();
g.fill(path);
} }
} }
...@@ -232,6 +244,21 @@ public class PlotContentLineChart extends PlotContent { ...@@ -232,6 +244,21 @@ public class PlotContentLineChart extends PlotContent {
g.draw(line); g.draw(line);
} }
} }
// close any open path for area charts
closePath(g, path, previousX, bounds, yTopMargin);
}
}
/**
* Closes a path for area charts if one is available.
*/
private void closePath(Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) {
if (path != null) {
double yBottomOfArea = bounds.getY() + bounds.getHeight() - yTopMargin + 1;
path.lineTo(previousX, yBottomOfArea);
path.closePath();
g.fill(path);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment