attempt to fix the reversing of the Y-axis for an already existing competitor chart

This commit is contained in:
Axel Uhl committed 2012-12-06 03:11:54 +01:00
1 parent 9527179ccd
commit 6b38a246fb
2 files changed
+27 -24

No files matched your search

@@ -96,12 +96,10 @@ public abstract class AbstractChartPanel<SettingsType extends ChartSettings> ext
dataSeriesByCompetitor = new HashMap<CompetitorDTO, Series>();
markPassingSeriesByCompetitor = new HashMap<CompetitorDTO, Series>();
setSize("100%", "100%");
noCompetitorsSelectedLabel = new Label(stringMessages.selectAtLeastOneCompetitor() + ".");
noCompetitorsSelectedLabel.setStyleName("abstractChartPanel-importantMessageOfChart");
createChart();
setSelectedDetailType(detailType);
competitorSelectionProvider.addCompetitorSelectionChangeListener(this);
raceSelectionProvider.addRaceSelectionChangeListener(this);
}
@@ -472,6 +470,10 @@ public abstract class AbstractChartPanel<SettingsType extends ChartSettings> ext
return this.selectedDetailType;
}
private boolean hasReversedYAxis(DetailType detailType) {
return detailType == DetailType.WINDWARD_DISTANCE_TO_OVERALL_LEADER || detailType == DetailType.GAP_TO_LEADER_IN_SECONDS;
}
/**
* Updates the {@link #selectedDetailType} field, clears the chart for the new <code>selectedDetailType</code> and
* clears the {@link #chartData}.<br />
@@ -482,15 +484,20 @@ public abstract class AbstractChartPanel<SettingsType extends ChartSettings> ext
protected boolean setSelectedDetailType(DetailType newSelectedDetailType) {
boolean hasDetailTypeChanged = newSelectedDetailType != this.selectedDetailType;
if (hasDetailTypeChanged) {
boolean oldReversedYAxis = hasReversedYAxis(this.selectedDetailType);
this.selectedDetailType = newSelectedDetailType;
// There is a bug in the highcharts library which prevents to change the reverse property of the YAxis
// Because we need this functionality we need to recreate the chart each time the YAxis changes
chart = createChart();
chart.setTitle(new ChartTitle().setText(DetailTypeFormatter.format(selectedDetailType, stringMessages)),
null);
// TODO There is a bug in the highcharts library which prevents to change the reverse property of the YAxis
// Because we need this functionality we need to recreate the chart each time the YAxis changes
if (oldReversedYAxis != hasReversedYAxis(selectedDetailType)) {
chart = createChart();
if (isZoomed) {
Pair<Date, Date> zoomRange = timeRangeWithZoomProvider.getTimeZoom();
onTimeZoomChanged(zoomRange.getA(), zoomRange.getB());
} else {
resetMinMaxAndExtremesInterval(/* redraw */ true);
}
}
chart.setTitle(new ChartTitle().setText(DetailTypeFormatter.format(selectedDetailType, stringMessages)), null);
final String unit = getDetailTypeUnit();
if (!compactChart) {
chart.getYAxis().setAxisTitleText(
@@ -498,12 +505,8 @@ public abstract class AbstractChartPanel<SettingsType extends ChartSettings> ext
} else {
chart.getYAxis().setAxisTitleText("[" + unit + "]");
}
chart.getYAxis()
.setReversed(
(selectedDetailType == DetailType.WINDWARD_DISTANCE_TO_OVERALL_LEADER || selectedDetailType == DetailType.GAP_TO_LEADER_IN_SECONDS) ? true
: false);
chart.getYAxis().setReversed(
selectedDetailType == DetailType.WINDWARD_DISTANCE_TO_OVERALL_LEADER || selectedDetailType == DetailType.GAP_TO_LEADER_IN_SECONDS);
final NumberFormat numberFormat = DetailTypeFormatter.getNumberFormat(selectedDetailType);
chart.setToolTip(new ToolTip().setEnabled(true).setFormatter(new ToolTipFormatter() {
@Override
@@ -111,7 +111,6 @@ public abstract class RaceChart extends SimplePanel implements RaceSelectionChan
protected void changeMinMaxAndExtremesInterval(Date minTimepoint, Date maxTimepoint, boolean redraw) {
XAxis xAxis = chart.getXAxis();
if (minTimepoint != null) {
xAxis.setMin(minTimepoint.getTime());
}
@@ -123,18 +122,16 @@ public abstract class RaceChart extends SimplePanel implements RaceSelectionChan
long tickInterval = (maxTimepoint.getTime() - minTimepoint.getTime()) / TICKCOUNT;
xAxis.setTickInterval(tickInterval);
}
if(redraw) {
if (redraw) {
chart.redraw();
}
}
protected void setSeriesPoints(Series series, Point[] points) {
if(timeRangeWithZoomProvider.isZoomed()) {
if (timeRangeWithZoomProvider.isZoomed()) {
Pair<Date, Date> timeZoom = timeRangeWithZoomProvider.getTimeZoom();
resetMinMaxAndExtremesInterval(false);
series.setPoints(points, false);
changeMinMaxAndExtremesInterval(timeZoom.getA(), timeZoom.getB(), false);
} else {
series.setPoints(points, false);
@@ -145,18 +142,21 @@ public abstract class RaceChart extends SimplePanel implements RaceSelectionChan
changeMinMaxAndExtremesInterval(timeRangeWithZoomProvider.getFromTime(), timeRangeWithZoomProvider.getToTime(), redraw);
}
@Override
public void onTimeZoomChanged(Date zoomStartTimepoint, Date zoomEndTimepoint) {
changeMinMaxAndExtremesInterval(zoomStartTimepoint, zoomEndTimepoint, true);
// Probably there is a function for this in a newer version of highcharts: http://jsfiddle.net/mqz3N/1071/
// chart.showResetZoom();
}
@Override
public void onTimeRangeChanged(Date fromTime, Date toTime) {
if(!(isZoomed && timer.getPlayMode() == PlayModes.Live)) {
changeMinMaxAndExtremesInterval(timeRangeWithZoomProvider.getFromTime(), timeRangeWithZoomProvider.getToTime(), true);
if (!(isZoomed && timer.getPlayMode() == PlayModes.Live)) {
resetMinMaxAndExtremesInterval(/* redraw */ true);
}
}
@Override
public void onTimeZoomReset() {
resetMinMaxAndExtremesInterval(true);
}