Skip to content

Commit c4226e8

Browse files
committed
Remove zoom-in boundary checking
- Clamp the maximum height of the scale bar to be 25% of the height of the Y-Axis
1 parent de8004a commit c4226e8

File tree

1 file changed

+24
-57
lines changed

1 file changed

+24
-57
lines changed

OpenEphys.Onix1.Design/Rhs2116StimulusSequenceDialog.cs

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ private void DrawStimulusWaveform(bool setZoomState = true)
280280

281281
double peakToPeak = GetPeakToPeakAmplitudeInMicroAmps() * 1.1;
282282

283-
ZoomInBoundaryY = 3;
284-
285283
double maxLength = 0;
286284

287285
for (int i = 0; i < Sequence.Stimuli.Length; i++)
@@ -331,8 +329,6 @@ private void DrawStimulusWaveform(bool setZoomState = true)
331329

332330
SetZoomOutBoundaries(zedGraphWaveform);
333331

334-
ZoomInBoundaryX = (ZoomOutBoundaryRight - ZoomOutBoundaryLeft) * 0.05;
335-
336332
dataGridViewStimulusTable.Refresh();
337333

338334
if (setZoomState)
@@ -363,12 +359,28 @@ private void DrawScale()
363359
zedGraphWaveform.GraphPane.GraphObjList.RemoveAll(x => x is TextObj);
364360
}
365361

366-
var zeroOffsetX = zedGraphWaveform.GraphPane.XAxis.Scale.Min + CalculateScaleRange(zedGraphWaveform.GraphPane.XAxis.Scale) * 0.025;
367-
var zeroOffsetY = zedGraphWaveform.GraphPane.YAxis.Scale.Min + CalculateScaleRange(zedGraphWaveform.GraphPane.YAxis.Scale) * 0.025;
362+
var xScaleRange = CalculateScaleRange(zedGraphWaveform.GraphPane.XAxis.Scale);
363+
var yScaleRange = CalculateScaleRange(zedGraphWaveform.GraphPane.YAxis.Scale);
364+
365+
const double ScaleFactor = 0.025;
368366

369-
var x = CalculateScaleRange(zedGraphWaveform.GraphPane.XAxis.Scale) * 0.05;
367+
var zeroOffsetX = zedGraphWaveform.GraphPane.XAxis.Scale.Min + xScaleRange * ScaleFactor;
368+
var zeroOffsetY = zedGraphWaveform.GraphPane.YAxis.Scale.Min + yScaleRange * ScaleFactor;
369+
370+
var x = xScaleRange * ScaleFactor * 2;
370371
var y = 1 / 2.2; // NB: Equal to 1/2 of the max peak-to-peak amplitude
371372

373+
double maxValueY = yScaleRange * 0.25;
374+
375+
double yScaleValue = GetPeakToPeakAmplitudeInMicroAmps() / 2;
376+
377+
if (y > maxValueY)
378+
{
379+
double ratio = y / maxValueY;
380+
yScaleValue /= ratio;
381+
y /= ratio;
382+
}
383+
372384
PointPairList points = new()
373385
{
374386
{ zeroOffsetX, zeroOffsetY },
@@ -382,13 +394,15 @@ private void DrawScale()
382394
line.Label.IsVisible = false;
383395
zedGraphWaveform.GraphPane.CurveList.Move(zedGraphWaveform.GraphPane.CurveList.Count - 1, -99);
384396

385-
TextObj timeScale = new(GetTimeScaleString(x) + " ms", zeroOffsetX + x * 1.02, zeroOffsetY, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
397+
const double TextObjScaleFactor = 1.02;
398+
399+
TextObj timeScale = new(GetTimeScaleString(x) + " ms", zeroOffsetX + x * TextObjScaleFactor, zeroOffsetY, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
386400
timeScale.FontSpec.Border.IsVisible = false;
387401
timeScale.FontSpec.Fill.IsVisible = false;
388402
timeScale.ZOrder = ZOrder.A_InFront;
389403
zedGraphWaveform.GraphPane.GraphObjList.Add(timeScale);
390404

391-
TextObj amplitudeScale = new((GetPeakToPeakAmplitudeInMicroAmps() / 2).ToString() + " µA", zeroOffsetX, zeroOffsetY + y * 1.02, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
405+
TextObj amplitudeScale = new(yScaleValue.ToString("0.##") + " µA", zeroOffsetX, zeroOffsetY + y * TextObjScaleFactor, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
392406
amplitudeScale.FontSpec.Border.IsVisible = false;
393407
amplitudeScale.FontSpec.Fill.IsVisible = false;
394408
amplitudeScale.ZOrder = ZOrder.A_InFront;
@@ -479,8 +493,6 @@ private void InitializeZedGraphWaveform()
479493
private double ZoomOutBoundaryRight = default;
480494
private double ZoomOutBoundaryBottom = default;
481495
private double ZoomOutBoundaryTop = default;
482-
private double? ZoomInBoundaryX = 5;
483-
private double? ZoomInBoundaryY = 2;
484496

485497
private void SetZoomOutBoundaries(ZedGraphControl zedGraphControl)
486498
{
@@ -511,9 +523,7 @@ private void CenterAxesOnCursor(ZedGraphControl zedGraphControl)
511523
if ((zedGraphControl.GraphPane.XAxis.Scale.Min == ZoomOutBoundaryLeft &&
512524
zedGraphControl.GraphPane.XAxis.Scale.Max == ZoomOutBoundaryRight &&
513525
zedGraphControl.GraphPane.YAxis.Scale.Min == ZoomOutBoundaryBottom &&
514-
zedGraphControl.GraphPane.YAxis.Scale.Max == ZoomOutBoundaryTop) ||
515-
ZoomInBoundaryX.HasValue && CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale) == ZoomInBoundaryX.Value ||
516-
ZoomInBoundaryY.HasValue && CalculateScaleRange(zedGraphControl.GraphPane.YAxis.Scale) == ZoomInBoundaryY.Value)
526+
zedGraphControl.GraphPane.YAxis.Scale.Max == ZoomOutBoundaryTop))
517527
{
518528
return;
519529
}
@@ -525,7 +535,6 @@ private void CenterAxesOnCursor(ZedGraphControl zedGraphControl)
525535
var currentMousePosition = TransformPixelsToCoordinates(mouseClientPosition, zedGraphControl.GraphPane);
526536

527537
var centerX = CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale) / 2 + zedGraphControl.GraphPane.XAxis.Scale.Min;
528-
529538
var centerY = CalculateScaleRange(zedGraphControl.GraphPane.YAxis.Scale) / 2 + zedGraphControl.GraphPane.YAxis.Scale.Min;
530539

531540
var diffX = centerX - currentMousePosition.X;
@@ -538,50 +547,8 @@ private void CenterAxesOnCursor(ZedGraphControl zedGraphControl)
538547
zedGraphControl.GraphPane.YAxis.Scale.Max += diffY;
539548
}
540549

541-
/// <summary>
542-
/// Checks if the <see cref="ZedGraphControl"/> is too zoomed in or out. If the graph is too zoomed in,
543-
/// reset the boundaries to match <see cref="ZoomInBoundaryX"/> and <see cref="ZoomInBoundaryY"/>. If the graph is too zoomed out,
544-
/// reset the boundaries to match the automatically generated boundaries based on the size of the waveforms.
545-
/// </summary>
546-
/// <param name="zedGraphControl">A <see cref="ZedGraphControl"/> object.</param>
547-
/// <returns>True if the zoom boundary has been correctly handled, False if the previous zoom state should be reinstated.</returns>
548550
private bool CheckZoomBoundaries(ZedGraphControl zedGraphControl)
549551
{
550-
var rangeX = CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale);
551-
var rangeY = CalculateScaleRange(zedGraphControl.GraphPane.YAxis.Scale);
552-
553-
if (ZoomInBoundaryX.HasValue && rangeX < ZoomInBoundaryX)
554-
{
555-
if (ZoomInBoundaryX.HasValue && rangeX / ZoomInBoundaryX == zedGraphControl.ZoomStepFraction)
556-
{
557-
return false;
558-
}
559-
else
560-
{
561-
if (ZoomInBoundaryX.HasValue && ZoomInBoundaryX.Value > 0)
562-
{
563-
var diffX = (ZoomInBoundaryX.Value - rangeX) / 2;
564-
zedGraphControl.GraphPane.XAxis.Scale.Min -= diffX;
565-
zedGraphControl.GraphPane.XAxis.Scale.Max += diffX;
566-
}
567-
}
568-
}
569-
570-
if (ZoomInBoundaryY.HasValue && rangeY < ZoomInBoundaryY)
571-
{
572-
if (ZoomInBoundaryY.HasValue && rangeY / ZoomInBoundaryY == zedGraphControl.ZoomStepFraction)
573-
return false;
574-
else
575-
{
576-
if (ZoomInBoundaryY.HasValue && ZoomInBoundaryY.Value > 0)
577-
{
578-
var diffY = (ZoomInBoundaryY.Value - rangeY) / 2;
579-
zedGraphControl.GraphPane.YAxis.Scale.Min -= diffY;
580-
zedGraphControl.GraphPane.YAxis.Scale.Max += diffY;
581-
}
582-
}
583-
}
584-
585552
if (CalculateScaleRange(zedGraphControl.GraphPane.XAxis.Scale) >= ZoomOutBoundaryRight - ZoomOutBoundaryLeft)
586553
{
587554
zedGraphControl.GraphPane.XAxis.Scale.Min = ZoomOutBoundaryLeft;

0 commit comments

Comments
 (0)