Added tooltips to the time line; Refactoring of the chart tool tip creation

This commit is contained in:
Lennart Hensler
2012-03-14 15:54:04 +01:00
parent 02d5b7ad40
commit e08599f7c0
5 changed files with 35 additions and 15 deletions
@@ -113,12 +113,22 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
chart.setToolTip(new ToolTip().setEnabled(true).setFormatter(new ToolTipFormatter() {
@Override
public String format(ToolTipData toolTipData) {
final String unit = toolTipData.getSeriesName().startsWith(stringMessages.fromDeg()+" ") ? stringMessages.degreesShort() :
stringMessages.averageSpeedInKnotsUnit();
return "<b>" + toolTipData.getSeriesName() + (toolTipData.getPointName() != null ? " "+toolTipData.getPointName() : "")
+ "</b><br/>" +
dateFormat.format(new Date(toolTipData.getXAsLong())) + ": " +
numberFormat.format(toolTipData.getYAsDouble()) + unit;
String seriesName = toolTipData.getSeriesName();
if (seriesName.equals(WindChart.this.stringMessages.time())) {
return "<b>" + seriesName + ":</b> " + dateFormat.format(new Date(toolTipData.getXAsLong()))
+ "<br/>(" + stringMessages.clickChartToSetTime() + ")";
} else if (seriesName.startsWith(stringMessages.fromDeg()+" ")) {
return "<b>" + seriesName + (toolTipData.getPointName() != null ? " "+toolTipData.getPointName() : "")
+ "</b><br/>" +
dateFormat.format(new Date(toolTipData.getXAsLong())) + ": " +
numberFormat.format(toolTipData.getYAsDouble()) + stringMessages.degreesShort();
} else {
return "<b>" + seriesName + (toolTipData.getPointName() != null ? " "+toolTipData.getPointName() : "")
+ "</b><br/>" +
dateFormat.format(new Date(toolTipData.getXAsLong())) + ": " +
numberFormat.format(toolTipData.getYAsDouble()) + stringMessages.averageSpeedInKnotsUnit();
}
}
}));
@@ -267,9 +277,9 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
return chart
.createSeries()
.setType(Series.Type.LINE)
.setName("TIME_LINE")
.setName(stringMessages.time())
.setYAxis(0)
.setPlotOptions(new LinePlotOptions().setEnableMouseTracking(false).setShowInLegend(false).setHoverStateEnabled(false).setLineWidth(2));
.setPlotOptions(new LinePlotOptions().setShowInLegend(false).setHoverStateEnabled(false).setLineWidth(2));
}
/**
@@ -271,4 +271,5 @@ public interface StringMessages extends Messages {
String trackBasedEstimationWindSourceTypeName();
String expeditionWindSourceTypeName();
String webWindSourceTypeName();
String clickChartToSetTime();
}
@@ -266,3 +266,4 @@ courseBasedWindSourceTypeName=Course Layout
trackBasedEstimationWindSourceTypeName=Estimation
expeditionWindSourceTypeName=Measured
webWindSourceTypeName=Manual
clickChartToSetTime=Click on the chart to set the time
@@ -266,4 +266,5 @@ combinedWindSourceTypeName=Kombiniert
courseBasedWindSourceTypeName=Kurslayout
trackBasedEstimationWindSourceTypeName=Schätzung
expeditionWindSourceTypeName=Messung
webWindSourceTypeName=Manuell
webWindSourceTypeName=Manuell
clickChartToSetTime=Klicke auf das Diagramm um die Zeit zu setzen
@@ -211,10 +211,17 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
chart.setToolTip(new ToolTip().setEnabled(true).setFormatter(new ToolTipFormatter() {
@Override
public String format(ToolTipData toolTipData) {
return "<b>" + toolTipData.getSeriesName() + (toolTipData.getPointName() != null ? " "+toolTipData.getPointName() : "")
+ "</b><br/>" +
dateFormat.format(new Date(toolTipData.getXAsLong())) + ": " +
numberFormat.format(toolTipData.getYAsDouble()) + unit;
String seriesName = toolTipData.getSeriesName();
if (seriesName.equals(stringMessages.time())) {
return "<b>" + seriesName + ":</b> " + dateFormat.format(new Date(toolTipData.getXAsLong()))
+ "<br/>(" + stringMessages.clickChartToSetTime() + ")";
} else {
return "<b>" + seriesName
+ (toolTipData.getPointName() != null ? " " + toolTipData.getPointName() : "")
+ "</b><br/>" + dateFormat.format(new Date(toolTipData.getXAsLong())) + ": "
+ numberFormat.format(toolTipData.getYAsDouble()) + unit;
}
}
}));
@@ -429,8 +436,8 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
return chart
.createSeries()
.setType(Series.Type.LINE)
.setName("TIME_LINE")
.setPlotOptions(new LinePlotOptions().setEnableMouseTracking(false).setShowInLegend(false).setHoverStateEnabled(false).setLineWidth(2));
.setName(stringMessages.time())
.setPlotOptions(new LinePlotOptions().setShowInLegend(false).setHoverStateEnabled(false).setLineWidth(2));
}
private String getUnit() {