DynamicDataDisplay D3:ChartPlotter zoom proplem

风流意气都作罢 提交于 2019-12-11 06:21:51

问题


I'm using a simple ChartPlotter in my C# WPF application. When I zoom in/out by mouse scrolling, both Axis are changed. How can I control the zooming by mouse scrolling so it will affect only the X-Axis?


回答1:


This feature is already built into D3, if you hover your mouse over one of the axes, and do a mouse wheel scroll, the zoom is only pertained to the axis you were hovered over. If you want to replicate this in your code, you can see examples of it in the source code.




回答2:


The zoom feature is implemented in "MouseNavigation.cs". The MouseWheel handler will call underneath function:

Viewport.Visible = Viewport.Visible.Zoom(zoomTo, zoomSpeed);

And fortunately, there is a ZoomX function for your needs. Thus just remove MouseNavigation from your plotter, then re-implement your own as below:

    // Remove mouse navigation
    plotter.Children.Remove(plotter.MouseNavigation);

    // ZoomX when wheeling mouse
    private void plotter_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
    {
        if (!e.Handled)
        {
            Point mousePos = e.GetPosition(this);
            Point zoomTo = mousePos.ScreenToViewport(plotter.Viewport.Transform);

            double zoomSpeed = Math.Abs(e.Delta / Mouse.MouseWheelDeltaForOneLine);
            zoomSpeed *= 1.2;
            if (e.Delta < 0)
            {
                zoomSpeed = 1 / zoomSpeed;
            }

            plotter.Viewport.SetChangeType(ChangeType.Zoom);
            plotter.Viewport.Visible = plotter.Viewport.Visible.ZoomX(zoomTo, zoomSpeed);
            plotter.Viewport.SetChangeType();
            e.Handled = true;
        }
    }


来源:https://stackoverflow.com/questions/14314071/dynamicdatadisplay-d3chartplotter-zoom-proplem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!