Added interpolation of Y value when two charts visible
This commit is contained in:
parent
0e812d08f2
commit
094d4ebf2a
2 changed files with 37 additions and 7 deletions
|
@ -586,7 +586,21 @@ public class MapUtils {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getInterpolatedY(float x1, float y1, float x2, float y2, float x) {
|
||||||
|
|
||||||
|
float a = y1 - y2;
|
||||||
|
float b = x2 - x1;
|
||||||
|
|
||||||
|
float d = -a * b;
|
||||||
|
if (d != 0) {
|
||||||
|
float c1 = y2 * x1 - x2 * y1;
|
||||||
|
float c2 = x * (y2 - y1);
|
||||||
|
|
||||||
|
return (a * (c1 - c2)) / d;
|
||||||
|
} else {
|
||||||
|
return y1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.github.mikephil.charting.components.MarkerView;
|
||||||
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.ChartData;
|
import com.github.mikephil.charting.data.ChartData;
|
||||||
|
import com.github.mikephil.charting.data.DataSet;
|
||||||
import com.github.mikephil.charting.data.Entry;
|
import com.github.mikephil.charting.data.Entry;
|
||||||
import com.github.mikephil.charting.data.LineDataSet;
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
||||||
|
@ -79,6 +80,7 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
import net.osmand.render.RenderingRuleProperty;
|
import net.osmand.render.RenderingRuleProperty;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
@ -1606,24 +1608,24 @@ public class GpxUiHelper {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (altSetIndex != -1) {
|
if (altSetIndex != -1) {
|
||||||
Entry eAlt = chartData.getEntryForHighlight(new Highlight(e.getX(), Float.NaN, altSetIndex));
|
float y = getInterpolatedY(altSetIndex == 0 ? dataSet1 : dataSet2, e);
|
||||||
((TextView) textAltView.findViewById(R.id.text_alt_value)).setText(Integer.toString((int) eAlt.getY()) + " ");
|
((TextView) textAltView.findViewById(R.id.text_alt_value)).setText(Integer.toString((int) y) + " ");
|
||||||
((TextView) textAltView.findViewById(R.id.text_alt_units)).setText((altSetIndex == 0 ? dataSet1.units : dataSet2.units));
|
((TextView) textAltView.findViewById(R.id.text_alt_units)).setText((altSetIndex == 0 ? dataSet1.units : dataSet2.units));
|
||||||
textAltView.setVisibility(VISIBLE);
|
textAltView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
textAltView.setVisibility(GONE);
|
textAltView.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
if (spdSetIndex != -1) {
|
if (spdSetIndex != -1) {
|
||||||
Entry eSpd = chartData.getEntryForHighlight(new Highlight(e.getX(), Float.NaN, spdSetIndex));
|
float y = getInterpolatedY(spdSetIndex == 0 ? dataSet1 : dataSet2, e);
|
||||||
((TextView) textSpdView.findViewById(R.id.text_spd_value)).setText(Integer.toString((int) eSpd.getY()) + " ");
|
((TextView) textSpdView.findViewById(R.id.text_spd_value)).setText(Integer.toString((int) y) + " ");
|
||||||
((TextView) textSpdView.findViewById(R.id.text_spd_units)).setText(spdSetIndex == 0 ? dataSet1.units : dataSet2.units);
|
((TextView) textSpdView.findViewById(R.id.text_spd_units)).setText(spdSetIndex == 0 ? dataSet1.units : dataSet2.units);
|
||||||
textSpdView.setVisibility(VISIBLE);
|
textSpdView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
textSpdView.setVisibility(GONE);
|
textSpdView.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
if (slpSetIndex != -1) {
|
if (slpSetIndex != -1) {
|
||||||
Entry eSlp = chartData.getEntryForHighlight(new Highlight(e.getX(), Float.NaN, slpSetIndex));
|
float y = getInterpolatedY(slpSetIndex == 0 ? dataSet1 : dataSet2, e);
|
||||||
((TextView) textSlpView.findViewById(R.id.text_slp_value)).setText(Integer.toString((int) eSlp.getY()) + " ");
|
((TextView) textSlpView.findViewById(R.id.text_slp_value)).setText(Integer.toString((int) y) + " ");
|
||||||
textSlpView.setVisibility(VISIBLE);
|
textSlpView.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
textSlpView.setVisibility(GONE);
|
textSlpView.setVisibility(GONE);
|
||||||
|
@ -1638,6 +1640,20 @@ public class GpxUiHelper {
|
||||||
super.refreshContent(e, highlight);
|
super.refreshContent(e, highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float getInterpolatedY(OrderedLineDataSet ds, Entry e) {
|
||||||
|
if (ds.getEntryIndex(e) == -1) {
|
||||||
|
Entry upEntry = ds.getEntryForXValue(e.getX(), Float.NaN, DataSet.Rounding.UP);
|
||||||
|
Entry downEntry = upEntry;
|
||||||
|
int upIndex = ds.getEntryIndex(upEntry);
|
||||||
|
if (upIndex > 0) {
|
||||||
|
downEntry = ds.getEntryForIndex(upIndex - 1);
|
||||||
|
}
|
||||||
|
return MapUtils.getInterpolatedY(downEntry.getX(), downEntry.getY(), upEntry.getX(), upEntry.getY(), e.getX());
|
||||||
|
} else {
|
||||||
|
return e.getY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MPPointF getOffset() {
|
public MPPointF getOffset() {
|
||||||
if (getChartView().getData().getDataSetCount() == 2) {
|
if (getChartView().getData().getDataSetCount() == 2) {
|
||||||
|
|
Loading…
Reference in a new issue