You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Charts pan undesireably when clicked for the first time, and ZoomMode and ChartPointPointerDown behaviors fire simultaneously even when the mouse was not dragged.
To Reproduce
Steps to reproduce the behavior:
Create a CartesianChart similar to the following, and populate it with a ColumnSeries:
Click on one of the columns, without dragging the mouse.
Expected behavior
The ChartPointPointerDown event fires, and the chart pan position / zoom level do not change (as the mouse was not moved).
Actual behavior
The ChartPointPointerDown event fires, and at the same time, the chart pans slightly to the right.
Screenshots
Initial state:
After clicking the bar on the far right (without moving the mouse -- no pan operation should have been performed):
The entire X axis shifts to the right, even though the mouse wasn't moved.
Desktop (please complete the following information):
OS: Windows 11 23H2 22631.3593
Platform: .NET 7.0 / WPF
LiveCharts2: v2.0.0-rc2
CommunityToolkit.Mvvm: 8.0.0
Additional context
Standard behavior in controls that support both click events and pan/zoom events is to not allow them to interfere with one another by default. Click events should not fire if the mouse was dragged between mousedown and mouseup events. Conversely, zoom/pan events should not fire if the mouse was single-clicked without dragging.
I understand that the "click" event in this case is a "pointerdown" event, rather than a "click/tap" event. This likely somewhat complicates matters, as pointerdown is more broad and independent of click, as I understand it. Still, currently I am struggling to determine how to ensure both behaviors don't interfere with each other, without completely reinventing the wheel on the entire pan/zoom system by removing ZoomMode and using MouseUp/MouseDown to drive the whole thing myself.
The text was updated successfully, but these errors were encountered:
planetarian
changed the title
Zoom interferes with Click
With ZoomMode=X, chart pans on click without dragging
May 16, 2024
Currently I am partially working around this by setting MinLimit = -(items.Count()/16.0), MaxLimit = items.Count() on the X Axis. This doesn't actually fix anything, but it at least sets the limits to be roughly similar to the post-pan limits by default, so that the movement on click isn't as jarring.
The secondary issue is that ChartPointPointerDown executes before it can even be determined whether the user is dragging or clicking, and there is no ChartPointPressed or ChartPointPointerUp or ChartPointClicked.
For that, I'm making use of everything I have at my disposal: ChartPointPointerDown to get the ChartPoint, and MouseDown and MouseUp to determine whether we're clicking or dragging.
object?mouseDownObject;Point?mouseDownPos;ChartPoint?chartPoint;privatevoidCartesianChart_MouseDown(objectsender,MouseButtonEventArgse){// Store the clicked object and mouse position for comparison on MouseUpmouseDownObject=sender;mouseDownPos= e.GetPosition(this);}privatevoidCartesianChart_ChartPointPointerDown(IChartViewchart,ChartPointpoint){// Store the clicked point for use on MouseUpchartPoint=point;}privatevoidCartesianChart_MouseUp(objectsender,MouseButtonEventArgse){if(DataContext is not MyViewModel vm)return;// Ensure we're still acting on the same objectif(sender!=mouseDownObject){mouseDownObject=null;return;}// If the new position isn't the same as the old one, we're dragging, not clickingPointpos= e.GetPosition(this);if(pos!=mouseDownPos)return;// Get the series and point model and execute the appropriate point activation function for that seriesvarseries=(ColumnSeries<(string Key,double Value)>)((CartesianChart)sender).Series.First();varpointModel=((string Key,double Value))chartPoint.Context.DataSource;
vm.ActivatePoint(series, pointModel);}
Describe the bug
Charts pan undesireably when clicked for the first time, and ZoomMode and ChartPointPointerDown behaviors fire simultaneously even when the mouse was not dragged.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The ChartPointPointerDown event fires, and the chart pan position / zoom level do not change (as the mouse was not moved).
Actual behavior
The ChartPointPointerDown event fires, and at the same time, the chart pans slightly to the right.
Screenshots
Initial state:
After clicking the bar on the far right (without moving the mouse -- no pan operation should have been performed):
The entire X axis shifts to the right, even though the mouse wasn't moved.
Desktop (please complete the following information):
Additional context
Standard behavior in controls that support both click events and pan/zoom events is to not allow them to interfere with one another by default. Click events should not fire if the mouse was dragged between mousedown and mouseup events. Conversely, zoom/pan events should not fire if the mouse was single-clicked without dragging.
I understand that the "click" event in this case is a "pointerdown" event, rather than a "click/tap" event. This likely somewhat complicates matters, as pointerdown is more broad and independent of click, as I understand it. Still, currently I am struggling to determine how to ensure both behaviors don't interfere with each other, without completely reinventing the wheel on the entire pan/zoom system by removing ZoomMode and using MouseUp/MouseDown to drive the whole thing myself.
The text was updated successfully, but these errors were encountered: