Skip to content

Commit

Permalink
Adding ScaleFactor to Zoom options.
Browse files Browse the repository at this point in the history
  • Loading branch information
joezearing committed Apr 8, 2021
1 parent 93884b5 commit 1ec1b67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Blazor.Diagrams.Core/Behaviors/ZoomBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Blazor.Diagrams.Core.Behaviors
{
public class ZoomBehavior : Behavior
{
private const float _scaleBy = 1.05f;

public ZoomBehavior(Diagram diagram) : base(diagram)
{
Diagram.Wheel += Diagram_Wheel;
Expand All @@ -18,9 +16,11 @@ private void Diagram_Wheel(WheelEventArgs e)
if (!Diagram.Options.Zoom.Enabled)
return;

var scale = Math.Clamp(Diagram.Options.Zoom.ScaleFactor, 1.01, 2);

var oldZoom = Diagram.Zoom;
var deltaY = Diagram.Options.Zoom.Inverse ? e.DeltaY * -1 : e.DeltaY;
var newZoom = deltaY > 0 ? oldZoom * _scaleBy : oldZoom / _scaleBy;
var newZoom = deltaY > 0 ? oldZoom * scale : oldZoom / scale;

if (newZoom < 0)
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Blazor.Diagrams.Core/DiagramOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class DiagramZoomOptions
public double Minimum { get; set; } = 0.1;
[Description("Maximum value allowed")]
public double Maximum { get; set; } = 2;
[Description("Zoom Scale Factor. Should be between 1.01 and 2. Default is 1.05.")]
public double ScaleFactor { get; set; } = 1.2;
}

public class DiagramGroupOptions
Expand Down

0 comments on commit 1ec1b67

Please sign in to comment.