Pre loader

Edit MouseWheelZoomModifier Behavior

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

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.

Version
8
  • Lex
    • Lex
    • 2 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 to post comments
0
0

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

  • You must to post comments
0
0

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;
}
}

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.