Search in sources :

Example 6 with BarModel

use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.

the class StackedBarChart method initializeGraph.

/**
     * This is the main entry point after the graph has been inflated. Used to initialize the graph
     * and its corresponding members.
     */
@Override
protected void initializeGraph() {
    super.initializeGraph();
    mData = new ArrayList<>();
    mSeperatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSeperatorPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mSeperatorPaint.setStrokeWidth(mSeparatorWidth);
    mSeperatorPaint.setColor(0xFFFFFFFF);
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setColor(0xFFFFFFFF);
    if (this.isInEditMode()) {
        StackedBarModel s1 = new StackedBarModel();
        s1.addBar(new BarModel(2.3f, 0xFF123456));
        s1.addBar(new BarModel(2.f, 0xFF1EF556));
        s1.addBar(new BarModel(3.3f, 0xFF1BA4E6));
        StackedBarModel s2 = new StackedBarModel();
        s2.addBar(new BarModel(1.1f, 0xFF123456));
        s2.addBar(new BarModel(2.7f, 0xFF1EF556));
        s2.addBar(new BarModel(0.7f, 0xFF1BA4E6));
        addBar(s1);
        addBar(s2);
    }
}
Also used : BarModel(org.eazegraph.lib.models.BarModel) StackedBarModel(org.eazegraph.lib.models.StackedBarModel) StackedBarModel(org.eazegraph.lib.models.StackedBarModel) Paint(android.graphics.Paint)

Example 7 with BarModel

use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.

the class StackedBarChart method calculateBounds.

/**
     * Calculates the bar boundaries based on the bar width and bar margin.
     * @param _Width    Calculated bar width
     * @param _Margin   Calculated bar margin
     */
protected void calculateBounds(float _Width, float _Margin) {
    int last = 0;
    for (StackedBarModel model : mData) {
        float lastY = 0;
        float cumulatedValues = 0;
        // used if seperators are enabled, to prevent information loss
        int usableGraphHeight = mGraphHeight - (int) (mSeparatorWidth * (model.getBars().size() - 1));
        for (BarModel barModel : model.getBars()) {
            cumulatedValues += barModel.getValue();
        }
        last += _Margin / 2;
        for (BarModel barModel : model.getBars()) {
            // calculate topX for the StackedBarModel part
            float newY = ((barModel.getValue() * usableGraphHeight) / cumulatedValues) + lastY;
            float height = newY - lastY;
            Rect textBounds = new Rect();
            String value = String.valueOf(barModel.getValue());
            mTextPaint.getTextBounds(value, 0, value.length(), textBounds);
            if (textBounds.height() * 1.5f < height && textBounds.width() * 1.1f < _Width) {
                barModel.setShowValue(true);
                barModel.setValueBounds(textBounds);
            }
            barModel.setBarBounds(new RectF(last, lastY, last + _Width, newY));
            lastY = newY;
        }
        model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
        last += _Width + (_Margin / 2);
    }
    Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) BarModel(org.eazegraph.lib.models.BarModel) StackedBarModel(org.eazegraph.lib.models.StackedBarModel) StackedBarModel(org.eazegraph.lib.models.StackedBarModel) Paint(android.graphics.Paint)

Example 8 with BarModel

use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.

the class VerticalBarChart method calculateBounds.

/**
     * Calculates the bar boundaries based on the bar width and bar margin.
     * @param _Width    Calculated bar width
     * @param _Margin   Calculated bar margin
     */
protected void calculateBounds(float _Width, float _Margin) {
    float maxValue = 0;
    int last = 0;
    float maxLegendWidth = 0;
    if (mUseMaximumValue) {
        maxValue = mMaximumValue;
    } else {
        for (BarModel model : mData) {
            if (model.getValue() > maxValue) {
                maxValue = model.getValue();
            }
        }
    }
    if (mShowBarLabel) {
        float measuredText;
        for (BarModel model : mData) {
            measuredText = mValuePaint.measureText(model.getLegendLabel());
            if (maxLegendWidth < measuredText) {
                maxLegendWidth = measuredText;
            }
        }
    }
    float legendWidthDistance = mShowBarLabel ? maxLegendWidth + mValueDistance : 0;
    float widthMultiplier = (mGraphWidth - legendWidthDistance) / maxValue;
    for (BarModel model : mData) {
        float width = model.getValue() * widthMultiplier;
        last += _Margin / 2;
        model.setBarBounds(new RectF(0, last, width, last + _Width));
        model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
        last += _Width + (_Margin / 2);
    }
    Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
    mMaxFontHeight = Utils.calculateMaxTextHeight(mValuePaint, "190");
}
Also used : RectF(android.graphics.RectF) BarModel(org.eazegraph.lib.models.BarModel) Paint(android.graphics.Paint)

Example 9 with BarModel

use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.

the class VerticalBarChart method drawBars.

/**
     * Callback method for drawing the bars in the child classes.
     * @param _Canvas The canvas object of the graph view.
     */
protected void drawBars(Canvas _Canvas) {
    RectF bounds;
    String valueString;
    float animatedRightOffset;
    for (BarModel model : mData) {
        bounds = model.getBarBounds();
        valueString = Utils.getFloatString(model.getValue(), mShowDecimal) + mValueUnit;
        animatedRightOffset = bounds.right * mRevealValue;
        mGraphPaint.setColor(model.getColor());
        _Canvas.drawRect(bounds.left, bounds.top, bounds.right * mRevealValue, bounds.bottom, mGraphPaint);
        if (mShowValues && animatedRightOffset > mValuePaint.measureText(valueString)) {
            mValuePaint.setColor(mLegendColor);
            _Canvas.drawText(valueString, bounds.left + mValueDistance, bounds.centerY() + (mMaxFontHeight / 2), mValuePaint);
        }
        if (mShowBarLabel) {
            mValuePaint.setColor(mBarLabelColor);
            _Canvas.drawText(model.getLegendLabel(), animatedRightOffset + mValueDistance, bounds.centerY() + (mMaxFontHeight / 2), mValuePaint);
        }
    }
}
Also used : RectF(android.graphics.RectF) BarModel(org.eazegraph.lib.models.BarModel)

Example 10 with BarModel

use of org.eazegraph.lib.models.BarModel in project EazeGraph by blackfizz.

the class VerticalBarChart method initializeGraph.

/**
     * This is the main entry point after the graph has been inflated. Used to initialize the graph
     * and its corresponding members.
     */
@Override
protected void initializeGraph() {
    super.initializeGraph();
    mData = new ArrayList<>();
    mValuePaint = new Paint(mLegendPaint);
    if (this.isInEditMode()) {
        addBar(new BarModel(2.3f));
        addBar(new BarModel(2.f));
        addBar(new BarModel(3.3f));
        addBar(new BarModel(1.1f));
        addBar(new BarModel(2.7f));
        addBar(new BarModel(2.3f));
        addBar(new BarModel(2.f));
        addBar(new BarModel(3.3f));
        addBar(new BarModel(1.1f));
        addBar(new BarModel(2.7f));
    }
}
Also used : BarModel(org.eazegraph.lib.models.BarModel) Paint(android.graphics.Paint)

Aggregations

BarModel (org.eazegraph.lib.models.BarModel)12 Paint (android.graphics.Paint)7 StackedBarModel (org.eazegraph.lib.models.StackedBarModel)7 RectF (android.graphics.RectF)6 Rect (android.graphics.Rect)1