|
Line 0
Link Here
|
|
|
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 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 |
* Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation |
| 11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners; |
| 13 |
|
| 14 |
import java.util.Collections; |
| 15 |
import java.util.Vector; |
| 16 |
|
| 17 |
import org.eclipse.linuxtools.lttng.analysis.Config; |
| 18 |
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView; |
| 19 |
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint; |
| 20 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.events.PaintEvent; |
| 22 |
import org.eclipse.swt.events.PaintListener; |
| 23 |
import org.eclipse.swt.graphics.Color; |
| 24 |
import org.eclipse.swt.graphics.Font; |
| 25 |
import org.eclipse.swt.graphics.GC; |
| 26 |
import org.eclipse.swt.graphics.Image; |
| 27 |
import org.eclipse.swt.graphics.Point; |
| 28 |
import org.eclipse.swt.graphics.Rectangle; |
| 29 |
import org.eclipse.swt.widgets.Display; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* Abstract paint listener. Draws the graphs on the view canvas. |
| 34 |
* |
| 35 |
* @author Philippe Sawicki |
| 36 |
*/ |
| 37 |
public abstract class AbstractPaintListener implements PaintListener { |
| 38 |
|
| 39 |
/** |
| 40 |
* A reference to the listener's view. |
| 41 |
*/ |
| 42 |
protected AbstractView view_; |
| 43 |
|
| 44 |
/** |
| 45 |
* Graph title |
| 46 |
*/ |
| 47 |
protected String graphTitle_; |
| 48 |
|
| 49 |
/** |
| 50 |
* X-axis label. |
| 51 |
*/ |
| 52 |
protected String xAxisLabel_; |
| 53 |
/** |
| 54 |
* Y-axis label. |
| 55 |
*/ |
| 56 |
protected String yAxisLabel_; |
| 57 |
|
| 58 |
/** |
| 59 |
* Horizontal offset for the x-axis label. |
| 60 |
*/ |
| 61 |
protected int xAxisLabelOffset_; |
| 62 |
|
| 63 |
/** |
| 64 |
* Vertical offset for the horizontal axis offset. |
| 65 |
*/ |
| 66 |
protected int horizontalAxisYOffset_ = 20; |
| 67 |
|
| 68 |
/** |
| 69 |
* Graph padding. |
| 70 |
*/ |
| 71 |
protected int padding_ = Config.GRAPH_PADDING; |
| 72 |
|
| 73 |
/** |
| 74 |
* Graph client area. |
| 75 |
*/ |
| 76 |
protected Rectangle clientArea_ = new Rectangle(0, 0, 1, 1); |
| 77 |
|
| 78 |
/** |
| 79 |
* Foreground color. |
| 80 |
*/ |
| 81 |
protected Color foregroundColor_; |
| 82 |
/** |
| 83 |
* Background color. |
| 84 |
*/ |
| 85 |
protected Color backgroundColor_; |
| 86 |
/** |
| 87 |
* Data plotting color. |
| 88 |
*/ |
| 89 |
protected Color dataColor_; |
| 90 |
/** |
| 91 |
* Axis label color. |
| 92 |
*/ |
| 93 |
protected Color labelColor_; |
| 94 |
/** |
| 95 |
* Text color. |
| 96 |
*/ |
| 97 |
protected Color textColor_; |
| 98 |
/** |
| 99 |
* Red. |
| 100 |
*/ |
| 101 |
protected Color redColor_; |
| 102 |
/** |
| 103 |
* White. |
| 104 |
*/ |
| 105 |
protected Color whiteColor_; |
| 106 |
|
| 107 |
/** |
| 108 |
* Original canvas font. |
| 109 |
*/ |
| 110 |
protected Font originalFont_; |
| 111 |
/** |
| 112 |
* Font for the title of the graph. |
| 113 |
*/ |
| 114 |
protected Font titleFont_; |
| 115 |
/** |
| 116 |
* Font for the values on the horizontal and vertical axis. |
| 117 |
*/ |
| 118 |
protected Font valuesFont_; |
| 119 |
/** |
| 120 |
* Font for the horizontal and vertical labels. |
| 121 |
*/ |
| 122 |
protected Font labelFont_; |
| 123 |
|
| 124 |
/** |
| 125 |
* Horizontal offset for the axis arrow. |
| 126 |
*/ |
| 127 |
protected final int ARROW_DELTA_X = 10; |
| 128 |
/** |
| 129 |
* Vertical offset for the axis arrow. |
| 130 |
*/ |
| 131 |
protected final int ARROW_DELTA_Y = 4; |
| 132 |
|
| 133 |
/** |
| 134 |
* Max horizontal distance between ticks. |
| 135 |
*/ |
| 136 |
protected final int MAX_WIDTH_BETWEEN_TICKS = 40; |
| 137 |
/** |
| 138 |
* Max vertical distance between ticks. |
| 139 |
*/ |
| 140 |
protected final int MAX_HEIGHT_BETWEEN_TICKS = 30; |
| 141 |
/** |
| 142 |
* Max characters that can be displayed on the vertical axis. |
| 143 |
*/ |
| 144 |
protected final int MAX_CHAR_VERTICAL_DISPLAY = 5; |
| 145 |
|
| 146 |
/** |
| 147 |
* Draw label each "drawLabelEachNTicks_" ticks. |
| 148 |
*/ |
| 149 |
protected int drawLabelEachNTicks_ = 1; |
| 150 |
|
| 151 |
/** |
| 152 |
* Image drawn on the canvas. |
| 153 |
*/ |
| 154 |
protected Image image_; |
| 155 |
/** |
| 156 |
* Paint canvas, where the values are plotted. |
| 157 |
*/ |
| 158 |
protected GC axisImage_; |
| 159 |
|
| 160 |
/** |
| 161 |
* Is the paint listener initialized ? |
| 162 |
*/ |
| 163 |
protected boolean initialised_ = false; |
| 164 |
/** |
| 165 |
* Does the listener need to be redrawn ? |
| 166 |
*/ |
| 167 |
protected boolean redraw_ = true; |
| 168 |
|
| 169 |
/** |
| 170 |
* Draw area. |
| 171 |
*/ |
| 172 |
protected Rectangle drawArea_; |
| 173 |
|
| 174 |
/** |
| 175 |
* Left padding (in pixels). |
| 176 |
*/ |
| 177 |
protected int paddingLeft_ = 10; |
| 178 |
/** |
| 179 |
* Right padding (in pixels). |
| 180 |
*/ |
| 181 |
protected int paddingRight_ = 10; |
| 182 |
/** |
| 183 |
* Top padding (in pixels). |
| 184 |
*/ |
| 185 |
protected int paddingTop_ = 10; |
| 186 |
/** |
| 187 |
* Bottom padding (in pixels). |
| 188 |
*/ |
| 189 |
protected int paddingBottom_ = 10; |
| 190 |
|
| 191 |
/** |
| 192 |
* Vertical axis offset (in pixels). |
| 193 |
*/ |
| 194 |
protected int verticalAxisOffset_ = 20; |
| 195 |
|
| 196 |
/** |
| 197 |
* Vertical axis factor for values (10^delta). |
| 198 |
* When values larger than MAX_CHAR_VERTICAL_DISPLAY. |
| 199 |
*/ |
| 200 |
protected int delta = 0; |
| 201 |
|
| 202 |
|
| 203 |
/** |
| 204 |
* Constructor. |
| 205 |
* @param view A reference to the listener's view. |
| 206 |
*/ |
| 207 |
public AbstractPaintListener(AbstractView view) { |
| 208 |
view_ = view; |
| 209 |
} |
| 210 |
|
| 211 |
@Override |
| 212 |
public void paintControl(PaintEvent e) { |
| 213 |
clientArea_ = view_.getClientArea(); |
| 214 |
|
| 215 |
foregroundColor_ = e.gc.getForeground(); |
| 216 |
backgroundColor_ = e.gc.getBackground(); |
| 217 |
dataColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_RED); |
| 218 |
labelColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK); |
| 219 |
textColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_DARK_GRAY); |
| 220 |
redColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_RED); |
| 221 |
whiteColor_ = e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE); |
| 222 |
|
| 223 |
originalFont_ = e.gc.getFont(); |
| 224 |
titleFont_ = new Font(e.display, "Arial", 10, SWT.BOLD); |
| 225 |
valuesFont_ = new Font(e.display, "Arial", 7, SWT.NORMAL); |
| 226 |
labelFont_ = new Font(e.display, "Arial", 8, SWT.NORMAL); |
| 227 |
|
| 228 |
|
| 229 |
if (!initialised_) { |
| 230 |
image_ = new Image(Display.getDefault(), view_.getBounds()); |
| 231 |
|
| 232 |
axisImage_ = new GC(image_); |
| 233 |
|
| 234 |
axisImage_.setForeground(foregroundColor_); |
| 235 |
axisImage_.setBackground(backgroundColor_); |
| 236 |
axisImage_.fillRectangle(image_.getBounds()); |
| 237 |
paintBackground(); |
| 238 |
|
| 239 |
initialised_ = true; |
| 240 |
} |
| 241 |
|
| 242 |
paintGraphTitle(); |
| 243 |
paintHorizontalAxis(); |
| 244 |
paintVerticalAxis(); |
| 245 |
postAddDraw(); |
| 246 |
|
| 247 |
e.gc.drawImage(image_, 0, 0); |
| 248 |
redraw_ = false; |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Paints the title of the graph. |
| 253 |
*/ |
| 254 |
public void paintGraphTitle() { |
| 255 |
if (graphTitle_ != null) { |
| 256 |
axisImage_.setFont(titleFont_); |
| 257 |
axisImage_.setForeground(labelColor_); |
| 258 |
axisImage_.setBackground(backgroundColor_); |
| 259 |
|
| 260 |
int zoomFactor = view_.getZoomFactor() / view_.getZoomIncrement() + 1; |
| 261 |
int labelWidth = axisImage_.stringExtent(graphTitle_).x; |
| 262 |
// Draws the zoom factor in the title only if there is one |
| 263 |
if (view_.getZoomFactor() > 1) |
| 264 |
axisImage_.drawText(graphTitle_+ " (" + zoomFactor + "x)", (view_.getBounds().width-padding_ - labelWidth)/2, 0); |
| 265 |
else |
| 266 |
axisImage_.drawText(graphTitle_, (view_.getBounds().width-padding_ - labelWidth)/2, 0); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Paints the background of the draw area. |
| 272 |
*/ |
| 273 |
public void paintBackground() { |
| 274 |
axisImage_.setBackground(whiteColor_); |
| 275 |
|
| 276 |
Rectangle rectangle = image_.getBounds(); |
| 277 |
axisImage_.fillRectangle(padding_+verticalAxisOffset_, padding_+paddingTop_, rectangle.width-2*padding_-20, rectangle.height-2*padding_-paddingTop_-10); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Paints the horizontal axis. |
| 282 |
*/ |
| 283 |
public void paintHorizontalAxis() { |
| 284 |
axisImage_.setForeground(foregroundColor_); |
| 285 |
|
| 286 |
int y = clientArea_.height - 2*padding_; |
| 287 |
|
| 288 |
axisImage_.drawLine( clientArea_.x+padding_+verticalAxisOffset_, |
| 289 |
y, |
| 290 |
clientArea_.width-padding_, |
| 291 |
y ); |
| 292 |
|
| 293 |
paintHorizontalArrow(clientArea_.width-padding_, y); |
| 294 |
// Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details |
| 295 |
// if the window timerange is so small that no latency can be computed, or if there are no matching events in |
| 296 |
// the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets). |
| 297 |
if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) { |
| 298 |
paintHorizontalTicks(y); |
| 299 |
paintHorizontalAxisValues(y+30); |
| 300 |
} |
| 301 |
paintHorizontalAxisLabel(y+5); |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Paints the vertical axis. |
| 306 |
*/ |
| 307 |
public void paintVerticalAxis() { |
| 308 |
axisImage_.setForeground(foregroundColor_); |
| 309 |
|
| 310 |
int x = clientArea_.x + padding_ + verticalAxisOffset_; |
| 311 |
|
| 312 |
axisImage_.drawLine( x, |
| 313 |
clientArea_.y + padding_, |
| 314 |
x, |
| 315 |
clientArea_.height - 2*padding_ ); |
| 316 |
|
| 317 |
paintVerticalArrow(x, clientArea_.y + padding_); |
| 318 |
// Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details |
| 319 |
// if the window timerange is so small that no latency can be computed, or if there are no matching events in |
| 320 |
// the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets). |
| 321 |
if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) { |
| 322 |
//paintVerticalTicks(x); |
| 323 |
paintVerticalAxisValues(x); |
| 324 |
} |
| 325 |
paintVerticalAxisLabel(x); |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Paints the arrow on the horizontal axis. |
| 330 |
* @param x The x-coordinate of the point where the arrow points. |
| 331 |
* @param y The y-coordinate of the point where the arrow points. |
| 332 |
*/ |
| 333 |
public void paintHorizontalArrow(int x, int y) { |
| 334 |
// Arrow top line |
| 335 |
axisImage_.drawLine(x-ARROW_DELTA_X, y-ARROW_DELTA_Y, x, y); |
| 336 |
// Arrow bottom line |
| 337 |
axisImage_.drawLine(x-ARROW_DELTA_X, y+ARROW_DELTA_Y, x, y ); |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Paints the arrow on the vertical axis. |
| 342 |
* @param x The x-coordinate of the point where the arrow points. |
| 343 |
* @param y The y-coordinate of the point where the arrow points. |
| 344 |
*/ |
| 345 |
public void paintVerticalArrow(int x, int y) { |
| 346 |
// Arrow left line |
| 347 |
axisImage_.drawLine(x-ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y); |
| 348 |
// Arrow right line |
| 349 |
axisImage_.drawLine(x+ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y); |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Paints the horizontal ticks. |
| 354 |
* @param y The y coordinate where to draw the axis. |
| 355 |
*/ |
| 356 |
public void paintHorizontalTicks(int y) { |
| 357 |
long xMin = view_.getXMin(); |
| 358 |
long xMax = view_.getXMax(); |
| 359 |
|
| 360 |
if (xMin != 0L && xMax != 0L) { |
| 361 |
int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS - 1; |
| 362 |
|
| 363 |
for (int i = 0; i <= nbTicks+1; i++) { |
| 364 |
int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_; |
| 365 |
axisImage_.drawLine(x, y, x, y+3); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
/** |
| 371 |
* Paints the horizontal axis values. |
| 372 |
* @param y The y coordinate where to draw the axis. |
| 373 |
*/ |
| 374 |
public void paintHorizontalAxisValues(int y) { |
| 375 |
long xMin = view_.getXMin(); |
| 376 |
long xMax = view_.getXMax(); |
| 377 |
|
| 378 |
if (xMin != 0L && xMax != 0L) { |
| 379 |
axisImage_.setForeground(textColor_); |
| 380 |
axisImage_.setBackground(backgroundColor_); |
| 381 |
|
| 382 |
int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS; |
| 383 |
//System.out.println("nbTicks = " + nbTicks); |
| 384 |
|
| 385 |
for (int i = 0; i < nbTicks; i++) { |
| 386 |
if (i % drawLabelEachNTicks_ == 0) { |
| 387 |
int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_; |
| 388 |
|
| 389 |
double step = (double)(xMax-xMin) / (double)nbTicks; |
| 390 |
long currentValue = (long) (xMin + i*step); |
| 391 |
String currentLabel = formatStringForHorizontalAxis(currentValue); |
| 392 |
|
| 393 |
axisImage_.setFont(valuesFont_); |
| 394 |
axisImage_.drawText(currentLabel, x, y-24); |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* Paints the horizontal axis label. |
| 402 |
* @param y The y-coordinate where to draw the label. |
| 403 |
*/ |
| 404 |
public void paintHorizontalAxisLabel(int y) { |
| 405 |
if (xAxisLabel_ != null) { |
| 406 |
axisImage_.setFont(labelFont_); |
| 407 |
axisImage_.setForeground(labelColor_); |
| 408 |
|
| 409 |
int labelWidth = axisImage_.stringExtent(xAxisLabel_).x; |
| 410 |
|
| 411 |
axisImage_.drawText(xAxisLabel_, view_.getBounds().width-padding_-labelWidth, y); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Paints the vertical axis ticks. |
| 417 |
* @param x The x-coordinate where to draw the ticks. |
| 418 |
* @deprecated The vertical ticks are now drawn at the same time as the vertical axis values. |
| 419 |
*/ |
| 420 |
public void paintVerticalTicks(int x) { |
| 421 |
long xMin = view_.getXMin(); |
| 422 |
long xMax = view_.getXMax(); |
| 423 |
|
| 424 |
if (xMin != 0L && xMax != 0L) { |
| 425 |
int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1; |
| 426 |
|
| 427 |
for (int i = 0; i <= nbTicks+1; i++) { |
| 428 |
int y = view_.getBounds().height - 2*padding_ - paddingTop_ - i*MAX_HEIGHT_BETWEEN_TICKS; |
| 429 |
axisImage_.drawLine(x-3, y+paddingTop_, x, y+paddingTop_); |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* Paints the vertical axis values. |
| 436 |
* @param x The x-coordinate where to draw the values. |
| 437 |
*/ |
| 438 |
public void paintVerticalAxisValues(int x) { |
| 439 |
long xMin = view_.getXMin(); |
| 440 |
long xMax = view_.getXMax(); |
| 441 |
int zoomFactor = 1; |
| 442 |
|
| 443 |
zoomFactor = view_.getZoomFactor(); |
| 444 |
|
| 445 |
if (xMin != 0L && xMax != 0L) { |
| 446 |
axisImage_.setForeground(textColor_); |
| 447 |
axisImage_.setBackground(backgroundColor_); |
| 448 |
|
| 449 |
long yMin = view_.getYMin(); |
| 450 |
// Apply the zoom to the max value of the graph for the next calculations |
| 451 |
long yMax = view_.getYMax() / zoomFactor; |
| 452 |
|
| 453 |
int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1; |
| 454 |
|
| 455 |
Vector<Integer> values = new Vector<Integer>(); |
| 456 |
boolean multipleSameValues = true; |
| 457 |
while (multipleSameValues) { |
| 458 |
double valueStep = (double)(yMax-yMin) / (double)(nbTicks-1); |
| 459 |
|
| 460 |
for (int i = 0; i < nbTicks; i++) { |
| 461 |
double currentValue = (double) (yMin + i*valueStep)/(Math.pow(10, delta)); |
| 462 |
|
| 463 |
values.add((int) currentValue); |
| 464 |
} |
| 465 |
|
| 466 |
Collections.sort(values); |
| 467 |
boolean hasRepetition = false; |
| 468 |
for (int i = 1; i < values.size(); i++) { |
| 469 |
if (values.get(i) == values.get(i-1)) { |
| 470 |
hasRepetition = true; |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
if (hasRepetition) { |
| 475 |
nbTicks--; |
| 476 |
values.clear(); |
| 477 |
} else { |
| 478 |
multipleSameValues = false; |
| 479 |
|
| 480 |
// Draw rectangle over the old values |
| 481 |
int height = view_.getBounds().height-4*padding_-paddingTop_; |
| 482 |
axisImage_.fillRectangle(0, padding_+paddingTop_, padding_+verticalAxisOffset_, height); |
| 483 |
|
| 484 |
double pixelStep = (getHeight() + 2.0*padding_ + paddingTop_ + 1)/*(view_.getBounds().height - 2*padding_ - 1*paddingTop_)*/ / values.size(); |
| 485 |
|
| 486 |
for (int i = 0; i < values.size(); i++) { |
| 487 |
double currentValue = values.get(i); |
| 488 |
|
| 489 |
int y = (int) (view_.getBounds().height - 2*padding_ - i*pixelStep); |
| 490 |
String currentLabel = formatStringForVerticalAxis((long) currentValue); |
| 491 |
|
| 492 |
axisImage_.setFont(valuesFont_); |
| 493 |
|
| 494 |
Point textDimensions = axisImage_.stringExtent(currentLabel); |
| 495 |
axisImage_.drawText(currentLabel, x-textDimensions.x-5, y-textDimensions.y/2); |
| 496 |
axisImage_.drawLine(x-3, y, x, y); |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Paints the vertical axis label. |
| 505 |
* @param x The x-coordinate where to draw the label. |
| 506 |
*/ |
| 507 |
public void paintVerticalAxisLabel(int x) { |
| 508 |
if (yAxisLabel_ != null) { |
| 509 |
axisImage_.setFont(labelFont_); |
| 510 |
axisImage_.setForeground(labelColor_); |
| 511 |
axisImage_.setBackground(backgroundColor_); |
| 512 |
|
| 513 |
if (delta >= 1) |
| 514 |
axisImage_.drawText(yAxisLabel_ + " (x10^" + delta + ")", x+10, paddingTop_-5); |
| 515 |
else |
| 516 |
axisImage_.drawText(yAxisLabel_, x+10, paddingTop_-5); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Adds points to the graph and draws them to the canvas. |
| 522 |
* @param points The buffer of points to draw. |
| 523 |
* @param nbPoints The number of points in the buffer. |
| 524 |
*/ |
| 525 |
public abstract void addPoints(ChartPoint[] points, int nbPoints); |
| 526 |
|
| 527 |
/** |
| 528 |
* Draw horizontal label each "nbTicks" ticks. |
| 529 |
* @param nbTicks The draw interval. |
| 530 |
*/ |
| 531 |
public void drawLabelEachNTicks(int nbTicks) { |
| 532 |
drawLabelEachNTicks_ = nbTicks; |
| 533 |
} |
| 534 |
|
| 535 |
/** |
| 536 |
* Sets the title of the graph. |
| 537 |
* @param graphTitle The title of the graph. |
| 538 |
*/ |
| 539 |
public void setGraphTitle(String graphTitle) { |
| 540 |
graphTitle_ = graphTitle; |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* Sets the horizontal axis label. |
| 545 |
* @param xAxisLabel The horizontal axis label. |
| 546 |
* @param offset The horizontal axis draw offset (in pixels). |
| 547 |
*/ |
| 548 |
public void setXAxisLabel(String xAxisLabel, int offset) { |
| 549 |
xAxisLabel_ = xAxisLabel; |
| 550 |
xAxisLabelOffset_ = offset; |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* Sets the vertical axis label. |
| 555 |
* @param yAxisLabel The vertical axis label. |
| 556 |
*/ |
| 557 |
public void setYAxisLabel(String yAxisLabel) { |
| 558 |
yAxisLabel_ = yAxisLabel; |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* Clears the image and prepares it for redrawing. |
| 563 |
*/ |
| 564 |
public void clear() { |
| 565 |
initialised_ = false; |
| 566 |
view_.askForRedraw(); |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* Returns a string representing the given value. This method is |
| 571 |
* redefined in "HistogramPaintListener.java" to convert value to |
| 572 |
* engineering notation. |
| 573 |
* @param value The numeric value to convert to String. |
| 574 |
* @return The String-formatted value. |
| 575 |
*/ |
| 576 |
public String formatStringForHorizontalAxis(long value) { |
| 577 |
return "" + value; |
| 578 |
} |
| 579 |
|
| 580 |
/** |
| 581 |
* Returns a string representing the given value. This method is |
| 582 |
* redefined in "GraphPaintListener.java" to convert value to |
| 583 |
* scientific notation. |
| 584 |
* @param value The numeric value to convert to String. |
| 585 |
* @return The String-formatted value. |
| 586 |
*/ |
| 587 |
public String formatStringForVerticalAxis(long value) { |
| 588 |
return "" + value; |
| 589 |
} |
| 590 |
|
| 591 |
/** |
| 592 |
* Clears the points buffer, if any exists. |
| 593 |
*/ |
| 594 |
public void clearPoints() { } |
| 595 |
|
| 596 |
/** |
| 597 |
* Called for drawing elements after points are added to the graph. |
| 598 |
*/ |
| 599 |
public void postAddDraw() { } |
| 600 |
|
| 601 |
/** |
| 602 |
* Returns the draw area height. |
| 603 |
* @return The draw area height. |
| 604 |
*/ |
| 605 |
public double getHeight() { |
| 606 |
return (clientArea_.height - 2.0*padding_ - horizontalAxisYOffset_ - 0*paddingTop_ - 1); |
| 607 |
} |
| 608 |
|
| 609 |
/** |
| 610 |
* Returns the histogram's draw area width. |
| 611 |
* @return The histogram's draw area width. |
| 612 |
*/ |
| 613 |
public double getWidth() { |
| 614 |
return (clientArea_.width - 2.0*padding_ - verticalAxisOffset_); //width of the plot area; |
| 615 |
} |
| 616 |
|
| 617 |
/** |
| 618 |
* Returns the histogram's draw area padding. |
| 619 |
* @return The histogram's draw area padding. |
| 620 |
*/ |
| 621 |
public int getPadding() { |
| 622 |
return padding_; |
| 623 |
} |
| 624 |
|
| 625 |
/** |
| 626 |
* Returns the histogram's draw area top padding. |
| 627 |
* @return The histogram's draw area top padding. |
| 628 |
*/ |
| 629 |
public int getPaddingTop() { |
| 630 |
return paddingTop_; |
| 631 |
} |
| 632 |
|
| 633 |
/** |
| 634 |
* Returns the histogram's vertical axis offset. |
| 635 |
* @return The histogram's vertical axis offset. |
| 636 |
*/ |
| 637 |
public int getVerticalAxisOffset() { |
| 638 |
return verticalAxisOffset_; |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* Returns the histogram's horizontal axis offset. |
| 643 |
* @return The histogram's horizontal axis offset. |
| 644 |
*/ |
| 645 |
public int getHorizontalAxisYOffset() { |
| 646 |
return horizontalAxisYOffset_; |
| 647 |
} |
| 648 |
|
| 649 |
} |