Skip to content

Commit

Permalink
Wait with fully zooming out until a first layout() was finished, when…
Browse files Browse the repository at this point in the history
… graph changed was called

* Reasoning: before, there was fixed timeout. However, with large datasets, it could have happened that graphchanged() + layout() was not completey performed before zoom out was started leading to unexpected behaviour. This commit introduces a process that lets the zooming out wait until the graph was layouted once according to the current data.
  • Loading branch information
stefanhahmann authored and tinevez committed Nov 12, 2024
1 parent ed5e781 commit eea86f2
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.Graphics;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -194,6 +195,8 @@ public class DataDisplayPanel< V extends Vertex< E > & HasTimepoint & HasLabel,

private final SelectionModel< DataVertex, DataEdge > selection;

private CountDownLatch latch;

/**
* If <code>true</code> the display will be updated live when the window
* target of context changes.
Expand Down Expand Up @@ -363,6 +366,8 @@ public void paint()
if ( flags.graphChanged )
{
layout.layout();
if ( latch != null )
latch.countDown();
layoutMinX = layout.getCurrentLayoutMinX();
layoutMaxX = layout.getCurrentLayoutMaxX();
layoutMinY = layout.getCurrentLayoutMinY();
Expand Down Expand Up @@ -947,13 +952,22 @@ void plot( final FeatureGraphConfig gc, final FeatureModel featureModel, final S
ylabel += " (" + yunits + ")";
graphOverlay.setYLabel( ylabel );

latch = new CountDownLatch( 1 );
graphChanged();
Executors.newSingleThreadScheduledExecutor().schedule( () -> {
if ( transform == null )
transformEventHandler.zoomOutFully();
else
transformEventHandler.zoomTo( transform.getMinX(), transform.getMaxX(), transform.getMinY(), transform.getMaxY() );
}, 100, TimeUnit.MILLISECONDS );
try
{
latch.await();
if ( transform == null )
transformEventHandler.zoomOutFully();
else
transformEventHandler.zoomTo( transform.getMinX(), transform.getMaxX(), transform.getMinY(), transform.getMaxY() );
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt();
}
}, 0, TimeUnit.SECONDS );
}

private RefSet< DataVertex > fromContext()
Expand Down

0 comments on commit eea86f2

Please sign in to comment.