Java Code Examples for lecho.lib.hellocharts.model.SubcolumnValue#getValue()

The following examples show how to use lecho.lib.hellocharts.model.SubcolumnValue#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private void calculateMaxViewportForStacked(ColumnChartData data) {
    for (Column column : data.getColumns()) {
        float sumPositive = baseValue;
        float sumNegative = baseValue;
        for (SubcolumnValue columnValue : column.getValues()) {
            if (columnValue.getValue() >= baseValue) {
                sumPositive += columnValue.getValue();
            } else {
                sumNegative += columnValue.getValue();
            }
        }
        if (sumPositive > tempMaximumViewport.top) {
            tempMaximumViewport.top = sumPositive;
        }
        if (sumNegative < tempMaximumViewport.bottom) {
            tempMaximumViewport.bottom = sumNegative;
        }
    }
}
 
Example 2
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void calculateMaxViewportForSubcolumns(ColumnChartData data) {
    for (Column column : data.getColumns()) {
        for (SubcolumnValue columnValue : column.getValues()) {
            if (columnValue.getValue() >= baseValue && columnValue.getValue() > tempMaximumViewport.top) {
                tempMaximumViewport.top = columnValue.getValue();
            }
            if (columnValue.getValue() < baseValue && columnValue.getValue() < tempMaximumViewport.bottom) {
                tempMaximumViewport.bottom = columnValue.getValue();
            }
        }
    }
}
 
Example 3
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void processColumnForStacked(Canvas canvas, Column column, float columnWidth, int columnIndex, int mode) {
    final float rawX = computator.computeRawX(columnIndex);
    final float halfColumnWidth = columnWidth / 2;
    float mostPositiveValue = baseValue;
    float mostNegativeValue = baseValue;
    float subcolumnBaseValue = baseValue;
    int valueIndex = 0;
    for (SubcolumnValue columnValue : column.getValues()) {
        columnPaint.setColor(columnValue.getColor());
        if (columnValue.getValue() >= baseValue) {
            // Using values instead of raw pixels make code easier to
            // understand(for me)
            subcolumnBaseValue = mostPositiveValue;
            mostPositiveValue += columnValue.getValue();
        } else {
            subcolumnBaseValue = mostNegativeValue;
            mostNegativeValue += columnValue.getValue();
        }
        final float rawBaseY = computator.computeRawY(subcolumnBaseValue);
        final float rawY = computator.computeRawY(subcolumnBaseValue + columnValue.getValue());
        calculateRectToDraw(columnValue, rawX - halfColumnWidth, rawX + halfColumnWidth, rawBaseY, rawY);
        switch (mode) {
            case MODE_DRAW:
                drawSubcolumn(canvas, column, columnValue, true);
                break;
            case MODE_HIGHLIGHT:
                highlightSubcolumn(canvas, column, columnValue, valueIndex, true);
                break;
            case MODE_CHECK_TOUCH:
                checkRectToDraw(columnIndex, valueIndex);
                break;
            default:
                // There no else, every case should be handled or exception will
                // be thrown
                throw new IllegalStateException("Cannot process column in mode: " + mode);
        }
        ++valueIndex;
    }
}
 
Example 4
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void calculateRectToDraw(SubcolumnValue columnValue, float left, float right, float rawBaseY, float rawY) {
    // Calculate rect that will be drawn as column, subcolumn or label background.
    drawRect.left = left;
    drawRect.right = right;
    if (columnValue.getValue() >= baseValue) {
        drawRect.top = rawY;
        drawRect.bottom = rawBaseY - subcolumnSpacing;
    } else {
        drawRect.bottom = rawY;
        drawRect.top = rawBaseY + subcolumnSpacing;
    }
}
 
Example 5
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void drawLabel(Canvas canvas, Column column, SubcolumnValue columnValue, boolean isStacked, float offset) {
    final int numChars = column.getFormatter().formatChartValue(labelBuffer, columnValue);

    if (numChars == 0) {
        // No need to draw empty label
        return;
    }

    final float labelWidth = labelPaint.measureText(labelBuffer, labelBuffer.length - numChars, numChars);
    final int labelHeight = Math.abs(fontMetrics.ascent);
    float left = drawRect.centerX() - labelWidth / 2 - labelMargin;
    float right = drawRect.centerX() + labelWidth / 2 + labelMargin;
    float top;
    float bottom;
    if (isStacked && labelHeight < drawRect.height() - (2 * labelMargin)) {
        // For stacked columns draw label only if label height is less than subcolumn height - (2 * labelMargin).
        if (columnValue.getValue() >= baseValue) {
            top = drawRect.top;
            bottom = drawRect.top + labelHeight + labelMargin * 2;
        } else {
            top = drawRect.bottom - labelHeight - labelMargin * 2;
            bottom = drawRect.bottom;
        }
    } else if (!isStacked) {
        // For not stacked draw label at the top for positive and at the bottom for negative values
        if (columnValue.getValue() >= baseValue) {
            top = drawRect.top - offset - labelHeight - labelMargin * 2;
            if (top < computator.getContentRectMinusAllMargins().top) {
                top = drawRect.top + offset;
                bottom = drawRect.top + offset + labelHeight + labelMargin * 2;
            } else {
                bottom = drawRect.top - offset;
            }
        } else {
            bottom = drawRect.bottom + offset + labelHeight + labelMargin * 2;
            if (bottom > computator.getContentRectMinusAllMargins().bottom) {
                top = drawRect.bottom - offset - labelHeight - labelMargin * 2;
                bottom = drawRect.bottom - offset;
            } else {
                top = drawRect.bottom + offset;
            }
        }
    } else {
        // Draw nothing.
        return;
    }

    labelBackgroundRect.set(left, top, right, bottom);
    drawLabelTextAndBackground(canvas, labelBuffer, labelBuffer.length - numChars, numChars,
            columnValue.getDarkenColor());

}