Skip to content

Instantly share code, notes, and snippets.

@ulmangt
Last active December 14, 2015 13:38
Show Gist options
  • Save ulmangt/5095092 to your computer and use it in GitHub Desktop.
Save ulmangt/5095092 to your computer and use it in GitHub Desktop.
Glimpse CollapsibleTimelinePlotExample extension demonstrating use of TaggedAxis Constraints
// replace the default StackedTimePlot2D mouse listener behavior with
// the default tagged axis behavior (the selected area will not follow
// the mouse, but the user can move it by clicking and dragging inside
// the selected area)
plot.setTimeAxisMouseListener( new TaggedAxisMouseListener1D( ) );
// lock the timeline at the current max selection value
plot.setCurrentTimeLocked( true );
// add a constraint which prevents the max selection value
// from moving past the max timeline value
plot.getTimeAxis( ).addConstraint( new Constraint( )
{
@Override
public String getName( )
{
return "CurrentTimeLocked";
}
@Override
public void applyConstraint( TaggedAxis1D axis )
{
if ( plot.isCurrentTimeLocked( ) )
{
Tag minTag = plot.getTimeSelectionMinTag( );
Tag maxTag = plot.getTimeSelectionMaxTag( );
double min = minTag.getValue( );
double max = maxTag.getValue( );
double diff = max - min;
if ( max > axis.getMax( ) )
{
minTag.setValue( axis.getMax( ) - diff );
maxTag.setValue( axis.getMax( ) );
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment