Skip to content

Commit

Permalink
WI00761833 - Updates for Blazor Diagrams mouse configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
shams-azam-wtg committed Jul 4, 2024
1 parent eddd879 commit cfa5fec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
14 changes: 14 additions & 0 deletions site/Site/Pages/Documentation/Diagram/Behaviors.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ Diagram.UnregisterBehavior<SelectionBehavior>();
Diagram.RegisterBehavior(new MySelectionBehavior(Diagram));
</code></pre>

<h2>Using Different Behaviors</h2>

You can use the following ways to add different behaviors to the diagram.

<h3>Scroll Behavior</h3>

<p>To scroll the diagram using the mouse wheel you can register the Scroll Behavior.</p>

<pre><code class="language-cs">
Diagram.UnregisterBehavior&lt;WheelBehavior&gt;();
Diagram.RegisterBehavior(new ScrollBehavior(Diagram));
</code></pre>


<NavigationButtons PreviousLink="/documentation/diagram"
PreviousTitle="Overview"
NextTitle="Ordering"
Expand Down
3 changes: 2 additions & 1 deletion src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
BlazorDiagram.SetContainer(await JSRuntime.GetBoundingClientRect(elementReference));
await JSRuntime.ObserveResizes(elementReference, _reference!);
await JSRuntime.AddDefaultPreventingHandler(elementReference);
}
}

Expand Down Expand Up @@ -101,7 +102,7 @@ private void OnKeyDown(KeyboardEventArgs e)
BlazorDiagram.TriggerKeyDown(e.ToCore());
}

private void OnWheel(WheelEventArgs e)
private async void OnWheel(WheelEventArgs e)

Check warning on line 105 in src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

View workflow job for this annotation

GitHub Actions / Build - Debug

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 105 in src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

View workflow job for this annotation

GitHub Actions / Build - Debug

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 105 in src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

View workflow job for this annotation

GitHub Actions / Build - Debug

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 105 in src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

View workflow job for this annotation

GitHub Actions / Build - Release

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
BlazorDiagram.TriggerWheel(e.ToCore());
}
Expand Down
5 changes: 5 additions & 0 deletions src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementRefe
{
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
}

public static async Task AddDefaultPreventingHandler(this IJSRuntime jsRuntime, ElementReference element)
{
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.addDefaultPreventingHandler", element, "wheel");
}
}
3 changes: 3 additions & 0 deletions src/Blazor.Diagrams/wwwroot/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ var s = {
}
delete s.tracked[id];
delete s.canvases[id];
},
addDefaultPreventingHandler: (element, eventName) => {
element.addEventListener(eventName, e => e.preventDefault(), { passive: false });
}
};
window.ZBlazorDiagrams = s;
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams/wwwroot/script.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cfa5fec

Please sign in to comment.