use of com.db.chart.model.ChartSet in project WilliamChart by diogobernardino.
the class ChartView method init.
private void init() {
mReadyToDraw = false;
mThresholdStartValues = new ArrayList<>();
mThresholdEndValues = new ArrayList<>();
mThresholdStartLabels = new ArrayList<>();
mThresholdEndLabels = new ArrayList<>();
mIsDrawing = false;
data = new ArrayList<>();
mRegions = new ArrayList<>();
mAnimListener = new ChartAnimationListener() {
@Override
public boolean onAnimationUpdate(ArrayList<ChartSet> data) {
if (!mIsDrawing) {
addData(data);
postInvalidate();
return true;
}
return false;
}
};
}
use of com.db.chart.model.ChartSet in project WilliamChart by diogobernardino.
the class LineChartView method onDrawChart.
/**
* Method responsible to draw a line with the parsed screen points.
*
* @param canvas The canvas to draw on.
*/
@Override
public void onDrawChart(Canvas canvas, ArrayList<ChartSet> data) {
LineSet lineSet;
Path linePath;
for (ChartSet set : data) {
lineSet = (LineSet) set;
if (lineSet.isVisible()) {
mStyle.mLinePaint.setColor(lineSet.getColor());
mStyle.mLinePaint.setStrokeWidth(lineSet.getThickness());
applyShadow(mStyle.mLinePaint, lineSet.getAlpha(), lineSet.getShadowDx(), lineSet.getShadowDy(), lineSet.getShadowRadius(), lineSet.getShadowColor());
if (lineSet.isDashed())
mStyle.mLinePaint.setPathEffect(new DashPathEffect(lineSet.getDashedIntervals(), lineSet.getDashedPhase()));
else
mStyle.mLinePaint.setPathEffect(null);
if (!lineSet.isSmooth())
linePath = createLinePath(lineSet);
else
linePath = createSmoothLinePath(lineSet);
//Draw background
if (lineSet.hasFill() || lineSet.hasGradientFill())
canvas.drawPath(createBackgroundPath(new Path(linePath), lineSet), mStyle.mFillPaint);
//Draw line
canvas.drawPath(linePath, mStyle.mLinePaint);
//Draw points
drawPoints(canvas, lineSet);
}
}
}
use of com.db.chart.model.ChartSet in project WilliamChart by diogobernardino.
the class AxisRenderer method findBorders.
/**
* Find out what are the minimum and maximum values of the
* axis based on {@link ChartSet} values.
*
* @param sets {@link ArrayList} containing {@link ChartSet} elements of chart
*
* @return Int vector containing both minimum and maximum value to be used.
*/
int[] findBorders(ArrayList<ChartSet> sets) {
float max = Integer.MIN_VALUE;
float min = Integer.MAX_VALUE;
// Find minimum and maximum value out of all chart entries
for (ChartSet set : sets) {
for (ChartEntry e : set.getEntries()) {
if (e.getValue() >= max)
max = e.getValue();
if (e.getValue() <= min)
min = e.getValue();
}
}
max = (max < 0) ? 0 : (int) Math.ceil(max);
min = (min > 0) ? 0 : (int) Math.floor(min);
// All given set values are equal
if (min == max)
max += 1;
return new int[] { (int) min, (int) max };
}
use of com.db.chart.model.ChartSet in project WilliamChart by diogobernardino.
the class ChartView method notifyDataUpdate.
/**
* Notify {@link ChartView} about updated values. {@link ChartView} will be validated.
*/
public void notifyDataUpdate() {
// Ignore update if chart is not even ready to draw or if it is still animating
if (mAnim != null && !mAnim.isPlaying() && mReadyToDraw || mAnim == null && mReadyToDraw) {
ArrayList<float[][]> oldCoords = new ArrayList<>(data.size());
ArrayList<float[][]> newCoords = new ArrayList<>(data.size());
for (ChartSet set : data) oldCoords.add(set.getScreenPoints());
digestData();
for (ChartSet set : data) newCoords.add(set.getScreenPoints());
defineRegions(mRegions, data);
if (mAnim != null)
mAnim.prepareUpdateAnimation(oldCoords, newCoords);
else
invalidate();
} else {
Log.w(TAG, "Unexpected data update notification. " + "Chart is still not displayed or still displaying.");
}
}
Aggregations