Search in sources :

Example 6 with AxisValue

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

the class BgGraphBuilder method yAxis.

// ///////AXIS RELATED//////////////
public Axis yAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(true);
    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    yAxis.setValues(axisValues);
    yAxis.setHasLines(false);
    return yAxis;
}
Also used : AxisValue(lecho.lib.hellocharts.model.AxisValue) ArrayList(java.util.ArrayList) Axis(lecho.lib.hellocharts.model.Axis)

Example 7 with AxisValue

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

the class BasalChart method chartXAxis.

private static Axis chartXAxis(int size) {
    final Axis xAxis = new Axis();
    xAxis.setAutoGenerated(false);
    xAxis.setHasTiltedLabels(true);
    xAxis.setTiltAngle(-90f);
    xAxis.setMaxLabelChars(7);
    SimpleDateFormat sdf = new SimpleDateFormat(DateFormat.is24HourFormat(xdrip.getAppContext()) ? "HH:mm" : "a h:mm", Locale.ENGLISH);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
    // OVERRIDE SOME symbols WHILE RETAINING OTHERS
    symbols.setAmPmStrings(new String[] { "a", "p" });
    sdf.setDateFormatSymbols(symbols);
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.setTimeInMillis(JoH.tsl());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    xAxis.setAutoGenerated(false);
    final List<AxisValue> axisValues = new ArrayList<>();
    final int step = size / segments;
    final long dayStartMs = calendar.getTimeInMillis();
    final long increment = Constants.DAY_IN_MS / segments;
    for (int i = 0; i < size; i = i + step) {
        calendar.setTimeInMillis(dayStartMs + i * increment);
        axisValues.add(new AxisValue(((float) i / step) + ((float) step / 6), sdf.format(calendar.getTimeInMillis()).toCharArray()));
    }
    xAxis.setValues(axisValues);
    return xAxis;
}
Also used : AxisValue(lecho.lib.hellocharts.model.AxisValue) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Axis(lecho.lib.hellocharts.model.Axis)

Example 8 with AxisValue

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

the class BasalChart method chartYAxis.

// TODO recalculate axis on every change
@NonNull
public static Axis chartYAxis(float max_height) {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    yAxis.setHasLines(true);
    // max_height = max_height * 3;
    final float yStep = chooseClosestStep(max_height / 20f);
    // rounding???
    final List<AxisValue> axisValues = new ArrayList<>();
    // TODO autoscale this - rebuild on data change??
    for (float j = 0; j <= max_height + yStep; j += yStep) {
        axisValues.add(new AxisValue(j));
    }
    yAxis.setValues(axisValues);
    // yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(false);
    // yAxis.setTextSize(axisTextSize);
    AxisValueFormatter formatter = new SimpleAxisValueFormatter(2);
    yAxis.setFormatter(formatter);
    return yAxis;
}
Also used : AxisValue(lecho.lib.hellocharts.model.AxisValue) SimpleAxisValueFormatter(lecho.lib.hellocharts.formatter.SimpleAxisValueFormatter) ArrayList(java.util.ArrayList) Axis(lecho.lib.hellocharts.model.Axis) SimpleAxisValueFormatter(lecho.lib.hellocharts.formatter.SimpleAxisValueFormatter) AxisValueFormatter(lecho.lib.hellocharts.formatter.AxisValueFormatter) NonNull(android.support.annotation.NonNull)

Example 9 with AxisValue

use of lecho.lib.hellocharts.model.AxisValue in project Dxditor by kimi2009.

the class XjjcLiveActivity method initAxisView.

/**
 * 初始化显示坐标轴
 */
private void initAxisView() {
    pointValueList = new ArrayList<PointValue>();
    linesList = new ArrayList<Line>();
    /**
     * 初始化Y轴
     */
    axisY = new Axis();
    // 添加Y轴的名称
    axisY.setName("温度(单位:℃)");
    // Y轴分割线
    axisY.setHasLines(true);
    // 设置字体大小
    axisY.setTextSize(10);
    // axisY.setTextColor(Color.parseColor("#AFEEEE")); //设置Y轴颜色,默认浅灰色
    lineChartData = new LineChartData(linesList);
    // 设置Y轴在左边
    lineChartData.setAxisYLeft(axisY);
    /**
     * 初始化X轴
     */
    axisX = new Axis();
    // X坐标轴字体是斜的显示还是直的,true是斜的显示
    axisX.setHasTiltedLabels(false);
    // axisX.setTextColor(Color.CYAN); //设置X轴颜色
    // X轴名称
    axisX.setName("时间(单位:s)");
    // X轴分割线
    axisX.setHasLines(true);
    // 设置字体大小
    axisX.setTextSize(10);
    // 设置0的话X轴坐标值就间隔为1
    axisX.setMaxLabelChars(0);
    List<AxisValue> mAxisXValues = new ArrayList<AxisValue>();
    for (int i = 0; i < 10000; i++) {
        // 间隔5秒
        // mAxisXValues.add(new AxisValue(i).setLabel(i * 5 + ""));
        // 间隔1秒
        mAxisXValues.add(new AxisValue(i).setLabel(i + ""));
    }
    // 填充X轴的坐标名称
    axisX.setValues(mAxisXValues);
    // X轴在底部
    lineChartData.setAxisXBottom(axisX);
    xj_ChartView.setLineChartData(lineChartData);
    // 初始化X轴10个间隔坐标
    Viewport port = initViewPort(0, 10);
    xj_ChartView.setCurrentViewportWithAnimation(port);
    // 设置不可交互
    xj_ChartView.setInteractive(false);
    xj_ChartView.setScrollEnabled(true);
    xj_ChartView.setValueTouchEnabled(false);
    xj_ChartView.setFocusableInTouchMode(false);
    xj_ChartView.setViewportCalculationEnabled(false);
    xj_ChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    xj_ChartView.startDataAnimation();
}
Also used : Line(lecho.lib.hellocharts.model.Line) AxisValue(lecho.lib.hellocharts.model.AxisValue) PointValue(lecho.lib.hellocharts.model.PointValue) LineChartData(lecho.lib.hellocharts.model.LineChartData) ArrayList(java.util.ArrayList) Viewport(lecho.lib.hellocharts.model.Viewport) Axis(lecho.lib.hellocharts.model.Axis)

Example 10 with AxisValue

use of lecho.lib.hellocharts.model.AxisValue in project openScale by oliexdev.

the class GraphFragment method generateLineData.

