lecho.lib.hellocharts.model.Viewport Java Examples

The following examples show how to use lecho.lib.hellocharts.model.Viewport. 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: GoodBadChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_good_bad, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);

    generateDefaultData();
    chart.setLineChartData(data);

    // Increase viewport height for better look
    Viewport v = chart.getMaximumViewport();
    float dy = v.height() * 0.2f;
    v.inset(0, -dy);
    chart.setMaximumViewport(v);
    chart.setCurrentViewport(v);

    return rootView;
}
 
Example #2
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView                = inflater.inflate(R.layout.fragment_active_iobcob_barchart, container, false);
    iobcobChart             = (ColumnChartView) rootView.findViewById(R.id.iobcobchart);
    iobcobChart.setViewportCalculationEnabled(false);
    iobcobchartLoading      = (ProgressBar) rootView.findViewById(R.id.iobcobchartLoading);
    Viewport view           = iobcobChart.getMaximumViewport();
    view.top = 80;
    view.left = -1;
    view.right = 6;
    iobcobChart.setCurrentViewport(view);

    updateChart();

    return rootView;
}
 
Example #3
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostExecute(LineChartData result) {
    //Write some code you want to execute on UI after doInBackground() completes
    iobcobPastLoading.setVisibility(View.GONE);
    iobcobPastChart.setVisibility(View.VISIBLE);

    //refreshes data and sets viewpoint
    iobcobPastChart.setLineChartData(result);
    iobv            = new Viewport(iobcobPastChart.getMaximumViewport());                   //Sets the min and max for Top and Bottom of the viewpoint
    iobv.top        = Float.parseFloat(iobcobLineGraph.yCOBMax.toString());
    iobv.bottom     = Float.parseFloat(iobcobLineGraph.yCOBMin.toString());
    iobv.left       = previewChart.getCurrentViewport().left;
    iobv.right      = previewChart.getCurrentViewport().right;
    iobcobPastChart.setMaximumViewport(iobv);
    iobcobPastChart.setCurrentViewport(iobv);
    return ;
}
 
Example #4
Source File: ChartScroller.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: BasalProfileEditor.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private Viewport autoSetViewPort(boolean reset) {

        final Viewport moveViewPort = getNewMaxViewport();
        android.util.Log.d(TAG, "Setting viewport: " + moveViewPort.top);

        chart.setViewportCalculationEnabled(false);
        chart.setMaximumViewport(moveViewPort);

        if (reset) {
            chart.setCurrentViewport(moveViewPort);
        } else {
            final Viewport current = chart.getCurrentViewport();
            current.top = moveViewPort.top; // expand top
            chart.setCurrentViewport(current);
        }
        //chart.setZoomLevel
        BasalChart.refreshAxis(chart);
        return moveViewPort;
    }
 
Example #6
Source File: BasalProfileEditor.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private Viewport autoSetViewPort(boolean reset) {

        final Viewport moveViewPort = getNewMaxViewport();
        android.util.Log.d(TAG, "Setting viewport: " + moveViewPort.top);

        chart.setViewportCalculationEnabled(false);
        chart.setMaximumViewport(moveViewPort);

        if (reset) {
            chart.setCurrentViewport(moveViewPort);
        } else {
            final Viewport current = chart.getCurrentViewport();
            current.top = moveViewPort.top; // expand top
            chart.setCurrentViewport(current);
        }
        //chart.setZoomLevel
        BasalChart.refreshAxis(chart);
        return moveViewPort;
    }
 
Example #7
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 6 votes vote down vote up
/**
* 初始化视图
* */
protected void initView(LineChartView lineChartView) {
    pointValueList = new ArrayList<>();
    linesList = new ArrayList<>();
    //初始化坐标轴
    axisY = new Axis();
    axisX = new Axis();
    lineChartData = initData(null);
    lineChartView.setLineChartData(lineChartData);
    Viewport port = initViewPort(0, 50,150);
    lineChartView.setCurrentViewportWithAnimation(port);
    lineChartView.setInteractive(false);
    lineChartView.setScrollEnabled(true);
    lineChartView.setValueTouchEnabled(true);
    lineChartView.setFocusableInTouchMode(true);
    lineChartView.setViewportCalculationEnabled(false);
    lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    lineChartView.startDataAnimation();
    points = new ArrayList<>();
}
 
