Page 1 of 1

Fixing one side of the zoom rectangle?

Posted: Tue Jul 22, 2008 8:44 pm
by 9641609
Hi,

My tool allows the user to fix any of the axis limits. If, say, they've fixed the min y value at zero, is it possible to ensure that the zoom rectangle always goes to zero on the bottom axis? This is very similar to the Zoom direction feature, but I want to split it in half again, i.e. where Zoom horizontal keeps the Ymax and Ymin values the same and draws the zoom rectangle from top to the bottom of the chart (regardless of where the mouse is), I'd like to be able to keep only one of those values fixed and correspondingly only draw the zoom rectangle to one extent.

I hope this makes sense.

Thanks for any help,
Phil.

Posted: Wed Jul 23, 2008 9:01 am
by yeray
Hi Phil,

If we understood well, you are trying to do something as following:

Code: Select all

Dim MinLeft As Double
    
Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scPoint
  TChart1.Series(0).FillSampleValues 25
  
  TChart1.Environment.InternalRepaint
  
  MinLeft = TChart1.Axis.Left.Minimum
  MinBottom = TChart1.Axis.Bottom.Minimum
End Sub


Private Sub TChart1_OnZoom()
  TChart1.Axis.Bottom.AutomaticMinimum = False
  TChart1.Axis.Left.AutomaticMinimum = False
  
  TChart1.Axis.Bottom.Minimum = MinBottom
  TChart1.Axis.Left.Minimum = MinLeft
End Sub

Posted: Thu Jul 24, 2008 8:38 am
by 9641609
Hi,

Thanks for the quick response. This isn't quite what I want to do.

What I'm keen to do is show the user that they have one dimension fixed, so I want to be able to modify the graphical zoom rectangle that is displayed over the graph as the user drags his mouse to create a zoom area...i.e. not just after he's let go of the mouse at OnZoom time.

So I'm talking about changing the zoom rectangle that is drawn ontop of the graph, not the actual zoom rectangle that specifies the new graph extents.

Is it possible to set the dimensions of this displayed rectangle as the user is dragging the mouse?

Many thanks,
Phil.

Posted: Thu Jul 24, 2008 9:38 am
by yeray
Hi Phil,

Then you should draw your custom Rectangle while the mouse holds down and apply a custom zoom at OnMouseUp event. Something as follows:

Code: Select all

Dim EndX, EndY As Double
Dim Go As Boolean

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scPoint
  TChart1.Series(0).FillSampleValues 25
  
  TChart1.Zoom.Enable = False
  Go = False
  
  TChart1.Axis.Bottom.PositionUnits = puPixels
  TChart1.Axis.Left.PositionUnits = puPixels
  TChart1.Axis.Right.PositionUnits = puPixels
  TChart1.Axis.Top.PositionUnits = puPixels
End Sub

Private Sub TChart1_OnAfterDraw()
  If Go Then
    TChart1.Canvas.Pen.Color = vbWhite
    TChart1.Canvas.Brush.Style = bsClear
    TChart1.Canvas.Rectangle TChart1.Axis.Left.Position, EndY, EndX, TChart1.Axis.Bottom.Position
  End If
End Sub

Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If Button = mbLeft Then
    Go = True
  End If
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If Go Then
    EndX = X
    EndY = Y
    TChart1.Environment.InternalRepaint
  End If
End Sub

Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If Button = mbLeft Then
    Go = False
    TChart1.Environment.InternalRepaint
    If X > TChart1.Axis.Left.Position And _
       X < TChart1.Axis.Right.Position And _
       Y > TChart1.Axis.Top.Position And _
       Y < TChart1.Axis.Bottom.Position Then
      TChart1.Zoom.ZoomRect TChart1.Axis.Left.Position, Y, X, TChart1.Axis.Bottom.Position
    End If
  End If
End Sub

Posted: Thu Jul 24, 2008 9:43 am
by 9641609
Perfect. Thanks very much.