Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
455
Detect Axis Click
posted

Hello,

Is there a way to detect when the user clicks on an Axis?

I am trying to modify the code from

http://news.infragistics.com/forums/p/10441/46970.aspx#46970   because I have multiple Y axis in multiple layers in a composite chart, and I want the user to be able to move only 1 Y axis at a time.

 Is there a way to return the location of the Axis or a hittest that will return a boolean if the current click was over the axis?

 Thanks in advance

Talal

 

Parents
  • 455
    Offline posted

    I wrote the following code to drag the "Nearest" Y axis, but I still haven't found a way to detect an actual click or hover ON or above the axis itself (I would like to be able to change mouse cursor when hovering over an axis before moving it, for example)

     

    --------------------------------------------------------- 

    Public Class DraggingYAxisTool

    Inherits InteractionTool

    Private prevPoint As Point

    Private axisItem As AxisItem

    ''' <summary>

    ''' Initializes a new instance of the <see cref="DraggingYAxisTool"/> class.

    ''' </summary>

    ''' <param name="ultraChart">The ultra chart.</param>

    Public Sub New(ByVal ultraChart As UltraChart)

    MyBase.New(ultraChart)

    End Sub

    ''' <summary>

    ''' Determines whether this tool can start.

    ''' </summary>

    ''' <returns>

    ''' <c>true</c> if this tool can start; otherwise, <c>false</c>.

    ''' </returns>

    Public Overloads Overrides Function CanStart() As Boolean

    Dim MouseDelta As Integer

    Dim NearestAxis As AxisItem

    MouseDelta = 500000 'very large number bigger than possible chart size to get started with

    NearestAxis = Nothing

    For Each area As ChartArea In Me.UltraChart.CompositeChart.ChartAreas

    Dim curMouseDelta As Integer

    For Each item As AxisItem In area.Axes

    If (item.axisNumber = AxisNumber.Y_Axis) Then

    curMouseDelta = Math.Abs(Me.LastInput.ViewPoint.X - item.Extent)

    If curMouseDelta < MouseDelta Then

    NearestAxis = item

    MouseDelta = curMouseDelta

    End If

    ElseIf (item.axisNumber = AxisNumber.Y2_Axis) Then

    'Axis on far right so we need to add chart width to margin

    curMouseDelta = Math.Abs(Me.LastInput.ViewPoint.X - (Me.UltraChart.Width - item.Extent))

    If curMouseDelta < MouseDelta Then

    NearestAxis = item

    MouseDelta = curMouseDelta

    End If

    End If

    Next

    Next

    If Not (NearestAxis Is Nothing) Then

    Me.axisItem = NearestAxis

    Return True

    Else

    Return False

    End If

    Return False

    End Function

    Public Overloads Overrides Sub Start()

    MyBase.Start()

    Me.prevPoint = Me.LastInput.ViewPoint

    System.Windows.Forms.Cursor.Current = Cursors.SizeWE

    End Sub

    ''' <summary>

    ''' Called when this tool is started and the mouse is moved.

    ''' </summary>

    Public Overloads Overrides Sub MouseMove()

    MyBase.MouseMove()

    Dim newExtend As Integer

    Dim dx As Integer = Me.LastInput.ViewPoint.X - prevPoint.X

    If Me.axisItem.OrientationType = AxisNumber.Y2_Axis Then

    newExtend = Me.axisItem.Extent - dx

    ElseIf Me.axisItem.OrientationType = AxisNumber.Y_Axis Then

    newExtend = Me.axisItem.Extent + dx

    End If

    If newExtend < 0 Then

    newExtend = 0

    End If

    If newExtend > 500 Then

    newExtend = 500

    End If

    'left side axis requires the negative value or mouse direction will be contrary to axis movement

    Me.axisItem.Extent = newExtend

    Me.prevPoint = Me.LastInput.ViewPoint

    Me.InvalidateView(CacheLevel.ImageLevelCache)

    End Sub

    ''' <summary>

    ''' Called when this tool stops.

    ''' </summary>

    Public Overloads Overrides Sub [Stop]()

    System.Windows.Forms.Cursor.Current = Cursors.[Default]

    MyBase.[Stop]()

    End Sub

    End Class

Reply Children
No Data