AxisZooming by Right-Drag

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
fukasawa
Posts: 18
Joined: Fri Sep 04, 2015 11:13 am

AxisZooming by Right-Drag

Post by fukasawa » Tue May 10, 2016 2:20 am

Hi,

I want to change Axis range by Right-Drag on the Axis.
RightDrag_Zoom.png
RightDrag_Zoom.png (21.27 KiB) Viewed 7591 times
I used ViewXY.
I already used Left-Drag on the Axis to Scrolling (AxisXYBase.MouseScrolling) and RectangleZoom on innerArea (ZoomPanOptions).
But, I want to zoom-in (-out) only one Axis without MouseWheel.

Is it possible?
or, Could you add it in future updating?

Best Regard,

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: AxisZooming by Right-Drag

Post by ArctionPasi » Tue May 10, 2016 8:10 pm

Hi Fukasawa,

by pressing Ctrl + Alt it zooms all the Y axis in the segment when clicking the left or right mouse button. But that's over the graph area, not over the axis. Maybe it helps you, I don't know.

We'll keep your suggestion on mind for future development. Thanks :D
LightningChart Support Team, PT

fukasawa
Posts: 18
Joined: Fri Sep 04, 2015 11:13 am

Re: AxisZooming by Right-Drag

Post by fukasawa » Mon May 16, 2016 5:11 am

Hi Pasi,

Thank you for your reply.
But, I want to do it without keyboard.
So then I tried it with MouseDown and MouseMove.

At constructor

Code: Select all

            YAxes.ForEach(yAx =>
            yAx.MouseDown += (s, e) => Ax_MouseDown(e, yAx));
            XAxes.ForEach(xAx =>
            xAx.MouseDown += (s, e) => Ax_MouseDown(e, xAx));
field

Code: Select all

        private AxisXYBase axDragged;
        private Point previousMouseLocation;
method

Code: Select all


        private void Ax_MouseDown(MouseEventArgs e, AxisXYBase ax)
        {
            if (e.Button != MouseButtons.Right)
                return;

            axDragged = ax;
            previousMouseLocation = e.Location;
            lChart.MouseMove += Ax_Dragging;
        }

        private void Ax_Dragging(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                lChart.MouseMove -= Ax_Dragging;
                return;
            }

            double maxValue = axDragged.Maximum;
            double minValue = axDragged.Minimum;

            double langeAxValue = maxValue - minValue;
            int distanceMouseMove = 0;
            //double langeAxCoord = axDragged.ValueToCoord(minValue) - axDragged.ValueToCoord(maxValue);
            double langeAxCoord = 0d;
            if (axDragged.GetType() == typeof(AxisY))
            {
                distanceMouseMove = previousMouseLocation.Y - e.Y;
                langeAxCoord = ((AxisY)axDragged).ValueToCoord(minValue) - ((AxisY)axDragged).ValueToCoord(maxValue);
            }
            else
            {
                distanceMouseMove = previousMouseLocation.X - e.X;
                langeAxCoord = ((AxisX)axDragged).ValueToCoord(minValue) - ((AxisX)axDragged).ValueToCoord(maxValue);
            }

            double distanceAxValue = distanceMouseMove / langeAxCoord * langeAxValue;
            maxValue += distanceAxValue;
            minValue -= distanceAxValue;

            axDragged.SetRange(minValue, maxValue);
            previousMouseLocation = e.Location;
        }
I have 2 question.
Is there anything problem or improvement?
Why doesn't AxisXYBase have ValueToCoord()?

Best Regard,

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: AxisZooming by Right-Drag

Post by ArctionPasi » Tue May 17, 2016 1:54 pm

That seems to work very well :)

CoordToValue and ValueToCoord methods are not implemented in the AxisXYBase class because X axis has additional parameter for CoordToValue. There's many differences in the axes, but mostly the properties and methods are identical.
LightningChart Support Team, PT

Post Reply