Hi,
I know that when I use MouseWheelZoomModifier with my chart surface, the default behavior is:
1. On mouse wheel (No keyboard mod) – Zoom according to the “ActionType” propery, and direction according to the “XYDirection” property.
2. On mouse wheel + CTRL – X-Axis pan
3. On mouse wheel + Shift – Y-Axis pan
I want to achieve this behavior:
1. On mouse wheel (No keyboard mod) – Zoom according to the “ActionType” propery, and direction according to the “XYDirection” property.
2. On mouse wheel + CTRL – XY-Axis Zoom
3. On mouse wheel + Shift – Y-Axis Zoom
Any idea how to achieve this behavior?
Thanks, Ben.
- Ben Mendel asked 5 months ago
-
Hi Ben, Thanks for your question. I’ll discuss this with our team and will get back to you with an update. Kind regards, Lex S., MSEE, SciChart Technical Support Engineer
- You must login to post comments
Hi Ben,
We discussed your inquiry.
To change the zooming direction you can override the OverrideKeyboardAction() method and change ActionTypeProperty and XyDirectionProperty values.
Please find the default OverrideKeyboardAction() method implementation below:
protected virtual void OverrideKeyboardAction(MouseModifier modifier)
{
if (ExecuteWhen == MouseModifier.None)
{
if (modifier == MouseModifier.Ctrl)
{
this.SetCurrentValue(ActionTypeProperty, ActionType.Pan);
this.SetCurrentValue(XyDirectionProperty, XyDirection.YDirection);
}
else if (modifier == MouseModifier.Shift)
{
this.SetCurrentValue(ActionTypeProperty, ActionType.Pan);
this.SetCurrentValue(XyDirectionProperty, XyDirection.XDirection);
}
}
}
With best regards,
Lex S., MSEE
SciChart Technical Support Engineer
- Lex answered 5 months ago
- You must login to post comments
Hi Lex,
Eventually there was another requirement that “Shift” modifier will produce an X-axis pan, “Ctrl” modifier will produce Y-axis zoom, and “Alt” modifier will produce XY-axes zoom.
Therefore I eventually concluded that it would be easier to inherit “RelativeZoomModifierBase” and override “OnModifierMouseWheel” method.
public class XAxisZoomWithModifiers : RelativeZoomModifierBase
{
public XAxisZoomWithModifiers()
{
GrowFactor = .1;
}
public override void OnModifierMouseWheel(ModifierMouseArgs e)
{
base.OnModifierMouseWheel(e);
e.Handled = true;
if ((ExecuteWhen != MouseModifier.None) && ExecuteWhen != e.Modifier)
{
return;
}
SetZoomState(ZoomStates.UserZooming);
using IUpdateSuspender updateSuspender = ParentSurface.SuspendUpdates();
double arg = -e.Delta / 120.0;
if (e.Modifier == MouseModifier.Shift)
{
foreach (var axis in XAxes)
{
axis.Scroll(arg * GrowFactor * GetAxisSize(axis), ClipMode.None);
}
return;
}
var point = GetPointRelativeTo(e.MousePoint, base.ModifierSurface);
XyDirection = e.Modifier switch
{
MouseModifier.None => XyDirection.XDirection,
MouseModifier.Ctrl => XyDirection.YDirection,
_ => XyDirection.XYDirection,
};
PerformZoom(point, arg, arg);
}
protected virtual double GetAxisSize(IAxis axis)
{
double num = axis.IsHorizontalAxis ? axis.Width : axis.Height;
if (Math.Abs(num) < double.Epsilon && (ParentSurface != null) && (ParentSurface.RenderSurface != null))
{
num = axis.IsHorizontalAxis ? ParentSurface.RenderSurface.ActualWidth : ParentSurface.RenderSurface.ActualHeight;
}
if (axis.IsPolarAxis)
{
num /= 2.0;
}
return num;
}
}
- Ben Mendel answered 5 months ago
- last edited 5 months ago
- You must login to post comments
Please login first to submit.