DataRenderer.java
5.09 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.huaheng.wms.WMSLog;
/**
* Superclass of all render classes for the different data types (line, bar, ...).
*
* @author Philipp Jahoda
*/
public abstract class DataRenderer extends Renderer {
/**
* the animator object used to perform animations on the chart data
*/
protected ChartAnimator mAnimator;
/**
* main paint object used for rendering
*/
protected Paint mRenderPaint;
/**
* paint used for highlighting values
*/
protected Paint mHighlightPaint;
protected Paint mDrawPaint;
/**
* paint object for drawing values (text representing values of chart
* entries)
*/
protected Paint mValuePaint;
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(viewPortHandler);
this.mAnimator = animator;
mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRenderPaint.setStyle(Style.FILL);
mDrawPaint = new Paint(Paint.DITHER_FLAG);
mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValuePaint.setColor(Color.rgb(63, 63, 63));
mValuePaint.setTextAlign(Align.CENTER);
mValuePaint.setTextSize(Utils.convertDpToPixel(9f));
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setStyle(Paint.Style.STROKE);
mHighlightPaint.setStrokeWidth(2f);
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
protected boolean isDrawingValuesAllowed(ChartInterface chart) {
return chart.getData().getEntryCount() < chart.getMaxVisibleCount()
* mViewPortHandler.getScaleX();
}
/**
* Returns the Paint object this renderer uses for drawing the values
* (value-text).
*
* @return
*/
public Paint getPaintValues() {
return mValuePaint;
}
/**
* Returns the Paint object this renderer uses for drawing highlight
* indicators.
*
* @return
*/
public Paint getPaintHighlight() {
return mHighlightPaint;
}
/**
* Returns the Paint object used for rendering.
*
* @return
*/
public Paint getPaintRender() {
return mRenderPaint;
}
/**
* Applies the required styling (provided by the DataSet) to the value-paint
* object.
*
* @param set
*/
protected void applyValueTextStyle(IDataSet set) {
mValuePaint.setTypeface(set.getValueTypeface());
mValuePaint.setTextSize(set.getValueTextSize());
}
/**
* Initializes the buffers used for rendering with a new size. Since this
* method performs memory allocations, it should only be called if
* necessary.
*/
public abstract void initBuffers();
/**
* Draws the actual data in form of lines, bars, ... depending on Renderer subclass.
*
* @param c
*/
public abstract void drawData(Canvas c);
/**
* Loops over all Entrys and draws their values.
*
* @param c
*/
public abstract void drawValues(Canvas c);
/**
* Draws the value of the given entry by using the provided IValueFormatter.
*
* @param c canvas
* @param formatter formatter for custom value-formatting
* @param value the value to be drawn
* @param entry the entry the value belongs to
* @param dataSetIndex the index of the DataSet the drawn Entry belongs to
* @param x position
* @param y position
* @param color
*/
public void drawValue(Canvas c, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
mValuePaint.setColor(color);
WMSLog.d("drawValue:" + value);
c.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint);
WMSLog.d("drawValue getFormattedValue:" + formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler));
}
/**
* Draws any kind of additional information (e.g. line-circles).
*
* @param c
*/
public abstract void drawExtras(Canvas c);
/**
* Draws all highlight indicators for the values that are currently highlighted.
*
* @param c
* @param indices the highlighted values
*/
public abstract void drawHighlighted(Canvas c, Highlight[] indices);
}