package com.cpm.lorealbaMabeline.utils;

import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.renderer.BarChartRenderer;
import com.github.mikephil.charting.utils.ViewPortHandler;

public class GradientBarChartRenderer extends BarChartRenderer {
    private Drawable targetDrawable;
    private Drawable actualDrawable;

    public GradientBarChartRenderer(BarChart chart, ViewPortHandler viewPortHandler, Drawable targetDrawable, Drawable actualDrawable) {
        super(chart, chart.getAnimator(), viewPortHandler);
        this.targetDrawable = targetDrawable;
        this.actualDrawable = actualDrawable;
    }

    @Override
    protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
        float[] buffer = mBarBuffers[index].buffer;
        for (int j = 0; j < buffer.length; j += 4) {
            float left = buffer[j];
            float top = buffer[j + 1];
            float right = buffer[j + 2];
            float bottom = buffer[j + 3];

            if (j % 8 == 0) { // Target segment
                targetDrawable.setBounds((int) left, (int) top, (int) right, (int) bottom);
                targetDrawable.draw(c);
            } else { // Actual segment
                actualDrawable.setBounds((int) left, (int) top, (int) right, (int) bottom);
                actualDrawable.draw(c);
            }
        }
    }
}
