Giter VIP home page Giter VIP logo

Comments (12)

swharden avatar swharden commented on June 14, 2024 1

I now appreciate the issue is about multi-axis syncing across multiple plots. I think the issue is here, as it's not getting and setting all 4 axis limits. I'll create an updated code sample in a few minutes...

dest.Plot.Axes.SetLimits(source.Plot.Axes.GetLimits());
dest.Plot.Axes.SetLimitsX(source.Plot.Axes.GetLimits());
dest.Plot.Axes.SetLimitsX(source.Plot.Axes.GetLimits(), dest.Plot.Axes.Top);

from scottplot.

rubenslkirchner avatar rubenslkirchner commented on June 14, 2024

trips playback plotters scottplot_QD330sd38S

from scottplot.

rubenslkirchner avatar rubenslkirchner commented on June 14, 2024

@swharden This issue is the most critical because the user can reproduce easily and we don't have any workaround.

from scottplot.

swharden avatar swharden commented on June 14, 2024

Hi @rubenslkirchner, I made a simple app to test this out and it works as expected. Could the issue be related to something your code is doing differently? Hopefully this is enough to help you get your app working, but if not let me know and we can re-open this issue and take a closer look 👍

using ScottPlot;

namespace Sandbox.WinForms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin(mult: 0.001));
        sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
        sig1.Axes.XAxis = formsPlot1.Plot.Axes.Bottom;
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Left, sig1.Color);
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Bottom, sig1.Color);

        var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos(mult: 1000));
        sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
        sig2.Axes.XAxis = formsPlot1.Plot.Axes.Top;
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Right, sig2.Color);
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Top, sig2.Color);

        formsPlot1.Plot.HideGrid();
    }
}

zooming

from scottplot.

swharden avatar swharden commented on June 14, 2024

This works for me, let me know if the strategy works for you too!

I changed the logic a bit: (1) I use a timer to manage axis copying and rendering for a little better performance and to ensure one plot isn't modified inside the render loop of another and (2) all axis limits are copied, not just the primary ones

using ScottPlot;

namespace Sandbox.WinForms;

public partial class Form1 : Form
{
    readonly System.Windows.Forms.Timer RefreshTimer = new();

    public Form1()
    {
        InitializeComponent();

        // plot 1 signal 1
        var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin(mult: 0.001));
        sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
        sig1.Axes.XAxis = formsPlot1.Plot.Axes.Bottom;
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Left, sig1.Color);
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Bottom, sig1.Color);

        // plot 1 signal 2
        var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos(mult: 1000));
        sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
        sig2.Axes.XAxis = formsPlot1.Plot.Axes.Top;
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Right, sig2.Color);
        formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Top, sig2.Color);
        formsPlot1.Plot.HideGrid();

        // plot 2 signal 1
        var sig3 = formsPlot2.Plot.Add.Signal(Generate.Sin(mult: 0.001));
        sig3.Axes.YAxis = formsPlot2.Plot.Axes.Left;
        sig3.Axes.XAxis = formsPlot2.Plot.Axes.Bottom;
        formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Left, sig1.Color);
        formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Bottom, sig1.Color);

        // plot 2 signal 2
        var sig4 = formsPlot2.Plot.Add.Signal(Generate.Cos(mult: 1000));
        sig4.Axes.YAxis = formsPlot2.Plot.Axes.Right;
        sig4.Axes.XAxis = formsPlot2.Plot.Axes.Top;
        formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Right, sig2.Color);
        formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Top, sig2.Color);
        formsPlot2.Plot.HideGrid();

        // when one plot changes update the other plot
        formsPlot1.Plot.RenderManager.AxisLimitsChanged += (s, e) => PlotsToCopy = (formsPlot1, formsPlot2);
        formsPlot2.Plot.RenderManager.AxisLimitsChanged += (s, e) => PlotsToCopy = (formsPlot2, formsPlot1);

        // setup a timer to manage refreshes
        RefreshTimer.Interval = 10;
        RefreshTimer.Tick += (s, e) => CopyLimits();
        RefreshTimer.Start();
    }

    private (IPlotControl from, IPlotControl to)? PlotsToCopy = null;

    private void CopyLimits()
    {
        if (PlotsToCopy is null)
            return;
        (IPlotControl source, IPlotControl target) = PlotsToCopy.Value;
        AxisLimits limits1 = source.Plot.Axes.GetLimits(source.Plot.Axes.Bottom, source.Plot.Axes.Left);
        AxisLimits limits2 = source.Plot.Axes.GetLimits(source.Plot.Axes.Top, source.Plot.Axes.Right);
        target.Plot.Axes.SetLimits(limits1, target.Plot.Axes.Bottom, target.Plot.Axes.Left);
        target.Plot.Axes.SetLimits(limits2, target.Plot.Axes.Top, target.Plot.Axes.Right);
        target.Refresh();
    }
}

image

from scottplot.

rubenslkirchner avatar rubenslkirchner commented on June 14, 2024

The user is expecting that when zoomed on the left and right axis ALL series will increase or decrease and not just the series that are linked to the axis. Same thing for the top and bottom axes.

from scottplot.

rubenslkirchner avatar rubenslkirchner commented on June 14, 2024

Even version 5.0.29 has the same issue. The user was expecting that when scrolling on the Y axis, ALL series would change vertically. In the print I'm sending, notice that only the series in blue is changing the zoom.

trips playback plotters scottplot_RvVVXh3NmK

from scottplot.

swharden avatar swharden commented on June 14, 2024

Ah, I understand the disconnect. Let me re-state your description of the issue:

"The user was expecting that when scrolling on the LEFT Y axis, the RIGHT Y axis would also change"

This is not the default behavior. The axis system was designed so whatever axis the cursor is over is the one that will be adjusted. However, I'm sure we can come up with a way to modify your code to achieve the functionality you're looking for. I'll re-open this issue as a reminder to revisit it later today and update you with the solution I come up with.

... quick idea in case you want to try this before I get to it, the last code sample I shared could be modified to evaluate "what percent the axis limits changed after copying", then you could call SetAxisLimits to change the other axis by that same percentage the first axis was changed.

bool leftAxisChanged = /* calculate this */
bool rightAxisChanged = /* calculate this */

if (leftAxisChanged){
    double fractionLeftAxisChanged = /* calculate this */
    formsPlot1.Plot.Axes.Right.Range.ZoomFrac(fractionLeftAxisChanged);
}

if (rightAxisChanged){
    double fractionRightAxisChanged = /* calculate this */
    formsPlot1.Plot.Axes.Left.Range.ZoomFrac(fractionRightAxisChanged);
}

from scottplot.

swharden avatar swharden commented on June 14, 2024

Trying to implement this myself and it's getting pretty dicey with all the logic checks. I'll see about adding a flag that enables behavior like "if the left axis changes, change the right axis by the same fractional amount".

Interestingly this feature is unrelated to multi-axis plots. This is the sample code I'm starting with

using ScottPlot;

namespace Sandbox.WinForms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin());
        sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
        formsPlot1.Plot.Axes.Color(sig1.Axes.YAxis, sig1.Color);

        var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos());
        sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
        formsPlot1.Plot.Axes.Color(sig2.Axes.YAxis, sig2.Color);
    }
}

spbefore

from scottplot.

swharden avatar swharden commented on June 14, 2024

Logic blocks like this here are the offending code:

if (axisUnderMouse is not null)
{
// modify a single axis
float scaledDelta = axisUnderMouse.IsHorizontal() ? scaledDeltaX : scaledDeltaY;
float dataSize = axisUnderMouse.IsHorizontal() ? dataRect.Width : dataRect.Height;
axisUnderMouse.Range.PanMouse(scaledDelta, dataSize);
}

Modifying it a bit we start to observe the OP's desired behavior

spafter2

from scottplot.

swharden avatar swharden commented on June 14, 2024

This feature will be in the next release as an opt-in feature:

formsPlot1.Interaction.ChangeOpposingAxesTogether = true;

spafter3

from scottplot.

rubenslkirchner avatar rubenslkirchner commented on June 14, 2024

Scott, this new configuration was perfect! Thank you very much for your efforts!!!

from scottplot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.