Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Custom zoom functionality
posted

Hi, so I am trying to create a zoom functionality for the XamDataChart using the zoom bars like the one in Python:

  • moving the mouse right, the chart zooms in horizontally (with mouse start position as zoom focus point)
  • moving the mouse left, the chart zooms out horizontally (with mouse start position as zoom focus point)

On the mouse_down event I have saved the starting X,Y of the mouse and the on the mouse_move I have this: 

if (e.RightButton == MouseButtonState.Pressed && Keyboard.Modifiers == ModifierKeys.Shift)
{
long deltaMouse;
GetXMousePositionOnChart(out var xpos);
GetYMousePositionOnChart(out var ypos);
var xMaxViewPort = xmDataChart.ViewportRect.Right;
var yMaxViewPort = xmDataChart.ViewportRect.Bottom;
var xAxis = xmDataChart.Axes[0];
var yAxis = xmDataChart.Axes[1];
var winRectContext = new Rect(0, 0, 1, 1);
var xScalerParams = new ScalerParams(winRectContext, xmDataChart.ViewportRect, xAxis.IsInverted);
var yScalerParams = new ScalerParams(winRectContext, xmDataChart.ViewportRect, yAxis.IsInverted);
if (xpos.Ticks > vm.XStartPosition)
deltaMouse = xpos.Ticks - vm.XStartPosition;

else
deltaMouse = vm.XStartPosition - xpos.Ticks;

var maxRange = vm.MaxTicks;
var chartCenter = (xmNumericSlider.MinValue + xmNumericSlider.MaxValue) / 2;
var deltaRangeMax = (deltaMouse * 0.05 * maxRange) + (vm.XStartPosition - chartCenter);
var deltaRangeMin = (deltaMouse * 0.05 * maxRange) - (vm.XStartPosition - chartCenter);


if (vm.XStartPosition != xpos.Ticks)
if (!xMaxViewPort.Equals(0))
{
xmDataChart.HorizontalZoombar.Range = new Range
{
Minimum = xAxis.GetScaledValue(deltaRangeMin, xScalerParams) / xMaxViewPort,
Maximum = xAxis.GetScaledValue(deltaRangeMax, xScalerParams) / xMaxViewPort
};
}

But the zoombars go crazy, what am I doing wrong?

Parents Reply Children
No Data