-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphView.java
63 lines (47 loc) · 1.61 KB
/
GraphView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cz.ales.training;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by ales on 6.3.18.
*/
public class GraphView extends View {
public GraphView(Context context) {
super(context);
}
public GraphView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GraphView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
float graphSizeX = getWidth();
float graphSizeY = getHeight();
float borderX = 50;
float borderY = 50;
drawBackground(paint, canvas);
drawAxes(paint, canvas, graphSizeX, graphSizeY, borderX, borderY);
}
private void drawBackground(Paint paint, Canvas canvas) {
paint.setColor(Color.LTGRAY); //bílé pozadí
canvas.drawPaint(paint);
}
private void drawAxes(Paint paint, Canvas canvas, float sizeX, float sizeY, float borderX, float borderY) {
float overlapX = 150;
float overlapY = 100;
paint.setColor(Color.DKGRAY);
paint.setStrokeWidth(10);
paint.setStrokeCap(Paint.Cap.ROUND);
//y axis
canvas.drawLine(borderX+overlapX, sizeY-borderY, borderX+overlapX, borderY, paint);
//x
canvas.drawLine(borderX, sizeY-borderY-overlapY, sizeX-borderX, sizeY-borderY-overlapY, paint);
}
}