Example #8
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 最大显示区域
 */
protected Viewport initMaxViewPort(float right,float top) {
    Viewport port = new Viewport();
    if(max > top){
        port.top = max + 150;
       // Log.d("IF",max + "");
    }else {
        max = top;
        port.top = max + 150;
       // Log.d("ELSE",max + "");
    }
    port.bottom = 0;
    port.left = 0;
    port.right = right + 500;
    return port;
}
 
Example #9
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingPreviewViewport) {
        updatingChartViewport = true;
        previewChart.setZoomType(ZoomType.HORIZONTAL);
        previewChart.setCurrentViewport(newViewport, false);
        updatingChartViewport = false;
    }
}
 
Example #10
Source File: Home.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingPreviewViewport) {
        updatingChartViewport = true;
        previewChart.setZoomType(ZoomType.HORIZONTAL);
        previewChart.setCurrentViewport(newViewport);
        updatingChartViewport = false;
    }
}
 
Example #11
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 5 votes vote down vote up
protected void makeCharts(final LineChartView lineChartView,float uT){
    //实时添加新的点
    PointValue value1 = new PointValue(position * 5, uT);
    value1.setLabel("00:00");
    pointValueList.add(value1);
    float x = value1.getX();
    float y = uT;
    //根据新的点的集合画出新的线
    Line line = new Line(pointValueList);
    line.setColor(Color.RED);
    line.setShape(ValueShape.CIRCLE);
    line.setCubic(true);//曲线是否平滑
    line.setHasPoints(false);//设置折线是否含点
    linesList.clear();
    linesList.add(line);
    lineChartData = initData(linesList);
    lineChartView.setLineChartData(lineChartData);
    //根据点的横坐实时变换坐标的视图范围
    Viewport port;
    if (x > 500) {
            port = initViewPort(x - 500, x, y);
    } else {
        port = initViewPort(0, 500 ,y);
    }
    lineChartView.setCurrentViewport(port);//当前窗口

    Viewport maxPort = initMaxViewPort(x,y);//更新最大窗口设置
    lineChartView.setMaximumViewport(maxPort);//最大窗口
    position++;
}
 
Example #12
Source File: ChartZoomer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void setCurrentViewport(ChartComputator computator, float left, float top, float right, float bottom) {
    Viewport currentViewport = computator.getCurrentViewport();
    if (ZoomType.HORIZONTAL_AND_VERTICAL == zoomType) {
        computator.setCurrentViewport(left, top, right, bottom);
    } else if (ZoomType.HORIZONTAL == zoomType) {
        computator.setCurrentViewport(left, currentViewport.top, right, currentViewport.bottom);
    } else if (ZoomType.VERTICAL == zoomType) {
        computator.setCurrentViewport(currentViewport.left, top, currentViewport.right, bottom);
    }
}
 
Example #13
Source File: PreviewLineChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void previewX(boolean animate) {
    Viewport tempViewport = new Viewport(chart.getMaximumViewport());
    float dx = tempViewport.width() / 4;
    tempViewport.inset(dx, 0);
    if (animate) {
        previewChart.setCurrentViewportWithAnimation(tempViewport);
    } else {
        previewChart.setCurrentViewport(tempViewport);
    }
    previewChart.setZoomType(ZoomType.HORIZONTAL);
}
 
Example #14
Source File: PreviewColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void previewY() {
    Viewport tempViewport = new Viewport(chart.getMaximumViewport());
    float dy = tempViewport.height() / 4;
    tempViewport.inset(0, dy);
    previewChart.setCurrentViewportWithAnimation(tempViewport);
    previewChart.setZoomType(ZoomType.VERTICAL);
}
 
