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
I added functionality for detecting click on the axis:
public class MovingAxisTool : InteractionTool
{
private Point prevPoint;
/// <summary>
/// Initializes a new instance of the <see cref="MovingAxisTool"/> class.
/// </summary>
/// <param name="ultraChart">The ultra chart.</param>
}
/// Determines whether this tool can start.
/// <returns>
/// <c>true</c> if this tool can start; otherwise, <c>false</c>.
/// </returns>
areaBounds.Height += range / 2;
this.axisItem = item;
chartBounds.Height += range / 2;
IAdvanceAxis axis = chartLayer.Grid["Y"] as IAdvanceAxis;
/// Called when this tool starts.
this.prevPoint = this.LastInput.ViewPoint;
/// Called when this tool is started and the mouse is moved.
int dy = this.LastInput.ViewPoint.Y - prevPoint.Y;
newExtend = 0;
newExtend = 500;
/// Called when this tool stops.
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)
---------------------------------------------------------
Inherits InteractionTool
Private axisItem As AxisItem
''' <summary>
''' Initializes a new instance of the <see cref="DraggingYAxisTool"/> class.
''' </summary>
''' <param name="ultraChart">The ultra chart.</param>
MyBase.New(ultraChart)
End Sub
''' Determines whether this tool can start.
''' <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
MouseDelta = 500000 'very large number bigger than possible chart size to get started with
NearestAxis = Nothing
Dim curMouseDelta As Integer
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))
Next
If Not (NearestAxis Is Nothing) Then
Return True
Else
Return False
End Function
MyBase.Start()
System.Windows.Forms.Cursor.Current = Cursors.SizeWE
''' Called when this tool is started and the mouse is moved.
MyBase.MouseMove()
Dim newExtend As Integer
If Me.axisItem.OrientationType = AxisNumber.Y2_Axis Then
ElseIf Me.axisItem.OrientationType = AxisNumber.Y_Axis Then
If newExtend < 0 Then
newExtend = 0
If newExtend > 500 Then
newExtend = 500
'left side axis requires the negative value or mouse direction will be contrary to axis movement
Me.prevPoint = Me.LastInput.ViewPoint
''' Called when this tool stops.
System.Windows.Forms.Cursor.Current = Cursors.[Default]
End Class