use of lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter in project xDrip by NightscoutFoundation.
the class BgGraphBuilder method treatmentValuesLine.
public Line[] treatmentValuesLine() {
Line[] lines = new Line[9];
try {
lines[0] = new Line(treatmentValues);
lines[0].setColor(getCol(X.color_treatment_dot_background));
lines[0].setHasLines(false);
lines[0].setPointRadius(pointSize * 5 / 2);
lines[0].setHasPoints(true);
lines[1] = new Line(treatmentValues);
lines[1].setColor(getCol(X.color_treatment_dot_foreground));
lines[1].setHasLines(false);
lines[1].setPointRadius(pointSize * 5 / 4);
lines[1].setHasPoints(true);
lines[1].setShape(ValueShape.DIAMOND);
lines[1].setHasLabels(true);
LineChartValueFormatter formatter = new SimpleLineChartValueFormatter(1);
lines[1].setFormatter(formatter);
// insulin on board
lines[2] = new Line(iobValues);
lines[2].setColor(getCol(X.color_treatment));
// need splitter for cubics
lines[2].setHasLines(true);
lines[2].setCubic(false);
lines[2].setFilled(true);
lines[2].setAreaTransparency(35);
lines[2].setFilled(true);
lines[2].setPointRadius(1);
lines[2].setHasPoints(true);
// lines[2].setShape(ValueShape.DIAMOND);
// lines[2].setHasLabels(true);
// iactivity on board
lines[3] = new Line(activityValues);
lines[3].setColor(getCol(X.color_treatment_dark));
lines[3].setHasLines(false);
lines[3].setCubic(false);
lines[3].setFilled(false);
lines[3].setFilled(false);
lines[3].setPointRadius(1);
lines[3].setHasPoints(true);
// annotations
lines[4] = new Line(annotationValues);
lines[4].setColor(getCol(X.color_treatment_dot_foreground));
lines[4].setHasLines(false);
lines[4].setCubic(false);
lines[4].setFilled(false);
lines[4].setPointRadius(0);
lines[4].setHasPoints(true);
lines[4].setHasLabels(true);
lines[5] = new Line(predictedBgValues);
lines[5].setColor(getCol(X.color_predictive));
lines[5].setHasLines(false);
lines[5].setCubic(false);
lines[5].setStrokeWidth(1);
lines[5].setFilled(false);
lines[5].setPointRadius(2);
lines[5].setHasPoints(true);
lines[5].setHasLabels(false);
lines[6] = new Line(cobValues);
lines[6].setColor(getCol(X.color_predictive_dark));
lines[6].setHasLines(false);
lines[6].setCubic(false);
lines[6].setFilled(false);
lines[6].setPointRadius(1);
lines[6].setHasPoints(true);
lines[6].setHasLabels(false);
lines[7] = new Line(polyBgValues);
lines[7].setColor(ChartUtils.COLOR_RED);
lines[7].setHasLines(false);
lines[7].setCubic(false);
lines[7].setStrokeWidth(1);
lines[7].setFilled(false);
lines[7].setPointRadius(1);
lines[7].setHasPoints(true);
lines[7].setHasLabels(false);
lines[8] = new Line(noisePolyBgValues);
lines[8].setColor(ChartUtils.COLOR_ORANGE);
lines[8].setHasLines(true);
lines[8].setCubic(false);
lines[8].setStrokeWidth(1);
lines[8].setFilled(false);
lines[8].setPointRadius(1);
lines[8].setHasPoints(true);
lines[8].setHasLabels(false);
} catch (Exception e) {
if (d)
Log.i(TAG, "Exception making treatment lines: " + e.toString());
}
return lines;
}
use of lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter in project xDrip by NightscoutFoundation.
the class BgGraphBuilder method treatmentValuesLine.
public Line[] treatmentValuesLine() {
Line[] lines = new Line[2];
try {
lines[0] = new Line(treatmentValues);
// getCol(X.color_treatment_dot_background) 0xFFFFFF
lines[0].setColor(highColor);
lines[0].setHasLines(false);
// pointSize * 5 / 2
lines[0].setPointRadius(pointSize * 5 / 3);
lines[0].setHasPoints(true);
// KS
lines[0].setShape(ValueShape.DIAMOND);
lines[1] = new Line(treatmentValues);
// getCol(X.color_treatment_dot_foreground)//0x77aa00 //lowColor
lines[1].setColor(Color.GREEN);
lines[1].setHasLines(false);
// pointSize * 5 / 4
lines[1].setPointRadius(pointSize * 5 / 4);
lines[1].setHasPoints(true);
lines[1].setShape(ValueShape.DIAMOND);
// lines[1].setHasLabels(true);
LineChartValueFormatter formatter = new SimpleLineChartValueFormatter(1);
lines[1].setFormatter(formatter);
} catch (Exception e) {
if (d)
UserError.Log.i(TAG, "Exception making treatment lines: " + e.toString());
}
return lines;
}
use of lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter 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);
}
use of lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter in project xDrip-plus by jamorham.
the class BgGraphBuilder method treatmentValuesLine.
public Line[] treatmentValuesLine() {
Line[] lines = new Line[2];
try {
lines[0] = new Line(treatmentValues);
// getCol(X.color_treatment_dot_background) 0xFFFFFF
lines[0].setColor(highColor);
lines[0].setHasLines(false);
// pointSize * 5 / 2
lines[0].setPointRadius(pointSize * 5 / 3);
lines[0].setHasPoints(true);
// KS
lines[0].setShape(ValueShape.DIAMOND);
lines[1] = new Line(treatmentValues);
// getCol(X.color_treatment_dot_foreground)//0x77aa00 //lowColor
lines[1].setColor(Color.GREEN);
lines[1].setHasLines(false);
// pointSize * 5 / 4
lines[1].setPointRadius(pointSize * 5 / 4);
lines[1].setHasPoints(true);
lines[1].setShape(ValueShape.DIAMOND);
// lines[1].setHasLabels(true);
LineChartValueFormatter formatter = new SimpleLineChartValueFormatter(1);
lines[1].setFormatter(formatter);
} catch (Exception e) {
if (d)
UserError.Log.i(TAG, "Exception making treatment lines: " + e.toString());
}
return lines;
}
use of lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter in project openScale by oliexdev.
the class OverviewFragment method updateLastLineChart.
private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
final Calendar now = Calendar.getInstance();
Calendar histCalendar = Calendar.getInstance();
scaleMeasurementLastDays = new ArrayList<>();
List<AxisValue> axisValues = new ArrayList<>();
int max_i = Math.min(7, scaleMeasurementList.size());
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
scaleMeasurementLastDays.add(measurement);
histCalendar.setTime(measurement.getDateTime());
int days = DateTimeHelpers.daysBetween(now, histCalendar);
String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
axisValues.add(new AxisValue(i, label.toCharArray()));
}
List<Line> diagramLineList = new ArrayList<>();
for (MeasurementView view : measurementViews) {
if (!view.isVisible() || !view.getSettings().isInOverviewGraph() || !(view instanceof FloatMeasurementView)) {
continue;
}
FloatMeasurementView measurementView = (FloatMeasurementView) view;
Stack<PointValue> valuesStack = new Stack<PointValue>();
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
measurementView.loadFrom(measurement, null);
if (measurementView.getValue() != 0.0f) {
valuesStack.push(new PointValue(i, measurementView.getValue()));
}
}
diagramLineList.add(new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1)));
}
LineChartData lineData = new LineChartData(diagramLineList);
lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineChartLast.setLineChartData(lineData);
lineChartLast.setViewportCalculationEnabled(true);
lineChartLast.setZoomEnabled(false);
}
Aggregations