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);
}
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);
}
}
Aggregations