Example #15
Source File: AbstractChartView.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
/**
 * When embedded in a ViewPager, this will be called in order to know if we can scroll.
 * If this returns true, the ViewPager will ignore the drag so that we can scroll our content.
 * If this return false, the ViewPager will assume we won't be able to scroll and will consume the drag
 *
 * @param direction Amount of pixels being scrolled (x axis)
 * @return true if the chart can be scrolled (ie. zoomed and not against the edge of the chart)
 */
@Override
public boolean canScrollHorizontally(int direction) {
    if (getZoomLevel() <= 1.0) {
        return false;
    }
    final Viewport currentViewport = getCurrentViewport();
    final Viewport maximumViewport = getMaximumViewport();
    if (direction < 0) {
        return currentViewport.left > maximumViewport.left;
    } else {
        return currentViewport.right < maximumViewport.right;
    }
}
 
Example #16
Source File: AbstractChartView.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setCurrentViewport(Viewport targetViewport) {
    if (null != targetViewport) {
        chartRenderer.setCurrentViewport(targetViewport);
    }
    ViewCompat.postInvalidateOnAnimation(this);
}
 
Example #17
Source File: PreviewColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: ChartViewportAnimatorV8.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration) {
    this.startViewport.set(startViewport);
    this.targetViewport.set(targetViewport);
    this.duration = duration;
    isAnimationStarted = true;
    animationListener.onAnimationStarted();
    start = SystemClock.uptimeMillis();
    handler.post(runnable);
}
 
Example #19
Source File: ChartViewportAnimatorV14.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration) {
    this.startViewport.set(startViewport);
    this.targetViewport.set(targetViewport);
    animator.setDuration(duration);
    animator.start();
}
 
Example #20
Source File: PreviewLineChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void previewXY() {
    // Better to not modify viewport of any chart directly so create a copy.
    Viewport tempViewport = new Viewport(chart.getMaximumViewport());
    // Make temp viewport smaller.
    float dx = tempViewport.width() / 4;
    float dy = tempViewport.height() / 4;
    tempViewport.inset(dx, dy);
    previewChart.setCurrentViewportWithAnimation(tempViewport);
}
 
Example #21
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(2);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example #22
Source File: Home.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingChartViewport) {
        updatingPreviewViewport = true;
        chart.setZoomType(ZoomType.HORIZONTAL);
        chart.setCurrentViewport(newViewport);
        tempViewport = newViewport;
        updatingPreviewViewport = false;
    }
    if (updateStuff) {
        holdViewport.set(newViewport.left, newViewport.top, newViewport.right, newViewport.bottom);
    }
}
 
Example #23
Source File: BasalProfileEditor.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private Viewport getNewMaxViewport() {
    final Viewport moveViewPort = new Viewport(chart.getMaximumViewport());
    final float max = BasalChart.getMaxYvalue(chart.getChartData());
    final float calc = ((float) Math.round((max * 2) + 0.5f + 0.2f)) / 2 + 0.1f;
    UserError.Log.d(TAG, "BASAL max: " + max + " " + calc);
    moveViewPort.top = calc;
    //moveViewPort.set(0, 24, 0, 2);
    return moveViewPort;
}
 
Example #24
Source File: BgGraph.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
public Viewport advanceViewport(Chart chart, Chart previewChart) {
    viewport = new Viewport(previewChart.getMaximumViewport());
    viewport.inset((float) (86400000 / 2.5), 0);
    double distance_to_move = (new Date().getTime()) - viewport.left - (((viewport.right - viewport.left) / 2));
    viewport.offset((float) distance_to_move, 0);
    return viewport;
}
 
Example #25
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 5 votes vote down vote up
protected Viewport initViewPort(float left, float right,float top) {
    Viewport port = new Viewport();
    if(max > top){
        port.top = max + 150;
        // Log.d("IF",max + "");
    }else {
        max = top;
        port.top = max + 150;
        //Log.d("ELSE",max + "");
    }
    port.bottom = 0;
    port.left = left;
    port.right = right;
    return port;
}
 
Example #26
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingChartViewport) {
        updatingPreviewViewport = true;
        bgChart.setZoomType(ZoomType.HORIZONTAL);
        bgChart.setCurrentViewport(newViewport);
        tempViewport = newViewport;
        updatingPreviewViewport = false;

        if (iobcobFragmentObject.getView() != null) {                                       //Fragment is loaded
            LineChartView iobcobPastChart = (LineChartView) findViewById(R.id.iobcobPast);
            iobcobPastChart.setCurrentViewport(newViewport);
            Viewport iobv = new Viewport(iobcobPastChart.getMaximumViewport());             //Update the IOB COB Line Chart Viewport to stay inline with the preview
            iobv.left   = newViewport.left;
            iobv.right  = newViewport.right;
            iobv.top    = iobcobPastChart.getMaximumViewport().top;
            iobv.bottom = iobcobPastChart.getMaximumViewport().bottom;
            iobcobPastChart.setMaximumViewport(iobv);
            iobcobPastChart.setCurrentViewport(iobv);
        }
        if (basalvsTempBasalObject.getView() != null){
            LineChartView bvbChart = (LineChartView) findViewById(R.id.basalvsTempBasal_LineChart);
            Viewport bvbv = new Viewport(bgChart.getMaximumViewport());
            bvbv.left = newViewport.left;
            bvbv.right = newViewport.right;
            bvbv.top    = bvbChart.getMaximumViewport().top;
            bvbv.bottom = bvbChart.getMaximumViewport().bottom;
            bvbChart.setMaximumViewport(bvbv);
            bvbChart.setCurrentViewport(bvbv);

        }
    }
    if (updateStuff) {
        holdViewport.set(newViewport.left, newViewport.top, newViewport.right, newViewport.bottom);
    }
}
 
Example #27
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingPreviewViewport) {
        updatingChartViewport = true;
        bgPreviewChart.setZoomType(ZoomType.HORIZONTAL);
        bgPreviewChart.setCurrentViewport(newViewport);
        updatingChartViewport = false;

        if (iobcobFragmentObject.getView() != null) {                                       //Fragment is loaded
            LineChartView iobcobPastChart = (LineChartView) findViewById(R.id.iobcobPast);
            Viewport iobv = new Viewport(bgChart.getMaximumViewport());                       //Update the IOB COB Line Chart Viewport to stay inline with the preview
            iobv.left   = newViewport.left;
            iobv.right  = newViewport.right;
            iobv.top    = iobcobPastChart.getMaximumViewport().top;
            iobv.bottom = iobcobPastChart.getMaximumViewport().bottom;
            iobcobPastChart.setMaximumViewport(iobv);
            iobcobPastChart.setCurrentViewport(iobv);
        }
        if (basalvsTempBasalObject.getView() != null){
            LineChartView bvbChart = (LineChartView) findViewById(R.id.basalvsTempBasal_LineChart);
            Viewport bvbv = new Viewport(bgChart.getMaximumViewport());
            bvbv.left   = newViewport.left;
            bvbv.right  = newViewport.right;
            bvbv.top    = bvbChart.getMaximumViewport().top;
            bvbv.bottom = bvbChart.getMaximumViewport().bottom;
            bvbChart.setMaximumViewport(bvbv);
            bvbChart.setCurrentViewport(bvbv);
        }
    }
}
 
Example #28
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public Viewport advanceViewport(Chart chart, Chart previewChart) {
    viewport = new Viewport(previewChart.getMaximumViewport());
    viewport.inset((float) ((86400000 / 2.5) / FUZZER), 0);
    double distance_to_move = ((new Date().getTime())/ FUZZER) - viewport.left - (((viewport.right - viewport.left) /2));
    viewport.offset((float) distance_to_move, 0);
    return viewport;
}
 
Example #29
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(1);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0,0,0,0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example #30
Source File: Home.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingChartViewport) {
        updatingPreviewViewport = true;
        chart.setZoomType(ZoomType.HORIZONTAL);
        chart.setCurrentViewport(newViewport, false);
        tempViewport = newViewport;
        updatingPreviewViewport = false;
    }
    if (updateStuff == true) {
        holdViewport.set(newViewport.left, newViewport.top, newViewport.right, newViewport.bottom);
    }
}