* {@link HistogramDataModel#countEvent(long,long, ITmfTrace)} and
* {@link HistogramDataModel#scaleTo(int,int,int)}.
*/
- @Test(expected = IllegalStateException.class)
+ @Test
public void testCountEvent_2() {
final int nbBuckets = 100;
final int maxHeight = 10;
model.countEvent(0, 1, null);
HistogramScaledData result = model.scaleTo(nbBuckets, maxHeight, 1);
- assertEquals(_1, result.fData[0]);
- assertArrayEqualsInt(1, result.fData, 1);
+ for (int i = 0; i < result.fData.length - 1; i++) {
+ assertEquals(_1, result.fData[i]);
+ }
+ assertEquals(_0, result.fData[result.fData.length - 1]);
testModelConsistency(model, nbBuckets, 1, 1, 1, 1, 1, nbBuckets + 1);
}
/*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson
+ * Copyright (c) 2011, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* Update the range text controls
*/
private void updateRangeTextControls() {
- if (fDataModel.getStartTime() < fDataModel.getEndTime()) {
+ if (fDataModel.getNbEvents() != 0) {
fTimeRangeStartLabel.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getStartTime()));
fTimeRangeEndLabel.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
} else {
@Override
public void mouseHover(final MouseEvent event) {
- if (fDataModel.getStartTime() < fDataModel.getEndTime() && fScaledData != null) {
+ if (fDataModel.getNbEvents() != 0 && fScaledData != null) {
final String tooltip = formatToolTipLabel(event.x - fOffset);
fCanvas.setToolTipText(tooltip);
return;
if ((width <= 0) || (height <= 0) || (barWidth <= 0)) {
throw new AssertionError("Invalid histogram dimensions (" + width + "x" + height + ", barWidth=" + barWidth + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
- if (fLastBucket == 0 || fBucketDuration == 0) {
+ if (fBucketDuration == 0) {
throw new IllegalStateException("Bucket width is 0, that should be impossible"); //$NON-NLS-1$
}
double bucketsPerBar = ((double) fLastBucket / nbBars);
final long modelBucketStartTime = fFirstBucketTime;
final long modelBucketEndTime = fEndTime;
- result.fBucketDuration = (modelBucketEndTime - modelBucketStartTime) / (double) nbBars;
+ /*
+ * If there is only one model bucket, use a duration of 1 to spread the
+ * value over the scaled width, but store a scaled bucket duration of 0
+ * to prevent the half-bucket offset in the bucket time calculations.
+ */
+ double bucketDuration = Math.max(modelBucketEndTime - modelBucketStartTime, 1) / (double) nbBars;
+ result.fBucketDuration = fLastBucket == 0 ? 0 : bucketDuration;
int scaledCount = 0;
int scaledCountLostEvent = 0;
- int offset = (int) (0.5 / result.fBucketDuration);
+ int offset = (int) (0.5 / bucketDuration);
for (int i = 0; i < result.fData.length; i++) {
result.fData[i] = new HistogramBucket(getNbTraces());
}