private void generateLineData(int field, List<ScaleMeasurement> scaleMeasurementList) {
    SimpleDateFormat day_date = new SimpleDateFormat("D", Locale.getDefault());
    if (field == Calendar.DAY_OF_MONTH) {
        day_date = new SimpleDateFormat("dd", Locale.getDefault());
        if (prefs.getBoolean("showWeek", false)) {
            field = Calendar.WEEK_OF_MONTH;
            day_date = new SimpleDateFormat("w", Locale.getDefault());
        }
    } else if (field == Calendar.DAY_OF_YEAR) {
        day_date = new SimpleDateFormat("D", Locale.getDefault());
        if (prefs.getBoolean("averageData", true)) {
            field = Calendar.MONTH;
            day_date = new SimpleDateFormat("MMM", Locale.getDefault());
        }
        if (prefs.getBoolean("showWeek", false)) {
            field = Calendar.WEEK_OF_YEAR;
            day_date = new SimpleDateFormat("w", Locale.getDefault());
        }
    }
    Calendar calDays = (Calendar) calLastSelected.clone();
    calDays.setMinimalDaysInFirstWeek(7);
    calDays.set(field, calDays.getMinimum(field));
    int maxDays = calDays.getMaximum(field);
    List<AxisValue> axisValues = new ArrayList<>();
    for (int i = 0; i < calDays.getMaximum(field) + 1; i++) {
        String day_name = day_date.format(calDays.getTime());
        AxisValue xAxisValue = new AxisValue(i + calDays.getActualMinimum(field));
        xAxisValue.setLabel(day_name);
        axisValues.add(xAxisValue);
        calDays.add(field, 1);
    }
    List<Line> diagramLineList = new ArrayList<Line>();
    Calendar calDB = Calendar.getInstance();
    pointIndexScaleMeasurementList = new ArrayList<>();
    floatingActionBar.removeAllViews();
    PolynomialFitter polyFitter = new PolynomialFitter(Integer.parseInt(prefs.getString("regressionLineOrder", "1")));
    for (MeasurementView view : measurementViews) {
        if (view instanceof FloatMeasurementView) {
            FloatMeasurementView measurementView = (FloatMeasurementView) view;
            if (measurementView instanceof BMRMeasurementView) {
                continue;
            }
            Stack<PointValue> valuesStack = new Stack<>();
            ArrayList<Float>[] avgBins = new ArrayList[maxDays + 1];
            ScaleMeasurement[] indexScaleMeasurement = new ScaleMeasurement[maxDays + 1];
            for (ScaleMeasurement measurement : scaleMeasurementList) {
                measurementView.loadFrom(measurement, null);
                calDB.setTime(measurement.getDateTime());
                calDB.setMinimalDaysInFirstWeek(7);
                if (avgBins[calDB.get(field)] == null) {
                    avgBins[calDB.get(field)] = new ArrayList<>();
                }
                if (measurementView.getValue() != 0.0f) {
                    avgBins[calDB.get(field)].add(measurementView.getValue());
                    indexScaleMeasurement[calDB.get(field)] = measurement;
                }
            }
            for (int i = 0; i < maxDays + 1; i++) {
                ArrayList avgBin = avgBins[i];
                if (avgBin == null) {
                    continue;
                }
                float sum = 0.0f;
                for (int j = 0; j < avgBin.size(); j++) {
                    sum += (float) avgBin.get(j);
                }
                PointValue avgValue = new PointValue(i, sum / avgBin.size());
                if (prefs.getBoolean("regressionLine", false) && measurementView instanceof WeightMeasurementView) {
                    polyFitter.addPoint((double) avgValue.getX(), (double) avgValue.getY());
                }
                if (avgBin.size() > 1) {
                    avgValue.setLabel(String.format("Ø %.2f", avgValue.getY()));
                }
                valuesStack.push(avgValue);
                pointIndexScaleMeasurementList.add(indexScaleMeasurement[i]);
            }
            Line diagramLine = new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1));
            if (measurementView.isVisible()) {
                addFloatingActionButton(measurementView);
                if (measurementView.getSettings().isInGraph()) {
                    diagramLineList.add(diagramLine);
                }
            }
        }
    }
    LineChartData lineData = new LineChartData(diagramLineList);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(textColor));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(textColor));
    chartBottom.setLineChartData(lineData);
    defaultTopViewport = new Viewport(calDays.getActualMinimum(field), chartBottom.getCurrentViewport().top, calDays.getMaximum(field) + 1, chartBottom.getCurrentViewport().bottom);
    if (prefs.getBoolean("goalLine", true)) {
        Stack<PointValue> valuesGoalLine = new Stack<PointValue>();
        float goalWeight = openScale.getSelectedScaleUser().getGoalWeight();
        valuesGoalLine.push(new PointValue(0, goalWeight));
        valuesGoalLine.push(new PointValue(maxDays, goalWeight));
        Line goalLine = new Line(valuesGoalLine).setHasPoints(false);
        goalLine.setPathEffect(new DashPathEffect(new float[] { 10, 30 }, 0));
        diagramLineList.add(goalLine);
    }
    if (prefs.getBoolean("regressionLine", false)) {
        PolynomialFitter.Polynomial polynom = polyFitter.getBestFit();
        Stack<PointValue> valuesLinearRegression = new Stack<>();
        for (int i = 0; i < maxDays; i++) {
            double y_value = polynom.getY(i);
            valuesLinearRegression.push(new PointValue((float) i, (float) y_value));
        }
        Line linearRegressionLine = new Line(valuesLinearRegression).setColor(ChartUtils.COLOR_VIOLET).setHasPoints(false).setCubic(true);
        linearRegressionLine.setPathEffect(new DashPathEffect(new float[] { 10, 30 }, 0));
        diagramLineList.add(linearRegressionLine);
    }
    chartBottom.setLineChartData(lineData);
    chartBottom.setCurrentViewport(defaultTopViewport);
}
Also used : FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) WeightMeasurementView(com.health.openscale.gui.views.WeightMeasurementView) ArrayList(java.util.ArrayList) BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) LineChartData(lecho.lib.hellocharts.model.LineChartData) Axis(lecho.lib.hellocharts.model.Axis) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) PointValue(lecho.lib.hellocharts.model.PointValue) Calendar(java.util.Calendar) Viewport(lecho.lib.hellocharts.model.Viewport) DashPathEffect(android.graphics.DashPathEffect) WeightMeasurementView(com.health.openscale.gui.views.WeightMeasurementView) Stack(java.util.Stack) SimpleLineChartValueFormatter(lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter) Line(lecho.lib.hellocharts.model.Line) AxisValue(lecho.lib.hellocharts.model.AxisValue) PolynomialFitter(com.health.openscale.core.utils.PolynomialFitter) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AxisValue (lecho.lib.hellocharts.model.AxisValue)20 ArrayList (java.util.ArrayList)18 Axis (lecho.lib.hellocharts.model.Axis)18 GregorianCalendar (java.util.GregorianCalendar)7 SimpleDateFormat (java.text.SimpleDateFormat)6 NonNull (android.support.annotation.NonNull)4 Calendar (java.util.Calendar)4 Column (lecho.lib.hellocharts.model.Column)3 ColumnChartData (lecho.lib.hellocharts.model.ColumnChartData)3 Line (lecho.lib.hellocharts.model.Line)3 LineChartData (lecho.lib.hellocharts.model.LineChartData)3 SelectedValue (lecho.lib.hellocharts.model.SelectedValue)3 SubcolumnValue (lecho.lib.hellocharts.model.SubcolumnValue)3 Context (android.content.Context)2 Paint (android.graphics.Paint)2 Rect (android.graphics.Rect)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 TextView (android.widget.TextView)2 InjectView (butterknife.InjectView)2