1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-23 07:11:52 +02:00

Fiix visal glitch in weeksteps chart (first and last bar only partly visible)

This commit is contained in:
cpfeiffer 2016-10-07 21:46:00 +02:00
parent 7479c3d420
commit 558c9e4664
7 changed files with 79 additions and 35 deletions

View File

@ -11,6 +11,7 @@ import android.support.v4.app.FragmentActivity;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.view.View; import android.view.View;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.AxisBase; import com.github.mikephil.charting.components.AxisBase;
@ -18,6 +19,7 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.CombinedData; import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineData;
@ -360,6 +362,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected void configureBarLineChartDefaults(BarLineChartBase<?> chart) { protected void configureBarLineChartDefaults(BarLineChartBase<?> chart) {
configureChartDefaults(chart); configureChartDefaults(chart);
if (chart instanceof BarChart) {
((BarChart) chart).setFitBars(true);
}
// enable scaling and dragging // enable scaling and dragging
chart.setDragEnabled(true); chart.setDragEnabled(true);
@ -712,16 +717,16 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
return (int) ((date.getTime() / 1000)); return (int) ((date.getTime() / 1000));
} }
public static class DefaultChartsData extends ChartsData { public static class DefaultChartsData<T extends ChartData<?>> extends ChartsData {
private final CombinedData combinedData; private final T data;
public DefaultChartsData(CombinedData combinedData, ArrayList<String> xLabels) { public DefaultChartsData(T data, ArrayList<String> xLabels) {
this.combinedData = combinedData; this.data = data;
setxLabels(xLabels); setxLabels(xLabels);
} }
public CombinedData getCombinedData() { public T getData() {
return combinedData; return data;
} }
} }

View File

@ -13,7 +13,6 @@ import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.CombinedData;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -120,7 +119,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR); mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317 mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
xIndexFormatter.setxLabels(dcd.getXLabels()); xIndexFormatter.setxLabels(dcd.getXLabels());
mChart.setData(dcd.getCombinedData()); mChart.setData(dcd.getData());
} }
@Override @Override

View File

@ -14,6 +14,7 @@ import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieDataSet;
@ -101,7 +102,7 @@ public class SleepChartFragment extends AbstractChartFragment {
mActivityChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317 mActivityChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
xIndexFormatter.setxLabels(mcd.getChartsData().getXLabels()); xIndexFormatter.setxLabels(mcd.getChartsData().getXLabels());
mActivityChart.setData(mcd.getChartsData().getCombinedData()); mActivityChart.setData(mcd.getChartsData().getData());
} }
@Override @Override
@ -239,10 +240,10 @@ public class SleepChartFragment extends AbstractChartFragment {
} }
private static class MyChartsData extends ChartsData { private static class MyChartsData extends ChartsData {
private final DefaultChartsData chartsData; private final DefaultChartsData<CombinedData> chartsData;
private final MySleepChartsData pieData; private final MySleepChartsData pieData;
public MyChartsData(MySleepChartsData pieData, DefaultChartsData chartsData) { public MyChartsData(MySleepChartsData pieData, DefaultChartsData<CombinedData> chartsData) {
this.pieData = pieData; this.pieData = pieData;
this.chartsData = chartsData; this.chartsData = chartsData;
} }
@ -251,7 +252,7 @@ public class SleepChartFragment extends AbstractChartFragment {
return pieData; return pieData;
} }
public DefaultChartsData getChartsData() { public DefaultChartsData<CombinedData> getChartsData() {
return chartsData; return chartsData;
} }
} }

View File

@ -6,8 +6,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.LimitLine; import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.XAxis;
@ -15,7 +15,6 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.data.PieEntry;
@ -43,7 +42,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
private int mTargetSteps = 10000; private int mTargetSteps = 10000;
private PieChart mTodayStepsChart; private PieChart mTodayStepsChart;
private CombinedChart mWeekStepsChart; private BarChart mWeekStepsChart;
@Override @Override
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) { protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
@ -65,7 +64,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mTodayStepsChart.setData(mcd.getDaySteps().data); mTodayStepsChart.setData(mcd.getDaySteps().data);
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317 mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getCombinedData()); mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getData());
mWeekStepsChart.getLegend().setEnabled(false); mWeekStepsChart.getLegend().setEnabled(false);
xIndexFormatter.setxLabels(mcd.getWeekBeforeStepsData().getXLabels()); xIndexFormatter.setxLabels(mcd.getWeekBeforeStepsData().getXLabels());
} }
@ -76,7 +75,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mTodayStepsChart.invalidate(); mTodayStepsChart.invalidate();
} }
private DefaultChartsData refreshWeekBeforeSteps(DBHandler db, CombinedChart combinedChart, Calendar day, GBDevice device) { private DefaultChartsData refreshWeekBeforeSteps(DBHandler db, BarChart barChart, Calendar day, GBDevice device) {
ActivityAnalysis analysis = new ActivityAnalysis(); ActivityAnalysis analysis = new ActivityAnalysis();
@ -98,16 +97,13 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false); barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
LimitLine target = new LimitLine(mTargetSteps); LimitLine target = new LimitLine(mTargetSteps);
combinedChart.getAxisLeft().removeAllLimitLines(); barChart.getAxisLeft().removeAllLimitLines();
combinedChart.getAxisLeft().addLimitLine(target); barChart.getAxisLeft().addLimitLine(target);
CombinedData combinedData = new CombinedData(); return new DefaultChartsData(barData, labels);
combinedData.setData(barData);
return new DefaultChartsData(combinedData, labels);
} }
private DaySteps refreshDaySteps(DBHandler db, Calendar day, GBDevice device) { private DaySteps refreshDaySteps(DBHandler db, Calendar day, GBDevice device) {
ActivityAnalysis analysis = new ActivityAnalysis(); ActivityAnalysis analysis = new ActivityAnalysis();
@ -139,7 +135,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
mLocale = getResources().getConfiguration().locale; mLocale = getResources().getConfiguration().locale;
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false); View rootView = inflater.inflate(R.layout.fragment_weeksteps_chart, container, false);
GBDevice device = getChartsHost().getDevice(); GBDevice device = getChartsHost().getDevice();
if (device != null) { if (device != null) {
@ -147,8 +143,8 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress()); mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress());
} }
mWeekStepsChart = (CombinedChart) rootView.findViewById(R.id.sleepchart); mTodayStepsChart = (PieChart) rootView.findViewById(R.id.todaystepschart);
mTodayStepsChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep); mWeekStepsChart = (BarChart) rootView.findViewById(R.id.weekstepschart);
setupWeekStepsChart(); setupWeekStepsChart();
setupTodayStepsChart(); setupTodayStepsChart();
@ -178,6 +174,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR); mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR);
mWeekStepsChart.getDescription().setTextColor(DESCRIPTION_COLOR); mWeekStepsChart.getDescription().setTextColor(DESCRIPTION_COLOR);
mWeekStepsChart.getDescription().setText(""); mWeekStepsChart.getDescription().setText("");
mWeekStepsChart.setFitBars(true);
configureBarLineChartDefaults(mWeekStepsChart); configureBarLineChartDefaults(mWeekStepsChart);
@ -251,10 +248,10 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
} }
private static class MyChartsData extends ChartsData { private static class MyChartsData extends ChartsData {
private final DefaultChartsData weekBeforeStepsData; private final DefaultChartsData<BarData> weekBeforeStepsData;
private final DaySteps daySteps; private final DaySteps daySteps;
public MyChartsData(DaySteps daySteps, DefaultChartsData weekBeforeStepsData) { public MyChartsData(DaySteps daySteps, DefaultChartsData<BarData> weekBeforeStepsData) {
this.daySteps = daySteps; this.daySteps = daySteps;
this.weekBeforeStepsData = weekBeforeStepsData; this.weekBeforeStepsData = weekBeforeStepsData;
} }
@ -263,7 +260,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
return daySteps; return daySteps;
} }
public DefaultChartsData getWeekBeforeStepsData() { public DefaultChartsData<BarData> getWeekBeforeStepsData() {
return weekBeforeStepsData; return weekBeforeStepsData;
} }
} }

View File

@ -0,0 +1,27 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment"
android:orientation="horizontal">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/todaystepschart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="40">
</com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/weekstepschart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20" />
<!--<TextView-->
<!--android:text="Test"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="fill_parent"-->
<!--android:layout_weight="20" />-->
</LinearLayout>

View File

@ -18,10 +18,4 @@
android:layout_weight="20" /> android:layout_weight="20" />
<!--<TextView-->
<!--android:text="Test"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="fill_parent"-->
<!--android:layout_weight="20" />-->
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment"
android:orientation="vertical">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/todaystepschart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/weekstepschart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20" />
</LinearLayout>