Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WI00761833 - Updates for Blazor Diagrams mouse configuration #45

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Different Behaviors seems like a duplicate of the above section, Replacing a behavior. I think what we really want to document here is how to configure behaviors use DiagramBehaviorOptions which is a class we added. This class allows the user to configure some of the standard behaviors to be on different inputs. This is different to using a different behavior/replacing a behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with Matt if not sure how DiagramBehaviorOptions works.


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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not enable scroll on wheel behavior.
We need to use the diagram BehaviorOptions to configure what action scrolls the diagram. I think BehaviorOptions is what we need to document here.
e.g. to scroll on wheel for a diagram, use _diagram.BehaviorOptions.DiagramWheelBehavior = _diagram.GetBehavior<ScrollBehavior>();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

</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 @@
{
BlazorDiagram.SetContainer(await JSRuntime.GetBoundingClientRect(elementReference));
await JSRuntime.ObserveResizes(elementReference, _reference!);
await JSRuntime.AddDefaultPreventingHandler(elementReference);
Heathermcx marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -101,7 +102,7 @@
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.
Heathermcx marked this conversation as resolved.
Show resolved Hide resolved
{
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)
Heathermcx marked this conversation as resolved.
Show resolved Hide resolved
{
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.

Loading