Skip to content

SP4 AxisLimits: WithPan() #2863

@LapinFou

Description

@LapinFou

Feature Suggestion

Feature description:
In my application, I want to use keys to be able to move the plots.
This is equivalent to creating a "Pan" function.
With Scott's help, I've written an event handler that does the job. However, it would be really handy to have an existing function that does this work.
For example, WithPan().
The arguments would be: X, Y, PanRatio.
PanRatio would be optional with a default value of 0.1.

Code example:
What would be nice:
This will move the pan up-right by one step.
The step corresponds to 10% of the display axis limits (default value).

var limits = formsPlot1.Plot.GetAxisLimits();
var newLimits = limits.WithPan(X: 1, Y: 1);
formsPlot1.Plot.SetAxisLimits(newLimits);

This will move the pan down by one step.
The step corresponds to 50% of the display axis limits.

var limits = formsPlot1.Plot.GetAxisLimits();
var newLimits = limits.WithPan(Y: -1, PanRatio: 0.5);
formsPlot1.Plot.SetAxisLimits(newLimits);

Here is the code I wrote for my application.

       private void formsPlot_KeyDown(object sender, KeyEventArgs e)
       {
           // read current limits
           var limits = formsPlot1.Plot.GetAxisLimits();

           double limitXMax = limits.XMax;
           double limitXMin = limits.XMin;
           double limitYMax = limits.YMax;
           double limitYMin = limits.YMin;

           double XStep = (limitXMax - limitXMin) * 0.1;
           double YStep = (limitYMax - limitYMin) * 0.1;

           switch (e.KeyCode)
           {
               case Keys.F:    // fit view
                   formsPlot1.Plot.AxisAuto();
                   break;

               case Keys.Z:   // pan Y up
                   limitYMax += YStep;
                   limitYMin += YStep;
                   formsPlot1.Plot.SetAxisLimits(yMax: limitYMax, yMin: limitYMin);
                   break;

               case Keys.S: // pan Y down
                   limitYMax -= YStep;
                   limitYMin -= YStep;
                   formsPlot1.Plot.SetAxisLimits(yMax: limitYMax, yMin: limitYMin);
                   break;

               case Keys.Q: // pan X left
                   limitXMax -= XStep;
                   limitXMin -= XStep;
                   formsPlot1.Plot.SetAxisLimits(xMax: limitXMax, xMin: limitXMin);
                   break;

               case Keys.D:    // pan X right
                   limitXMax += XStep;
                   limitXMin += XStep;
                   formsPlot1.Plot.SetAxisLimits(xMax: limitXMax, xMin: limitXMin);
                   break;
           }
           formsPlot1.Refresh();

           // event has been handled
           e.Handled = true;
       }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions