| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2015, 2016 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Bernd Hufmann - Initial API and implementation |
| 11 | **********************************************************************/ |
| 12 | package org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.scatter; |
| 13 | |
| 14 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
| 15 | |
| 16 | import org.eclipse.jdt.annotation.Nullable; |
| 17 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
| 18 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
| 19 | import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.ITmfChartTimeProvider; |
| 20 | import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfClosestDataPointTooltipProvider; |
| 21 | import org.swtchart.ISeries; |
| 22 | |
| 23 | /** |
| 24 | * Tooltip provider for durations scatter charts. It displays the y value of |
| 25 | * position x as well as it highlights the closest data point. |
| 26 | * |
| 27 | * @author Bernd Hufmann |
| 28 | */ |
| 29 | public class SegmentStoreScatterGraphTooltipProvider extends TmfClosestDataPointTooltipProvider{ |
| 30 | |
| 31 | // ------------------------------------------------------------------------ |
| 32 | // Constructors |
| 33 | // ------------------------------------------------------------------------ |
| 34 | /** |
| 35 | * Constructor for the segment store scatter chart tooltip provider. |
| 36 | * |
| 37 | * @param tmfChartViewer |
| 38 | * - the parent chart viewer |
| 39 | */ |
| 40 | public SegmentStoreScatterGraphTooltipProvider(ITmfChartTimeProvider tmfChartViewer) { |
| 41 | super(tmfChartViewer); |
| 42 | register(); |
| 43 | } |
| 44 | |
| 45 | // ------------------------------------------------------------------------ |
| 46 | // TmfClosestDataPointTooltipProvider |
| 47 | // ------------------------------------------------------------------------ |
| 48 | @Override |
| 49 | protected @Nullable String createToolTipText(Parameter param) { |
| 50 | ISeries[] series = getChart().getSeriesSet().getSeries(); |
| 51 | int seriesIndex = param.getSeriesIndex(); |
| 52 | int dataIndex = param.getDataIndex(); |
| 53 | if ((series != null) && (seriesIndex < series.length)) { |
| 54 | ISeries serie = series[seriesIndex]; |
| 55 | double[] xS = serie.getXSeries(); |
| 56 | double[] yS = serie.getYSeries(); |
| 57 | if ((xS != null) && (yS != null) && (dataIndex < xS.length) && (dataIndex < yS.length)) { |
| 58 | StringBuffer buffer = new StringBuffer(); |
| 59 | buffer.append(checkNotNull(Messages.SegmentStoreScatterGraphViewer_xAxis)).append('='); |
| 60 | buffer.append(new TmfTimestamp((long) xS[dataIndex] + getChartViewer().getTimeOffset(), ITmfTimestamp.NANOSECOND_SCALE).toString()); |
| 61 | buffer.append('\n'); |
| 62 | buffer.append(Messages.SegmentStoreScatterGraphViewer_yAxis).append('='); |
| 63 | buffer.append((long) yS[dataIndex]); |
| 64 | return buffer.toString(); |
| 65 | } |
| 66 | } |
| 67 | return null; |
| 68 | } |
| 69 | |
| 70 | } |