mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
introduced parameter to setSeriesPoints, used to avoid zoom management when replacing fixes
Change-Id: I2c157ed697c475cd1a8c22794500f7e28426c2ab
This commit is contained in:
1 parent
5eb7000e13
commit
9856ef451b
5 files changed
+70
-24
No files matched your search
+1
-1
@@ -75,7 +75,7 @@ public abstract class AbstractCompetitorLeaderboardChart<SettingsType extends Ge
|
||||
private final List<String> raceColumnNamesWithData;
|
||||
protected final String leaderboardName;
|
||||
protected final StringMessages stringMessages;
|
||||
|
||||
|
||||
public AbstractCompetitorLeaderboardChart(Component<?> parent, ComponentContext<?> context,
|
||||
SailingServiceAsync sailingService,
|
||||
AsyncActionsExecutor asyncActionsExecutor, String leaderboardName,
|
||||
|
||||
+48
-9
@@ -102,6 +102,17 @@ public abstract class AbstractCompetitorRaceChart<SettingsType extends ChartSett
|
||||
private final TimingHolder primary = new TimingHolder();
|
||||
private final TimingHolder secondary = new TimingHolder();
|
||||
|
||||
/**
|
||||
* Whenever data is received from the server, the effective step size of that data is captured
|
||||
* in this field. Ideally, it would equal the {@link #getStepSizeInMillis() desired step size}, but
|
||||
* long time ranges covered by the chart and the lack of zoom may require increasing the effective step size
|
||||
* so as to reduce the number of fixes requested from the server.<p>
|
||||
*
|
||||
* However, when zooming this will be re-evaluated, and a more fine-grained request to the server, limited to
|
||||
* the zoom range, may then be issued.
|
||||
*/
|
||||
private long effectiveStepSize = -1;
|
||||
|
||||
AbstractCompetitorRaceChart(Component<?> parent, ComponentContext<?> context, SailingServiceAsync sailingService,
|
||||
AsyncActionsExecutor asyncActionsExecutor,
|
||||
CompetitorSelectionProvider competitorSelectionProvider, RegattaAndRaceIdentifier selectedRaceIdentifier,
|
||||
@@ -237,24 +248,38 @@ public abstract class AbstractCompetitorRaceChart<SettingsType extends ChartSett
|
||||
// If the time interval is too long and the step size too small, the number of fixes the query would have to
|
||||
// produce may exceed any reasonable limit. Therefore, we limit the number of fixes that such a query may ask
|
||||
// for:
|
||||
doLoadDataForCompetitorsAndDataType(from, to, append, competitorsToLoad, getSelectedFirstDetailType(),primary);
|
||||
doLoadDataForCompetitorsAndDataType(from, to, append, competitorsToLoad, getSelectedFirstDetailType(), primary);
|
||||
if (getSelectedSecondDetailType() != null) {
|
||||
doLoadDataForCompetitorsAndDataType(from, to, append, competitorsToLoad, getSelectedSecondDetailType(),secondary);
|
||||
doLoadDataForCompetitorsAndDataType(from, to, append, competitorsToLoad, getSelectedSecondDetailType(), secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void changeMinMaxAndExtremesInterval(Date minTimepoint, Date maxTimepoint, boolean redraw) {
|
||||
super.changeMinMaxAndExtremesInterval(minTimepoint, maxTimepoint, redraw);
|
||||
updateChartIfEffectiveStepSizeChanged(minTimepoint, maxTimepoint);
|
||||
}
|
||||
|
||||
protected void updateChartIfEffectiveStepSizeChanged(Date minTimepoint, Date maxTimepoint) {
|
||||
long effectiveStepSize = getEffectiveStepSize(minTimepoint, maxTimepoint);
|
||||
if (this.effectiveStepSize != -1 && this.effectiveStepSize != effectiveStepSize) {
|
||||
// the change has had an impact on the effective step size; trigger a re-load
|
||||
updateChart(minTimepoint, maxTimepoint, /* append==false means replace points in chart by the new ones */ false);
|
||||
}
|
||||
}
|
||||
|
||||
private void doLoadDataForCompetitorsAndDataType(final Date from, final Date to, final boolean append,
|
||||
ArrayList<CompetitorDTO> competitorsToLoad, final DetailType selectedDataTypeToRetrieve, final TimingHolder tholder) {
|
||||
long stepSize = Math.max(getStepSizeInMillis(),
|
||||
from==null||to==null ? 0 : Math.abs(to.getTime()-from.getTime())/SailingServiceConstants.MAX_NUMBER_OF_FIXES_TO_QUERY);
|
||||
long effectiveStepSize = getEffectiveStepSize(from, to);
|
||||
GetCompetitorsRaceDataAction getCompetitorsRaceDataAction = new GetCompetitorsRaceDataAction(sailingService,
|
||||
selectedRaceIdentifier, competitorsToLoad, from, to, stepSize, selectedDataTypeToRetrieve,
|
||||
selectedRaceIdentifier, competitorsToLoad, from, to, effectiveStepSize, selectedDataTypeToRetrieve,
|
||||
leaderboardGroupName, leaderboardName);
|
||||
AsyncCallback<CompetitorsRaceDataDTO> dataLoadedCallback = new AsyncCallback<CompetitorsRaceDataDTO>() {
|
||||
@Override
|
||||
public void onSuccess(final CompetitorsRaceDataDTO result) {
|
||||
hideLoading();
|
||||
AbstractCompetitorRaceChart.this.effectiveStepSize = effectiveStepSize;
|
||||
if (result != null) {
|
||||
if (result.isEmpty() && chartContainsNoData()) {
|
||||
setWidget(noDataFoundLabel);
|
||||
@@ -285,6 +310,21 @@ public abstract class AbstractCompetitorRaceChart<SettingsType extends ChartSett
|
||||
getCompetitorsRaceDataAction.execute(dataLoadedCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on a time range and a {@link #getStepSizeInMillis() desired step size} computes an effective
|
||||
* step size that observes a maximum number of fixes that may be queried in one request from the server
|
||||
* ({@link SailingServiceConstants#MAX_NUMBER_OF_FIXES_TO_QUERY}). If the time range and the desired step
|
||||
* size do not exceed this limit, the step size desired will be returned. Otherwise, the step size will be
|
||||
* extended such that {@link SailingServiceConstants#MAX_NUMBER_OF_FIXES_TO_QUERY} fixes will be requested
|
||||
* for the time range between {@code from} and {@code to}.
|
||||
*
|
||||
* @return the effective step size in milliseconds
|
||||
*/
|
||||
private long getEffectiveStepSize(final Date from, final Date to) {
|
||||
return Math.max(getStepSizeInMillis(),
|
||||
from==null||to==null ? 0 : Math.abs(to.getTime()-from.getTime())/SailingServiceConstants.MAX_NUMBER_OF_FIXES_TO_QUERY);
|
||||
}
|
||||
|
||||
private boolean chartContainsNoData() {
|
||||
for (Series competitorSeries : dataSeriesForDetailTypeAndCompetitor.values()) {
|
||||
@@ -344,7 +384,7 @@ public abstract class AbstractCompetitorRaceChart<SettingsType extends ChartSett
|
||||
* Fills the series for the selected competitors with the data in {@link AbstractCompetitorRaceChart#chartData}.<br />
|
||||
*/
|
||||
private synchronized void updateChartSeries(CompetitorsRaceDataDTO chartData, DetailType retrievedDataType,
|
||||
boolean append,TimingHolder tholder) {
|
||||
boolean append, TimingHolder tholder) {
|
||||
// Make sure the busy indicator is removed at this point, or plotting the data results in an exception
|
||||
setWidget(chart);
|
||||
for (CompetitorDTO competitor : chartData.getCompetitors()) {
|
||||
@@ -389,15 +429,14 @@ public abstract class AbstractCompetitorRaceChart<SettingsType extends ChartSett
|
||||
newRaceDataPoints = new Point[currentPointIndex];
|
||||
System.arraycopy(raceDataPointsToAdd, 0, newRaceDataPoints, 0, currentPointIndex);
|
||||
}
|
||||
setSeriesPoints(competitorDataSeries, newRaceDataPoints);
|
||||
setSeriesPoints(competitorDataSeries, newRaceDataPoints, /* manageZoom */ append);
|
||||
// Adding the series if chart doesn't contain it
|
||||
List<Series> chartSeries = Arrays.asList(chart.getSeries());
|
||||
if (!chartSeries.contains(competitorDataSeries)) {
|
||||
chart.addSeries(competitorDataSeries);
|
||||
chart.addSeries(markPassingSeries);
|
||||
//this is to prevent a bug, that will prohibit the initial rendering
|
||||
// this is to prevent a bug, that will prohibit the initial rendering
|
||||
chart.setSizeToMatchContainer();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -184,13 +184,13 @@ public abstract class AbstractRaceChart<SettingsType extends Settings> extends A
|
||||
if (!isZoomed) {
|
||||
isZoomed = true;
|
||||
}
|
||||
//Set a minute as max time zoom just as for chart
|
||||
// Set a minute as max time zoom just as for chart
|
||||
if (xAxisMax - xAxisMin > MINUTE_IN_MILLIS) {
|
||||
Date rangeStart = new Date(xAxisMin);
|
||||
Date rangeEnd = new Date(xAxisMax);
|
||||
timeRangeWithZoomProvider.setTimeZoom(rangeStart, rangeEnd, this);
|
||||
updateChartIfEffectiveStepSizeChanged(rangeStart, rangeEnd);
|
||||
fireEvent(new ChartZoomChangedEvent(rangeStart, rangeEnd));
|
||||
|
||||
} else {
|
||||
fireEvent(new ChartZoomResetEvent());
|
||||
return false;
|
||||
@@ -199,7 +199,7 @@ public abstract class AbstractRaceChart<SettingsType extends Settings> extends A
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
// in case the user clicks the "reset zoom" button chartSelectionEvent.getXAxisMinAsLong() throws in exception
|
||||
// in case the user clicks the "reset zoom" button chartSelectionEvent.getXAxisMinAsLong() throws an exception
|
||||
isZoomed = false;
|
||||
timeRangeWithZoomProvider.resetTimeZoom();
|
||||
// redraw is triggered by the call to onTimeZoomReset() and therefore not necessary again here
|
||||
@@ -223,6 +223,13 @@ public abstract class AbstractRaceChart<SettingsType extends Settings> extends A
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing here; subclasses have the possibility to override if they need to re-load data
|
||||
* based on changes in the visible area that may lead to step size / resolution adjustments
|
||||
*/
|
||||
protected void updateChartIfEffectiveStepSizeChanged(Date minTimepoint, Date maxTimepoint) {
|
||||
}
|
||||
|
||||
protected void changeMinMaxAndExtremesInterval(Date minTimepoint, Date maxTimepoint, boolean redraw) {
|
||||
if (chart != null) {
|
||||
@@ -246,14 +253,14 @@ public abstract class AbstractRaceChart<SettingsType extends Settings> extends A
|
||||
}
|
||||
}
|
||||
|
||||
protected void setSeriesPoints(Series series, Point[] points) {
|
||||
if (timeRangeWithZoomProvider.isZoomed()) {
|
||||
protected void setSeriesPoints(Series series, Point[] points, boolean manageZoom) {
|
||||
if (manageZoom && timeRangeWithZoomProvider.isZoomed()) {
|
||||
com.sap.sse.common.Util.Pair<Date, Date> timeZoom = timeRangeWithZoomProvider.getTimeZoom();
|
||||
resetMinMaxAndExtremesInterval(/* redraw */ false);
|
||||
series.setPoints(points, false);
|
||||
series.setPoints(points, /* redraw */ false);
|
||||
changeMinMaxAndExtremesInterval(timeZoom.getA(), timeZoom.getB(), /* redraw */ false);
|
||||
} else {
|
||||
series.setPoints(points, false);
|
||||
series.setPoints(points, /* redraw */ false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -514,7 +514,7 @@ public class EditMarkPositionPanel extends AbstractRaceChart<AbstractSettings> i
|
||||
Point[] points = markSeries.getPoints();
|
||||
if (points.length > index) {
|
||||
setRedPoint(points, index);
|
||||
setSeriesPoints(markSeries, points);
|
||||
setSeriesPoints(markSeries, points, /* manageZoom */ true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ public class EditMarkPositionPanel extends AbstractRaceChart<AbstractSettings> i
|
||||
Point[] points = getSeriesPoints(marks.get(selectedMark).keySet());
|
||||
if (points.length > index) {
|
||||
setRedPoint(points, index);
|
||||
setSeriesPoints(markSeries, points);
|
||||
setSeriesPoints(markSeries, points, /* manageZoom */ true);
|
||||
chart.redraw();
|
||||
}
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public class EditMarkPositionPanel extends AbstractRaceChart<AbstractSettings> i
|
||||
Point[] points = markSeries.getPoints();
|
||||
if (points.length > index) {
|
||||
points[index].setMarker(new Marker().setFillColor(selectedMark.color==null?null:selectedMark.color.getAsHtml()));
|
||||
setSeriesPoints(markSeries, points);
|
||||
setSeriesPoints(markSeries, points, /* manageZoom */ true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,11 +700,11 @@ public class EditMarkPositionPanel extends AbstractRaceChart<AbstractSettings> i
|
||||
}
|
||||
|
||||
private void setSeriesPoints(MarkDTO mark) {
|
||||
setSeriesPoints(markSeries, getSeriesPoints(marks.get(mark).keySet()));
|
||||
setSeriesPoints(markSeries, getSeriesPoints(marks.get(mark).keySet()), /* manageZoom */ true);
|
||||
}
|
||||
|
||||
public void setSeriesPoints(Point[] points) {
|
||||
setSeriesPoints(markSeries, points);
|
||||
setSeriesPoints(markSeries, points, /* manageZoom */ true);
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
|
||||
+2
-2
@@ -447,10 +447,10 @@ public class WindChart extends AbstractRaceChart<WindChartSettings> implements R
|
||||
newDirectionPoints = directionPoints;
|
||||
newSpeedPoints = speedPoints;
|
||||
}
|
||||
setSeriesPoints(directionSeries, newDirectionPoints);
|
||||
setSeriesPoints(directionSeries, newDirectionPoints, /* manageZoom */ true);
|
||||
windSourceDirectionPoints.put(windSource, newDirectionPoints);
|
||||
if (windSource.getType().useSpeed()) {
|
||||
setSeriesPoints(speedSeries, newSpeedPoints);
|
||||
setSeriesPoints(speedSeries, newSpeedPoints, /* manageZoom */ true);
|
||||
windSourceSpeedPoints.put(windSource, newSpeedPoints);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user