1
/*******************************************************************************
2
* Copyright (c) 2010, 2011 Ericsson
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
10
* Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
* Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12
* Bernd Hufmann - Adapted to new model-view-controller design, display improvements
13
*******************************************************************************/
14
package org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners;
16
import java.text.DecimalFormat;
18
import org.eclipse.linuxtools.internal.lttng.ui.views.latency.AbstractViewer;
19
import org.eclipse.linuxtools.internal.lttng.ui.views.latency.GraphViewer;
20
import org.eclipse.linuxtools.internal.lttng.ui.views.latency.model.Config;
21
import org.eclipse.linuxtools.internal.lttng.ui.views.latency.model.GraphScaledData;
22
import org.eclipse.linuxtools.internal.lttng.ui.views.latency.model.IGraphDataModel;
23
import org.eclipse.linuxtools.tmf.ui.views.distribution.model.BaseDistributionData;
24
import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramUtils;
27
* <b><u>GraphPaintListener</u></b>
29
* Graph paint listener.
31
* @author Philippe Sawicki
33
public class GraphPaintListener extends AbstractPaintListener {
35
// ------------------------------------------------------------------------
37
// ------------------------------------------------------------------------
40
* Scaled data from data model
42
protected GraphScaledData fScaledData;
44
// ------------------------------------------------------------------------
46
// ------------------------------------------------------------------------
51
* A reference to the listener's viewer.
53
public GraphPaintListener(AbstractViewer view) {
57
// ------------------------------------------------------------------------
59
// ------------------------------------------------------------------------
63
* @see org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener#scale()
68
// width of the plot area
69
double width = getWidth();
70
// height of the plot area
71
double height = getHeight();
73
IGraphDataModel model = ((GraphViewer)fViewer).getModel();
74
fScaledData = model.scaleTo((int)width, (int)height, fBarWith);
76
fXMin = fScaledData.getHorFirstBucketTime() > 0 ? fScaledData.getHorFirstBucketTime() : 0;
78
if (fScaledData.getHorLastBucket() > 0) {
79
fXMax = fScaledData.getHorBucketEndTime(fScaledData.getHorNbBuckets() - 1);
82
fYMin = fScaledData.getVerFirstBucketTime() > 0 ? fScaledData.getVerFirstBucketTime() : 0;
84
if (fScaledData.getVerLastBucket() > 0) {
85
fYMax = fScaledData.getVerBucketEndTime(fScaledData.getVerNbBuckets() - 1);
91
* @see org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener#paintContent()
94
public void paintContent() {
95
if (fXMin >= 0 && fXMax >= 0 && fYMin >= 0 && fYMax >= 0 && fScaledData != null) {
97
fAxisImage.setForeground(fDataColor);
98
fAxisImage.setBackground(fDataColor);
100
double height = getHeight();
102
int xLen = fScaledData.getHorNbBuckets();
103
int yLen = fScaledData.getVerNbBuckets();
105
int barWidth = fScaledData.getBarWidth();
107
for (int i = 0; i < xLen; i++) {
108
for (int j = 0; j < yLen; j++) {
109
if (fScaledData.getEventCount(i, j) > 0) {
111
double x = fPadding + i * barWidth + fVerticalAxisOffset + 1;
112
double y = fPadding + fPaddingTop + height - j * barWidth;
114
// Avoid over-drawing background area
115
int yBarWidth = fBarWith;
116
if (y - yBarWidth < fPadding + fPaddingTop) {
117
yBarWidth = (int) (y - fPadding - fPaddingTop);
119
int xBarWidth = fBarWith;
120
if(x + xBarWidth > fClientArea.width - fPadding - fPaddingRight) {
121
xBarWidth = (int)(fClientArea.width - fPadding - fPaddingRight - x);
123
fAxisImage.fillRectangle((int) x, (int) y - (int) yBarWidth, (int) xBarWidth, (int) yBarWidth);
128
if (fScaledData.isCurrentEventTimeValid()) {
129
// Draw vertical line
130
int index = fScaledData.getHorBucketIndex(fScaledData.getCurrentEventTime());
132
int x = fPadding + index * barWidth + fVerticalAxisOffset + 1;
133
fAxisImage.setForeground(fCurrentEventColor);
134
fAxisImage.setBackground(fCurrentEventColor);
135
fAxisImage.drawLine(x, fPadding + fPaddingTop, x, fClientArea.height - fPadding - fHorizontalAxisYOffset);
142
* @see org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener#formatStringForVerticalAxis(long)
145
public String formatStringForVerticalAxis(long value) {
146
DecimalFormat formatter = new DecimalFormat("0.0E0"); //$NON-NLS-1$
147
return formatter.format(value);
152
* @see org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener#formatStringForHorizontalAxis(long)
155
public String formatStringForHorizontalAxis(long value) {
156
return HistogramUtils.nanosecondsToString(value);
161
* @see org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener#formatToolTipLabel(int, int)
164
public String formatToolTipLabel(int x, int y) {
166
int index = getIndexFromHorizontalValue(x);
167
int yIndex = getIndexFromVerticalValue(y);
169
if (index != BaseDistributionData.OUT_OF_RANGE_BUCKET && yIndex != BaseDistributionData.OUT_OF_RANGE_BUCKET) {
170
if (fScaledData.getEventCount(index, yIndex) > 0) {
171
StringBuffer buffer = new StringBuffer();
172
buffer.append("Time Range in s = ["); //$NON-NLS-1$
173
// TODO change Utility
174
long startTime = fScaledData.getHorBucketStartTime(index) > 0 ? fScaledData.getHorBucketStartTime(index) : 0;
175
buffer.append(HistogramUtils.nanosecondsToString(startTime));
176
buffer.append(","); //$NON-NLS-1$
177
buffer.append(HistogramUtils.nanosecondsToString(fScaledData.getHorBucketEndTime(index)));
178
buffer.append("]\n"); //$NON-NLS-1$
179
buffer.append("Latency Range in s = ["); //$NON-NLS-1$
180
long yStartTime = fScaledData.getVerBucketStartTime(yIndex) > 0 ? fScaledData.getVerBucketStartTime(yIndex) : 0;
181
buffer.append(HistogramUtils.nanosecondsToString(yStartTime));
182
buffer.append(","); //$NON-NLS-1$
183
buffer.append(HistogramUtils.nanosecondsToString(fScaledData.getVerBucketEndTime(yIndex)));
184
buffer.append("]\n"); //$NON-NLS-1$
185
buffer.append("Latency count = "); //$NON-NLS-1$
186
buffer.append(fScaledData.getEventCount(index, yIndex));
187
return buffer.toString();
190
return ""; //$NON-NLS-1$
193
public int getIndexFromHorizontalValue(int x) {
194
if (fScaledData != null) {
195
double barWidth = fScaledData.getBarWidth();
197
int index = (int) ((x - fPadding - fVerticalAxisOffset - 1) / barWidth);
198
if ((index >= 0) && (fScaledData.getHorNbBuckets() > index)) {
202
return BaseDistributionData.OUT_OF_RANGE_BUCKET;
205
public int getIndexFromVerticalValue(int y) {
206
if (fScaledData != null) {
207
double barWidth = fScaledData.getBarWidth();
208
double height = getHeight(); // height of the plot area
210
int index = (int) ((height - (y - fPadding - fPaddingTop)) / barWidth);
211
if (index >= 0 && fScaledData.getVerNbBuckets() > index) {
215
return BaseDistributionData.OUT_OF_RANGE_BUCKET;
218
public long getCurrentTimeFromHorizontalValue(int x) {
219
if (fXMin >= 0 && fXMax >= 0) {
220
int index = getIndexFromHorizontalValue(x);
221
if (index != BaseDistributionData.OUT_OF_RANGE_BUCKET) {
222
return fScaledData.getHorBucketStartTime(index);
225
return Config.INVALID_EVENT_TIME;
b'\\ No newline at end of file'