It should be allowed to have a last bucket set to 0 in the histogram
data model. This can happen if all trace events have the same timestamp.
The histogram time range is fixed to display even if the start and end
times are equal, as long as there is at least one event in the model.
The scaling is updated to make sure that these single-timestamp events
are spread over the whole width of the histogram. The scaled model will
have a bucket duration of 0 when it represents a single timestamp.
Change-Id: I5341aa6a158a3b4c1b3d4edee982ed67558e8a51
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/48224
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
* {@link HistogramDataModel#countEvent(long,long, ITmfTrace)} and
* {@link HistogramDataModel#scaleTo(int,int,int)}.
*/
* {@link HistogramDataModel#countEvent(long,long, ITmfTrace)} and
* {@link HistogramDataModel#scaleTo(int,int,int)}.
*/
- @Test(expected = IllegalStateException.class)
public void testCountEvent_2() {
final int nbBuckets = 100;
final int maxHeight = 10;
public void testCountEvent_2() {
final int nbBuckets = 100;
final int maxHeight = 10;
model.countEvent(0, 1, null);
HistogramScaledData result = model.scaleTo(nbBuckets, maxHeight, 1);
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);
}
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
*
* 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() {
* 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 {
fTimeRangeStartLabel.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getStartTime()));
fTimeRangeEndLabel.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
} else {
@Override
public void mouseHover(final MouseEvent event) {
@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;
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 ((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$
}
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;
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 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());
}
for (int i = 0; i < result.fData.length; i++) {
result.fData[i] = new HistogramBucket(getNbTraces());
}