Fix slope graph
This commit is contained in:
parent
6ff477c9ec
commit
127645eb44
4 changed files with 29 additions and 29 deletions
|
@ -1230,7 +1230,7 @@ public class GpxUiHelper {
|
|||
}
|
||||
|
||||
private static List<Entry> calculateElevationArray(GPXTrackAnalysis analysis, GPXDataSetAxisType axisType,
|
||||
float divX, float convEle, boolean useGeneralTrackPoints, boolean calcGaps) {
|
||||
float divX, float convEle, boolean useGeneralTrackPoints, boolean calcWithoutGaps) {
|
||||
List<Entry> values = new ArrayList<>();
|
||||
List<Elevation> elevationData = analysis.elevationData;
|
||||
float nextX = 0;
|
||||
|
@ -1252,7 +1252,7 @@ public class GpxUiHelper {
|
|||
x = e.distance;
|
||||
}
|
||||
if (x > 0) {
|
||||
if (!(!calcGaps && e.firstPoint && lastEntry != null)) {
|
||||
if (!(calcWithoutGaps && e.firstPoint && lastEntry != null)) {
|
||||
nextX += x / divX;
|
||||
}
|
||||
if (!Float.isNaN(e.elevation)) {
|
||||
|
@ -1386,7 +1386,7 @@ public class GpxUiHelper {
|
|||
@NonNull GPXDataSetAxisType axisType,
|
||||
boolean useRightAxis,
|
||||
boolean drawFilled,
|
||||
boolean calcGaps) {
|
||||
boolean calcWithoutGaps) {
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
||||
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
|
||||
|
@ -1396,11 +1396,11 @@ public class GpxUiHelper {
|
|||
float divX;
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTime(xAxis, calcGaps ? analysis.timeSpan : analysis.timeSpanWithoutGaps);
|
||||
divX = setupXAxisTime(xAxis, calcWithoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan);
|
||||
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTimeOfDay(xAxis, analysis.startTime);
|
||||
} else {
|
||||
divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
|
||||
divX = setupAxisDistance(ctx, xAxis, calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance);
|
||||
}
|
||||
|
||||
final String mainUnitY = useFeet ? ctx.getString(R.string.foot) : ctx.getString(R.string.m);
|
||||
|
@ -1424,7 +1424,7 @@ public class GpxUiHelper {
|
|||
}
|
||||
});
|
||||
|
||||
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true, calcGaps);
|
||||
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true, calcWithoutGaps);
|
||||
|
||||
OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.ALTITUDE, axisType);
|
||||
dataSet.priority = (float) (analysis.avgElevation - analysis.minElevation) * convEle;
|
||||
|
@ -1471,22 +1471,23 @@ public class GpxUiHelper {
|
|||
}
|
||||
|
||||
public static OrderedLineDataSet createGPXSpeedDataSet(@NonNull OsmandApplication ctx,
|
||||
@NonNull LineChart mChart,
|
||||
@NonNull GPXTrackAnalysis analysis,
|
||||
@NonNull GPXDataSetAxisType axisType,
|
||||
boolean useRightAxis,
|
||||
boolean drawFilled) {
|
||||
@NonNull LineChart mChart,
|
||||
@NonNull GPXTrackAnalysis analysis,
|
||||
@NonNull GPXDataSetAxisType axisType,
|
||||
boolean useRightAxis,
|
||||
boolean drawFilled,
|
||||
boolean calcWithoutGaps) {
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
boolean light = settings.isLightContent();
|
||||
|
||||
float divX;
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTime(xAxis, analysis.timeSpan);
|
||||
divX = setupXAxisTime(xAxis, calcWithoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan);
|
||||
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
|
||||
divX = setupXAxisTimeOfDay(xAxis, analysis.startTime);
|
||||
} else {
|
||||
divX = setupAxisDistance(ctx, xAxis, analysis.totalDistance);
|
||||
divX = setupAxisDistance(ctx, xAxis, calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance);
|
||||
}
|
||||
|
||||
OsmandSettings.SpeedConstants sps = settings.SPEED_SYSTEM.get();
|
||||
|
@ -1546,7 +1547,9 @@ public class GpxUiHelper {
|
|||
values.add(new Entry(nextX + 1, 0));
|
||||
values.add(new Entry(nextX + x - 1, 0));
|
||||
}
|
||||
nextX += x / divX;
|
||||
if (!(calcWithoutGaps && s.firstPoint)) {
|
||||
nextX += x / divX;
|
||||
}
|
||||
if (Float.isNaN(divSpeed)) {
|
||||
nextY = s.speed * mulSpeed;
|
||||
} else {
|
||||
|
@ -1644,7 +1647,7 @@ public class GpxUiHelper {
|
|||
@Nullable List<Entry> eleValues,
|
||||
boolean useRightAxis,
|
||||
boolean drawFilled,
|
||||
boolean calcGaps) {
|
||||
boolean calcWithoutGaps) {
|
||||
if (axisType == GPXDataSetAxisType.TIME || axisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1653,10 +1656,10 @@ public class GpxUiHelper {
|
|||
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
||||
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
|
||||
final float convEle = useFeet ? 3.28084f : 1.0f;
|
||||
final float totalDistance = calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps;
|
||||
final float totalDistance = calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||
|
||||
XAxis xAxis = mChart.getXAxis();
|
||||
float divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
|
||||
float divX = setupAxisDistance(ctx, xAxis, calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance);
|
||||
|
||||
final String mainUnitY = "%";
|
||||
|
||||
|
@ -1681,7 +1684,7 @@ public class GpxUiHelper {
|
|||
|
||||
List<Entry> values;
|
||||
if (eleValues == null) {
|
||||
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false, calcGaps);
|
||||
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false, calcWithoutGaps);
|
||||
} else {
|
||||
values = new ArrayList<>(eleValues.size());
|
||||
for (Entry e : eleValues) {
|
||||
|
|
|
@ -590,7 +590,7 @@ public class TrackDetailsMenu {
|
|||
break;
|
||||
case SPEED:
|
||||
dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis,
|
||||
gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true);
|
||||
gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true, false);
|
||||
break;
|
||||
case SLOPE:
|
||||
dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis,
|
||||
|
|
|
@ -426,19 +426,19 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
if (dataSets == null && chart != null) {
|
||||
dataSets = new ArrayList<>();
|
||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
||||
GpxDataItem gpxDataItem = getGpxDataItem();
|
||||
boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments();
|
||||
switch (tabType) {
|
||||
case GPX_TAB_ITEM_GENERAL: {
|
||||
OrderedLineDataSet speedDataSet = null;
|
||||
OrderedLineDataSet elevationDataSet = null;
|
||||
if (analysis.hasSpeedData) {
|
||||
speedDataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart,
|
||||
analysis, GPXDataSetAxisType.DISTANCE, true, true);
|
||||
analysis, GPXDataSetAxisType.DISTANCE, true, true, calcWithoutGaps);
|
||||
}
|
||||
if (analysis.hasElevationData) {
|
||||
GpxDataItem gpxDataItem = getGpxDataItem();
|
||||
boolean calcGaps = gpxDataItem != null && gpxDataItem.isJoinSegments() && gpxItem.isGeneralTrack() || !gpxItem.isGeneralTrack();
|
||||
elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, chart,
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcWithoutGaps);
|
||||
}
|
||||
if (speedDataSet != null) {
|
||||
dataSets.add(speedDataSet);
|
||||
|
@ -453,17 +453,15 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
break;
|
||||
}
|
||||
case GPX_TAB_ITEM_ALTITUDE: {
|
||||
GpxDataItem gpxDataItem = getGpxDataItem();
|
||||
boolean calcGaps = gpxDataItem != null && gpxDataItem.isJoinSegments() && gpxItem.isGeneralTrack() || !gpxItem.isGeneralTrack();
|
||||
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, chart,
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcWithoutGaps);
|
||||
if (elevationDataSet != null) {
|
||||
dataSets.add(elevationDataSet);
|
||||
}
|
||||
if (analysis.hasElevationData) {
|
||||
List<Entry> eleValues = elevationDataSet != null && !gpxItem.isGeneralTrack() ? elevationDataSet.getValues() : null;
|
||||
OrderedLineDataSet slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart,
|
||||
analysis, GPXDataSetAxisType.DISTANCE, eleValues, true, true, calcGaps);
|
||||
analysis, GPXDataSetAxisType.DISTANCE, eleValues, true, true, calcWithoutGaps);
|
||||
if (slopeDataSet != null) {
|
||||
dataSets.add(slopeDataSet);
|
||||
}
|
||||
|
@ -473,7 +471,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
|||
}
|
||||
case GPX_TAB_ITEM_SPEED: {
|
||||
OrderedLineDataSet speedDataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart,
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true);
|
||||
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcWithoutGaps);
|
||||
if (speedDataSet != null) {
|
||||
dataSets.add(speedDataSet);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
|||
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
|
||||
import com.github.mikephil.charting.listener.OnChartGestureListener;
|
||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
||||
import com.github.mikephil.charting.utils.MPPointD;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
|
Loading…
Reference in a new issue