Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeline: fix low zoom limit for huge simultion tmes - prevent crashe… #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions java/org/contikios/cooja/plugins/TimeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public class TimeLine extends VisPlugin implements HasQuickHelp {
private static final long[] ZOOM_LEVELS = {
1, 2, 5, 10,
20, 50, 100, 200, 500, 1000,
2000, 5000, 10000, 20000, 50000, 100000 };
2000, 5000, 10000, 20000, 50000, 100000,
100000*2, 100000*5, 100000*10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the crash related to zoom levels not containing enough values, or is this change for usability?

};

private boolean needZoomOut = false;

Expand Down Expand Up @@ -589,11 +591,21 @@ private static double zoomLevelToDivisor(int zoomLevel) {
return ZOOM_LEVELS[zoomLevel];
}

private void zoomFinish (final double zoomDivisor,
private void zoomFinish (double zoomDivisor,
final long focusTime,
final double focusCenter) {
currentPixelDivisor = zoomDivisor;
final double focusCenter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the opening brace where it was (this is how almost all code in Cooja is formatted).

{
String note = "";

long now = simulation.getSimulationTime();
if (now/zoomDivisor > Integer.MAX_VALUE) {
// limit zoom to fits sim-time in timeline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same indentation size as the rest of the file, in this file the code uses 2 spaces.

int min_level = zoomGetLevel( now/Integer.MAX_VALUE );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other variables use camelCase for naming, and remove the space before/after the method argument.

zoomDivisor = zoomLevelToDivisor( min_level );
note = " (LIM)";
}

currentPixelDivisor = zoomDivisor;
if (ZOOM_LEVELS[0] >= zoomDivisor) {
currentPixelDivisor = ZOOM_LEVELS[0];
note = " (MIN)";
Expand All @@ -604,6 +616,8 @@ private void zoomFinish (final double zoomDivisor,
if (zoomDivisor != currentPixelDivisor) {
logger.info("Zoom level: adjusted out-of-range " + zoomDivisor + " us/pixel");
}

if (note != "")
logger.info("Zoom level: " + currentPixelDivisor + " microseconds/pixel " + note);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I removed the noise in commit 83c13a9, just remove this line instead of making it conditional.


forceRepaintAndFocus(focusTime, focusCenter);
Expand Down Expand Up @@ -2550,9 +2564,14 @@ public void actionPerformed(ActionEvent e) {
/* Update timeline size */
int newWidth;
if (now/currentPixelDivisor > Integer.MAX_VALUE) {
/* Need zoom out */
newWidth = 1;
needZoomOut = true;
// if zoom not fits in timeline, try zoomout to apropriate level
int level = zoomGetLevel( now/Integer.MAX_VALUE );
zoomFinishLevel(level, getCenterPointTime(), 0.5);
}
if (now/currentPixelDivisor > Integer.MAX_VALUE) {
/* Need zoom out */
newWidth = 1;
needZoomOut = true;
} else {
newWidth = (int) (now/currentPixelDivisor);
needZoomOut = false;
Expand Down