Skip to content

Commit 3cf1330

Browse files
authored
Merge pull request #2436 from Open-Systems-Pharmacology/2435-zooming-not-working-ok-on-3-axis
2435 zooming not working ok on 3 axis
2 parents 43f2511 + 149f586 commit 3cf1330

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/OSPSuite.UI/Views/Charts/ChartDisplayView.cs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using DevExpress.Utils;
88
using DevExpress.XtraBars;
99
using DevExpress.XtraCharts;
10-
using DevExpress.XtraCharts.Native;
1110
using DevExpress.XtraEditors;
1211
using OSPSuite.Assets;
1312
using OSPSuite.Core.Chart;
@@ -47,7 +46,7 @@ public ChartDisplayView(IImageListRetriever imageListRetriever)
4746
_doubleFormatter = new DoubleFormatter();
4847
_hintControl = new LabelControl();
4948
_toolTipController = new ToolTipController();
50-
PopupBarManager = new BarManager {Form = this, Images = imageListRetriever.AllImagesForContextMenu};
49+
PopupBarManager = new BarManager { Form = this, Images = imageListRetriever.AllImagesForContextMenu };
5150
SetDockStyle(Presentation.Views.Dock.Fill);
5251
}
5352

@@ -164,7 +163,6 @@ protected override void OnDragDrop(DragEventArgs dragDropEventArgs)
164163
var seriesBeingMoved = dragDropEventArgs.Data.GetData(typeof(Series)).DowncastTo<Series>();
165164
if (seriesBeingMoved != null)
166165
dropLegendHere(hitInfo.Series.DowncastTo<Series>(), seriesBeingMoved);
167-
168166
}
169167

170168
protected override void OnDragOver(DragEventArgs dragOverEventArgs)
@@ -275,9 +273,46 @@ private bool isInXAxis(ChartHitInfo hitInfo)
275273

276274
private void zoomAction(Control control, Rectangle rectangle)
277275
{
278-
var cc = control as IChartContainer;
279-
if (cc != null && cc.Chart != null && !rectangle.IsEmpty)
280-
cc.Chart.PerformZoomIn(rectangle);
276+
if (rectangle.IsEmpty || xyDiagram == null)
277+
return;
278+
279+
var topLeftCoord = xyDiagram.PointToDiagram(rectangle.Location);
280+
var bottomRightCoord = xyDiagram.PointToDiagram(new Point(rectangle.Right, rectangle.Bottom));
281+
282+
if (topLeftCoord == null || bottomRightCoord == null)
283+
return;
284+
285+
xyDiagram.AxisX.VisualRange.Auto = false;
286+
xyDiagram.AxisX.VisualRange.SetMinMaxValues(
287+
Math.Min(topLeftCoord.NumericalArgument, bottomRightCoord.NumericalArgument),
288+
Math.Max(topLeftCoord.NumericalArgument, bottomRightCoord.NumericalArgument));
289+
290+
setAxisVisualRange(AxisTypes.Y, topLeftCoord?.NumericalValue, bottomRightCoord?.NumericalValue);
291+
zoomAxis(AxisTypes.Y2, rectangle);
292+
zoomAxis(AxisTypes.Y3, rectangle);
293+
}
294+
295+
private void zoomAxis(AxisTypes axisType, Rectangle rectangle)
296+
{
297+
var axis = getAxisFromType(axisType);
298+
if (axis == null) return;
299+
300+
var topLeftCoord = xyDiagram.PointToDiagram(rectangle.Location).GetAxisValue(axis);
301+
var bottomRightCoord = xyDiagram.PointToDiagram(new Point(rectangle.Right, rectangle.Bottom)).GetAxisValue(axis);
302+
303+
if (topLeftCoord == null || bottomRightCoord == null)
304+
return;
305+
306+
setAxisVisualRange(axisType, topLeftCoord.NumericalValue, bottomRightCoord.NumericalValue);
307+
}
308+
309+
private void setAxisVisualRange(AxisTypes axisType, double? minValue, double? maxValue)
310+
{
311+
var axis = getAxisFromType(axisType);
312+
if (axis == null || minValue == null || maxValue == null) return;
313+
314+
axis.VisualRange.Auto = false;
315+
axis.VisualRange.SetMinMaxValues(Math.Min(minValue.Value, maxValue.Value), Math.Max(minValue.Value, maxValue.Value));
281316
}
282317

283318
private Color diagramBackColor

0 commit comments

Comments
 (0)