Search in sources :

Example 16 with Bar

use of com.db.chart.model.Bar in project WilliamChart by diogobernardino.

the class StackBarChartView method defineRegions.

@Override
void defineRegions(ArrayList<ArrayList<Region>> regions, ArrayList<ChartSet> data) {
    int dataSize = data.size();
    int setSize = data.get(0).size();
    float verticalOffset;
    float currBottomY;
    float negVerticalOffset;
    float negCurrBottomY;
    float y1;
    float barSize;
    BarSet barSet;
    Bar bar;
    float zeroPosition = this.getZeroPosition();
    for (int i = 0; i < setSize; i++) {
        // Vertical offset to keep drawing bars on top of the others
        verticalOffset = 0;
        negVerticalOffset = 0;
        // Bottom of the next bar to be drawn
        currBottomY = zeroPosition;
        negCurrBottomY = zeroPosition;
        for (int j = 0; j < dataSize; j++) {
            barSet = (BarSet) data.get(j);
            bar = (Bar) barSet.getEntry(i);
            barSize = Math.abs(zeroPosition - bar.getY());
            // Then no need to have region
            if (!barSet.isVisible())
                continue;
            if (bar.getValue() > 0) {
                y1 = zeroPosition - (barSize + verticalOffset);
                regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) y1, (int) (bar.getX() + barWidth / 2), (int) currBottomY);
                currBottomY = y1;
                verticalOffset += barSize + 2;
            } else if (bar.getValue() < 0) {
                y1 = zeroPosition + (barSize - negVerticalOffset);
                regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) negCurrBottomY, (int) (bar.getX() + barWidth / 2), (int) y1);
                negCurrBottomY = y1;
                negVerticalOffset -= barSize;
            } else {
                // If bar.getValue() == 0, force region to 1 pixel
                y1 = zeroPosition - (1 + verticalOffset);
                regions.get(j).get(i).set((int) (bar.getX() - barWidth / 2), (int) y1, (int) (bar.getX() + barWidth / 2), (int) currBottomY);
            }
        }
    }
}
Also used : Bar(com.db.chart.model.Bar) BarSet(com.db.chart.model.BarSet)

Aggregations

Bar (com.db.chart.model.Bar)16 BarSet (com.db.chart.model.BarSet)16 Before (org.junit.Before)4 Rect (android.graphics.Rect)3 LinearGradient (android.graphics.LinearGradient)2 Paint (android.graphics.Paint)2 MediumTest (android.test.suitebuilder.annotation.MediumTest)2 Test (org.junit.Test)2 CardView (android.support.v7.widget.CardView)1 View (android.view.View)1 TextView (android.widget.TextView)1 Animation (com.db.chart.animation.Animation)1 OnEntryClickListener (com.db.chart.listener.OnEntryClickListener)1 Tooltip (com.db.chart.tooltip.Tooltip)1 HorizontalBarChartView (com.db.chart.view.HorizontalBarChartView)1