All labes scaled

COB is not here
This commit is contained in:
Roumen Georgiev 2017-11-30 11:28:26 +02:00 committed by GitHub
parent 24b9326602
commit d683ea2f0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,6 +47,11 @@ import java.util.Iterator;
* @author jjoe64
*/
public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> extends BaseSeries<E> {
// Default spSize
int spSize = 12;
// Convert the sp to pixels
Context context = MainApp.instance().getApplicationContext();
float scaledTextSize = spSize * context.getResources().getDisplayMetrics().scaledDensity;
/**
* choose a predefined shape to render for
* each data point.
@ -72,9 +77,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
OPENAPSOFFLINE,
EXERCISE,
GENERAL,
GENERALWITHDURATION,
BG,
PREDICTION
GENERALWITHDURATION
}
/**
@ -196,11 +199,10 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
// draw data point
if (!overdraw) {
if (value.getShape() == Shape.BG) {
mPaint.setStyle(Paint.Style.FILL);
if (value.getShape() == Shape.POINT) {
mPaint.setStrokeWidth(0);
canvas.drawCircle(endX, endY, value.getSize(), mPaint);
} else if (value.getShape() == Shape.RECTANGLE) {
} else if (value.getShape() == Shape.RECTANGLE) {
canvas.drawRect(endX-value.getSize(), endY-value.getSize(), endX+value.getSize(), endY+value.getSize(), mPaint);
} else if (value.getShape() == Shape.TRIANGLE) {
mPaint.setStrokeWidth(0);
@ -226,7 +228,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
Rect bounds = new Rect((int)endX, (int)endY + 3, (int) (xpluslength), (int) endY + 8);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawRect(bounds, mPaint);
mPaint.setTextSize((int) (value.getSize() * 2.5));
mPaint.setTextSize((int) (scaledTextSize * 2.5));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true);
canvas.drawText(value.getLabel(), endX, endY, mPaint);
@ -234,12 +236,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
} else if (value.getShape() == Shape.PROFILE) {
mPaint.setStrokeWidth(0);
if (value.getLabel() != null) {
//mPaint.setTextSize((int) (value.getSize() * 6));
int spSize = 14;
//your sp size
// Convert the sp to pixels
Context context = MainApp.instance().getApplicationContext();
float scaledTextSize = spSize * context.getResources().getDisplayMetrics().scaledDensity;
mPaint.setTextSize((int) (value.getSize() * 3));
mPaint.setTextSize(scaledTextSize);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect();
@ -256,6 +253,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
} else if (value.getShape() == Shape.MBG) {
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
float w = mPaint.getStrokeWidth();
canvas.drawCircle(endX, endY, value.getSize(), mPaint);
} else if (value.getShape() == Shape.BGCHECK) {
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
@ -282,7 +280,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0);
if (value.getLabel() != null) {
mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3));
mPaint.setTextSize((int) (scaledTextSize * 3));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -297,7 +295,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0);
if (value.getLabel() != null) {
mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3));
mPaint.setTextSize(scaledTextSize);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -312,7 +310,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
mPaint.setStrokeWidth(0);
if (value.getLabel() != null) {
mPaint.setStrokeWidth(0);
mPaint.setTextSize((int) (value.getSize() * 3));
mPaint.setTextSize(scaledTextSize * 3);
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
Rect bounds = new Rect();
mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds);
@ -366,7 +364,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
float py = endY + value.getSize();
canvas.save();
canvas.rotate(-45, px, py);
mPaint.setTextSize((int) (value.getSize() * 2.5));
mPaint.setTextSize((float) (scaledTextSize*0.8));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true);
mPaint.setTextAlign(Paint.Align.RIGHT);
@ -378,7 +376,7 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
float py = endY - value.getSize();
canvas.save();
canvas.rotate(-45, px, py);
mPaint.setTextSize((int) (value.getSize() * 2.5));
mPaint.setTextSize((float) (scaledTextSize*0.8));
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
mPaint.setFakeBoldText(true);
canvas.drawText(value.getLabel(), px + value.getSize(), py, mPaint);