下面列出了android.graphics.Path#moveTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Draws all paths.
*/
private void drawPaths() {
boolean[] hasMoved = new boolean[series.length];
for (int i = 0; i < chartData.size(); i++) {
double[] dataPoint = chartData.get(i);
for (int j = 0; j < series.length; j++) {
double value = dataPoint[j + 1];
if (Double.isNaN(value)) {
continue;
}
ChartValueSeries chartValueSeries = series[j];
Path path = chartValueSeries.getPath();
int x = getX(dataPoint[0]);
int y = getY(chartValueSeries, value);
if (!hasMoved[j]) {
hasMoved[j] = true;
path.moveTo(x, y);
} else {
path.lineTo(x, y);
}
}
}
}
protected void drawPath(Point[] points) {
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
int total = points.length;
for (int i = 0; i < total; i++) {
Point point = points[i];
if (i == 0) {
path.moveTo(point.x * _scale, point.y * _scale);
} else {
path.lineTo(point.x * _scale, point.y * _scale);
}
}
path.close();
_bitmapCanvas.drawPath(path, _bitmapPaint);
}
/**
* Draws the zero line.
*/
protected void drawZeroLine(Canvas c) {
int clipRestoreCount = c.save();
mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth());
c.clipRect(mZeroLineClippingRect);
// draw zero line
MPPointD pos = mTrans.getPixelForValues(0f, 0f);
mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());
Path zeroLinePath = mDrawZeroLinePath;
zeroLinePath.reset();
zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y);
zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y);
// draw a path because lines don't support dashing on lower android versions
c.drawPath(zeroLinePath, mZeroLinePaint);
c.restoreToCount(clipRestoreCount);
}
protected Path getPath(GeoLineString lineString) {
List<GeoPoint> points = lineString.getPoints();
Path path = new Path();
float x0, y0;
if (points.size() > 0) {
x0 = (float) points.get(0).getX();
y0 = (float) points.get(0).getY();
path.moveTo(x0, y0);
for (int i = 1; i < points.size(); i++) {
x0 = (float) points.get(i).getX();
y0 = (float) points.get(i).getY();
path.lineTo(x0, y0);
}
}
return path;
}
@Override
public void onDraw(Canvas canvas, Rect showRect, String tableName, TableConfig config) {
Paint paint = config.getPaint();
config.tableTitleStyle.fillPaint(paint);
Rect rect = getRect();
int startX = rect.centerX();
Path path = new Path();
switch (direction) {
case TOP:
case BOTTOM:
DrawUtils.drawMultiText(canvas, paint, rect, tableName.split("\n"));
break;
case LEFT:
case RIGHT:
int textWidth = (int) paint.measureText(tableName);
path.moveTo(startX, rect.top);
path.lineTo(startX, rect.bottom);
canvas.drawTextOnPath(tableName, path, textWidth / 2, 0, paint);
break;
}
}
/**
* 绘制A区域右阴影
*
* @param canvas
*/
private void drawPathARightShadow(Canvas canvas, Path pathA) {
canvas.restore();
canvas.save();
float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view对角线长度
int left = (int) h.x;
int right = (int) (h.x + viewDiagonalLength * 10);//需要足够长的长度
int top;
int bottom;
GradientDrawable gradientDrawable;
if (style.equals(STYLE_TOP_RIGHT)) {
gradientDrawable = drawableRightTopRight;
top = (int) (h.y - rPathAShadowDis / 2);
bottom = (int) h.y;
} else {
gradientDrawable = drawableRightLowerRight;
top = (int) h.y;
bottom = (int) (h.y + rPathAShadowDis / 2);
}
gradientDrawable.setBounds(left, top, right, bottom);
Path mPath = new Path();
mPath.moveTo(a.x - Math.max(rPathAShadowDis, lPathAShadowDis) / 2, a.y);
// mPath.lineTo(i.x,i.y);
mPath.lineTo(h.x, h.y);
mPath.lineTo(a.x, a.y);
mPath.close();
canvas.clipPath(pathA);
canvas.clipPath(mPath, Region.Op.INTERSECT);
float mDegrees = (float) Math.toDegrees(Math.atan2(a.y - h.y, a.x - h.x));
canvas.rotate(mDegrees, h.x, h.y);
gradientDrawable.draw(canvas);
}
/**
* Generates the path that is used for filled drawing.
*
* @param dataSet
* @return
*/
private Path generateFilledPath(ILineDataSet dataSet, int from, int to) {
float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
Path filled = new Path();
Entry entry = dataSet.getEntryForIndex(from);
filled.moveTo(entry.getXIndex(), fillMin);
filled.lineTo(entry.getXIndex(), entry.getVal() * phaseY);
// create a new path
for (int x = from + 1, count = (int) Math.ceil((to - from) * phaseX + from); x < count; x++) {
Entry e = dataSet.getEntryForIndex(x);
filled.lineTo(e.getXIndex(), e.getVal() * phaseY);
}
// close up
filled.lineTo(
dataSet.getEntryForIndex(
Math.max(
Math.min((int) Math.ceil((to - from) * phaseX + from) - 1,
dataSet.getEntryCount() - 1), 0)).getXIndex(), fillMin);
filled.close();
return filled;
}
private void drawTriangle(Canvas canvas) {
Path p = new Path();
if (rotate_degree >= 0 && rotate_degree < 30) {
first_pointX = radius - triangle_length * Math.abs(Math.cos(Math.PI / 3 + rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
first_pointY = radius - triangle_length * Math.abs(Math.sin(Math.PI / 3 + rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
} else if (rotate_degree >= 30 && rotate_degree <= 120) {
first_pointX = radius + triangle_length * Math.abs(Math.cos(Math.PI / 3 + rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
first_pointY = radius - triangle_length * Math.abs(Math.sin(Math.PI / 3 + rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
}
if (rotate_degree >= 0 && rotate_degree < 90) {
second_pointX = radius + triangle_length * Math.abs(Math.cos(rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
second_pointY = radius + triangle_length * Math.abs(Math.sin(rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
} else if (rotate_degree > 90 && rotate_degree <= 120) {
second_pointX = radius - triangle_length * Math.abs(Math.cos(rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
second_pointY = radius + triangle_length * Math.abs(Math.sin(rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
}
if (rotate_degree >= 0 && rotate_degree < 60) {
third_pointX = radius - triangle_length * Math.abs(Math.cos(Math.PI / 3 - rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
third_pointY = radius + triangle_length * Math.abs(Math.sin(Math.PI / 3 - rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
} else if (rotate_degree >= 60 && rotate_degree <= 120) {
third_pointX = radius - triangle_length * Math.abs(Math.cos(Math.PI / 3 - rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
third_pointY = radius - triangle_length * Math.abs(Math.sin(Math.PI / 3 - rotate_degree * Math.PI / 180) * Math.sqrt(3) / 3);
}
p.moveTo((float) first_pointX, (float) first_pointY);
p.lineTo((float) second_pointX, (float) second_pointY);
p.lineTo((float) third_pointX, (float) third_pointY);
p.close();
canvas.drawPath(p, mTrianglePaint);
redrawTriangle();
}
private void initArrows(int w, int h) {
mArrowBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mArrowBitmap.eraseColor(Color.TRANSPARENT);
Canvas arrowCanvas = new Canvas(mArrowBitmap);
mArrowRotator = new Matrix();
int hw = w / 2;
int hh = h / 2;
int t1 = (int) (w * 0.35);
int t2 = (int) (w * 0.05);
Point d = new Point(hw - t2, hh);
Point e = new Point(hw + t2, hh);
Point f = new Point(hw, hh - t1);
Point g = new Point(hw, hh + t1);
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(d.x, d.y);
path.lineTo(e.x, e.y);
path.lineTo(f.x, f.y);
path.close();
Path path2 = new Path();
path2.setFillType(Path.FillType.EVEN_ODD);
path2.moveTo(d.x, d.y);
path2.lineTo(e.x, e.y);
path2.lineTo(g.x, g.y);
path2.close();
arrowCanvas.drawPath(path, mCirclePaint);
arrowCanvas.drawPath(path2, mWhiteArrowPaint);
arrowCanvas.save();
}
private void createShineArea() {
int width = getWidth();
int height = (int) (0.9 * getHeight());
path = new Path();
path.moveTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width, height);
path.close();
paint.setShader(new LinearGradient(0, 0, 0, height, 0x55ffffff,
0x10ffffff, Shader.TileMode.CLAMP));
}
/**
* Initializes the paths that are used by the ObjectAnimator to scale the view.
*/
private void initPaths() {
// Path for 'in' animation: growing from 20% to 100%
mPathIn = new Path();
mPathIn.moveTo(0.2f, 0.2f);
mPathIn.lineTo(1f, 1f);
// Path for 'out' animation: shrinking from 100% to 20%
mPathOut = new Path();
mPathOut.moveTo(1f, 1f);
mPathOut.lineTo(0.2f, 0.2f);
}
/**
* Draws the trapezoid background for the horizontal tabs on a canvas object using
* the specified color.
*
* @param canvas the canvas to draw upon
* @param color the color to use to draw the tab
*/
public static void drawTrapezoid(@NonNull Canvas canvas, int color, boolean withShader) {
Paint paint = new Paint();
paint.setColor(color);
paint.setStyle(Paint.Style.FILL);
// paint.setFilterBitmap(true);
paint.setAntiAlias(true);
paint.setDither(true);
if (withShader) {
paint.setShader(new LinearGradient(0, 0.9f * canvas.getHeight(),
0, canvas.getHeight(),
color, mixTwoColors(Color.BLACK, color, 0.5f),
Shader.TileMode.CLAMP));
} else {
paint.setShader(null);
}
int width = canvas.getWidth();
int height = canvas.getHeight();
double radians = Math.PI / 3;
int base = (int) (height / Math.tan(radians));
Path wallpath = new Path();
wallpath.reset();
wallpath.moveTo(0, height);
wallpath.lineTo(width, height);
wallpath.lineTo(width - base, 0);
wallpath.lineTo(base, 0);
wallpath.close();
canvas.drawPath(wallpath, paint);
}
@Override
protected Path createShapePath() {
Path path = new Path();
path.moveTo(shapeBox.left, shapeBox.bottom);
path.lineTo(shapeBox.centerX(), shapeBox.top);
path.lineTo(shapeBox.right, shapeBox.bottom);
path.lineTo(shapeBox.left, shapeBox.bottom);
return path;
}
protected void drawAreas(Canvas canvas) {
if (null == bandData) {
return;
}
// distance between two points
float lineLength = getDataQuadrantPaddingWidth() / displayNumber - 1;
// start point‘s X
float startX;
float lastY = 0;
float lastX = 0;
LineEntity<DateValueEntity> line1 = (LineEntity<DateValueEntity>) bandData
.get(0);
LineEntity<DateValueEntity> line2 = (LineEntity<DateValueEntity>) bandData
.get(1);
List<DateValueEntity> line1Data = line1.getLineData();
List<DateValueEntity> line2Data = line2.getLineData();
if (line1.isDisplay() == false || line2.isDisplay() == false) {
return;
}
if (line1Data == null || line2Data == null) {
return;
}
Paint mPaint = new Paint();
mPaint.setColor(line1.getLineColor());
mPaint.setAlpha(70);
mPaint.setAntiAlias(true);
// set start point’s X
startX = getDataQuadrantPaddingStartX() + lineLength / 2f;
Path areaPath = new Path();
for (int j = displayFrom;
j < displayFrom + displayNumber;
j++) {
float value1 = line1Data.get(j).getValue();
float value2 = line2Data.get(j).getValue();
// calculate Y
float valueY1 = (float) ((1f - (value1 - minValue)
/ (maxValue - minValue)) * getDataQuadrantPaddingHeight())
+ getDataQuadrantPaddingStartY();
float valueY2 = (float) ((1f - (value2 - minValue)
/ (maxValue - minValue)) * getDataQuadrantPaddingHeight())
+ getDataQuadrantPaddingStartY();
// 绘制线条路径
if (j == displayFrom) {
areaPath.moveTo(startX, valueY1);
areaPath.lineTo(startX, valueY2);
areaPath.moveTo(startX, valueY1);
} else {
areaPath.lineTo(startX, valueY1);
areaPath.lineTo(startX, valueY2);
areaPath.lineTo(lastX, lastY);
areaPath.close();
areaPath.moveTo(startX, valueY1);
}
lastX = startX;
lastY = valueY2;
startX = startX + 1 + lineLength;
}
areaPath.close();
canvas.drawPath(areaPath, mPaint);
}
private Path getTickPath(Path path, float x, float y, float size, float progress, boolean in){
if(mTickPathProgress == progress)
return path;
mTickPathProgress = progress;
float x1 = x + size * TICK_DATA[0];
float y1 = y + size * TICK_DATA[1];
float x2 = x + size * TICK_DATA[2];
float y2 = y + size * TICK_DATA[3];
float x3 = x + size * TICK_DATA[4];
float y3 = y + size * TICK_DATA[5];
float d1 = (float)Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
float d2 = (float)Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
float midProgress = d1 / (d1 + d2);
path.reset();
if(in){
path.moveTo(x1, y1);
if(progress < midProgress){
progress = progress / midProgress;
path.lineTo(x1 * (1 - progress) + x2 * progress, y1 * (1 - progress) + y2 * progress);
}
else{
progress = (progress - midProgress) / (1f - midProgress);
path.lineTo(x2, y2);
path.lineTo(x2 * (1 - progress) + x3 * progress, y2 * (1 - progress) + y3 * progress);
}
}
else{
path.moveTo(x3, y3);
if(progress < midProgress){
progress = progress / midProgress;
path.lineTo(x2, y2);
path.lineTo(x1 * (1 - progress) + x2 * progress, y1 * (1 - progress) + y2 * progress);
}
else{
progress = (progress - midProgress) / (1f - midProgress);
path.lineTo(x2 * (1 - progress) + x3 * progress, y2 * (1 - progress) + y3 * progress);
}
}
return path;
}
private Path getModeRightBottomTrianglePath(Path path, int w, int h) {
path.moveTo(0,h);
path.lineTo(w,h);
path.lineTo(w,0);
return path;
}
@Override
public Path getPath(float startX, float startY, float endX, float endY) {
Path path = new Path();
path.moveTo(startX, startY);
float ex;
float ey;
if (startY == endY) {
ex = (startX + endX) / 2;
ey = startY + mMinimumHorizontalTangent * Math.abs(endX - startX) / 2;
} else if (startX == endX) {
ex = startX + mMinimumVerticalTangent * Math.abs(endY - startY) / 2;
ey = (startY + endY) / 2;
} else {
float deltaX = endX - startX;
float deltaY;
if (endY < startY) {
deltaY = startY - endY; // Y is inverted compared to diagram above.
} else {
deltaY = endY - startY;
}
// hypotenuse squared.
float h2 = deltaX * deltaX + deltaY * deltaY;
// Midpoint between start and end
float dx = (startX + endX) / 2;
float dy = (startY + endY) / 2;
// Distance squared between end point and mid point is (1/2 hypotenuse)^2
float midDist2 = h2 * 0.25f;
float minimumArcDist2;
if (Math.abs(deltaX) < Math.abs(deltaY)) {
// Similar triangles bfa and bde mean that (ab/fb = eb/bd)
// Therefore, eb = ab * bd / fb
// ab = hypotenuse
// bd = hypotenuse/2
// fb = deltaY
float eDistY = h2 / (2 * deltaY);
ey = endY + eDistY;
ex = endX;
minimumArcDist2 = midDist2 * mMinimumVerticalTangent
* mMinimumVerticalTangent;
} else {
// Same as above, but flip X & Y
float eDistX = h2 / (2 * deltaX);
ex = endX + eDistX;
ey = endY;
minimumArcDist2 = midDist2
* mMinimumHorizontalTangent
* mMinimumHorizontalTangent;
}
float arcDistX = dx - ex;
float arcDistY = dy - ey;
float arcDist2 = arcDistX * arcDistX + arcDistY * arcDistY;
float maximumArcDist2 = midDist2 * mMaximumTangent * mMaximumTangent;
float newArcDistance2 = 0;
if (arcDist2 < minimumArcDist2) {
newArcDistance2 = minimumArcDist2;
} else if (arcDist2 > maximumArcDist2) {
newArcDistance2 = maximumArcDist2;
}
if (newArcDistance2 != 0) {
float ratio2 = newArcDistance2 / arcDist2;
float ratio = (float) Math.sqrt(ratio2);
ex = dx + (ratio * (ex - dx));
ey = dy + (ratio * (ey - dy));
}
}
float controlX1 = (startX + ex) / 2;
float controlY1 = (startY + ey) / 2;
float controlX2 = (ex + endX) / 2;
float controlY2 = (ey + endY) / 2;
path.cubicTo(controlX1, controlY1, controlX2, controlY2, endX, endY);
return path;
}
private static void drawClipPath(String clipPath, Canvas canvas, Paint paint, RectF bounds, float density) {
// Sample string is polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
String functionName = clipPath.substring(0, clipPath.indexOf("("));
String value = clipPath.substring(clipPath.indexOf("(") + 1, clipPath.indexOf(")"));
String[] arr;
float top;
float right;
float bottom;
float left;
switch (functionName) {
case "rect":
arr = spaceAndComma.split(value);
top = cssValueToDevicePixels(arr[0], bounds.bottom, density);
right = cssValueToDevicePixels(arr[1], bounds.right, density);
bottom = cssValueToDevicePixels(arr[2], bounds.bottom, density);
left = cssValueToDevicePixels(arr[3], bounds.right, density);
canvas.drawRect(left, top, right, bottom, paint);
break;
case "inset":
arr = spaceAndComma.split(value);
String topString = "0";
String rightString = "0";
String bottomString = "0";
String leftString = "0";
if (arr.length == 1) {
topString = rightString = bottomString = leftString = arr[0];
} else if (arr.length == 2) {
topString = bottomString = arr[0];
rightString = leftString = arr[1];
} else if (arr.length == 3) {
topString = arr[0];
rightString = leftString = arr[1];
bottomString = arr[2];
} else if (arr.length == 4) {
topString = arr[0];
rightString = arr[1];
bottomString = arr[2];
leftString = arr[3];
}
top = cssValueToDevicePixels(topString, bounds.bottom, density);
right = cssValueToDevicePixels("100%", bounds.right, density) - cssValueToDevicePixels(rightString, bounds.right, density);
bottom = cssValueToDevicePixels("100%", bounds.bottom, density) - cssValueToDevicePixels(bottomString, bounds.bottom, density);
left = cssValueToDevicePixels(leftString, bounds.right, density);
canvas.drawRect(left, top, right, bottom, paint);
break;
case "circle":
arr = space.split(value);
float radius = cssValueToDevicePixels(arr[0], (bounds.width() > bounds.height() ? bounds.height() : bounds.width()) / 2, density);
float y = cssValueToDevicePixels(arr[2], bounds.height(), density);
float x = cssValueToDevicePixels(arr[3], bounds.width(), density);
canvas.drawCircle(x, y, radius, paint);
break;
case "ellipse":
arr = space.split(value);
float rX = cssValueToDevicePixels(arr[0], bounds.right, density);
float rY = cssValueToDevicePixels(arr[1], bounds.bottom, density);
float cX = cssValueToDevicePixels(arr[3], bounds.right, density);
float cY = cssValueToDevicePixels(arr[4], bounds.bottom, density);
left = cX - rX;
top = cY - rY;
right = (rX * 2) + left;
bottom = (rY * 2) + top;
canvas.drawOval(new RectF(left, top, right, bottom), paint);
break;
case "polygon":
Path path = new Path();
PointF firstPoint = null;
arr = value.split(",");
for (String s : arr) {
String[] xy = space.split(s.trim());
PointF point = new PointF(cssValueToDevicePixels(xy[0], bounds.width(), density), cssValueToDevicePixels(xy[1], bounds.height(), density));
if (firstPoint == null) {
firstPoint = point;
path.moveTo(point.x, point.y);
}
path.lineTo(point.x, point.y);
}
if (firstPoint != null) {
path.lineTo(firstPoint.x, firstPoint.y);
}
canvas.drawPath(path, paint);
break;
}
}
private Path makePathAndBoundingBox(Rect obj)
{
float x, y, w, h, rx, ry;
if (obj.rx == null && obj.ry == null) {
rx = 0;
ry = 0;
} else if (obj.rx == null) {
rx = ry = obj.ry.floatValueY(this);
} else if (obj.ry == null) {
rx = ry = obj.rx.floatValueX(this);
} else {
rx = obj.rx.floatValueX(this);
ry = obj.ry.floatValueY(this);
}
rx = Math.min(rx, obj.width.floatValueX(this) / 2f);
ry = Math.min(ry, obj.height.floatValueY(this) / 2f);
x = (obj.x != null) ? obj.x.floatValueX(this) : 0f;
y = (obj.y != null) ? obj.y.floatValueY(this) : 0f;
w = obj.width.floatValueX(this);
h = obj.height.floatValueY(this);
if (obj.boundingBox == null) {
obj.boundingBox = new Box(x, y, w, h);
}
float right = x + w;
float bottom = y + h;
Path p = new Path();
if (rx == 0 || ry == 0)
{
// Simple rect
p.moveTo(x, y);
p.lineTo(right, y);
p.lineTo(right, bottom);
p.lineTo(x, bottom);
p.lineTo(x, y);
}
else
{
// Rounded rect
// Bexier control point lengths for a 90 degress arc
float cpx = rx * BEZIER_ARC_FACTOR;
float cpy = ry * BEZIER_ARC_FACTOR;
p.moveTo(x, y+ry);
p.cubicTo(x, y+ry-cpy, x+rx-cpx, y, x+rx, y);
p.lineTo(right-rx, y);
p.cubicTo(right-rx+cpx, y, right, y+ry-cpy, right, y+ry);
p.lineTo(right, bottom-ry);
p.cubicTo(right, bottom-ry+cpy, right-rx+cpx, bottom, right-rx, bottom);
p.lineTo(x+rx, bottom);
p.cubicTo(x+rx-cpx, bottom, x, bottom-ry+cpy, x, bottom-ry);
p.lineTo(x, y+ry);
}
p.close();
return p;
}
/**
* Draws the LimitLines associated with this axis to the screen.
*
* @param c
*/
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mYAxis.getLimitLines();
if (limitLines == null || limitLines.size() <= 0)
return;
float[] pts = mRenderLimitLinesBuffer;
pts[0] = 0;
pts[1] = 0;
Path limitLinePath = mRenderLimitLines;
limitLinePath.reset();
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if (!l.isEnabled())
continue;
int clipRestoreCount = c.save();
mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
mLimitLineClippingRect.inset(0.f, -l.getLineWidth());
c.clipRect(mLimitLineClippingRect);
mLimitLinePaint.setStyle(Paint.Style.STROKE);
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
pts[1] = l.getLimit();
mTrans.pointValuesToPixel(pts);
limitLinePath.moveTo(mViewPortHandler.contentLeft(), pts[1]);
limitLinePath.lineTo(mViewPortHandler.contentRight(), pts[1]);
c.drawPath(limitLinePath, mLimitLinePaint);
limitLinePath.reset();
// c.drawLines(pts, mLimitLinePaint);
String label = l.getLabel();
// if drawing the limit-value label is enabled
if (label != null && !label.equals("")) {
mLimitLinePaint.setStyle(l.getTextStyle());
mLimitLinePaint.setPathEffect(null);
mLimitLinePaint.setColor(l.getTextColor());
mLimitLinePaint.setTypeface(l.getTypeface());
mLimitLinePaint.setStrokeWidth(0.5f);
mLimitLinePaint.setTextSize(l.getTextSize());
final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset();
float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset();
final LimitLine.LimitLabelPosition position = l.getLabelPosition();
if (position == LimitLine.LimitLabelPosition.RIGHT_TOP) {
mLimitLinePaint.setTextAlign(Paint.Align.RIGHT);
c.drawText(label,
mViewPortHandler.contentRight() - xOffset,
pts[1] - yOffset + labelLineHeight, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {
mLimitLinePaint.setTextAlign(Paint.Align.RIGHT);
c.drawText(label,
mViewPortHandler.contentRight() - xOffset,
pts[1] + yOffset, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) {
mLimitLinePaint.setTextAlign(Paint.Align.LEFT);
c.drawText(label,
mViewPortHandler.contentLeft() + xOffset,
pts[1] - yOffset + labelLineHeight, mLimitLinePaint);
} else {
mLimitLinePaint.setTextAlign(Paint.Align.LEFT);
c.drawText(label,
mViewPortHandler.offsetLeft() + xOffset,
pts[1] + yOffset, mLimitLinePaint);
}
}
c.restoreToCount(clipRestoreCount);
}
}