Pre loader

Panning an axis by dragging the mouse

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

Answered
1
0

I am considering applying server-side licensing for my javerScript application.

In the document below, there is a phrase “Our server-side licensing component is written in C++.”
(https://support-dev.scichart.com/index.php?/Knowledgebase/Article/View/17256/42/)

However, there is only asp.net sample code on the provided github.
(https://github.com/ABTSoftware/SciChart.JS.Examples/tree/master/Sandbox/demo-dotnet-server-licensing)

I wonder if there is a sample code implemented in C++ for server-side licensing.

Can you provide c++ sample code?
Also, are there any examples to run on Ubuntu?

Images
  • You must to post comments
Best Answer
1
0

Hi Stefaan,

It is possible to pan a single axis by dragging the axis. Please see the XAxisDragModifier and YAxisDragModifier. The property you need to set to enable panning on an axis is *AxisDragModifier.DragMode, which has values of Pan and Scale.

If you wanted to go one further you could create your own ChartModifier (as you have done) to pan a single axis. Please see our tutorial on Creating a Custom ZoomPanModifier. If you take this code (found in the first tutorial) and add an AxisId DependencyProperty you could make it generic to filter on a specific axis by using the ChartModifierBase.GetYAxis(string id) and GetXAxis methods.

Hope this helps!

Andrew

  • srillaert
    Hello Andrew, thanks a lot for the reply. It helps me but I am still missing a piece in the puzzle. Let me explain : The YAxisDragModifier works for one y-axis by setting an AxisId DependencyProperty. That is fine, but in my chart there is a dynamically changing collection of y-axes (2 in the screenshot but it can be any number of y-axes, i forgot to add this information to the question). I could dynamically add and remove YAxisDragModifiers I guess but then the code would get a bit convoluted. So ideally I would go for the second option, creating a custom ZoomPanModifier that would handle all the y-axes and the single x-axis. But there my problem is (as outlined in the question) that the mouse events OnModifierMouseMove and OnModifierMouseUp are not triggered when the mouse moves out of the chart area. In a way the SimpleZoomPanModifier of the tutorial is too simple and is missing some key event handling that is needed for a good implementation (when the mouse moves to another part of the WPF window or outside of the application window). It is possible to write a ChartModifier that handles these events well because that is actually what modifiers like ZoomPanModifier and YAxisDragModifier are doing but I don't know how... Best greetings, Stefaan
  • Andrew Burnett-Thompson
    Yes, it is too simple (deliberately so!), but it's not too hard to fix this. Simply call ModifierSurface.CaptureMouse() in MouseDown after testing the mouse was down on the main chart area, and ModifierSurface.ReleaseMouseCapture() in MouseUp. This is what we do in our own ZoomPanModifier implementation.
  • srillaert
    Thanks a lot Andrew, ModifierSurface.CaptureMouse() and ModifierSurface.ReleaseMouseCapture() were indeed the last puzzle pieces. I still have to work a bit on my own code here but I am confident now that I can come to a good working solution for the panning of the (dynamic number of) YAxes. Thanks again for the help and a great product !
  • You must to post comments
1
0

Hello,

here my code if other people later want to have some similar dragging behavior. Works with a flexible collection of x-axes and y-axis (although I only tested with one x-axis). Please feel free to use the code.

/// <summary>
/// ChartModifier for panning through dragging the mouse, allows for panning a specific axis.
/// </summary>
/// <remarks>
/// See : https://www.scichart.com/questions/question/panning-an-axis-by-dragging-the-mouse
/// </remarks>
public class PanModifier : ChartModifierBase
{
    private class PanningState
    {
        public Point LastPoint;
        public IEnumerable<IAxis> XAxesToScroll;
        public IEnumerable<IAxis> YAxesToScroll;
    }

    private PanningState _state;

    private PanningState CreateInitialPanningState(ModifierMouseArgs e) {
        foreach (var xAxis in XAxes) {
            if (HitTestableContainsMousePoint(xAxis, e)) {
                // Dragging started on an x-axis, only pan that x-axis.
                return new PanningState {
                    LastPoint = e.MousePoint,
                    XAxesToScroll = new IAxis[] { xAxis },
                    YAxesToScroll = new IAxis[0]
                };
            }
        }
        foreach (var yAxis in YAxes) {
            if (HitTestableContainsMousePoint(yAxis, e)) {
                // Dragging started on an y-axis, only pan that y-axis.
                return new PanningState {
                    LastPoint = e.MousePoint,
                    XAxesToScroll = new IAxis[0],
                    YAxesToScroll = new IAxis[] { yAxis }
                };
            }
        }
        // Dragging started on the main chart area, pan all the axes.
        return new PanningState {
            LastPoint = e.MousePoint,
            XAxesToScroll = XAxes,
            YAxesToScroll = YAxes
        };
    }

    private bool HitTestableContainsMousePoint(IHitTestable hitTestable, ModifierMouseArgs e) {
        Rect bounds = hitTestable.GetBoundsRelativeTo(RootGrid);
        return bounds.Contains(e.MousePoint);
    }

    public override void OnModifierMouseDown(ModifierMouseArgs e) {
        base.OnModifierMouseDown(e);
        ModifierSurface.CaptureMouse();
        _state = CreateInitialPanningState(e);
        e.Handled = true;
    }

    public override void OnModifierMouseMove(ModifierMouseArgs e) {
        base.OnModifierMouseMove(e);
        if (_state == null) return;

        var currentPoint = e.MousePoint;
        var xDelta = currentPoint.X - _state.LastPoint.X;
        var yDelta = _state.LastPoint.Y - currentPoint.Y;

        using (ParentSurface.SuspendUpdates()) {
            foreach (var xAxis in _state.XAxesToScroll) {
                xAxis.Scroll(XAxis.IsHorizontalAxis ? xDelta : -yDelta, ClipMode.None);
            }

            foreach (var yAxis in _state.YAxesToScroll) {
                yAxis.Scroll(YAxis.IsHorizontalAxis ? -xDelta : yDelta, ClipMode.None);
            }
        }

        _state.LastPoint = currentPoint;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e) {
        base.OnModifierMouseUp(e);
        ModifierSurface.ReleaseMouseCapture();
        _state = null;
    }
}

Best greetings,
Stefaan

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies