|
| 1 | +@page "/" |
| 2 | + |
| 3 | +@using Syncfusion.Blazor.Diagram |
| 4 | +@using Syncfusion.Blazor.Buttons |
| 5 | +@inject IJSRuntime JS; |
| 6 | + |
| 7 | +<SfDiagramComponent @ref="@diagram" Created="created" Click="MouseEvent" Height="600px" InteractionController="@tool" Nodes="@nodes"> |
| 8 | +</SfDiagramComponent> |
| 9 | + |
| 10 | +@code |
| 11 | +{ |
| 12 | + public DiagramInteractions tool = DiagramInteractions.Default; |
| 13 | + private void MouseEvent(ClickEventArgs args) |
| 14 | + { |
| 15 | + if (args.Button == MouseButtons.Right) |
| 16 | + { |
| 17 | + tool = DiagramInteractions.ZoomPan; |
| 18 | + } |
| 19 | + } |
| 20 | + [JSInvokable] |
| 21 | + public void OnMouseWheel(double delta) |
| 22 | + { |
| 23 | + // Handle zoom in or out based on delta |
| 24 | + if (delta > 0) |
| 25 | + { |
| 26 | + diagram.Zoom(1 / 1.2, new DiagramPoint() { X = 100, Y = 100 }); |
| 27 | + } |
| 28 | + else |
| 29 | + { |
| 30 | + diagram.Zoom(1.2, new DiagramPoint() { X = 100, Y = 100 }); |
| 31 | + } |
| 32 | + } |
| 33 | + //Reference to diagram |
| 34 | + static SfDiagramComponent diagram; |
| 35 | + // Initialize diagram's node collection |
| 36 | + DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>(); |
| 37 | + [JSInvokable] |
| 38 | + public static void InvokeEvent(object e) |
| 39 | + { |
| 40 | + diagram.Zoom(1.2, new DiagramPoint() { X = 100, Y = 100 }); |
| 41 | + } |
| 42 | + private async Task created() |
| 43 | + { |
| 44 | + var id = diagram.ID; |
| 45 | + var dotNetRef = DotNetObjectReference.Create(this); |
| 46 | + await JSRuntimeExtensions.InvokeAsync<string>(JS, "WiredEvent", id, dotNetRef); |
| 47 | + } |
| 48 | + protected override void OnInitialized() |
| 49 | + { |
| 50 | + Node node1 = new Node() |
| 51 | + { |
| 52 | + ID = "node1", |
| 53 | + Width = 50, |
| 54 | + Height = 30, |
| 55 | + OffsetX = 500, |
| 56 | + OffsetY = 100, |
| 57 | + Shape = new BasicShape() { Type = NodeShapes.Basic, Shape = NodeBasicShapes.Rectangle }, |
| 58 | + Style = new ShapeStyle() { Fill = "#6495ED", StrokeColor = "#6495ED" } |
| 59 | + }; |
| 60 | + nodes.Add(node1); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments