private void previewY() { Viewport tempViewport = new Viewport(recordChart.getMaximumViewport()); float dy = (tempViewport.height() + 0.2f) / 4; tempViewport.inset(0, dy); recordPreviewChart.setCurrentViewportWithAnimation(tempViewport); recordPreviewChart.setZoomType(ZoomType.VERTICAL); }
private void previewXY() { // Better to not modify viewport of any recordChart directly so create a copy. Viewport tempViewport = new Viewport(recordChart.getMaximumViewport()); // Make temp viewport smaller. float dx = tempViewport.width() / 4; float dy = tempViewport.height() / 4; tempViewport.inset(dx, dy); recordPreviewChart.setCurrentViewportWithAnimation(tempViewport); }
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); }
@Override public void onViewportChanged(Viewport newViewport) { if (!updatingChartViewport) { updatingPreviewViewport = true; chart.setZoomType(ZoomType.HORIZONTAL); chart.setCurrentViewport(newViewport); tempViewport = newViewport; updatingPreviewViewport = false; if (iobcobFragmentObject.getView() != null) { // Fragment is loaded LineChartView iobcobPastChart = (LineChartView) findViewById(R.id.iobcobPast); iobcobPastChart.setZoomType(ZoomType.HORIZONTAL); 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; iobcobPastChart.setCurrentViewport(iobv); } if (basalvsTempBasalObject.getView() != null) { LineChartView bvbChart = (LineChartView) findViewById(R.id.basalvsTempBasal_LineChart); bvbChart.setZoomType(ZoomType.HORIZONTAL); bvbChart.setCurrentViewport(newViewport); Viewport bvbv = new Viewport(bvbChart.getMaximumViewport()); bvbv.left = newViewport.left; bvbv.right = newViewport.right; bvbChart.setCurrentViewport(bvbv); } } if (updateStuff == true) { holdViewport.set(newViewport.left, newViewport.top, newViewport.right, newViewport.bottom); } }
public void setupCharts() { if (bgDataList.size() > 0) { // Dont crash things just because we dont have values, people dont like crashy things if (singleLine) { bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, pointSize, midColor); } else { bgGraphBuilder = new BgGraphBuilder( getApplicationContext(), bgDataList, pointSize, highColor, lowColor, midColor); } chart.setLineChartData(bgGraphBuilder.lineData()); chart.setViewportCalculationEnabled(true); chart.setMaximumViewport(chart.getMaximumViewport()); } else { ListenerService.requestData(this); } }
public void setupChart() { basalvsTempBasalChart.setZoomType(ZoomType.HORIZONTAL); basalvsTempBasalChart.setLineChartData(extendedGraphBuilder.basalvsTempBasalData()); Viewport iobv = new Viewport( basalvsTempBasalChart .getMaximumViewport()); // Sets the min and max for Top and Bottom of the // viewpoint iobv.top = extendedGraphBuilder.maxBasal.floatValue(); iobv.bottom = -(extendedGraphBuilder.maxBasal.floatValue() - 1); basalvsTempBasalChart.setMaximumViewport(iobv); iobv.left = previewChart.getCurrentViewport().left; iobv.right = previewChart.getCurrentViewport().right; basalvsTempBasalChart.setCurrentViewport(iobv); basalvsTempBasalChart.setViewportCalculationEnabled(true); // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener()); // //causes a crash, no idea why #// TODO: 28/08/2015 }
public void setupChart() { iobcobPastChart.setZoomType(ZoomType.HORIZONTAL); iobcobPastChart.setLineChartData(extendedGraphBuilder.iobcobPastLineData()); Viewport iobv = new Viewport( iobcobPastChart .getMaximumViewport()); // Sets the min and max for Top and Bottom of the // viewpoint iobv.top = Float.parseFloat(extendedGraphBuilder.yCOBMax.toString()); iobv.bottom = Float.parseFloat(extendedGraphBuilder.yCOBMin.toString()); iobcobPastChart.setMaximumViewport(iobv); iobv.left = previewChart.getCurrentViewport().left; iobv.right = previewChart.getCurrentViewport().right; iobcobPastChart.setCurrentViewport(iobv); iobcobPastChart.setViewportCalculationEnabled(true); // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener()); // //causes a crash, no idea why #// TODO: 28/08/2015 }
private void updateGraph(Cursor cursor) { // set up the goal line SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int goalCalories = Integer.parseInt(prefs.getString("preference_calorie_goal", "2000")); List<PointValue> goalValues = new ArrayList<>(); // set up the data List<PointValue> values = new ArrayList<>(); cursor.moveToFirst(); if (!cursor.isAfterLast()) { goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories)); } while (cursor.isAfterLast() == false) { float value = cursor.getFloat(cursor.getColumnIndex("total")); // Log.d("graph", "adding " + value + " on " + sdf.format(getTimeFromRow(cursor))); values.add(new PointValue(getTimeFromRow(cursor), value)); cursor.moveToNext(); } cursor.moveToLast(); goalValues.add(new PointValue(getTimeFromRow(cursor), goalCalories)); List<Line> lines = new ArrayList<Line>(); Line goalLine = new Line(goalValues).setColor(Color.parseColor("#ff0000")); lines.add(goalLine); Line line = new Line(values).setColor(Color.parseColor("#44a134")).setCubic(true); // line.setFilled(true); // line.setHasLabels(true); lines.add(line); LineChartData data = new LineChartData(); data.setLines(lines); Axis timeAxis = new Axis(); // timeAxis.setName(""); // timeAxis.setTextColor(ChartUtils.COLOR_ORANGE); timeAxis.setMaxLabelChars(5); timeAxis.setFormatter(new TimestampAxisFormatter()); timeAxis.setHasLines(true); timeAxis.setHasTiltedLabels(true); data.setAxisXBottom(timeAxis); Axis calorieAxis = new Axis(); // weightAxis.setName(""); // weightAxis.setTextColor(ChartUtils.COLOR_GREEN); calorieAxis.setMaxLabelChars(7); calorieAxis.setFormatter(new SimpleAxisValueFormatter().setAppendedText(" C".toCharArray())); calorieAxis.setHasLines(true); calorieAxis.setHasTiltedLabels(true); data.setAxisYLeft(calorieAxis); hellochart.setLineChartData(data); hellochart.setZoomType(ZoomType.HORIZONTAL); hellochart.setOnValueTouchListener(new ValueTouchListener()); // set up zoom so we can see 0 calories Viewport viewport = new Viewport(hellochart.getMaximumViewport()); viewport.bottom = 0; hellochart.setMaximumViewport(viewport); hellochart.setCurrentViewport(viewport); hellochart.invalidate(); }