Last active
          December 14, 2015 13:39 
        
      - 
      
- 
        Save ulmangt/5095282 to your computer and use it in GitHub Desktop. 
    Constrain CollapsibleTimelinePlotExample selected region to not extend past a particular time.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | final TimeStamp maxTimeStamp = t0.add( Time.fromMinutes( 300 ) ); | |
| final double maxTime = plot.fromTimeStamp( maxTimeStamp ); | |
| // 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"; | |
| } | |
| Double previousMin = null; | |
| @Override | |
| public void applyConstraint( TaggedAxis1D axis ) | |
| { | |
| Tag minTag = plot.getTimeSelectionMinTag( ); | |
| Tag maxTag = plot.getTimeSelectionMaxTag( ); | |
| TimeStamp max = plot.getTimeSelectionMax( ); | |
| if ( max.isAfter( maxTimeStamp ) ) | |
| { | |
| // reset min tag value | |
| if ( previousMin != null ) minTag.setValue( previousMin ); | |
| // cap max tag value | |
| maxTag.setValue( maxTime ); | |
| } | |
| // remember last min tag value | |
| previousMin = minTag.getValue( ); | |
| } | |
| }); | |
| // add a painter to draw the red region | |
| plot.getOverlayLayout( ).addPainter( new GlimpseDataPainter1D( ) | |
| { | |
| @Override | |
| public void paintTo( GL gl, GlimpseBounds bounds, Axis1D axis ) | |
| { | |
| int height = bounds.getHeight( ); | |
| GlimpseColor.glColor( gl, GlimpseColor.getRed( 0.4f ) ); | |
| double axisMax = axis.getMax( ); | |
| gl.glBegin( GL.GL_QUADS ); | |
| try | |
| { | |
| gl.glVertex2d( maxTime, 0 ); | |
| gl.glVertex2d( maxTime, height ); | |
| gl.glVertex2d( axisMax, height ); | |
| gl.glVertex2d( axisMax, 0 ); | |
| } | |
| finally | |
| { | |
| gl.glEnd( ); | |
| } | |
| } | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment