Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify LineChart: draw point circle with stroke #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions hellocharts-library/src/lecho/lib/hellocharts/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Line {
public static final int UNINITIALIZED = 0;
private int color = ChartUtils.DEFAULT_COLOR;
private int pointColor = UNINITIALIZED;
private int pointStrokeColor = ChartUtils.DEFAULT_COLOR;
private int pointStrokeWidth = DEFAULT_LINE_STROKE_WIDTH_DP;
private int darkenColor = ChartUtils.DEFAULT_DARKEN_COLOR;
/**
* Transparency of area when line is filled. *
Expand Down Expand Up @@ -54,6 +56,7 @@ public Line(Line line) {
this.areaTransparency = line.areaTransparency;
this.strokeWidth = line.strokeWidth;
this.pointRadius = line.pointRadius;

this.hasPoints = line.hasPoints;
this.hasLines = line.hasLines;
this.hasLabels = line.hasLabels;
Expand Down Expand Up @@ -292,4 +295,20 @@ public Line setFormatter(LineChartValueFormatter formatter) {
}
return this;
}

public int getPointStrokeColor() {
return pointStrokeColor;
}

public void setPointStrokeColor(int pointStrokeColor) {
this.pointStrokeColor = pointStrokeColor;
}

public int getPointStrokeWidth() {
return pointStrokeWidth;
}

public void setPointStrokeWidth(int pointStrokeWidth) {
this.pointStrokeWidth = pointStrokeWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,21 @@ private void drawPoint(Canvas canvas, Line line, PointValue pointValue, float ra
canvas.drawRect(rawX - pointRadius, rawY - pointRadius, rawX + pointRadius, rawY + pointRadius,
pointPaint);
} else if (ValueShape.CIRCLE.equals(line.getShape())) {
canvas.drawCircle(rawX, rawY, pointRadius, pointPaint);
if (line.getPointColor() == line.getPointStrokeColor()) {
canvas.drawCircle(rawX, rawY, pointRadius, pointPaint); // draw fill circle;
} else {
// draw hollow circle with stroke;
Paint tempPointPaint = new Paint();
tempPointPaint.setAntiAlias(true);
tempPointPaint.setStyle(Paint.Style.STROKE);
tempPointPaint.setColor(line.getPointStrokeColor());
tempPointPaint.setPathEffect(line.getPathEffect());
int strokeWidth = ChartUtils.dp2px(density, line.getPointStrokeWidth());
tempPointPaint.setStrokeWidth(strokeWidth);
canvas.drawCircle(rawX, rawY, pointRadius, pointPaint); // fill
canvas.drawCircle(rawX, rawY, pointRadius, tempPointPaint); // stroke;
}

} else if (ValueShape.DIAMOND.equals(line.getShape())) {
canvas.save();
canvas.rotate(45, rawX, rawY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lecho.lib.hellocharts.samples;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
Expand Down Expand Up @@ -182,6 +183,10 @@ private LineChartData generateLineData() {
line.setHasLabels(hasLabels);
line.setHasLines(hasLines);
line.setHasPoints(hasPoints);
line.setFilled(false);
line.setPointRadius(4);
line.setPointColor(Color.WHITE);
line.setPointStrokeColor(ChartUtils.COLORS[i]);
lines.add(line);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lecho.lib.hellocharts.samples;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
Expand Down Expand Up @@ -237,6 +238,8 @@ private void generateData() {
line.setHasLabelsOnlyForSelected(hasLabelForSelected);
line.setHasLines(hasLines);
line.setHasPoints(hasPoints);
line.setPointColor(Color.WHITE);
line.setPointStrokeColor(ChartUtils.COLORS[i]);
if (pointsHaveDifferentColor){
line.setPointColor(ChartUtils.COLORS[(i + 1) % ChartUtils.COLORS.length]);
}
Expand Down