Search in sources :

Example 6 with Viewport

use of lecho.lib.hellocharts.model.Viewport in project hellocharts-android by lecho.

the class BubbleChartRenderer method removeMargins.

/**
     * Removes empty spaces on sides of chart(left-right for landscape, top-bottom for portrait). *This method should be
     * called after layout had been drawn*. Because most often chart is drawn as rectangle with proportions other than
     * 1:1 and bubbles have to be drawn as circles not ellipses I am unable to calculate correct margins based on chart
     * data only. I need to know chart dimension to remove extra empty spaces, that bad because viewport depends a
     * little on contentRectMinusAllMargins.
     */
public void removeMargins() {
    final Rect contentRect = computator.getContentRectMinusAllMargins();
    if (contentRect.height() == 0 || contentRect.width() == 0) {
        // View probably not yet measured, skip removing margins.
        return;
    }
    final float pxX = computator.computeRawDistanceX(maxRadius * bubbleScaleX);
    final float pxY = computator.computeRawDistanceY(maxRadius * bubbleScaleY);
    final float scaleX = computator.getMaximumViewport().width() / contentRect.width();
    final float scaleY = computator.getMaximumViewport().height() / contentRect.height();
    float dx = 0;
    float dy = 0;
    if (isBubbleScaledByX) {
        dy = (pxY - pxX) * scaleY * 0.75f;
    } else {
        dx = (pxX - pxY) * scaleX * 0.75f;
    }
    Viewport maxViewport = computator.getMaximumViewport();
    maxViewport.inset(dx, dy);
    Viewport currentViewport = computator.getCurrentViewport();
    currentViewport.inset(dx, dy);
    computator.setMaxViewport(maxViewport);
    computator.setCurrentViewport(currentViewport);
}
Also used : Rect(android.graphics.Rect) Viewport(lecho.lib.hellocharts.model.Viewport)

Example 7 with Viewport

use of lecho.lib.hellocharts.model.Viewport in project hellocharts-android by lecho.

the class PreviewColumnChartRenderer method drawUnclipped.

@Override
public void drawUnclipped(Canvas canvas) {
    super.drawUnclipped(canvas);
    final Viewport currentViewport = computator.getCurrentViewport();
    final float left = computator.computeRawX(currentViewport.left);
    final float top = computator.computeRawY(currentViewport.top);
    final float right = computator.computeRawX(currentViewport.right);
    final float bottom = computator.computeRawY(currentViewport.bottom);
    previewPaint.setAlpha(DEFAULT_PREVIEW_TRANSPARENCY);
    previewPaint.setStyle(Paint.Style.FILL);
    canvas.drawRect(left, top, right, bottom, previewPaint);
    previewPaint.setStyle(Paint.Style.STROKE);
    previewPaint.setAlpha(FULL_ALPHA);
    canvas.drawRect(left, top, right, bottom, previewPaint);
}
Also used : Viewport(lecho.lib.hellocharts.model.Viewport)

Example 8 with Viewport

use of lecho.lib.hellocharts.model.Viewport in project hellocharts-android by lecho.

the class PreviewLineChartRenderer method drawUnclipped.

@Override
public void drawUnclipped(Canvas canvas) {
    super.drawUnclipped(canvas);
    final Viewport currentViewport = computator.getCurrentViewport();
    final float left = computator.computeRawX(currentViewport.left);
    final float top = computator.computeRawY(currentViewport.top);
    final float right = computator.computeRawX(currentViewport.right);
    final float bottom = computator.computeRawY(currentViewport.bottom);
    previewPaint.setAlpha(DEFAULT_PREVIEW_TRANSPARENCY);
    previewPaint.setStyle(Paint.Style.FILL);
    canvas.drawRect(left, top, right, bottom, previewPaint);
    previewPaint.setStyle(Paint.Style.STROKE);
    previewPaint.setAlpha(FULL_ALPHA);
    canvas.drawRect(left, top, right, bottom, previewPaint);
}
Also used : Viewport(lecho.lib.hellocharts.model.Viewport)

Example 9 with Viewport

use of lecho.lib.hellocharts.model.Viewport in project hellocharts-android by lecho.

the class AbstractChartView method moveToWithAnimation.

@Override
public void moveToWithAnimation(float x, float y) {
    Viewport scrollViewport = computeScrollViewport(x, y);
    setCurrentViewportWithAnimation(scrollViewport);
}
Also used : Viewport(lecho.lib.hellocharts.model.Viewport)

Example 10 with Viewport

use of lecho.lib.hellocharts.model.Viewport in project hellocharts-android by lecho.

the class ChartScroller method computeScrollOffset.

public boolean computeScrollOffset(ChartComputator computator) {
    if (scroller.computeScrollOffset()) {
        // The scroller isn't finished, meaning a fling or programmatic pan operation is
        // currently active.
        final Viewport maxViewport = computator.getMaximumViewport();
        computator.computeScrollSurfaceSize(surfaceSizeBuffer);
        final float currXRange = maxViewport.left + maxViewport.width() * scroller.getCurrX() / surfaceSizeBuffer.x;
        final float currYRange = maxViewport.top - maxViewport.height() * scroller.getCurrY() / surfaceSizeBuffer.y;
        computator.setViewportTopLeft(currXRange, currYRange);
        return true;
    }
    return false;
}
Also used : Viewport(lecho.lib.hellocharts.model.Viewport)

Aggregations

Viewport (lecho.lib.hellocharts.model.Viewport)16 Rect (android.graphics.Rect)4 Paint (android.graphics.Paint)2 ZoomType (lecho.lib.hellocharts.gesture.ZoomType)1 AxisValue (lecho.lib.hellocharts.model.AxisValue)1