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

View file

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

View file

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

View file

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