diff --git a/hellocharts-library/src/lecho/lib/hellocharts/model/Line.java b/hellocharts-library/src/lecho/lib/hellocharts/model/Line.java index f7c38850..83e9333e 100644 --- a/hellocharts-library/src/lecho/lib/hellocharts/model/Line.java +++ b/hellocharts-library/src/lecho/lib/hellocharts/model/Line.java @@ -30,6 +30,7 @@ public class Line { private boolean hasLabels = false; private boolean hasLabelsOnlyForSelected = false; private boolean isCubic = false; + private boolean isSquare = false; private boolean isFilled = false; private ValueShape shape = ValueShape.CIRCLE; private PathEffect pathEffect; @@ -200,6 +201,19 @@ public boolean isCubic() { public Line setCubic(boolean isCubic) { this.isCubic = isCubic; + if(isSquare) + setSquare(false); + return this; + } + + public boolean isSquare() { + return isSquare; + } + + public Line setSquare(boolean isSquare) { + this.isSquare = isSquare; + if(isCubic) + setCubic(false); return this; } diff --git a/hellocharts-library/src/lecho/lib/hellocharts/renderer/LineChartRenderer.java b/hellocharts-library/src/lecho/lib/hellocharts/renderer/LineChartRenderer.java index 9fadb9a3..39b40d53 100644 --- a/hellocharts-library/src/lecho/lib/hellocharts/renderer/LineChartRenderer.java +++ b/hellocharts-library/src/lecho/lib/hellocharts/renderer/LineChartRenderer.java @@ -114,6 +114,8 @@ public void draw(Canvas canvas) { if (line.hasLines()) { if (line.isCubic()) { drawSmoothPath(drawCanvas, line); + } else if (line.isSquare()) { + drawSquarePath(drawCanvas, line); } else { drawPath(drawCanvas, line); } @@ -237,6 +239,38 @@ private void drawPath(Canvas canvas, final Line line) { path.reset(); } + private void drawSquarePath(Canvas canvas, final Line line) { + prepareLinePaint(line); + + int valueIndex = 0; + float previousRawY = 0; + for (PointValue pointValue : line.getValues()) { + + final float rawX = computator.computeRawX(pointValue.getX()); + final float rawY = computator.computeRawY(pointValue.getY()); + + if (valueIndex == 0) { + path.moveTo(rawX, rawY); + } else { + path.lineTo(rawX, previousRawY); + path.lineTo(rawX, rawY); + } + + previousRawY = rawY; + + ++valueIndex; + + } + + canvas.drawPath(path, linePaint); + + if (line.isFilled()) { + drawArea(canvas, line); + } + + path.reset(); + } + private void drawSmoothPath(Canvas canvas, final Line line) { prepareLinePaint(line);