Bug #348267 - Documentation navigation arrows missing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / HistogramContent.java
CommitLineData
378e7718
WB
1/*******************************************************************************
2 * Copyright (c) 2009 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 * William Bourque - Initial API and implementation
f05aabed
FC
11 *
12 * Modifications:
13 * 2010-07-16 Yuriy Vashchuk - Heritage correction.
378e7718 14 *******************************************************************************/
6e512b93
ASL
15package org.eclipse.linuxtools.lttng.ui.views.histogram;
16
17
050df4a5
WB
18/**
19 * <b><u>HistogramContent</u></b>
20 * <p>
21 * This class hold the content that will be used to draw the Histograms.
22 * <p>
23 */
6e512b93 24public class HistogramContent {
1406f802 25
7c1540ab 26 // Start and end time of the content
f05aabed
FC
27 private long startTime = 0L;
28 private long endTime = 0L;
7c1540ab
WB
29
30 // Some information about the content
31 // Most of them are required to calculate position and/or draw
32 // Make sure they stay consistent!
f05aabed
FC
33 private long elementsTimeInterval = 1L;
34 private double heightFactor = 100.0;
35 private long heighestEventCount = 0L;
36 private int maxHeight = 0;
37 private int canvasWindowSize = 0;
38 private int barsWidth = 0;
050df4a5
WB
39
40 // This value is used to calculate at which point we should "cut" bar that are too tall.
41 // Default value is large enought so that no bar should be cut
f05aabed 42 private double maxDifferenceToAverage = HistogramConstant.DEFAULT_DIFFERENCE_TO_AVERAGE;
7ef9ae3f 43 // This is a factor we might apply on the max difference to average, as example if we concatenate interval together
f05aabed 44 private double maxDifferenceFactor = 1.0;
7c1540ab
WB
45
46 // By default we will only consider element up to this position
f05aabed 47 private int readyUpToPosition = 0;
ecfd1d41 48
7c1540ab
WB
49 // The average number of events in the content
50 // Note : this IS needed to draw
f05aabed 51 private int averageNumberOfEvents = 0;
b59134e1 52
7c1540ab
WB
53 // This is to draw the selected event of the TMF framework in another color
54 // Set the 0 to ignore
f05aabed 55 private long selectedEventTimeInWindow = -1L;
6e512b93 56
7c1540ab 57 // The table that hold the elements
f05aabed 58 private HistogramElement[] elementTable;
088c1d4e 59
b59134e1 60
050df4a5
WB
61 /**
62 * Default constructor for the HistogramContent.
63 *
64 * @param tableSize The size ofthe element table that will be created.
65 * @param newCanvasSize The full size of the canvas. Used for positionning; need to be consistent with canvas.
66 * @param newMaxHeight The maximum height of a bar, usually same as the height of the canvas.
67 */
1406f802 68 public HistogramContent(int tableSize, int newCanvasSize, int newBarWidth, int newMaxHeight) {
7c1540ab 69 this(tableSize, newCanvasSize, newBarWidth, newMaxHeight, HistogramConstant.DEFAULT_DIFFERENCE_TO_AVERAGE);
050df4a5
WB
70 }
71
72 /**
73 * Default constructor for the HistogramContent.
74 *
75 * @param tableSize The size ofthe element table that will be created.
76 * @param newCanvasSize The full size of the canvas. Used for positionning; need to be consistent with canvas.
77 * @param newMaxHeight The maximum height of a bar, usually same as the height of the canvas.
78 * @param newDiffToAverage This value at which point we "cut" bar that are too tall.
79 */
1406f802 80 public HistogramContent(int tableSize, int newCanvasSize, int newBarWidth, int newMaxHeight, double newDiffToAverage) {
7c1540ab
WB
81 canvasWindowSize = newCanvasSize;
82 barsWidth = newBarWidth;
6e512b93 83 maxHeight = newMaxHeight;
7ef9ae3f 84 maxDifferenceToAverage = newDiffToAverage;
6e512b93 85
050df4a5
WB
86 // Create a new element table from the above value
87 // The table will not get initialized until resetTable() is called.
6e512b93
ASL
88 createNewTable(tableSize);
89 }
90
050df4a5
WB
91 /**
92 * Create a new table to hold the content element.<p>
93 * Note that the table is not initialized (and so unusable) until resetTable() is called.
94 *
95 * @param newTableSize The size (number of element) of the table.
96 */
1406f802 97 public void createNewTable(int newTableSize) {
6e512b93
ASL
98 elementTable = new HistogramElement[newTableSize];
99
100 for ( int x=0; x<elementTable.length; x++) {
101 elementTable[x] = new HistogramElement();
7c1540ab 102 elementTable[x].index = x;
6e512b93
ASL
103 }
104 }
105
050df4a5
WB
106 /**
107 * Reset all HistogramContent attributes, but keep the elements table untouched.<p>
108 */
833a21aa 109 public void clearContentData() {
6e512b93
ASL
110 startTime = 0L;
111 endTime = 0L;
112
1406f802
WB
113 elementsTimeInterval = 1L;
114 heightFactor = 100.0;
6e512b93
ASL
115 heighestEventCount = 0L;
116
117 readyUpToPosition = 0;
118 }
119
050df4a5
WB
120 /**
121 * Reset the data in the elements table.<p>
833a21aa 122 * NOTE : For this to be consistent and usuable, "startTime", "endTime" and "intervalTime" need to be set already.
050df4a5 123 */
ecfd1d41 124 public void resetTable() {
6e512b93 125 for ( int x=0; x<elementTable.length; x++) {
7c1540ab 126 elementTable[x].index = x;
3fda53ab 127 elementTable[x].firstIntervalTimestamp = startTime + (x*elementsTimeInterval);
6e512b93
ASL
128 elementTable[x].intervalNbEvents = 0L;
129 elementTable[x].intervalHeight = 0;
130 }
131 }
132
833a21aa
WB
133 /**
134 * Reset the data in the elements table.<p>
3fda53ab
WB
135 * Start and EndTime will be used to calculate elementsTimeInterval.<p>
136 *
137 * @param newStartTime The new start time to use
138 * @param newEndTime The new stop time to use
833a21aa 139 */
1406f802 140 public void resetTable(long newStartTime, long newEndTime) {
3fda53ab
WB
141 resetTable(newStartTime, newEndTime, elementsTimeInterval);
142 }
143
144 /**
145 * Reset the data in the elements table.<p>
146 * elementsTimeInterval will be set to the one give, use this for fixed interval.<p>
147 *
148 * @param newStartTime The new start time to use
149 * @param newEndTime The new stop time to use
150 * @param newTimeInterval The new time interval to use
151 */
1406f802 152 public void resetTable(long newStartTime, long newEndTime, long newTimeInterval) {
833a21aa
WB
153
154 startTime = newStartTime;
155 endTime = newEndTime;
3fda53ab 156 recalculateElementsTimeInterval(newStartTime, newEndTime);
833a21aa
WB
157
158 for ( int x=0; x<elementTable.length; x++) {
7c1540ab 159 elementTable[x].index = x;
3fda53ab 160 elementTable[x].firstIntervalTimestamp = startTime + (x*elementsTimeInterval);
833a21aa
WB
161 elementTable[x].intervalNbEvents = 0L;
162 elementTable[x].intervalHeight = 0;
163 }
164 }
165
833a21aa
WB
166 /**
167 * Clear (zeroed) the data in the elements table.<p>
168 * NOTE : Unlike reset, this does not recalculate the content,
169 * so it should be done either by hand or by calling reset table after.
170 */
171 public void clearTable() {
172 for ( int x=0; x<elementTable.length; x++) {
7c1540ab 173 elementTable[x].index = x;
833a21aa
WB
174 elementTable[x].firstIntervalTimestamp = 0L;
175 elementTable[x].intervalNbEvents = 0L;
176 elementTable[x].intervalHeight = 0;
177 }
178 }
179
050df4a5
WB
180 /**
181 * Print all HistogramContent attributes, but the elements table.
182 */
3b38ea61 183 @SuppressWarnings("nls")
ecfd1d41
WB
184 public void printContentInfo() {
185 System.out.println("startTime : " + startTime);
186 System.out.println("endTime : " + endTime );
187 System.out.println();
3fda53ab 188 System.out.println("intervalTime : " + elementsTimeInterval);
ecfd1d41
WB
189 System.out.println("heightFactor : " + heightFactor);
190 System.out.println("heighestEventCount : " + heighestEventCount);
191 System.out.println();
192 System.out.println("readyUpToPosition : " + readyUpToPosition);
193 }
194
050df4a5
WB
195 /**
196 * Print the data in the elements table.<p>
197 */
3b38ea61 198 @SuppressWarnings("nls")
b59134e1 199 public void printTable() {
6e512b93 200 for ( int x=0; x<elementTable.length; x++) {
833a21aa 201 System.out.println("X:" + x + " -> " + elementTable[x].intervalNbEvents + ":" + elementTable[x].intervalHeight + " (" + elementTable[x].firstIntervalTimestamp + ")");
6e512b93
ASL
202 }
203 }
204
088c1d4e
WB
205 /**
206 * Getter for the timestamp of the selected event in the window.<p>
207 *
208 * @return The time of the event.
209 */
1406f802 210 public long getSelectedEventTimeInWindow() {
088c1d4e
WB
211 return selectedEventTimeInWindow;
212 }
213
214 /**
215 * Setter for the timestamp of the selected event in the window.<p>
216 *
217 * This allow to pinpoint a certain event or position in the window.
218 * Set to 0 or lower to ignore.
219 *
220 * @param newPosition The new event time.
221 */
1406f802 222 public void setSelectedEventTimeInWindow(long newTime) {
088c1d4e
WB
223 this.selectedEventTimeInWindow = newTime;
224 }
225
050df4a5
WB
226 /**
227 * Get an element in the table by its index.<p>
228 * Null is returned if the index is out of range.<p>
229 * Note that you can get an element past "readyUpToPosition", the index is NOT tested against it.
230 *
231 * @param index The index of the element (0 < index < nbElement)
232 *
233 * @return The element found or null if the index is wrong.
234 */
1406f802 235 public HistogramElement getElementByIndex(int index) {
6e512b93
ASL
236 HistogramElement returnedElement = null;
237
238 if ( (index >= 0) && (index < elementTable.length) ) {
239 returnedElement = elementTable[index];
240 }
241
242 return returnedElement;
243 }
244
050df4a5
WB
245 /**
246 * Return the closest element to a X position on the canvas.<p>
7c1540ab 247 * Note : canvasWindowSize need to be set correctly here, otherwise unexpected element might be returned.<p>
050df4a5
WB
248 * <p>
249 * NOTE : This <b>ALWAYS</b> return an element;
250 * If calculation lead outside the table, the first or the last element will be returned.
251 *
252 * @param position The X position we are looking at (0 < pos < canvasWidth)
253 *
254 * @return The <i>closest</i> element found.
255 */
1406f802 256 public HistogramElement getClosestElementFromXPosition(int position) {
b59134e1 257
1155ca9f 258 int index = (int)Math.round((double)elementTable.length * ((double)position / (double)canvasWindowSize) );
6e512b93 259
050df4a5 260 // If we are out of bound, return the closest border (first or last element)
6e512b93
ASL
261 if ( index < 0) {
262 index = 0;
263 }
ecfd1d41
WB
264 else if ( index >= elementTable.length ) {
265 index = (elementTable.length -1);
266 }
b59134e1 267
050df4a5
WB
268 return elementTable[index];
269 }
270
833a21aa
WB
271 /**
272 * Return the closest element's timestamp to a X position on the canvas.<p>
7c1540ab 273 * Note : canvasWindowSize need to be set correctly here, otherwise unexpected timestamp might be returned.<p>
833a21aa
WB
274 * <p>
275 * NOTE : This <b>ALWAYS</b> return a timestamp;
276 * If calculation lead outside the table, the first or the last timestamp will be returned.
277 *
278 * @param position The X position we are looking at (0 < pos < canvasWidth)
279 *
280 * @return The <i>closest</i> timestamp found.
281 */
1406f802 282 public long getClosestTimestampFromXPosition(int position) {
833a21aa
WB
283 return getClosestElementFromXPosition(position).firstIntervalTimestamp;
284 }
285
050df4a5
WB
286 /**
287 * Return the X position (relative to the canvas) of a certain element.<p>
7c1540ab 288 * Note : canvasWindowSize need to be set correctly here, otherwise unexpected element might be returned.<p>
050df4a5
WB
289 *
290 * NOTE : This <b>ALWAYS</b> return an element;
291 * If calculation lead outside the table, the first or the last element will be returned.
292 *
293 * @param targetElement The element we are looking to find the position
294 *
295 * @return The <i>closest</i> found element.
296 */
297 public int getXPositionFromElement(HistogramElement targetElement) {
1155ca9f 298 return (int)Math.round( ((double)targetElement.index / (double)elementTable.length)*(double)canvasWindowSize );
050df4a5
WB
299 }
300
301 /**
302 * Return the closest element to a timestamp (long) given.<p>
303 * Note : startTime and intervalTime need to be set correctly here, otherwise unexpected element might be returned.<p>
304 * <p>
305 * NOTE : This <b>ALWAYS</b> return an element;
306 * If calculation lead outside the table, the first or the last element will be returned.
307 *
308 * @param timestamp The timestamp (in nanosecond, as long) of the element we are looking for (startTime < timestamp < endTime)
309 *
310 * @return The <i>closest</i> element found.
311 */
1406f802 312 public HistogramElement getClosestElementFromTimestamp(long timestamp) {
1155ca9f 313 int index = (int)Math.round( (double)(timestamp - startTime)/(double)elementsTimeInterval );
6e512b93 314
050df4a5 315 // If we are out of bound, return the closest border (first or last element)
6e512b93
ASL
316 if ( index < 0) {
317 index = 0;
318 }
050df4a5
WB
319 else if ( index >= elementTable.length ) {
320 index = (elementTable.length -1);
321 }
6e512b93 322
050df4a5
WB
323 return elementTable[index];
324 }
325
833a21aa
WB
326 /**
327 * Return the closest X position to a timestamp (long) given.<p>
328 * Note : startTime and intervalTime need to be set correctly here, otherwise unexpected position might be returned.<p>
329 * <p>
330 * NOTE : This <b>ALWAYS</b> return a position;
331 * If calculation lead outside the table, the first or the last position will be returned.
332 *
333 * @param timestamp The timestamp (in nanosecond, as long) of the element we are looking for (startTime < timestamp < endTime)
334 *
335 * @return The <i>closest</i> position found.
336 */
1406f802 337 public int getClosestXPositionFromTimestamp(long timestamp) {
833a21aa
WB
338 return getXPositionFromElement(getClosestElementFromTimestamp(timestamp));
339 }
340
050df4a5
WB
341 /**
342 * Return the closest element to an element and a time interval to this element.<p>
343 * The time interval can be negative or positive (before or after the element).
344 *
345 * Note : IntervalTime and StartTime need to be set correctly here, otherwise unexpected result might be returned.<p>
346 *
347 * @param targetElement The element we compare the interval with.
348 * @param intervalToElement Time negative or positive time interval (in nanosecond) to this element.
349 *
350 * @return The <i>closest</i> found element, or null if given data are wrong.
351 */
1406f802 352 public HistogramElement getClosestElementByElementAndTimeInterval(HistogramElement targetElement, long intervalToElement) {
6e512b93 353
050df4a5
WB
354 // Get the timestamp of the target element
355 // This should always be valid as long the table is initialized
1406f802 356 long elementTime = targetElement.firstIntervalTimestamp;
050df4a5 357 elementTime = elementTime + intervalToElement;
6e512b93 358
050df4a5
WB
359 return getClosestElementFromTimestamp(elementTime);
360 }
361
362 /**
363 * Return the closest element to an element's timestamp (as long) and a time interval to this element.<p>
364 * The time interval can be negative or positive (before or after the element).
365 *
366 * Note : IntervalTime and StartTime need to be set correctly here, otherwise unexpected result might be returned.<p>
367 *
368 * @param timestamp The timestamp (in nanoseconds, as long) of the element we want to compare from.
369 * @param intervalToElement Time negative or positive time interval (in nanosecond) to this element.
370 *
371 * @return The <i>closest</i> found element, or null if given data are wrong.
372 */
1406f802 373 public int getClosestElementByTimestampAndTimeInterval(long timestamp, long intervalToElement) {
050df4a5
WB
374 HistogramElement targetElement = getClosestElementFromTimestamp(timestamp);
375 HistogramElement newElement = getClosestElementByElementAndTimeInterval(targetElement, intervalToElement);
6e512b93 376
050df4a5
WB
377 return getXPositionFromElement(newElement);
378 }
379
380 /**
381 * Return the closest element to an element's position and a time interval to this element.<p>
382 * The time interval can be negative or positive (before or after the element).
383 *
384 * Note : IntervalTime and StartTime need to be set correctly here, otherwise unexpected result might be returned.<p>
385 *
386 * @param targetPosition The position (relative to the canvas) of the element we want to compare from.
387 * @param intervalToElement Time negative or positive time interval (in nanosecond) to this element.
388 *
389 * @return The <i>closest</i> found element, or null if given data are wrong.
390 */
1406f802 391 public int getXPositionByPositionAndTimeInterval(int targetPosition, long intervalToElement) {
050df4a5
WB
392 HistogramElement targetElement = getClosestElementFromXPosition(targetPosition);
393 HistogramElement newElement = getClosestElementByElementAndTimeInterval(targetElement, intervalToElement);
ecfd1d41 394
050df4a5 395 return getXPositionFromElement(newElement);
ecfd1d41
WB
396 }
397
050df4a5
WB
398 /**
399 * Getter for the number of element.<p>
400 * The same as the value of tableSize given at construction.
401 *
402 * @return The number of element in the elements table.
403 */
404 public int getNbElement() {
405 return elementTable.length;
6e512b93
ASL
406 }
407
050df4a5
WB
408 /**
409 * Getter for the average number of events by interval in the content.<p>
410 *
411 * Note : Might be set externally (instead of calculated internally), so consistency with the content is not guarantee.
412 *
413 * @return Average number of events we currently use in
414 */
6e512b93
ASL
415 public int getAverageNumberOfEvents() {
416 return averageNumberOfEvents;
417 }
418
050df4a5
WB
419 /**
420 * Setter for averageNumberOfEvents.<p>
421 *
422 * Note : this is used in some drawing calculation so make sure this number make sense.
423 * Note : you might want to call recalculateEventHeight() if you change this.
424 *
425 * @param newAverageNumberOfEvents The new average number of events to use.
426 */
6e512b93
ASL
427 public void setAverageNumberOfEvents(int newAverageNumberOfEvents) {
428 this.averageNumberOfEvents = newAverageNumberOfEvents;
429 }
430
050df4a5
WB
431 /**
432 * Recalculate the average number of events by time interval.<p>
433 *
434 * Note : This run over all the element so this is quite cpu intensive, use with care.
435 */
436 public void recalculateAverageNumberOfEvents() {
437
438 int nbInterval = 0;
439 int totalNbEvents = 0;
440
441 // Go over the element up to readyUpToPosition (further position might not be ready)
442 for ( int x=0; x<readyUpToPosition; x++) {
443 // Skip the empty interval if we were asked to do so.
444 if ( HistogramConstant.SKIP_EMPTY_INTERVALS_WHEN_CALCULATING_AVERAGE ) {
445 if ( elementTable[x].intervalNbEvents > 0 ) {
446 nbInterval++;
447 }
448 }
449 else {
450 nbInterval++;
451 }
452
453 totalNbEvents += elementTable[x].intervalNbEvents;
454 }
455 // Calculate the average here
1155ca9f 456 averageNumberOfEvents = (int)Math.round((double)totalNbEvents / (double)nbInterval);
050df4a5
WB
457 }
458
459 /**
460 * Getter for the start time of the content.<p>
461 *
462 * @return The start time we currently use.
463 */
1406f802 464 public long getStartTime() {
6e512b93
ASL
465 return startTime;
466 }
467
050df4a5
WB
468 /**
469 * Setter for the start time of the content.<p>
470 * Note : You probably want to call "resetTable()" if you change this, otherwise data might be inconsistent.
471 *
472 * @param newStartTime the new start time
473 */
1406f802 474 public void setStartTime(long newStartTime) {
6e512b93
ASL
475 this.startTime = newStartTime;
476 }
477
478
050df4a5
WB
479 /**
480 * Getter for the end time of the content.<p>
481 *
482 * @return The end time we currently use.
483 */
1406f802 484 public long getEndTime() {
6e512b93
ASL
485 return endTime;
486 }
050df4a5 487
050df4a5
WB
488 /**
489 * Setter for the end time of the content.<p>
490 * Note : You probably want to call "resetTable()" if you change this, otherwise data might be inconsistent.
491 *
492 * @param newStartTime the new end time
493 */
1406f802 494 public void setEndTime(long newEndTime) {
6e512b93
ASL
495 this.endTime = newEndTime;
496 }
497
050df4a5
WB
498 /**
499 * Getter for the complete time interval of the content.<p>
500 * Note : This return "endTime" minus "startTime", unlike getReadyTimeInterval() it won't check the actual time of elements.
501 *
502 * @return The complete time interval
503 */
1406f802 504 public long getCompleteTimeInterval() {
6cf16d22
WB
505 return ( endTime - startTime );
506 }
6e512b93 507
050df4a5
WB
508 /**
509 * Getter for the time interval for the element between first and readyUpToPosition<p>
510 * Note : This return element[readyPosition].time - element[first].time , not the full interval like getCompleteTimeInterval()
511 *
512 * @return The time interval of the position that are ready.
513 */
1406f802 514 public long getReadyTimeInterval() {
050df4a5
WB
515 return ( elementTable[readyUpToPosition].firstIntervalTimestamp - elementTable[0].firstIntervalTimestamp );
516 }
517
518 /**
519 * Getter for the height factor of the bar.<p>
520 * Note : height = "nb events in interval" * heightFactor
521 *
522 * @return Height factor currently used.
523 */
1406f802 524 public double getHeightFactor() {
6e512b93
ASL
525 return heightFactor;
526 }
527
050df4a5 528 /**
3fda53ab
WB
529 * Recalculate the height factor of the element table.<p>
530 * Assume values of "maxHeight", "heighestEventCount" or "averageNumberOfEvents" are set correctly.
050df4a5 531 */
3fda53ab 532 public void recalculateHeightFactor() {
050df4a5
WB
533 // Recalculate the new HeightFactor for the element;
534 // the highest bar will get "maxHeight" and other bar a fraction of it.
7ef9ae3f 535 double diffToConsider = (maxDifferenceToAverage * maxDifferenceFactor * (double)barsWidth);
1406f802
WB
536
537 if ( heighestEventCount > (long)(diffToConsider * (double)averageNumberOfEvents) ) {
7ef9ae3f 538 heightFactor = (double)maxHeight/( diffToConsider * (double)averageNumberOfEvents);
050df4a5
WB
539 }
540 else {
541 heightFactor = (double)maxHeight/(double)heighestEventCount;
542 }
3fda53ab
WB
543 }
544
545 /**
546 * Recalculate the height of each bar in the elements table.<p>
547 * This assume "heightFactor" is already set correctly.<p>
548 *
549 * NOTE : if "maxHeight", "heighestEventCount" or "averageNumberOfEvents" changes,
550 * recalculateHeightFactor() should be recalled.
551 */
552 public void recalculateEventHeight() {
050df4a5
WB
553 // Recalculate the height of the bars up to "readyUpToPosition"
554 for ( int x=0; x<readyUpToPosition; x++) {
1155ca9f 555 elementTable[x].intervalHeight = (int)Math.ceil((double)elementTable[x].intervalNbEvents * heightFactor);
050df4a5 556 }
6e512b93
ASL
557 }
558
3fda53ab
WB
559 /**
560 * Recalculate the height of each bar in a certain interval of the elements table.<p>
561 * Unlike recalculateEventHeight(), this only recalculate for the given range, not the whole table.
562 *
563 */
1406f802 564 public void recalculateEventHeightInInterval(int startPosition, int stopPosition) {
3fda53ab
WB
565 // Basic error checking on start : should be bigger than 0
566 if ( startPosition < 0 ) {
567 startPosition = 0;
568 }
569
570 // Basic error checking on start : should be smaller than length - 1
571 if ( stopPosition >= elementTable.length) {
572 stopPosition = (elementTable.length-1);
573 }
574
575 // Recalculate the height of the bars from startPosition to stopPosition
576 for ( int x=startPosition; x<stopPosition; x++) {
1155ca9f 577 elementTable[x].intervalHeight = (int)Math.ceil((double)elementTable[x].intervalNbEvents * heightFactor);
3fda53ab
WB
578 }
579 }
580
050df4a5
WB
581 /**
582 * Getter for the full size of the canvas.<p>
583 * This is used for the positionnal calculation so should be consistent with the real canvas size.
584 *
585 * @return Size of the canvas we currently use.
586 */
1406f802 587 public int getCanvasWindowSize() {
7c1540ab
WB
588 return canvasWindowSize;
589 }
590
591 /**
592 * Set a new full size of the canvas.<p>
593 * This is used for the positionnal calculation so should be consistent with the real canvas size.
594 *
595 * @param newSize New canvas size;
596 */
1406f802 597 public void setCanvasWindowSize(int newSize) {
7c1540ab 598 canvasWindowSize = newSize;
050df4a5
WB
599 }
600
601 /**
602 * Getter for the heighest event count recorded so far for an interval.<p>
603 *
604 * Note : Might be set externally (instead of calculated internally), so consistency with the content is not guarantee.
605 *
606 * @return Current heighestEventCount
607 */
1406f802 608 public long getHeighestEventCount() {
6e512b93
ASL
609 return heighestEventCount;
610 }
611
050df4a5
WB
612 /**
613 * Setter for setHeighestEventCount.<p>
614 *
615 * Note : this is used in some drawing calculation so make sure this number make sense.
616 * Note : you might want to call recalculateEventHeight() if you change this.
617 *
618 * @param newHeighestEventCount Heighest event count for a single interval.
619 */
1406f802 620 public void setHeighestEventCount(long newHeighestEventCount) {
050df4a5
WB
621 this.heighestEventCount = newHeighestEventCount;
622 }
623
624 /**
625 * Recalculate the heightest event count for a single time interval.<p>
626 *
627 * Note : This run over all the element so this is quite cpu intensive, use with care.
628 */
629 public void recalculateHeighestEventCount() {
630 // Go over the element up to readyUpToPosition (further position might not be ready)
631 for ( int x=0; x<readyUpToPosition; x++) {
632 if ( elementTable[x].intervalNbEvents > heighestEventCount ) {
633 this.heighestEventCount = elementTable[x].intervalNbEvents;
634 }
635 }
6e512b93
ASL
636 }
637
050df4a5
WB
638 /**
639 * Getter for the max height of a bar in the content.<p>
640 *
641 * @return maximum height for a bar we currently use.
642 */
1406f802 643 public int getMaxHeight() {
6e512b93
ASL
644 return maxHeight;
645 }
050df4a5
WB
646
647 /**
648 * Setter for maxHeight.<p>
649 *
650 * Note : this is used in some drawing calculation so make sure this number make sense.
651 * Note : you might want to call recalculateEventHeight() if you change this.
652 *
653 * @param maxHeight The new maximum height for a bar to use.
654 */
1406f802 655 public void setMaxHeight(int maxHeight) {
6e512b93
ASL
656 this.maxHeight = maxHeight;
657 }
658
050df4a5
WB
659 /**
660 * Getter for the max difference to the average height a bar can have.<p>
661 * This determine at which point a bar too tall is "cut". Set a very large value (like 1000.0) to ignore.
662 *
663 * @return maximum difference to the average we currently use.
664 */
1406f802 665 public double getMaxDifferenceToAverage() {
ecfd1d41
WB
666 return maxDifferenceToAverage;
667 }
668
050df4a5
WB
669 /**
670 * Setter for the max difference to the average height a bar can have.<p>
671 * This determine at which point a bar too tall is "cut". Set a very large value (like 1000.0) to ignore.
672 *
673 * Note : this is used in some drawing calculation so make sure this number make sense.
674 * Note : you might want to call recalculateEventHeight() if you change this.
675 *
676 * @param newDiffToAverage The new maximum difference to the average to use.
677 */
1406f802 678 public void setMaxDifferenceToAverage(double newDiffToAverage) {
7ef9ae3f
WB
679 maxDifferenceToAverage = newDiffToAverage;
680 }
681
682
683 /**
684 * Getter for a factor applied to the max difference to the average height a bar can have.<p>
685 * This is muliplied to maxDifferenceToAverage. Set to value 1.0 to ignore.
686 *
687 * Note : this is useful if you concatenate some intervals to gether but want the average to be consistent
688 *
689 * @return maximum difference to the average we currently use.
690 */
1406f802 691 public double getMaxDifferenceToAverageFactor() {
7ef9ae3f
WB
692 return maxDifferenceFactor;
693 }
694
695 /**
696 * Setter for a factor applied to the max difference to the average height a bar can have.<p>
697 *
698 * Note : this is used in some drawing calculation so make sure this number make sense.
699 * Note : you might want to call recalculateEventHeight() if you change this.
700 * Note : setting to 0 will cause bar to have a zero size... use 1.0 to desactivate
701 *
702 * @param newFactor The new factor to use.
703 */
1406f802 704 public void setMaxDifferenceToAverageFactor(double newFactor) {
7ef9ae3f 705 maxDifferenceFactor = newFactor;
ecfd1d41
WB
706 }
707
708
050df4a5
WB
709 /**
710 * Getter for the interval time of each interval.<p>
711 * This is usually "(EndTime - StartTime) / NbElement"
712 *
713 * @return Currently used interval time.
714 */
1406f802 715 public long getElementsTimeInterval() {
3fda53ab 716 return elementsTimeInterval;
6e512b93
ASL
717 }
718
050df4a5
WB
719
720 /**
721 * Setter for the interval time of each interval.<p>
722 *
723 * Note : this is used in some drawing calculation so make sure this number make sense.
724 * Note : you migth want to call resetTable() to to fill the element's table again if you change this.
725 *
726 * @return New interval time.
727 */
1406f802 728 public void setElementsTimeInterval(long newInterval) {
3fda53ab
WB
729 this.elementsTimeInterval = newInterval;
730 }
731
732
733 /**
734 * Calculate the correct time interval of each element from the given time.<p>
735 *
736 * @return The complete time interval
737 */
1406f802 738 public void recalculateElementsTimeInterval(long startTime, long endTime) {
1155ca9f 739 long tmpInterval = (long)Math.ceil((double)(endTime - startTime)/ (double)getNbElement());
1406f802
WB
740
741 if ( tmpInterval <= 0 ) {
742 tmpInterval = 1L;
743 }
744
745 this.elementsTimeInterval = tmpInterval;
6e512b93
ASL
746 }
747
050df4a5
WB
748
749 /**
750 * Getter for readyUpToPosition.<p>
751 * This should tell to which point the content is filled, calculated and ready to use.
752 *
753 * @return Last position processed so far.
754 */
1406f802 755 public int getReadyUpToPosition() {
050df4a5
WB
756 return readyUpToPosition;
757 }
758
759 /**
760 * Setter for readyUpToPosition.<p>
761 * Set a new point (position) up to where the content is filled, calculated and ready to use.
762 *
763 * @param newReadyUpToPosition The new position to use.
764 */
765 public void setReadyUpToPosition(int newReadyUpToPosition) {
766 this.readyUpToPosition = newReadyUpToPosition;
767 }
768
7c1540ab
WB
769 /**
770 * Getter for the bar width.<p>
771 * This is needed by the paint listener usually.
772 *
773 * @return current bars width;
774 */
1406f802 775 public int getBarsWidth() {
7c1540ab
WB
776 return barsWidth;
777 }
778
779 /**
780 * Setter for the bar width.<p>
781 * Setting this to 0 will hide all the bar in the histogram.
782 *
783 * @param newBarsWidth new bars width;
784 */
1406f802 785 public void setBarsWidth(int newBarsWidth) {
7c1540ab
WB
786 this.barsWidth = newBarsWidth;
787 }
788
6e512b93 789}
This page took 0.069653 seconds and 5 git commands to generate.