mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 19:33:52 +00:00
some bug fixes for the WindChart..
- Better initial loading - Fix for SettingsDialog (was not working)
This commit is contained in:
1 parent
4ad04e2acd
commit
394e0695fd
1 file changed
+59
-33
+59
-33
@@ -20,6 +20,7 @@ import org.moxieapps.gwt.highcharts.client.Series;
|
||||
import org.moxieapps.gwt.highcharts.client.ToolTip;
|
||||
import org.moxieapps.gwt.highcharts.client.ToolTipData;
|
||||
import org.moxieapps.gwt.highcharts.client.ToolTipFormatter;
|
||||
import org.moxieapps.gwt.highcharts.client.XAxis;
|
||||
import org.moxieapps.gwt.highcharts.client.events.ChartClickEvent;
|
||||
import org.moxieapps.gwt.highcharts.client.events.ChartClickEventHandler;
|
||||
import org.moxieapps.gwt.highcharts.client.events.ChartSelectionEvent;
|
||||
@@ -88,13 +89,16 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
private Long timeOfEarliestRequestInMillis;
|
||||
private Long timeOfLatestRequestInMillis;
|
||||
|
||||
private Date chartMinTimepoint;
|
||||
private Date chartMaxTimepoint;
|
||||
private Date minTimepoint;
|
||||
private Date maxTimepoint;
|
||||
private Date minSelectedTimepoint;
|
||||
private Date maxSelectedTimepoint;
|
||||
|
||||
private RaceIdentifier selectedRaceIdentifier;
|
||||
private RaceTimesInfoDTO lastRaceTimesInfo;
|
||||
|
||||
private final ColorMap<WindSource> colorMap;
|
||||
private boolean isZoomed = false;
|
||||
|
||||
/**
|
||||
* @param raceSelectionProvider
|
||||
@@ -171,10 +175,16 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
@Override
|
||||
public boolean onSelection(ChartSelectionEvent chartSelectionEvent) {
|
||||
try {
|
||||
chartSelectionEvent.getXAxisMaxAsLong();
|
||||
chartSelectionEvent.getXAxisMinAsLong();
|
||||
long xAxisMin = chartSelectionEvent.getXAxisMinAsLong();
|
||||
long xAxisMax = chartSelectionEvent.getXAxisMaxAsLong();
|
||||
WindChart.this.minSelectedTimepoint = new Date(xAxisMin);
|
||||
WindChart.this.maxSelectedTimepoint = new Date(xAxisMax);
|
||||
WindChart.this.isZoomed = true;
|
||||
ignoreClickOnce = true;
|
||||
} catch (Throwable t) {
|
||||
WindChart.this.minSelectedTimepoint = null;
|
||||
WindChart.this.maxSelectedTimepoint = null;
|
||||
WindChart.this.isZoomed = false;
|
||||
//Redrawing, or the chart wouldn't rezoom
|
||||
chart.redraw();
|
||||
}
|
||||
@@ -182,7 +192,6 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
chart.getXAxis().setType(Axis.Type.DATE_TIME).setMaxZoom(10000) // ten seconds
|
||||
.setAxisTitleText(stringMessages.time());
|
||||
chart.getYAxis(0).setAxisTitleText(stringMessages.fromDeg()).setStartOnTick(false).setShowFirstLabel(false)
|
||||
@@ -229,32 +238,35 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
|
||||
private void showVisibleSeries() {
|
||||
Series[] currentlyVisible = chart.getSeries();
|
||||
Set<Series> visible = new HashSet<Series>();
|
||||
Set<Series> seriesToRemove = new HashSet<Series>();
|
||||
for (Series series : currentlyVisible) {
|
||||
visible.add(series);
|
||||
seriesToRemove.add(series);
|
||||
}
|
||||
for (Map.Entry<WindSource, Series> e : windSourceDirectionSeries.entrySet()) {
|
||||
if (windSourceTypesToDisplay.contains(e.getKey().getType())) {
|
||||
if (!visible.contains(e.getValue())) {
|
||||
if (!seriesToRemove.contains(e.getValue())) {
|
||||
chart.addSeries(e.getValue());
|
||||
e.getValue().select(true); // ensures that the checkbox will be ticked
|
||||
} else {
|
||||
visible.remove(e.getValue());
|
||||
seriesToRemove.remove(e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<WindSource, Series> e : windSourceSpeedSeries.entrySet()) {
|
||||
if (windSourceTypesToDisplay.contains(e.getKey().getType())) {
|
||||
if (!visible.contains(e.getValue())) {
|
||||
if (!seriesToRemove.contains(e.getValue())) {
|
||||
chart.addSeries(e.getValue());
|
||||
e.getValue().select(true); // ensures that the checkbox will be ticked
|
||||
} else {
|
||||
visible.remove(e.getValue());
|
||||
seriesToRemove.remove(e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Series seriesToRemove : visible) {
|
||||
chart.removeSeries(seriesToRemove);
|
||||
|
||||
// never remove the timeLineSeries
|
||||
seriesToRemove.remove(timeLineSeries);
|
||||
for (Series series : seriesToRemove) {
|
||||
chart.removeSeries(series);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,17 +440,7 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
}
|
||||
windSourceTypesToDisplay.clear();
|
||||
windSourceTypesToDisplay.addAll(newSettings.getWindSourceTypesToDisplay());
|
||||
chart.removeAllSeries(/* redraw */ false);
|
||||
for (Map.Entry<WindSource, Series> e : windSourceDirectionSeries.entrySet()) {
|
||||
if (windSourceTypesToDisplay.contains(e.getKey().getType())) {
|
||||
chart.addSeries(e.getValue());
|
||||
e.getValue().select(true); // ensures that the checkbox will be ticked
|
||||
if (windSourceSpeedSeries.containsKey(e.getKey()) && e.getKey().getType().useSpeed()) {
|
||||
chart.addSeries(windSourceSpeedSeries.get(e.getKey()));
|
||||
windSourceSpeedSeries.get(e.getKey()).select(true); // ensures that the checkbox will be ticked
|
||||
}
|
||||
}
|
||||
}
|
||||
showVisibleSeries();
|
||||
chart.redraw();
|
||||
}
|
||||
|
||||
@@ -446,7 +448,7 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
timeOfEarliestRequestInMillis = null;
|
||||
timeOfLatestRequestInMillis = null;
|
||||
|
||||
loadData(selectedRaceIdentifier, chartMinTimepoint, chartMaxTimepoint, /* append */false);
|
||||
loadData(selectedRaceIdentifier, minTimepoint, maxTimepoint, /* append */false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -474,6 +476,7 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
if (raceIdentifier == null) {
|
||||
clearChart();
|
||||
} else if (needsDataLoading() && from != null && to != null) {
|
||||
chart.showLoading("Loading wind data...");
|
||||
GetWindInfoAction getWindInfoAction = new GetWindInfoAction(sailingService, raceIdentifier,
|
||||
// TODO Time interval should be determined by a selection in the chart but be at most 60s. See bug #121.
|
||||
// Consider incremental updates for new data only.
|
||||
@@ -482,18 +485,29 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
@Override
|
||||
public void onSuccess(WindInfoForRaceDTO result) {
|
||||
if (result != null) {
|
||||
XAxis xAxis = chart.getXAxis();
|
||||
|
||||
xAxis.setMin(minTimepoint.getTime());
|
||||
xAxis.setMax(maxTimepoint.getTime());
|
||||
xAxis.setStartOnTick(false);
|
||||
xAxis.setEndOnTick(false);
|
||||
|
||||
xAxis.setPlotLines(xAxis.createPlotLine().setColor("#CC0000").setValue(WindChart.this.timer.getTime().getTime()));
|
||||
|
||||
updateStripChartSeries(result, append);
|
||||
} else {
|
||||
if (!append) {
|
||||
clearChart(); // no wind known for untracked race
|
||||
}
|
||||
}
|
||||
chart.hideLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
errorReporter.reportError(stringMessages.errorFetchingWindInformationForRace() + " "
|
||||
errorReporter.reportError(stringMessages.errorFetchingWindInformationForRace() + " "
|
||||
+ raceIdentifier + ": " + caught.getMessage(), timer.getPlayMode() == PlayModes.Live);
|
||||
chart.hideLoading();
|
||||
}
|
||||
});
|
||||
asyncActionsExecutor.execute(getWindInfoAction);
|
||||
@@ -521,8 +535,8 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
|
||||
Pair<Date, Date> raceMinMax = RaceTimesCalculationUtil.caluclateRaceMinMax(timer, this.lastRaceTimesInfo);
|
||||
|
||||
this.chartMinTimepoint = raceMinMax.getA();
|
||||
this.chartMaxTimepoint = raceMinMax.getB();
|
||||
this.minTimepoint = raceMinMax.getA();
|
||||
this.maxTimepoint = raceMinMax.getB();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,15 +549,15 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
if (timer.getPlayMode() == PlayModes.Live) {
|
||||
// is date before first cache entry or is cache empty?
|
||||
if (timeOfEarliestRequestInMillis == null || timeOfEarliestRequestInMillis > date.getTime()) {
|
||||
loadData(selectedRaceIdentifier, chartMinTimepoint, date, /* append */ true);
|
||||
loadData(selectedRaceIdentifier, minTimepoint, date, /* append */ true);
|
||||
} else if (timeOfLatestRequestInMillis < date.getTime()) {
|
||||
loadData(selectedRaceIdentifier, new Date(timeOfLatestRequestInMillis), chartMaxTimepoint, /* append */true);
|
||||
loadData(selectedRaceIdentifier, new Date(timeOfLatestRequestInMillis), maxTimepoint, /* append */true);
|
||||
}
|
||||
// otherwise the cache spans across date and so we don't need to load anything
|
||||
} else {
|
||||
// assuming play mode is replay / non-live
|
||||
if (timeOfLatestRequestInMillis == null) {
|
||||
loadData(selectedRaceIdentifier, chartMinTimepoint, chartMaxTimepoint, /* append */false); // replace old series
|
||||
loadData(selectedRaceIdentifier, minTimepoint, maxTimepoint, /* append */false); // replace old series
|
||||
}
|
||||
}
|
||||
updateTimeLine(date);
|
||||
@@ -567,8 +581,8 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
try {
|
||||
Extremes extremes = chart.getYAxis(0).getExtremes();
|
||||
Point[] points = new Point[2];
|
||||
points[0] = new Point(x, extremes.getDataMin());
|
||||
points[1] = new Point(x, extremes.getDataMax());
|
||||
points[0] = new Point(x, extremes.getMin());
|
||||
points[1] = new Point(x, extremes.getMax());
|
||||
timeLineSeries.setPoints(points);
|
||||
ensureTimeLineIsVisible();
|
||||
} catch (NullPointerException e) {
|
||||
@@ -595,4 +609,16 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
|
||||
return isVisible();
|
||||
}
|
||||
|
||||
public Date getMinSelectedTimepoint() {
|
||||
return minSelectedTimepoint;
|
||||
}
|
||||
|
||||
public Date getMaxSelectedTimepoint() {
|
||||
return maxSelectedTimepoint;
|
||||
}
|
||||
|
||||
public boolean isZoomed() {
|
||||
return isZoomed;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user