Search in sources :

Example 26 with Axis

use of lecho.lib.hellocharts.model.Axis in project xDrip-plus by jamorham.

the class LibreTrendGraph method setupCharts.

public void setupCharts() {
    final TextView trendView = (TextView) findViewById(R.id.textLibreHeader);
    chart = (LineChartView) findViewById(R.id.libre_chart);
    List<Line> lines = new ArrayList<Line>();
    List<PointValue> lineValues = new ArrayList<PointValue>();
    final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);
    LibreBlock libreBlock = LibreBlock.getLatestForTrend();
    if (libreBlock == null) {
        trendView.setText("No libre data to display");
        setupEmptyCharts();
        return;
    }
    String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp));
    ArrayList<Float> bg_data = getLatestBg(libreBlock);
    if (bg_data == null) {
        trendView.setText("Error displaying data for " + time);
        setupEmptyCharts();
        return;
    }
    trendView.setText("Scan from " + time);
    float min = 1000;
    float max = 0;
    int i = 0;
    for (float bg : bg_data) {
        if (min > bg) {
            min = bg;
        }
        if (max < bg) {
            max = bg;
        }
        lineValues.add(new PointValue(-i, bg * conversion_factor_mmol));
        i++;
    }
    Line trendLine = new Line(lineValues);
    trendLine.setColor(ChartUtils.COLOR_RED);
    trendLine.setHasLines(false);
    trendLine.setHasPoints(true);
    lines.add(trendLine);
    final int MIN_GRAPH = 20;
    if (max - min < MIN_GRAPH) {
        // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way.
        // I will add two dummy invisible points that will cause the graph to look with bigger Y range.
        float average = (max + min) / 2;
        List<PointValue> dummyPointValues = new ArrayList<PointValue>();
        Line dummyPointLine = new Line(dummyPointValues);
        dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointLine.setColor(ChartUtils.COLOR_RED);
        dummyPointLine.setHasLines(false);
        dummyPointLine.setHasPoints(false);
        lines.add(dummyPointLine);
    }
    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setTextSize(16);
    axisY.setTextSize(16);
    axisX.setName("Time from last scan");
    axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));
    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);
}
Also used : PointValue(lecho.lib.hellocharts.model.PointValue) ArrayList(java.util.ArrayList) Date(java.util.Date) Line(lecho.lib.hellocharts.model.Line) LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock) LineChartData(lecho.lib.hellocharts.model.LineChartData) TextView(android.widget.TextView) Axis(lecho.lib.hellocharts.model.Axis)

Example 27 with Axis

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

the class AxesRenderer method drawInBackground.

/**
 * Prepare axes coordinates and draw axes lines(if enabled) in the background.
 *
 * @param canvas
 */
public void drawInBackground(Canvas canvas) {
    Axis axis = chart.getChartData().getAxisYLeft();
    if (null != axis) {
        prepareAxisToDraw(axis, LEFT);
        drawAxisLines(canvas, axis, LEFT);
    }
    axis = chart.getChartData().getAxisYRight();
    if (null != axis) {
        prepareAxisToDraw(axis, RIGHT);
        drawAxisLines(canvas, axis, RIGHT);
    }
    axis = chart.getChartData().getAxisXBottom();
    if (null != axis) {
        prepareAxisToDraw(axis, BOTTOM);
        drawAxisLines(canvas, axis, BOTTOM);
    }
    axis = chart.getChartData().getAxisXTop();
    if (null != axis) {
        prepareAxisToDraw(axis, TOP);
        drawAxisLines(canvas, axis, TOP);
    }
}
Also used : Axis(lecho.lib.hellocharts.model.Axis)

Aggregations

Axis (lecho.lib.hellocharts.model.Axis)27 ArrayList (java.util.ArrayList)21 AxisValue (lecho.lib.hellocharts.model.AxisValue)14 Line (lecho.lib.hellocharts.model.Line)10 LineChartData (lecho.lib.hellocharts.model.LineChartData)9 PointValue (lecho.lib.hellocharts.model.PointValue)8 GregorianCalendar (java.util.GregorianCalendar)5 TextView (android.widget.TextView)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 Column (lecho.lib.hellocharts.model.Column)3 ColumnChartData (lecho.lib.hellocharts.model.ColumnChartData)3 SelectedValue (lecho.lib.hellocharts.model.SelectedValue)3 SubcolumnValue (lecho.lib.hellocharts.model.SubcolumnValue)3 Viewport (lecho.lib.hellocharts.model.Viewport)3 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2