use of lecho.lib.hellocharts.model.Axis in project xDrip by NightscoutFoundation.
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);
}
use of lecho.lib.hellocharts.model.Axis in project xDrip by NightscoutFoundation.
the class CalibrationGraph method setupCharts.
public void setupCharts() {
chart = (LineChartView) findViewById(R.id.chart);
List<Line> lines = new ArrayList<Line>();
// calibration values
List<Calibration> calibrations = Calibration.allForSensor();
List<Line> greyLines = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF"));
calibrations = Calibration.allForSensorInLastFourDays();
List<Line> blueLines = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE);
Calibration calibration = Calibration.lastValid();
if (calibration != null) {
// set header
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept);
GraphHeader.setText(Header);
// red line
List<PointValue> lineValues = new ArrayList<PointValue>();
final float conversion_factor = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);
lineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (start_x * calibration.slope + calibration.intercept))));
lineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (end_x * calibration.slope + calibration.intercept))));
Line calibrationLine = new Line(lineValues);
calibrationLine.setColor(ChartUtils.COLOR_RED);
calibrationLine.setHasLines(true);
calibrationLine.setHasPoints(false);
lines.add(calibrationLine);
// calibration plugin
final CalibrationAbstract plugin = getCalibrationPluginFromPreferences();
if (plugin != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData();
final List<PointValue> plineValues = new ArrayList<PointValue>();
plineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(start_x, pcalibration)))));
plineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(end_x, pcalibration)))));
final Line pcalibrationLine = new Line(plineValues);
pcalibrationLine.setColor(Color.parseColor(plugin_color));
pcalibrationLine.setHasLines(true);
pcalibrationLine.setHasPoints(false);
lines.add(pcalibrationLine);
PluginHeader.setText("(" + plugin.getAlgorithmName() + ") " + "s = " + df.format(pcalibration.slope) + " i = " + df.format(pcalibration.intercept));
PluginHeader.setTextColor(Color.parseColor(plugin_color));
}
// add lines in order
for (Line greyLine : greyLines) {
lines.add(greyLine);
}
for (Line blueLine : blueLines) {
lines.add(blueLine);
}
}
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
axisX.setName("Raw Value");
axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));
data = new LineChartData(lines);
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
chart.setLineChartData(data);
}
use of lecho.lib.hellocharts.model.Axis in project xDrip-plus by jamorham.
the class CalibrationGraph method setupCharts.
public void setupCharts() {
chart = (LineChartView) findViewById(R.id.chart);
List<Line> lines = new ArrayList<Line>();
// calibration values
List<Calibration> calibrations = Calibration.allForSensor();
List<Line> greyLines = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF"));
calibrations = Calibration.allForSensorInLastFourDays();
List<Line> blueLines = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE);
Calibration calibration = Calibration.lastValid();
if (calibration != null) {
// set header
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept);
GraphHeader.setText(Header);
// red line
List<PointValue> lineValues = new ArrayList<PointValue>();
final float conversion_factor = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);
lineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (start_x * calibration.slope + calibration.intercept))));
lineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (end_x * calibration.slope + calibration.intercept))));
Line calibrationLine = new Line(lineValues);
calibrationLine.setColor(ChartUtils.COLOR_RED);
calibrationLine.setHasLines(true);
calibrationLine.setHasPoints(false);
lines.add(calibrationLine);
// calibration plugin
final CalibrationAbstract plugin = getCalibrationPluginFromPreferences();
if (plugin != null) {
final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData();
final List<PointValue> plineValues = new ArrayList<PointValue>();
plineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(start_x, pcalibration)))));
plineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(end_x, pcalibration)))));
final Line pcalibrationLine = new Line(plineValues);
pcalibrationLine.setColor(Color.parseColor(plugin_color));
pcalibrationLine.setHasLines(true);
pcalibrationLine.setHasPoints(false);
lines.add(pcalibrationLine);
PluginHeader.setText("(" + plugin.getAlgorithmName() + ") " + "s = " + df.format(pcalibration.slope) + " i = " + df.format(pcalibration.intercept));
PluginHeader.setTextColor(Color.parseColor(plugin_color));
}
// add lines in order
for (Line greyLine : greyLines) {
lines.add(greyLine);
}
for (Line blueLine : blueLines) {
lines.add(blueLine);
}
}
Axis axisX = new Axis();
Axis axisY = new Axis().setHasLines(true);
axisX.setName("Raw Value");
axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));
data = new LineChartData(lines);
data.setAxisXBottom(axisX);
data.setAxisYLeft(axisY);
chart.setLineChartData(data);
}
use of lecho.lib.hellocharts.model.Axis in project xDrip-plus by jamorham.
the class BgGraphBuilder method xAxis.
public Axis xAxis() {
// final boolean is24 = DateFormat.is24HourFormat(context);
Axis xAxis = new Axis();
xAxis.setAutoGenerated(false);
List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
SimpleDateFormat timeFormat = new SimpleDateFormat(is24 ? "HH" : "h a");
timeFormat.setTimeZone(TimeZone.getDefault());
double start_hour = today.getTime().getTime();
double timeNow = new Date().getTime();
for (int l = 0; l <= 24; l++) {
if ((start_hour + (60000 * 60 * (l))) < timeNow) {
if ((start_hour + (60000 * 60 * (l + 1))) >= timeNow) {
endHour = start_hour + (60000 * 60 * (l));
l = 25;
}
}
}
// Display current time on the graph
SimpleDateFormat longTimeFormat = new SimpleDateFormat(is24 ? "HH:mm" : "h:mm a");
xAxisValues.add(new AxisValue(fuzz(timeNow), (longTimeFormat.format(timeNow)).toCharArray()));
// Add whole hours to the axis (as long as they are more than 15 mins away from the current time)
for (int l = 0; l <= 24; l++) {
double timestamp = endHour - (60000 * 60 * l);
if ((timestamp - timeNow < 0) && (timestamp > start_time)) {
if (Math.abs(timestamp - timeNow) > (1000 * 60 * 8 * timespan)) {
xAxisValues.add(new AxisValue(fuzz(timestamp), (timeFormat.format(timestamp)).toCharArray()));
} else {
xAxisValues.add(new AxisValue(fuzz(timestamp), "".toCharArray()));
}
}
}
xAxis.setValues(xAxisValues);
xAxis.setTextSize(10);
xAxis.setHasLines(true);
return xAxis;
}
use of lecho.lib.hellocharts.model.Axis 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;
}
Aggregations