2323import org .eclipse .swt .graphics .Point ;
2424import org .eclipse .swt .graphics .RGBA ;
2525import org .eclipse .swt .widgets .Control ;
26+ import org .eclipse .tracecompass .internal .tmf .ui .Messages ;
2627import org .eclipse .tracecompass .tmf .core .presentation .RGBAColor ;
28+ import org .eclipse .tracecompass .tmf .core .timestamp .ITmfTimestamp ;
29+ import org .eclipse .tracecompass .tmf .core .timestamp .TmfTimestamp ;
2730import org .eclipse .tracecompass .tmf .ui .viewers .TmfAbstractToolTipHandler ;
2831import org .eclipse .tracecompass .tmf .ui .viewers .TmfAbstractToolTipHandler .ToolTipString ;
2932import org .eclipse .tracecompass .tmf .ui .viewers .xychart .IAxis ;
3033import org .eclipse .tracecompass .tmf .ui .viewers .xychart .ITmfChartTimeProvider ;
3134import org .eclipse .tracecompass .tmf .ui .viewers .xychart .IXYSeries ;
3235import org .eclipse .tracecompass .tmf .ui .viewers .xychart .TmfBaseProvider ;
33- import org .eclipse .tracecompass .tmf .ui .viewers .xychart .linechart .TmfCommonXAxisChartViewer ;
3436
3537/**
3638 * Displays a tooltip on line charts. For each series, it shows the y value at
@@ -93,16 +95,19 @@ protected boolean isValidSeriesIndex(IXYSeries series, int index) {
9395 }
9496
9597 protected void addAdditionalTooltipItems (double xCoordinate , String seriesKey ) {
96- // Default: no-op
98+ ITmfTimestamp time = TmfTimestamp .fromNanos ((long ) xCoordinate + getChartViewer ().getTimeOffset ());
99+ addItem (null ,
100+ ToolTipString .fromString (Messages .TmfCommonXLineChartTooltipProvider_time ),
101+ ToolTipString .fromTimestamp (time .toString (), time .toNanos ()));
97102 }
98103
99- protected void addSeriesTooltipItem (IXYSeries series , String key , int index , Format format ) {
104+ protected void addSeriesTooltipItem (IXYSeries series , int index , Format format ) {
100105 double [] ySeries = series .getYSeries ();
101106 if (ySeries == null || index < 0 || index >= ySeries .length ) {
102107 return ;
103108 }
104109
105- String label = formatSeriesLabel (series , key );
110+ String label = formatSeriesLabel (series );
106111 double yValue = ySeries [index ];
107112 if (format == null ) {
108113 addItem (null , ToolTipString .fromHtml (label ), ToolTipString .fromDecimal (yValue ));
@@ -111,7 +116,8 @@ protected void addSeriesTooltipItem(IXYSeries series, String key, int index, For
111116 }
112117 }
113118
114- protected String formatSeriesLabel (IXYSeries series , String key ) {
119+ protected String formatSeriesLabel (IXYSeries series ) {
120+ String key = series .getId ();
115121 String label = (key == null ) ? "" : key ; //$NON-NLS-1$
116122 Color color = series .getColor ();
117123 if (color != null ) {
@@ -147,19 +153,20 @@ public void fill(Control control, MouseEvent event, Point pt) {
147153 format = chartViewer .getSwtChart ().getAxisSet ().getYAxes ()[0 ].getTick ().getFormat ();
148154 }
149155
150- boolean additionalItemsAdded = false ;
156+ String firstValidSeriesKey = null ;
151157 for (IXYSeries xySeries : series ) {
152- if (!isValidSeriesIndex (xySeries , index )) {
153- continue ;
158+ if (isValidSeriesIndex (xySeries , index )) {
159+ firstValidSeriesKey = xySeries .getId ();
160+ break ;
154161 }
162+ }
163+ addAdditionalTooltipItems (xCoordinate , firstValidSeriesKey );
155164
156- String key = xySeries .getId ();
157- if (!additionalItemsAdded ) {
158- addAdditionalTooltipItems (xCoordinate , key );
159- additionalItemsAdded = true ;
165+ for (IXYSeries xySeries : series ) {
166+ if (!isValidSeriesIndex (xySeries , index )) {
167+ continue ;
160168 }
161-
162- addSeriesTooltipItem (xySeries , key , index , format );
169+ addSeriesTooltipItem (xySeries , index , format );
163170 }
164171 }
165172 }
0 commit comments