Search in sources :

Example 1 with ChartSet

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;
        }
    };
}
Also used : ChartSet(com.db.chart.model.ChartSet) ChartAnimationListener(com.db.chart.animation.ChartAnimationListener)

Example 2 with ChartSet

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);
        }
    }
}
Also used : Path(android.graphics.Path) DashPathEffect(android.graphics.DashPathEffect) LineSet(com.db.chart.model.LineSet) ChartSet(com.db.chart.model.ChartSet)

Example 3 with ChartSet

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 };
}
Also used : ChartEntry(com.db.chart.model.ChartEntry) ChartSet(com.db.chart.model.ChartSet)

Example 4 with ChartSet

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.");
    }
}
Also used : ArrayList(java.util.ArrayList) ChartSet(com.db.chart.model.ChartSet)

Aggregations

ChartSet (com.db.chart.model.ChartSet)4 DashPathEffect (android.graphics.DashPathEffect)1 Path (android.graphics.Path)1 ChartAnimationListener (com.db.chart.animation.ChartAnimationListener)1 ChartEntry (com.db.chart.model.ChartEntry)1 LineSet (com.db.chart.model.LineSet)1 ArrayList (java.util.ArrayList)1