Skip to content

Commit 9523308

Browse files
Merge pull request #130 from BalaVigneshRaviChandran/ES-940808-UserHandleUG
940808:UG sample for handing userhandle click event
2 parents 5f8bbe9 + ad44faf commit 9523308

27 files changed

+1230
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#UserHandle Sample
2+
3+
This sample demonstrates how to customize the click events of the user handles for the nodes and connectors.
4+
5+
Demo link:
6+
https://blazor.syncfusion.com/demos/diagramcomponent/userhandles?theme=fluent
7+
8+
## Prerequisites
9+
10+
* Visual Studio 2022
11+
12+
## How to run the project
13+
14+
* Checkout this project to a location in your disk.
15+
* Open the solution file using the Visual Studio 2022.
16+
* Restore the NuGet packages by rebuilding the solution.
17+
* Run the project.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@namespace UserHandleClickEvents
2+
<Router AppAssembly="@typeof(App).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
6+
</Found>
7+
<NotFound>
8+
<PageTitle>Not found</PageTitle>
9+
<LayoutView Layout="@typeof(MainLayout)">
10+
<p role="alert">Sorry, there's nothing at this address.</p>
11+
</LayoutView>
12+
</NotFound>
13+
</Router>
14+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
@page "/"
2+
3+
@using System.Collections.ObjectModel
4+
@using Syncfusion.Blazor.Diagram
5+
6+
<div>
7+
<SfDiagramComponent @ref="Diagram" Height="500px"
8+
Nodes="@nodes"
9+
Connectors="@connectors"
10+
SelectionSettings="@SelectedModel"
11+
GetCustomTool="GetCustomTool">
12+
<SnapSettings Constraints="SnapConstraints.None"></SnapSettings>
13+
</SfDiagramComponent>
14+
</div>
15+
16+
@code
17+
{
18+
public SfDiagramComponent Diagram;
19+
public DiagramObjectCollection<Node> nodes { get; set; }
20+
public DiagramObjectCollection<Connector> connectors { get; set; }
21+
// Defines diagram's SelectionSettings.
22+
DiagramSelectionSettings SelectedModel = new DiagramSelectionSettings();
23+
DiagramObjectCollection<UserHandle> UserHandles = new DiagramObjectCollection<UserHandle>();
24+
25+
protected override void OnInitialized()
26+
{
27+
nodes = new DiagramObjectCollection<Node>();
28+
connectors = new DiagramObjectCollection<Connector>();
29+
InitDiagramModel();
30+
}
31+
32+
public InteractionControllerBase GetCustomTool(DiagramElementAction action, string id)
33+
{
34+
return id == "clone" ? new CloneTool(Diagram) : new DeleteTool(Diagram);
35+
}
36+
37+
public class DeleteTool : InteractionControllerBase
38+
{
39+
SfDiagramComponent diagram;
40+
public DeleteTool(SfDiagramComponent diagram) : base(diagram) { this.diagram = diagram; }
41+
public override void OnMouseUp(DiagramMouseEventArgs args)
42+
{
43+
diagram.Delete();
44+
base.OnMouseUp(args);
45+
}
46+
}
47+
48+
public class CloneTool : DragController
49+
{
50+
SfDiagramComponent diagram;
51+
public CloneTool(SfDiagramComponent diagram) : base(diagram) { this.diagram = diagram; }
52+
public override void OnMouseDown(DiagramMouseEventArgs args)
53+
{
54+
diagram.Copy();
55+
diagram.Paste();
56+
base.OnMouseDown(args);
57+
}
58+
}
59+
60+
private void InitDiagramModel()
61+
{
62+
var node = new Node()
63+
{
64+
ID = "Node1",
65+
OffsetX = 300,
66+
OffsetY = 200,
67+
Width = 100,
68+
Height = 100,
69+
Style = new ShapeStyle() { Fill = "#6495ED", StrokeColor = "none" },
70+
Annotations = new DiagramObjectCollection<ShapeAnnotation>()
71+
{
72+
new ShapeAnnotation() { Content = "Node" }
73+
}
74+
};
75+
nodes.Add(node);
76+
77+
var connector = new Connector()
78+
{
79+
ID = "Connector1",
80+
SourcePoint = new DiagramPoint() { X = 500, Y = 150 },
81+
TargetPoint = new DiagramPoint() { X = 600, Y = 250 },
82+
Type = ConnectorSegmentType.Orthogonal,
83+
Annotations = new DiagramObjectCollection<PathAnnotation>()
84+
{
85+
new PathAnnotation(){ Content = "Connector" }
86+
}
87+
};
88+
connectors.Add(connector);
89+
var cloneHandle = new UserHandle()
90+
{
91+
Name = "clone",
92+
PathData = "M60.3,18H27.5c-3,0-5.5,2.4-5.5,5.5v38.2h5.5V23.5h32.7V18z M68.5,28.9h-30c-3,0-5.5,2.4-5.5,5.5v38.2c0,3,2.4,5.5,5.5,5.5h30c3,0,5.5-2.4,5.5-5.5V34.4C73.9,31.4,71.5,28.9,68.5,28.9z M68.5,72.5h-30V34.4h30V72.5z",
93+
Offset = 0,
94+
Side = Direction.Right,
95+
Visible = true,
96+
VisibleTarget = VisibleTarget.Node | VisibleTarget.Connector
97+
};
98+
var deleteHandle = new UserHandle()
99+
{
100+
Name = "delete",
101+
PathData = "M0.54700077,2.2130003 L7.2129992,2.2130003 7.2129992,8.8800011 C7.2129992,9.1920013 7.1049975,9.4570007 6.8879985,9.6739998 6.6709994,9.8910007 6.406,10 6.0939997,10 L1.6659999,10 C1.3539997,10 1.0890004,9.8910007 0.87200136,9.6739998 0.65500242,9.4570007 0.54700071,9.1920013 0.54700077,8.8800011 z M2.4999992,0 L5.2600006,0 5.8329986,0.54600048 7.7599996,0.54600048 7.7599996,1.6660004 0,1.6660004 0,0.54600048 1.9270014,0.54600048 z",
102+
Offset = 1,
103+
Side = Direction.Bottom,
104+
VisibleTarget = VisibleTarget.Node | VisibleTarget.Connector,
105+
Visible = true
106+
};
107+
UserHandles = new DiagramObjectCollection<UserHandle>()
108+
{
109+
cloneHandle, deleteHandle
110+
};
111+
SelectedModel = new DiagramSelectionSettings()
112+
{
113+
//Enable userhandle for selected model.
114+
Constraints = SelectorConstraints.UserHandle,
115+
116+
UserHandles = this.UserHandles
117+
};
118+
}
119+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
@namespace UserHandleClickEvents.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = "_Layout";
6+
}
7+
8+
<component type="typeof(App)" render-mode="ServerPrerendered" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@namespace UserHandleClickEvents.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<base href="~/" />
11+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
12+
<link href="css/site.css" rel="stylesheet" />
13+
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
14+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
15+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
16+
</head>
17+
<body>
18+
@RenderBody()
19+
20+
21+
22+
<script src="_framework/blazor.server.js"></script>
23+
</body>
24+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
using Microsoft.AspNetCore.Components;
3+
using Microsoft.AspNetCore.Components.Web;
4+
using Syncfusion.Blazor;
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
// Add services to the container.
9+
builder.Services.AddRazorPages();
10+
builder.Services.AddServerSideBlazor();
11+
builder.Services.AddSyncfusionBlazor();
12+
13+
var app = builder.Build();
14+
15+
// Configure the HTTP request pipeline.
16+
if (!app.Environment.IsDevelopment())
17+
{
18+
app.UseExceptionHandler("/Error");
19+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
20+
app.UseHsts();
21+
}
22+
23+
app.UseHttpsRedirection();
24+
25+
app.UseStaticFiles();
26+
27+
app.UseRouting();
28+
29+
app.MapBlazorHub();
30+
app.MapFallbackToPage("/_Host");
31+
32+
app.Run();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:11920",
7+
"sslPort": 44341
8+
}
9+
},
10+
"profiles": {
11+
"UserHandleClickEvents": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "https://localhost:7204;http://localhost:5236",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@namespace UserHandleClickEvents.Shared
2+
@inherits LayoutComponentBase
3+
4+
<PageTitle>UserHandleClickEvents</PageTitle>
5+
6+
<div class="page">
7+
<div class="sidebar">
8+
</div>
9+
10+
11+
<main>
12+
13+
<article class="content px-4">
14+
@Body
15+
</article>
16+
</main>
17+
</div>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.page {
2+
position: relative;
3+
display: flex;
4+
flex-direction: column;
5+
}
6+
7+
main {
8+
flex: 1;
9+
}
10+
11+
.sidebar {
12+
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
13+
}
14+
15+
.top-row {
16+
background-color: #f7f7f7;
17+
border-bottom: 1px solid #d6d5d5;
18+
justify-content: flex-end;
19+
height: 3.5rem;
20+
display: flex;
21+
align-items: center;
22+
}
23+
24+
.top-row ::deep a, .top-row .btn-link {
25+
white-space: nowrap;
26+
margin-left: 1.5rem;
27+
}
28+
29+
.top-row a:first-child {
30+
overflow: hidden;
31+
text-overflow: ellipsis;
32+
}
33+
34+
@media (max-width: 640.98px) {
35+
.top-row:not(.auth) {
36+
display: none;
37+
}
38+
39+
.top-row.auth {
40+
justify-content: space-between;
41+
}
42+
43+
.top-row a, .top-row .btn-link {
44+
margin-left: 0;
45+
}
46+
}
47+
48+
@media (min-width: 641px) {
49+
.page {
50+
flex-direction: row;
51+
}
52+
53+
.sidebar {
54+
width: 250px;
55+
height: 100vh;
56+
position: sticky;
57+
top: 0;
58+
}
59+
60+
.top-row {
61+
position: sticky;
62+
top: 0;
63+
z-index: 1;
64+
}
65+
66+
.top-row, article {
67+
padding-left: 2rem !important;
68+
padding-right: 1.5rem !important;
69+
}
70+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Blazor.Diagram" Version="*" />
11+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Folder Include="wwwroot\" />
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)