Update chart for joined segments

This commit is contained in:
Vitaliy 2020-01-09 17:44:50 +02:00
parent 145a33a66d
commit 6ff477c9ec
5 changed files with 32 additions and 24 deletions

View file

@ -1230,7 +1230,7 @@ public class GpxUiHelper {
}
private static List<Entry> calculateElevationArray(GPXTrackAnalysis analysis, GPXDataSetAxisType axisType,
float divX, float convEle, boolean useGeneralTrackPoints) {
float divX, float convEle, boolean useGeneralTrackPoints, boolean calcGaps) {
List<Entry> values = new ArrayList<>();
List<Elevation> elevationData = analysis.elevationData;
float nextX = 0;
@ -1252,7 +1252,9 @@ public class GpxUiHelper {
x = e.distance;
}
if (x > 0) {
if (!(!calcGaps && e.firstPoint && lastEntry != null)) {
nextX += x / divX;
}
if (!Float.isNaN(e.elevation)) {
elev = e.elevation;
if (prevElevOrig != -80000) {
@ -1383,7 +1385,8 @@ public class GpxUiHelper {
@NonNull GPXTrackAnalysis analysis,
@NonNull GPXDataSetAxisType axisType,
boolean useRightAxis,
boolean drawFilled) {
boolean drawFilled,
boolean calcGaps) {
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);
@ -1393,11 +1396,11 @@ public class GpxUiHelper {
float divX;
XAxis xAxis = mChart.getXAxis();
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
divX = setupXAxisTime(xAxis, analysis.timeSpan);
divX = setupXAxisTime(xAxis, calcGaps ? analysis.timeSpan : analysis.timeSpanWithoutGaps);
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
divX = setupXAxisTimeOfDay(xAxis, analysis.startTime);
} else {
divX = setupAxisDistance(ctx, xAxis, analysis.totalDistance);
divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
}
final String mainUnitY = useFeet ? ctx.getString(R.string.foot) : ctx.getString(R.string.m);
@ -1421,7 +1424,7 @@ public class GpxUiHelper {
}
});
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true);
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true, calcGaps);
OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.ALTITUDE, axisType);
dataSet.priority = (float) (analysis.avgElevation - analysis.minElevation) * convEle;
@ -1640,7 +1643,8 @@ public class GpxUiHelper {
@NonNull GPXDataSetAxisType axisType,
@Nullable List<Entry> eleValues,
boolean useRightAxis,
boolean drawFilled) {
boolean drawFilled,
boolean calcGaps) {
if (axisType == GPXDataSetAxisType.TIME || axisType == GPXDataSetAxisType.TIMEOFDAY) {
return null;
}
@ -1649,10 +1653,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 = analysis.totalDistance;
final float totalDistance = calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps;
XAxis xAxis = mChart.getXAxis();
float divX = setupAxisDistance(ctx, xAxis, analysis.totalDistance);
float divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
final String mainUnitY = "%";
@ -1677,7 +1681,7 @@ public class GpxUiHelper {
List<Entry> values;
if (eleValues == null) {
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false);
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false, calcGaps);
} else {
values = new ArrayList<>(eleValues.size());
for (Entry e : eleValues) {

View file

@ -586,7 +586,7 @@ public class TrackDetailsMenu {
switch (gpxItem.chartTypes[i]) {
case ALTITUDE:
dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis,
gpxItem.chartAxisType, false, true);
gpxItem.chartAxisType, false, true, false);
break;
case SPEED:
dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis,
@ -594,7 +594,7 @@ public class TrackDetailsMenu {
break;
case SLOPE:
dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis,
gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true);
gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, false);
break;
}
if (dataSet != null) {

View file

@ -435,8 +435,10 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
analysis, GPXDataSetAxisType.DISTANCE, true, true);
}
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);
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
}
if (speedDataSet != null) {
dataSets.add(speedDataSet);
@ -451,15 +453,17 @@ 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);
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
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);
analysis, GPXDataSetAxisType.DISTANCE, eleValues, true, true, calcGaps);
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);
}
@ -720,7 +724,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
updateSplitView();
updateContent();
for (int i = 0; i < getCount(); i++) {
View view = getViewAtPosition(i);
updateJoinGapsInfo(view, i);
@ -1156,14 +1160,14 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
((SwitchCompat) view.findViewById(R.id.gpx_join_gaps_switch)).setChecked(joinSegments);
if (analysis != null) {
if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL)) {
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistance, app));
((TextView) view.findViewById(R.id.duration_text)).setText(Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()));
} else if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_SPEED)) {
long timeMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
float totalDistanceMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
long timeMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
float totalDistanceMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
((TextView) view.findViewById(R.id.time_moving_text)).setText(Algorithms.formatDuration((int) (timeMoving / 1000), app.accessibilityEnabled()));
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistanceMoving, app));

View file

@ -244,11 +244,11 @@ public class RouteStatisticCard extends BaseCard {
List<ILineDataSet> dataSets = new ArrayList<>();
OrderedLineDataSet slopeDataSet = null;
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis,
GPXDataSetAxisType.DISTANCE, false, true);
GPXDataSetAxisType.DISTANCE, false, true, false);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis,
GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true, false);
}
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);

View file

@ -120,11 +120,11 @@ public class SimpleRouteCard extends BaseCard {
List<ILineDataSet> dataSets = new ArrayList<>();
OrderedLineDataSet slopeDataSet = null;
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis,
GpxUiHelper.GPXDataSetAxisType.DISTANCE, false, true);
GpxUiHelper.GPXDataSetAxisType.DISTANCE, false, true, false);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis,
GpxUiHelper.GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
GpxUiHelper.GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true, false);
}
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);