├── SpawnDev.BlazorJS.VisNetwork
├── _Imports.razor
├── Assets
│ └── icon-128.png
├── IVisNode.cs
├── NetworkPointerPoint.cs
├── IVisEdge.cs
├── VisNetworkView.razor
├── NetworkEventPointer.cs
├── NetworkZoomEvent.cs
├── NetworkDragEvent.cs
├── NetworkFocusEvent.cs
├── NetworkSelectEvent.cs
├── NetworkContextEvent.cs
├── VisFont.cs
├── VisNodeColor.cs
├── VisEdgeBackground.cs
├── VisEdgeArrows.cs
├── NodeDataSet.cs
├── EdgeDataSet.cs
├── NetworkEvent.cs
├── VisEdgeArrowOptions.cs
├── VisEdgeColor.cs
├── VisNetworkView.razor.css
├── SpawnDev.BlazorJS.VisNetwork.csproj
├── BarnesHutPhysicsOptions.cs
├── PhysicsOptions.cs
├── DataSet.cs
├── NetworkOptions.cs
├── VisEdge.cs
├── VisNode.cs
├── Network.cs
└── VisNetworkView.razor.cs
├── SpawnDev.BlazorJS.VisNetwork.Demo
├── wwwroot
│ ├── favicon.png
│ ├── icon-192.png
│ ├── github-mark-white.svg
│ ├── index.html
│ └── css
│ │ └── app.css
├── Layout
│ ├── MainLayout.razor
│ ├── NavMenu.razor
│ ├── MainLayout.razor.css
│ └── NavMenu.razor.css
├── _Imports.razor
├── App.razor
├── Program.cs
├── SpawnDev.BlazorJS.VisNetwork.Demo.csproj
├── Pages
│ └── Home.razor
└── Properties
│ └── launchSettings.json
├── README.md
├── LICENSE.txt
├── SpawnDev.BlazorJS.VisNetwork.sln
├── .gitattributes
└── .gitignore
/SpawnDev.BlazorJS.VisNetwork/_Imports.razor:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Components.Web
2 | @using SpawnDev.BlazorJS.VisNetwork
3 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/Assets/icon-128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LostBeard/SpawnDev.BlazorJS.VisNetwork/main/SpawnDev.BlazorJS.VisNetwork/Assets/icon-128.png
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LostBeard/SpawnDev.BlazorJS.VisNetwork/main/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/favicon.png
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LostBeard/SpawnDev.BlazorJS.VisNetwork/main/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/icon-192.png
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/IVisNode.cs:
--------------------------------------------------------------------------------
1 | namespace SpawnDev.BlazorJS.VisNetwork
2 | {
3 | public interface IVisNode
4 | {
5 | string Id { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkPointerPoint.cs:
--------------------------------------------------------------------------------
1 | namespace SpawnDev.BlazorJS.VisNetwork
2 | {
3 | public class NetworkPointerPoint
4 | {
5 | public double X { get; set; }
6 | public double Y { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/IVisEdge.cs:
--------------------------------------------------------------------------------
1 | namespace SpawnDev.BlazorJS.VisNetwork
2 | {
3 | public interface IVisEdge
4 | {
5 | string From { get; set; }
6 | string? Id { get; set; }
7 | string To { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisNetworkView.razor:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkEventPointer.cs:
--------------------------------------------------------------------------------
1 | namespace SpawnDev.BlazorJS.VisNetwork
2 | {
3 | public class NetworkEventPointer
4 | {
5 | public NetworkPointerPoint DOM { get; set; }
6 | public NetworkPointerPoint Canvas { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Layout/MainLayout.razor:
--------------------------------------------------------------------------------
1 | @inherits LayoutComponentBase
2 |
3 |
6 |
7 |
8 | @Body
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkZoomEvent.cs:
--------------------------------------------------------------------------------
1 | namespace SpawnDev.BlazorJS.VisNetwork
2 | {
3 | public class NetworkZoomEvent
4 | {
5 | public string Direction { get; set; } = "";
6 | public double Scale { get; set; }
7 | public NetworkPointerPoint Pointer { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkDragEvent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS.JSObjects;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | public class NetworkDragEvent : NetworkEvent
7 | {
8 | public NetworkDragEvent(IJSInProcessObjectReference _ref) : base(_ref) { }
9 | public DragEvent DragEvent => JSRef.Get("event");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkFocusEvent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS.JSObjects;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | public class NetworkFocusEvent : NetworkEvent
7 | {
8 | public NetworkFocusEvent(IJSInProcessObjectReference _ref) : base(_ref) { }
9 | public MouseEvent MouseEvent => JSRef.Get("event");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkSelectEvent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS.JSObjects;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | public class NetworkSelectEvent : NetworkEvent
7 | {
8 | public NetworkSelectEvent(IJSInProcessObjectReference _ref) : base(_ref) { }
9 | public DragEvent DragEvent => JSRef.Get("event");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkContextEvent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS.JSObjects;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | public class NetworkContextEvent : NetworkEvent
7 | {
8 | public NetworkContextEvent(IJSInProcessObjectReference _ref) : base(_ref) { }
9 | public MouseEvent DragEvent => JSRef.Get("event");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisFont.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | public class VisFont
6 | {
7 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8 | public string? Background { get; set; }
9 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
10 | public string? Color { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SpawnDev.BlazorJS.VisNetwork
2 |
3 | ## Vis.js Network for Blazor WASM
4 |
5 | #### References
6 | - [SpawnDev.BlazorJS](https://github.com/LostBeard/SpawnDev.BlazorJS)
7 | - [vis-network Repo](https://github.com/visjs/vis-network)
8 | - [Vis.js](https://visjs.org/)
9 | - [Vis.js Network Documentation](https://visjs.github.io/vis-network/docs/network/)
10 | - [Vis.js Network Examples](https://visjs.github.io/vis-network/examples/)
11 |
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisNodeColor.cs:
--------------------------------------------------------------------------------
1 | using SpawnDev.BlazorJS.JSObjects;
2 | using System.Drawing;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace SpawnDev.BlazorJS.VisNetwork
6 | {
7 | public class VisNodeColor
8 | {
9 |
10 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
11 | public string? Background { get; set; }
12 |
13 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
14 | public string? Border { get; set; }
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/_Imports.razor:
--------------------------------------------------------------------------------
1 | @using System.Net.Http
2 | @using System.Net.Http.Json
3 | @using Microsoft.AspNetCore.Components.Forms
4 | @using Microsoft.AspNetCore.Components.Routing
5 | @using Microsoft.AspNetCore.Components.Web
6 | @using Microsoft.AspNetCore.Components.Web.Virtualization
7 | @using Microsoft.AspNetCore.Components.WebAssembly.Http
8 | @using Microsoft.JSInterop
9 | @using SpawnDev.BlazorJS.VisNetwork
10 | @using SpawnDev.BlazorJS.VisNetwork.Demo
11 | @using SpawnDev.BlazorJS.VisNetwork.Demo.Layout
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/App.razor:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Not found
8 |
9 | Sorry, there's nothing at this address.
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisEdgeBackground.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | public class VisEdgeBackground
6 | {
7 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8 | public bool? Enabled { get; set; }
9 |
10 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
11 | public string? Color { get; set; }
12 |
13 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
14 | public int? Size { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Components.Web;
2 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
3 | using SpawnDev.BlazorJS;
4 | using SpawnDev.BlazorJS.VisNetwork.Demo;
5 |
6 | var builder = WebAssemblyHostBuilder.CreateDefault(args);
7 | builder.RootComponents.Add("#app");
8 | builder.RootComponents.Add("head::after");
9 | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
10 | builder.Services.AddBlazorJSRuntime();
11 | await builder.Build().RunAsync();
12 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/SpawnDev.BlazorJS.VisNetwork.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | enable
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/github-mark-white.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | SpawnDev.BlazorJS.VisNetwork.Demo
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | An unhandled error has occurred.
26 |
Reload
27 |
🗙
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisEdgeArrows.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | ///
6 | /// VisEdge arrows options
7 | ///
8 | public class VisEdgeArrows
9 | {
10 | ///
11 | /// When true, an arrowhead on the 'to' side of the edge is drawn, pointing to the 'to' node with default settings. To customize the size of the arrow, supply an object.
12 | ///
13 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
14 | public VisEdgeArrowOptions? To { get; set; }
15 | ///
16 | /// Similar to the 'to' object, but with an arrowhead in the center of the edge. The direction of the arrow can be flipped by using a negative value for arrows.middle.scaleFactor.
17 | ///
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
19 | public VisEdgeArrowOptions? Middle { get; set; }
20 | ///
21 | /// Exactly the same as the to object but with an arrowhead at the from node of the edge.
22 | ///
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
24 | public VisEdgeArrowOptions? From { get; set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NodeDataSet.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace SpawnDev.BlazorJS.VisNetwork
6 | {
7 | //public class NodeDataSet : JSObject
8 | //{
9 | // public NodeDataSet(IJSInProcessObjectReference _ref) : base(_ref) { }
10 | // public NodeDataSet(List nodes) : base(JS.New("vis.DataSet", nodes)) { }
11 | // public NodeDataSet() : base(JS.New("vis.DataSet", new List())) { }
12 | // public List GetIds() => JSRef.Call>("getIds");
13 | // public void Clear() => JSRef.CallVoid("clear");
14 | // public List Add(VisNode node) => JSRef.Call>("add", node);
15 | // public List Add(List nodes) => JSRef.Call>("add", nodes);
16 | // public List Update(VisNode node) => JSRef.Call>("update", node);
17 | // public List Update(List nodes) => JSRef.Call>("update", nodes);
18 | // public List Remove(List ids) => JSRef.Call>("remove", ids);
19 | // public List Remove(string id) => JSRef.Call>("remove", id);
20 | // public VisNode? Get(string id) => JSRef.Call("get", id);
21 | //}
22 | }
23 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Pages/Home.razor:
--------------------------------------------------------------------------------
1 | @page "/"
2 |
3 |
4 |
5 |
SpawnDev.BlazorJS.VisNetwork
6 |
7 |
8 |
9 |
10 |
11 |
12 | @code {
13 | bool firstUpdate = true;
14 | void OnNetVisReady(VisNetworkView visNetwork)
15 | {
16 | visNetwork.Nodes!.Add(new List
17 | {
18 | new VisNode{ Id = "1", Label = "Node 1" },
19 | new VisNode{ Id = "2", Label = "Node 2" },
20 | new VisNode{ Id = "3", Label = "Node 3" },
21 | new VisNode{ Id = "4", Label = "Node 4" },
22 | new VisNode{ Id = "5", Label = "Node 5" },
23 | });
24 | visNetwork.Edges!.Add(new List
25 | {
26 | new VisEdge{ From = "1", To = "3" },
27 | new VisEdge{ From = "1", To = "2" },
28 | new VisEdge{ From = "2", To = "4" },
29 | new VisEdge{ From = "2", To = "5" },
30 | new VisEdge{ From = "3", To = "5" },
31 | });
32 | }
33 | }
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/EdgeDataSet.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace SpawnDev.BlazorJS.VisNetwork
6 | {
7 |
8 | public class EdgeDataSet : JSObject
9 | {
10 | public VisEdge this[string id]
11 | {
12 | get => Get(id);
13 | }
14 | public EdgeDataSet(IJSInProcessObjectReference _ref) : base(_ref) { }
15 | public EdgeDataSet(List edges) : base(JS.New("vis.DataSet", edges)) { }
16 | public EdgeDataSet() : base(JS.New("vis.DataSet", new List())) { }
17 | public List GetIds() => JSRef.Call>("getIds");
18 | public void Clear() => JSRef.CallVoid("clear");
19 | public List Add(VisEdge edge) => JSRef.Call>("add", edge);
20 | public List Add(List edges) => JSRef.Call>("add", edges);
21 | public List Update(VisEdge edge) => JSRef.Call>("update", edge);
22 | public List Update(List edges) => JSRef.Call>("update", edges);
23 | public List Remove(List ids) => JSRef.Call>("remove", ids);
24 | public List Remove(string id) => JSRef.Call>("remove", id);
25 | public VisEdge Get(string id) => JSRef.Call("get", id);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Layout/NavMenu.razor:
--------------------------------------------------------------------------------
1 |
9 |
10 |
26 |
27 | @code {
28 | private bool collapseNavMenu = true;
29 |
30 | private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
31 |
32 | private void ToggleNavMenu()
33 | {
34 | collapseNavMenu = !collapseNavMenu;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkEvent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using SpawnDev.BlazorJS.JSObjects;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | ///
7 | /// A common network event object
8 | ///
9 | public class NetworkEvent : JSObject
10 | {
11 | ///
12 | /// Deserialization constructor
13 | ///
14 | ///
15 | public NetworkEvent(IJSInProcessObjectReference _ref) : base(_ref) { }
16 | ///
17 | /// Edges related to this event
18 | ///
19 | public List Edges => JSRef!.Get>("edges");
20 | ///
21 | /// Event
22 | ///
23 | public Event Event => JSRef!.Get("event");
24 | ///
25 | /// Return the event property as type T
26 | ///
27 | public T EventAs() => JSRef!.Get("event");
28 | ///
29 | /// Items related to this event
30 | ///
31 | public JSObject Items => JSRef!.Get("items");
32 | ///
33 | /// Nodes related to this event
34 | ///
35 | public List Nodes => JSRef!.Get>("nodes");
36 | ///
37 | /// Pointer information for this event
38 | ///
39 | public NetworkEventPointer Pointer => JSRef!.Get("pointer");
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:55461",
8 | "sslPort": 44362
9 | }
10 | },
11 | "profiles": {
12 | "http": {
13 | "commandName": "Project",
14 | "dotnetRunMessages": true,
15 | "launchBrowser": true,
16 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17 | "applicationUrl": "http://localhost:5161",
18 | "environmentVariables": {
19 | "ASPNETCORE_ENVIRONMENT": "Development"
20 | }
21 | },
22 | "https": {
23 | "commandName": "Project",
24 | "dotnetRunMessages": true,
25 | "launchBrowser": true,
26 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
27 | "applicationUrl": "https://localhost:7117;http://localhost:5161",
28 | "environmentVariables": {
29 | "ASPNETCORE_ENVIRONMENT": "Development"
30 | }
31 | },
32 | "IIS Express": {
33 | "commandName": "IISExpress",
34 | "launchBrowser": true,
35 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
36 | "environmentVariables": {
37 | "ASPNETCORE_ENVIRONMENT": "Development"
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 18
4 | VisualStudioVersion = 18.0.11205.157 d18.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpawnDev.BlazorJS.VisNetwork", "SpawnDev.BlazorJS.VisNetwork\SpawnDev.BlazorJS.VisNetwork.csproj", "{B7D7FBD3-B2BA-4E35-8040-61204F9EFAB8}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpawnDev.BlazorJS.VisNetwork.Demo", "SpawnDev.BlazorJS.VisNetwork.Demo\SpawnDev.BlazorJS.VisNetwork.Demo.csproj", "{4DE26F99-D162-41BC-BD8F-B62DE79FA2CD}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B7D7FBD3-B2BA-4E35-8040-61204F9EFAB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {B7D7FBD3-B2BA-4E35-8040-61204F9EFAB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {B7D7FBD3-B2BA-4E35-8040-61204F9EFAB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {B7D7FBD3-B2BA-4E35-8040-61204F9EFAB8}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {4DE26F99-D162-41BC-BD8F-B62DE79FA2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {4DE26F99-D162-41BC-BD8F-B62DE79FA2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {4DE26F99-D162-41BC-BD8F-B62DE79FA2CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {4DE26F99-D162-41BC-BD8F-B62DE79FA2CD}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {382E0C46-886F-455C-9E74-FABC05FA16EA}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisEdgeArrowOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | public class VisEdgeArrowOptions
6 | {
7 | ///
8 | /// When true, an arrowhead on the 'to' side of the edge is drawn, pointing to the 'to' node with default settings. To customize the size of the arrow, supply an object.
9 | ///
10 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
11 | public bool? Enabled { get; set; }
12 | ///
13 | /// The height of the image arrow. The height of the image file is used if this isn't defined.
14 | ///
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
16 | public float? ImageHeight { get; set; }
17 | ///
18 | /// The width of the image arrow. The width of the image file is used if this isn't defined.
19 | ///
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21 | public float? ImageWidth { get; set; }
22 | ///
23 | /// The scale factor allows you to change the size of the arrowhead.
24 | ///
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26 | public float? ScaleFactor { get; set; }
27 | ///
28 | /// The URL for the image arrow type.
29 | ///
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
31 | public string? Src { get; set; }
32 | ///
33 | /// The type of endpoint. Possible values are: arrow, bar, circle and image. The default is arrow
34 | ///
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
36 | public string? Type { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Layout/MainLayout.razor.css:
--------------------------------------------------------------------------------
1 | .page {
2 | position: relative;
3 | display: flex;
4 | flex-direction: column;
5 | }
6 |
7 | main {
8 | flex: 1;
9 | position: relative;
10 | }
11 |
12 | article {
13 | width: 100%;
14 | height: 100%;
15 | position: absolute;
16 | }
17 |
18 | .sidebar {
19 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
20 | }
21 |
22 | .top-row {
23 | background-color: #f7f7f7;
24 | border-bottom: 1px solid #d6d5d5;
25 | justify-content: flex-end;
26 | height: 3.5rem;
27 | display: flex;
28 | align-items: center;
29 | }
30 |
31 | .top-row ::deep a, .top-row ::deep .btn-link {
32 | white-space: nowrap;
33 | margin-left: 1.5rem;
34 | text-decoration: none;
35 | }
36 |
37 | .top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
38 | text-decoration: underline;
39 | }
40 |
41 | .top-row ::deep a:first-child {
42 | overflow: hidden;
43 | text-overflow: ellipsis;
44 | }
45 |
46 | @media (max-width: 640.98px) {
47 | .top-row {
48 | justify-content: space-between;
49 | }
50 |
51 | .top-row ::deep a, .top-row ::deep .btn-link {
52 | margin-left: 0;
53 | }
54 | }
55 |
56 | @media (min-width: 641px) {
57 | .page {
58 | flex-direction: row;
59 | }
60 |
61 | .sidebar {
62 | width: 250px;
63 | height: 100vh;
64 | position: sticky;
65 | top: 0;
66 | }
67 |
68 | .top-row {
69 | position: sticky;
70 | top: 0;
71 | z-index: 1;
72 | }
73 |
74 | .top-row.auth ::deep a:first-child {
75 | flex: 1;
76 | text-align: right;
77 | width: 0;
78 | }
79 |
80 | .top-row, article {
81 | padding-left: 2rem !important;
82 | padding-right: 1.5rem !important;
83 | }
84 | }
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisEdgeColor.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | ///
6 | /// Color options for VisEdge
7 | ///
8 | public class VisEdgeColor
9 | {
10 | ///
11 | /// The color of the edge when it is not selected or hovered over (assuming hover is enabled in the interaction module).
12 | ///
13 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
14 | public string? Color { get; set; }
15 | ///
16 | /// The color the edge when it is selected.
17 | ///
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
19 | public string? Highlight { get; set; }
20 | ///
21 | /// The color the edge when the mouse hovers over it (assuming hover is enabled in the interaction module).
22 | ///
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
24 | public string? Hover { get; set; }
25 | ///
26 | /// When color, highlight or hover are defined, inherit is set to false!
27 | /// Supported options are: true, false, 'from','to','both'.
28 | /// The default value is 'from' which does the same as true: the edge will inherit the color from the border of the node on the 'from' side.
29 | /// When set to 'to', the border color from the 'to' node will be used.
30 | /// When set to 'both', the color will fade from the from color to the to color. 'both' is computationally intensive because the gradient is recomputed every redraw.This is required because the angles change when the nodes move.
31 | ///
32 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
33 | public string? Inherit { get; set; }
34 | ///
35 | /// It can be useful to set the opacity of an edge without manually changing all the colors. The opacity option will convert all colors (also when using inherit) to adhere to the supplied opacity. The allowed range of the opacity option is between 0 and 1. This is only done once so the performance impact is not too big.
36 | ///
37 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
38 | public float? Opacity { get; set; }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisNetworkView.razor.css:
--------------------------------------------------------------------------------
1 | .lds-spinner {
2 | color: white;
3 | display: inline-block;
4 | position: relative;
5 | width: 80px;
6 | height: 80px;
7 | left: 50%;
8 | top: 50%;
9 | margin: -40px 0 0 -40px;
10 | }
11 |
12 | .lds-spinner div {
13 | transform-origin: 40px 40px;
14 | animation: lds-spinner 1.2s linear infinite;
15 | }
16 |
17 | .lds-spinner div:after {
18 | content: " ";
19 | display: block;
20 | position: absolute;
21 | top: 3px;
22 | left: 37px;
23 | width: 6px;
24 | height: 18px;
25 | border-radius: 20%;
26 | background: #fff;
27 | }
28 |
29 | .lds-spinner div:nth-child(1) {
30 | transform: rotate(0deg);
31 | animation-delay: -1.1s;
32 | }
33 |
34 | .lds-spinner div:nth-child(2) {
35 | transform: rotate(30deg);
36 | animation-delay: -1s;
37 | }
38 |
39 | .lds-spinner div:nth-child(3) {
40 | transform: rotate(60deg);
41 | animation-delay: -0.9s;
42 | }
43 |
44 | .lds-spinner div:nth-child(4) {
45 | transform: rotate(90deg);
46 | animation-delay: -0.8s;
47 | }
48 |
49 | .lds-spinner div:nth-child(5) {
50 | transform: rotate(120deg);
51 | animation-delay: -0.7s;
52 | }
53 |
54 | .lds-spinner div:nth-child(6) {
55 | transform: rotate(150deg);
56 | animation-delay: -0.6s;
57 | }
58 |
59 | .lds-spinner div:nth-child(7) {
60 | transform: rotate(180deg);
61 | animation-delay: -0.5s;
62 | }
63 |
64 | .lds-spinner div:nth-child(8) {
65 | transform: rotate(210deg);
66 | animation-delay: -0.4s;
67 | }
68 |
69 | .lds-spinner div:nth-child(9) {
70 | transform: rotate(240deg);
71 | animation-delay: -0.3s;
72 | }
73 |
74 | .lds-spinner div:nth-child(10) {
75 | transform: rotate(270deg);
76 | animation-delay: -0.2s;
77 | }
78 |
79 | .lds-spinner div:nth-child(11) {
80 | transform: rotate(300deg);
81 | animation-delay: -0.1s;
82 | }
83 |
84 | .lds-spinner div:nth-child(12) {
85 | transform: rotate(330deg);
86 | animation-delay: 0s;
87 | }
88 |
89 | @keyframes lds-spinner {
90 | 0% {
91 | opacity: 1;
92 | }
93 |
94 | 100% {
95 | opacity: 0;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/SpawnDev.BlazorJS.VisNetwork.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0;net7.0;net8.0;net9.0;net10.0
5 | enable
6 | enable
7 | 1.8.1
8 | True
9 | true
10 | true
11 | Embedded
12 | SpawnDev.BlazorJS.VisNetwork
13 | LostBeard
14 | VisNetwork in Blazor WebAssembly
15 | https://github.com/LostBeard/SpawnDev.BlazorJS.VisNetwork
16 | README.md
17 | LICENSE.txt
18 | icon-128.png
19 | https://github.com/LostBeard/SpawnDev.BlazorJS.VisNetwork.git
20 | git
21 | Blazor;VisNetwork;DataVisualization
22 | latest
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/Layout/NavMenu.razor.css:
--------------------------------------------------------------------------------
1 | .navbar-toggler {
2 | background-color: rgba(255, 255, 255, 0.1);
3 | }
4 |
5 | .top-row {
6 | height: 3.5rem;
7 | background-color: rgba(0,0,0,0.4);
8 | }
9 |
10 | .navbar-brand {
11 | font-size: 1.1rem;
12 | }
13 |
14 | .bi {
15 | display: inline-block;
16 | position: relative;
17 | width: 1.25rem;
18 | height: 1.25rem;
19 | margin-right: 0.75rem;
20 | top: -1px;
21 | background-size: cover;
22 | }
23 |
24 | .bi-house-door-fill-nav-menu {
25 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
26 | }
27 |
28 | .bi-plus-square-fill-nav-menu {
29 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
30 | }
31 |
32 | .bi-list-nested-nav-menu {
33 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
34 | }
35 |
36 | .nav-item {
37 | font-size: 0.9rem;
38 | padding-bottom: 0.5rem;
39 | }
40 |
41 | .nav-item:first-of-type {
42 | padding-top: 1rem;
43 | }
44 |
45 | .nav-item:last-of-type {
46 | padding-bottom: 1rem;
47 | }
48 |
49 | .nav-item ::deep a {
50 | color: #d7d7d7;
51 | border-radius: 4px;
52 | height: 3rem;
53 | display: flex;
54 | align-items: center;
55 | line-height: 3rem;
56 | }
57 |
58 | .nav-item ::deep a.active {
59 | background-color: rgba(255,255,255,0.37);
60 | color: white;
61 | }
62 |
63 | .nav-item ::deep a:hover {
64 | background-color: rgba(255,255,255,0.1);
65 | color: white;
66 | }
67 |
68 | @media (min-width: 641px) {
69 | .navbar-toggler {
70 | display: none;
71 | }
72 |
73 | .collapse {
74 | /* Never collapse the sidebar for wide screens */
75 | display: block;
76 | }
77 |
78 | .nav-scrollable {
79 | /* Allow sidebar to scroll for tall menus */
80 | height: calc(100vh - 3.5rem);
81 | overflow-y: auto;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/BarnesHutPhysicsOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | ///
6 | /// BarnesHut physics options
7 | /// https://visjs.github.io/vis-network/docs/network/physics.html#
8 | ///
9 | public class BarnesHutPhysicsOptions
10 | {
11 | ///
12 | /// This parameter determines the boundary between consolidated long range forces and individual short range forces. To oversimplify higher values are faster but generate more errors, lower values are slower but with less errors.
13 | /// Default: 0.5
14 | ///
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
16 | public double? Theta { get; set; }
17 | ///
18 | /// Gravity attracts. We like repulsion. So the value is negative. If you want the repulsion to be stronger, decrease the value (so -10000, -50000).
19 | /// Default: -2000
20 | ///
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
22 | public double? GravitationalConstant { get; set; }
23 | ///
24 | /// There is a central gravity attractor to pull the entire network back to the center.
25 | /// Default: 0.3
26 | ///
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
28 | public double? CentralGravity { get; set; }
29 | ///
30 | /// The edges are modelled as springs. This springLength here is the rest length of the spring.
31 | /// Default: 95
32 | ///
33 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
34 | public double? SpringLength { get; set; }
35 | ///
36 | /// This is how 'sturdy' the springs are. Higher values mean stronger springs.
37 | /// Default: 0.04
38 | ///
39 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
40 | public double? SpringConstant { get; set; }
41 | ///
42 | /// Accepted range: [0 .. 1]. The damping factor is how much of the velocity from the previous physics simulation iteration carries over to the next iteration.
43 | /// Default: 0.09
44 | ///
45 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
46 | public double? Damping { get; set; }
47 | ///
48 | /// Accepted range: [0 .. 1]. When larger than 0, the size of the node is taken into account. The distance will be calculated from the radius of the encompassing circle of the node for both the gravity model. Value 1 is maximum overlap avoidance.
49 | /// Default: 0
50 | ///
51 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
52 | public double? AvoidOverlap { get; set; }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/PhysicsOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | ///
6 | /// Handles the physics simulation, moving the nodes and edges to show them clearly.
7 | /// https://visjs.github.io/vis-network/docs/network/physics.html
8 | ///
9 | public class PhysicsOptions
10 | {
11 | ///
12 | /// Toggle the physics system on or off. This property is optional. If you define any of the options below and enabled is undefined, this will be set to true.
13 | /// Default: true
14 | ///
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
16 | public bool? Enabled { get; set; }
17 | ///
18 | /// BarnesHut is a quadtree based gravity model. This is the fastest, default and recommended solver for non-hierarchical layouts
19 | ///
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21 | public BarnesHutPhysicsOptions? BarnesHut { get; set; }
22 | ///
23 | /// The physics module limits the maximum velocity of the nodes to increase the time to stabilization. This is the maximum value.
24 | /// Default: 50
25 | ///
26 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
27 | public double? MaxVelocity { get; set; }
28 | ///
29 | /// Once the minimum velocity is reached for all nodes, we assume the network has been stabilized and the simulation stops.
30 | /// Default: 0.1
31 | ///
32 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
33 | public double? MinVelocity { get; set; }
34 | ///
35 | /// You can select your own solver.
36 | /// Possible options: 'barnesHut', 'repulsion', 'hierarchicalRepulsion', 'forceAtlas2Based'.
37 | /// When setting the hierarchical layout, the hierarchical repulsion solver is automatically selected, regardless of what you fill in here.
38 | /// Default: 'barnesHut'
39 | ///
40 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
41 | public string? Solver { get; set; }
42 | ///
43 | /// The physics simulation is discrete. This means we take a step in time, calculate the forces, move the nodes and take another step. If you increase this number the steps will be too large and the network can get unstable. If you see a lot of jittery movement in the network, you may want to reduce this value a little.
44 | /// Default: 0.5
45 | ///
46 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
47 | public double? TimeStep { get; set; }
48 | ///
49 | /// If this is enabled, the timestep will intelligently be adapted (only during the stabilization stage if stabilization is enabled!) to greatly decrease stabilization times. The timestep configured above is taken as the minimum timestep. This can be further improved by using the improvedLayout algorithm.
50 | /// Default: true
51 | ///
52 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
53 | public bool? AdaptiveTimestep { get; set; }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/DataSet.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | ///
6 | /// Vis.js comes with a flexible DataSet, which can be used to hold and
7 | /// manipulate unstructured data and listen for changes in the data.The DataSet
8 | /// is key/value based. Data items can be added, updated and removed from the
9 | /// DataSet, and one can subscribe to changes in the DataSet. The data in the
10 | /// DataSet can be filtered and ordered.Data can be normalized when appending it
11 | /// to the DataSet as well.
12 | /// https://github.com/visjs/vis-data/blob/master/src/data-set.ts
13 | ///
14 | public class DataSet : JSObject
15 | {
16 | public DataSet(IJSInProcessObjectReference _ref) : base(_ref) { }
17 | public DataSet() : base(JS.New("vis.DataSet")) { }
18 | public DataSet(List nodes) : base(JS.New("vis.DataSet", nodes)) { }
19 | public DataSet(List edges) : base(JS.New("vis.DataSet", edges)) { }
20 | public List GetIds() => JSRef.Call>("getIds");
21 | public void Clear() => JSRef.CallVoid("clear");
22 | public List Add(VisEdge edge) => JSRef.Call>("add", edge);
23 | public List Add(List edges) => JSRef.Call>("add", edges);
24 | public List Add(VisNode node) => JSRef.Call>("add", node);
25 | public List Add(List nodes) => JSRef.Call>("add", nodes);
26 | public List Update(VisEdge edge) => JSRef.Call>("update", edge);
27 | public List Update(List edges) => JSRef.Call>("update", edges);
28 | public List Update(VisNode node) => JSRef.Call>("update", node);
29 | public List Update(List nodes) => JSRef.Call>("update", nodes);
30 | public List Remove(List ids) => JSRef.Call>("remove", ids);
31 | public List Remove(string id) => JSRef.Call>("remove", id);
32 | public T Get(string id) => JSRef.Call("get", id);
33 | public int Length => JSRef.Get("length");
34 | }
35 | public class DataSet : JSObject
36 | {
37 | public DataSet(IJSInProcessObjectReference _ref) : base(_ref) { }
38 | public DataSet() : base(JS.New("vis.DataSet")) { }
39 | public DataSet(List items) : base(JS.New("vis.DataSet", items)) { }
40 | public List GetIds() => JSRef.Call>("getIds");
41 | public void Clear() => JSRef.CallVoid("clear");
42 | public List Add(T item) => JSRef.Call>("add", item);
43 | public List Add(List items) => JSRef.Call>("add", items);
44 | public List Update(T item) => JSRef.Call>("update", item);
45 | public List Update(List items) => JSRef.Call>("update", items);
46 | public List Remove(List ids) => JSRef.Call>("remove", ids);
47 | public List Remove(string id) => JSRef.Call>("remove", id);
48 | public T Get(string id) => JSRef.Call("get", id);
49 | public int Length => JSRef.Get("length");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork.Demo/wwwroot/css/app.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
3 | }
4 |
5 | h1:focus {
6 | outline: none;
7 | }
8 |
9 | a, .btn-link {
10 | color: #0071c1;
11 | }
12 |
13 | .btn-primary {
14 | color: #fff;
15 | background-color: #1b6ec2;
16 | border-color: #1861ac;
17 | }
18 |
19 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
20 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
21 | }
22 |
23 | .content {
24 | padding-top: 1.1rem;
25 | }
26 |
27 | .valid.modified:not([type=checkbox]) {
28 | outline: 1px solid #26b050;
29 | }
30 |
31 | .invalid {
32 | outline: 1px solid red;
33 | }
34 |
35 | .validation-message {
36 | color: red;
37 | }
38 |
39 | #blazor-error-ui {
40 | background: lightyellow;
41 | bottom: 0;
42 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
43 | display: none;
44 | left: 0;
45 | padding: 0.6rem 1.25rem 0.7rem 1.25rem;
46 | position: fixed;
47 | width: 100%;
48 | z-index: 1000;
49 | }
50 |
51 | #blazor-error-ui .dismiss {
52 | cursor: pointer;
53 | position: absolute;
54 | right: 0.75rem;
55 | top: 0.5rem;
56 | }
57 |
58 | .blazor-error-boundary {
59 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
60 | padding: 1rem 1rem 1rem 3.7rem;
61 | color: white;
62 | }
63 |
64 | .blazor-error-boundary::after {
65 | content: "An error has occurred."
66 | }
67 |
68 | .loading-progress {
69 | position: relative;
70 | display: block;
71 | width: 8rem;
72 | height: 8rem;
73 | margin: 20vh auto 1rem auto;
74 | }
75 |
76 | .loading-progress circle {
77 | fill: none;
78 | stroke: #e0e0e0;
79 | stroke-width: 0.6rem;
80 | transform-origin: 50% 50%;
81 | transform: rotate(-90deg);
82 | }
83 |
84 | .loading-progress circle:last-child {
85 | stroke: #1b6ec2;
86 | stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
87 | transition: stroke-dasharray 0.05s ease-in-out;
88 | }
89 |
90 | .loading-progress-text {
91 | position: absolute;
92 | text-align: center;
93 | font-weight: bold;
94 | inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
95 | }
96 |
97 | .loading-progress-text:after {
98 | content: var(--blazor-load-percentage-text, "Loading");
99 | }
100 |
101 | code {
102 | color: #c02d76;
103 | }
104 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/NetworkOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | public class NetworkData
6 | {
7 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8 | public DataSet? Nodes { get; set; }
9 |
10 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
11 | public DataSet? Edges { get; set; }
12 | }
13 |
14 | //https://visjs.github.io/vis-network/docs/network/
15 | public class NetworkOptions
16 | {
17 | ///
18 | /// If true, the Network will automatically detect when its container is resized, and redraw itself accordingly. If false, the Network can be forced to repaint after its container has been resized using the function redraw() and setSize().
19 | ///
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21 | public bool? AutoResize { get; set; }
22 | ///
23 | /// the width of the canvas. Can be in percentages or pixels (ie. '400px').
24 | ///
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26 | public string? Width { get; set; }
27 | ///
28 | /// the height of the canvas. Can be in percentages or pixels (ie. '400px').
29 | ///
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
31 | public string? Height { get; set; }
32 | ///
33 | /// Options for nodes
34 | ///
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
36 | public NetworkNodeOptions? Nodes { get; set; }
37 | ///
38 | /// Options for edges
39 | ///
40 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
41 | public NetworkEdgeOptions? Edges { get; set; }
42 | ///
43 | /// All options in this object are explained in the physics module.
44 | ///
45 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
46 | public PhysicsOptions? Physics { get; set; }
47 | }
48 |
49 | public class NetworkNodeOptions
50 | {
51 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
52 | public int? BorderWidth { get; set; }
53 |
54 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
55 | public int? Size { get; set; }
56 |
57 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
58 | public NodeColorOptions? Color { get; set; }
59 |
60 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
61 | public NodeFontOptions? Font { get; set; }
62 |
63 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
64 | public bool? Shadow { get; set; }
65 |
66 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
67 | public string? Shape { get; set; }
68 | }
69 |
70 | public class NodeColorOptions
71 | {
72 |
73 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
74 | public string? Border { get; set; }
75 |
76 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
77 | public string? Background { get; set; }
78 | }
79 |
80 | public class NodeFontOptions
81 | {
82 |
83 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
84 | public string? Border { get; set; }
85 |
86 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
87 | public string? Background { get; set; }
88 | }
89 |
90 | public class NetworkEdgeOptions
91 | {
92 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
93 | public string? Color { get; set; }
94 |
95 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
96 | public bool? Shadow { get; set; }
97 |
98 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
99 | public int? Width { get; set; }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisEdge.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.Metrics;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | ///
7 | /// vis-network edge options
8 | /// https://visjs.github.io/vis-network/docs/network/edges.html
9 | ///
10 | public class VisEdge : IVisEdge
11 | {
12 | ///
13 | /// Arrows options
14 | ///
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
16 | public VisEdgeArrows? Arrows { get; set; }
17 | ///
18 | /// Title to be displayed in a pop-up when the user hovers over the edge. The title can be an HTML element or a string containing plain text. See HTML in titles example if you want to parse HTML.
19 | ///
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21 | public string? Title { get; set; }
22 | ///
23 | /// Edges are between two nodes, one to and one from. This is where you define the from node. You have to supply the corresponding node ID. This naturally only applies to individual edges.
24 | ///
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26 | public string? From { get; set; }
27 | ///
28 | /// Edges are between two nodes, one to and one from. This is where you define the to node. You have to supply the corresponding node ID. This naturally only applies to individual edges.
29 | ///
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
31 | public string? To { get; set; }
32 | ///
33 | /// The id of the edge. The id is optional for edges. When not supplied, an UUID will be assigned to the edge. This naturally only applies to individual edges.
34 | ///
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
36 | public string? Id { get; set; }
37 | ///
38 | /// Edge font
39 | ///
40 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
41 | public VisFont? Font { get; set; }
42 | ///
43 | /// The label of the edge. HTML does not work in here because the network uses HTML5 Canvas.
44 | ///
45 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
46 | public string? Label { get; set; }
47 | ///
48 | /// When true, the edge will be drawn as a dashed line. You can customize the dashes by supplying an Array. Array formart: Array of numbers, gap length, dash length, gap length, dash length, ... etc. The array is repeated until the distance is filled. When using dashed lines in IE versions older than 11, the line will be drawn straight, not smooth.
49 | ///
50 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
51 | public bool? Dashes { get; set; }
52 | ///
53 | /// Edge background options
54 | ///
55 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
56 | public VisEdgeBackground? Background { get; set; }
57 | ///
58 | /// Edge color options
59 | ///
60 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
61 | public VisEdgeColor? Color { get; set; }
62 | ///
63 | /// Optional tag string
64 | ///
65 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
66 | public string? Tag { get; set; }
67 | ///
68 | /// The width of the edge. If value is set, this is not used.
69 | ///
70 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
71 | public float? Width { get; set; }
72 | ///
73 | /// When true, the edge is part of the physics simulation. When false, it will not act as a spring.
74 | ///
75 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
76 | public bool? Physics { get; set; }
77 | ///
78 | /// The physics simulation gives edges a spring length. This value can override the length of the spring in rest.
79 | ///
80 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
81 | public float? Length { get; set; }
82 | ///
83 | /// When true, the edge is not drawn. It is part still part of the physics simulation however!
84 | ///
85 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
86 | public bool? Hidden { get; set; }
87 | ///
88 | /// When true, the edge is drawn as a dynamic quadratic bezier curve.
89 | /// The drawing of these curves takes longer than that of straight
90 | /// curves but it looks better.There is a difference between dynamic
91 | /// smooth curves and static smooth curves.The dynamic smooth curves
92 | /// have an invisible support node that takes part in the physics
93 | /// simulation.If you have a lot of edges, you may want to consider
94 | /// picking a different type of smooth curves than dynamic for better
95 | /// performance.
96 | ///
97 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
98 | public bool? Smooth { get; set; }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace SpawnDev.BlazorJS.VisNetwork
5 | {
6 | ///
7 | /// vis-network node options
8 | /// https://visjs.github.io/vis-network/docs/network/nodes.html
9 | ///
10 | public class VisNode : IVisNode
11 | {
12 | ///
13 | /// Title to be displayed in a pop-up when the user hovers over the node. The title can be an HTML element or a string containing plain text. See HTML in titles example if you want to parse HTML.
14 | ///
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
16 | public string? Title { get; set; }
17 | ///
18 | /// The size is used to determine the size of node shapes that do not have the label inside of them. These shapes are: image, circularImage, diamond, dot, star, triangle, triangleDown, hexagon, square and icon
19 | ///
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21 | public float? Size { get; set; }
22 | ///
23 | /// The width of the border of the node.
24 | ///
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
26 | public float? BorderWidth { get; set; }
27 | ///
28 | /// The width of the border of the node when it is selected. When undefined, the borderWidth * 2 is used.
29 | ///
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
31 | public float? BorderWidthSelected { get; set; }
32 | ///
33 | /// When the shape is set to image or circularImage, this option can be an URL to a backup image in case the URL supplied in the image option cannot be resolved.
34 | ///
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
36 | public string? BrokenImage { get; set; }
37 | ///
38 | /// Overall opacity of a node (overrides any opacity on border, background, image, and shadow)
39 | ///
40 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
41 | public float? Opacity { get; set; }
42 | ///
43 | /// When not undefined, the node will belong to the defined group. Styling information of that group will apply to this node. Node specific styling overrides group styling.
44 | ///
45 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
46 | public string? Group { get; set; }
47 | ///
48 | /// When true, the node will not be shown. It will still be part of the physics simulation though!
49 | ///
50 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
51 | public bool? Hidden { get; set; }
52 | ///
53 | /// The id of the node. The id is mandatory for nodes and they have to be unique.
54 | ///
55 | public string Id { get; set; } = default!;
56 | ///
57 | /// The label is the piece of text shown in or under the node, depending on the shape.
58 | ///
59 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
60 | public string? Label { get; set; }
61 | ///
62 | /// When the shape is set to image or circularImage, this option should be the URL to an image. If the image cannot be found, the brokenImage option can be used.
63 | /// Note: Firefox has a SVG drawing bug, there is a workaround - add width/height attributes to root svg element of the SVG.
64 | ///
65 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
66 | public string? Image { get; set; }
67 | ///
68 | /// Label font
69 | ///
70 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
71 | public VisFont? Font { get; set; }
72 | ///
73 | /// The shape defines what the node looks like. There are three types of nodes. One type has the label inside of it and the other type has the label underneath it. The third type is a custom shape you can draw whatever you want to represent the node.
74 | /// The shapes with the label inside of it are: ellipse, circle, database, box, text.
75 | /// The shapes with the label outside of it are: image, circularImage, diamond, dot, star, triangle, triangleDown, hexagon, square and icon.
76 | /// If none of these shapes suffice, you can use the custom shape which will allow you to create your own shape rendered via ctxRenderer option.
77 | ///
78 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
79 | public string? Shape { get; set; }
80 | ///
81 | /// Colors for the node
82 | ///
83 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
84 | public VisNodeColor? Color { get; set; }
85 | ///
86 | /// Optional tag string
87 | ///
88 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
89 | public string? Tag { get; set; }
90 | ///
91 | /// When false, the node is not part of the physics simulation. It will not move except for from manual dragging.
92 | ///
93 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
94 | public bool? Physics { get; set; }
95 | ///
96 | /// The barnesHut physics model (which is enabled by default) is based on an inverted gravity model. By increasing the mass of a node, you increase it's repulsion.
97 | /// Values between 0 and 1 are not recommended. Negative or zero values are not allowed.These will generate a console error and will be set to 1.
98 | ///
99 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
100 | public float? Mass { get; set; }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/Network.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Components;
2 | using Microsoft.JSInterop;
3 | using SpawnDev.BlazorJS;
4 | using SpawnDev.BlazorJS.JSObjects;
5 |
6 | namespace SpawnDev.BlazorJS.VisNetwork
7 | {
8 | ///
9 | /// Network is a visualization to display networks and networks consisting of nodes and edges. The visualization is easy to use and supports custom shapes, styles, colors, sizes, images, and more. The network visualization works smooth on any modern browser for up to a few thousand nodes and edges. To handle a larger amount of nodes, Network has clustering support. Network uses HTML canvas for rendering.
10 | /// https://visjs.github.io/vis-network/docs/network/
11 | ///
12 | public class Network : JSObject
13 | {
14 | ///
15 | /// Deserialization constructor
16 | ///
17 | ///
18 | public Network(IJSInProcessObjectReference _ref) : base(_ref){ }
19 | ///
20 | /// Creates a new instance of vis.Network
21 | ///
22 | ///
23 | ///
24 | ///
25 | public Network(ElementReference container, NetworkData data, NetworkOptions options) : base(JS.New("vis.Network", container, data, options)){ }
26 | ///
27 | /// Zooms out so all nodes fit on the canvas.
28 | ///
29 | public void Fit() => JSRef!.CallVoid("fit");
30 | ///
31 | /// Returns a nodeId or undefined. The DOM positions are expected to be in pixels from the top left corner of the canvas.
32 | ///
33 | ///
34 | ///
35 | public string? GetNodeAt(NetworkPointerPoint pointer) => JSRef!.Call("getNodeAt", pointer);
36 | ///
37 | /// Selects the nodes corresponding to the id's in the input array. If highlightEdges is true or undefined, the neighbouring edges will also be selected. This method unselects all other objects before selecting its own objects. Does not fire events.
38 | ///
39 | ///
40 | public void SelectNodes(IEnumerable nodeIds) => JSRef!.CallVoid("selectNodes", nodeIds);
41 | ///
42 | /// Unselect all objects. Does not fire events.
43 | ///
44 | public void UnselectAll() => JSRef!.CallVoid("unselectAll");
45 | ///
46 | /// Returns the network div
47 | ///
48 | public HTMLElement Body => JSRef!.Get("body");
49 | ///
50 | /// Returns the network canvas
51 | ///
52 | public HTMLCanvasElement Canvas => JSRef!.Get("canvas");
53 | ///
54 | /// Fired when the user clicks the mouse or taps on a touchscreen device.
55 | ///
56 | public ActionEvent OnClick { get => new ActionEvent("click", On, Off); set { } }
57 | ///
58 | /// Fired when the user double clicks the mouse or double taps on a touchscreen device. Since a double click is in fact 2 clicks, 2 click events are fired, followed by a double click event. If you do not want to use the click events if a double click event is fired, just check the time between click events before processing them.
59 | ///
60 | public ActionEvent OnDoubleClick { get => new ActionEvent("doubleClick", On, Off); set { } }
61 | ///
62 | /// Fired when the user click on the canvas with the right mouse button. The right mouse button does not select by default. You can use the method getNodeAt to select the node if you want.
63 | ///
64 | public ActionEvent OnContext { get => new ActionEvent("oncontext", On, Off); set { } }
65 | ///
66 | /// Fired when dragging node(s) or the view.
67 | ///
68 | public ActionEvent OnDragging { get => new ActionEvent("dragging", On, Off); set { } }
69 | ///
70 | /// Fired when starting a drag.
71 | ///
72 | public ActionEvent OnDragStart { get => new ActionEvent("dragStart", On, Off); set { } }
73 | ///
74 | /// Fired when the drag has finished.
75 | ///
76 | public ActionEvent OnDragEnd { get => new ActionEvent("dragEnd", On, Off); set { } }
77 | ///
78 | /// Fired if the option interaction:{hover:true} is enabled and the mouse hovers over a node.
79 | ///
80 | public ActionEvent OnHoverNode { get => new ActionEvent("hoverNode", On, Off); set { } }
81 | ///
82 | /// Fired if the option interaction:{hover:true} is enabled and the mouse moved away from a node it was hovering over before.
83 | ///
84 | public ActionEvent OnBlurNode { get => new ActionEvent("blurNode", On, Off); set { } }
85 | ///
86 | /// Fired when the selection has changed by user action. This means a node or edge has been selected, added to the selection or deselected. All select events are only triggered on click and hold.
87 | ///
88 | public ActionEvent OnSelect { get => new ActionEvent("select", On, Off); set { } }
89 | ///
90 | /// Fired when a node has been selected by the user.
91 | ///
92 | public ActionEvent OnSelectNode { get => new ActionEvent("selectNode", On, Off); set { } }
93 | ///
94 | /// Fired when a node (or nodes) has (or have) been deselected by the user. The previous selection is the list of nodes and edges that were selected before the last user event. Passes an object with properties structured as
95 | ///
96 | public ActionEvent OnDeselectNode { get => new ActionEvent("deselectNode", On, Off); set { } }
97 | ///
98 | /// Fired when an edge has been selected by the user.
99 | ///
100 | public ActionEvent OnSelectEdge { get => new ActionEvent("selectEdge", On, Off); set { } }
101 | ///
102 | /// Fired when an edge (or edges) has (or have) been deselected by the user. The previous selection is the list of nodes and edges that were selected before the last user event.
103 | ///
104 | public ActionEvent OnDeselectEdge { get => new ActionEvent("deselectEdge", On, Off); set { } }
105 | ///
106 | /// Fired when the user zooms in or out. The properties tell you which direction the zoom is in. The scale is a number greater than 0, which is the same that you get with network.getScale(). When fired by clicking the zoom in or zoom out navigation buttons, the pointer property of the object passed will be null.
107 | ///
108 | public ActionEvent OnZoom { get => new ActionEvent("zoom", On, Off); set { } }
109 | ///
110 | /// Fired when the popup (tooltip) is shown.
111 | ///
112 | public ActionEvent OnShowPopup { get => new ActionEvent("showPopup", On, Off); set { } }
113 | ///
114 | /// Fired when the popup (tooltip) is hidden.
115 | ///
116 | public ActionEvent OnHidePopup { get => new ActionEvent("hidePopup", On, Off); set { } }
117 | ///
118 | /// Set an event listener. Depending on the type of event you get different parameters for the callback function. Look at the event section of the documentation for more information.
119 | ///
120 | ///
121 | ///
122 | public void On(string eventName, Callback callback) => JSRef!.CallVoid("on", eventName, callback);///
123 | /// Remove an event listener. The function you supply has to be the exact same as the one you used in the on function. If no function is supplied, all listeners will be removed. Look at the event section of the documentation for more information.
124 | ///
125 | ///
126 | ///
127 | public void Off(string eventName, Callback callback) => JSRef!.CallVoid("off", eventName, callback);
128 | ///
129 | /// Set an event listener only once. After it has taken place, the event listener will be removed. Depending on the type of event you get different parameters for the callback function. Look at the event section of the documentation for more information.
130 | ///
131 | ///
132 | ///
133 | public void Once(string eventName, Callback callback) => JSRef!.CallVoid("once", eventName, callback);
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/SpawnDev.BlazorJS.VisNetwork/VisNetworkView.razor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Components;
2 |
3 | namespace SpawnDev.BlazorJS.VisNetwork
4 | {
5 | // https://visjs.org/
6 | ///
7 | /// VisNetwork is a visualization to display networks and networks consisting of nodes and edges. The visualization is easy to use and supports custom shapes, styles, colors, sizes, images, and more. The network visualization works smooth on any modern browser for up to a few thousand nodes and edges. To handle a larger amount of nodes, Network has clustering support. Network uses HTML canvas for rendering.
8 | /// https://github.com/visjs/vis-network
9 | ///
10 | public partial class VisNetworkView : IDisposable
11 | {
12 | [Inject] BlazorJSRuntime JS { get; set; } = default!;
13 | ///
14 | /// Style to be applied to the container
15 | ///
16 | [Parameter] public string Style { get; set; } = "width: 100%; height: 100%;";
17 | ///
18 | /// Called after OnReady and when (re-)rendered (for example: when StateHasChanged() is called on the parent component)
19 | /// (Changing this to an EventCallback will cause this component to hang if disposed, and then recreated.)
20 | ///
21 | [Parameter] public Func? UpdateData { get; set; }
22 | ///
23 | /// Called when the control is ready
24 | ///
25 | [Parameter] public EventCallback OnReady { get; set; }
26 | ///
27 | /// Called on click
28 | ///
29 | [Parameter] public EventCallback OnClick { get; set; }
30 | ///
31 | /// Called on double click
32 | ///
33 | [Parameter] public EventCallback OnDoubleClick { get; set; }
34 | ///
35 | /// Called on context click
36 | ///
37 | [Parameter] public EventCallback OnContext { get; set; }
38 | ///
39 | /// Called when dragging
40 | ///
41 | [Parameter] public EventCallback OnDragging { get; set; }
42 | ///
43 | /// Called when dragging starts
44 | ///
45 | [Parameter] public EventCallback OnDragStart { get; set; }
46 | ///
47 | /// Called when dragging ends
48 | ///
49 | [Parameter] public EventCallback OnDragEnd { get; set; }
50 | ///
51 | /// Called on node hover
52 | ///
53 | [Parameter] public EventCallback OnHoverNode { get; set; }
54 | ///
55 | /// Called on node blur
56 | ///
57 | [Parameter] public EventCallback OnBlurNode { get; set; }
58 | ///
59 | /// Called on select
60 | ///
61 | [Parameter] public EventCallback OnSelect { get; set; }
62 | ///
63 | /// Called on node select
64 | ///
65 | [Parameter] public EventCallback OnSelectNode { get; set; }
66 | ///
67 | /// Called on node deselect
68 | ///
69 | [Parameter] public EventCallback OnDeselectNode { get; set; }
70 | ///
71 | /// Called on node edge select
72 | ///
73 | [Parameter] public EventCallback OnSelectEdge { get; set; }
74 | ///
75 | /// Called on node edge deselect
76 | ///
77 | [Parameter] public EventCallback OnDeselectEdge { get; set; }
78 | ///
79 | /// Called on zoom
80 | ///
81 | [Parameter] public EventCallback OnZoom { get; set; }
82 | ///
83 | /// Called on popup show
84 | ///
85 | [Parameter] public EventCallback OnShowPopup { get; set; }
86 | ///
87 | /// Called on popup hide
88 | ///
89 | [Parameter] public EventCallback OnHidePopup { get; set; }
90 |
91 | ElementReference _container;
92 | ///
93 | /// NetworkOptions to be used when Network is created
94 | ///
95 | [Parameter] public NetworkOptions? Options { get; set; }
96 | ///
97 | /// Returns the instance of Network
98 | ///
99 | public Network? Network { get; private set; }
100 | ///
101 | /// Contains the network data
102 | ///
103 | public NetworkData? NetworkData { get; private set; }
104 | ///
105 | /// Accesses NetworkData.Nodes
106 | ///
107 | public DataSet? Nodes => NetworkData?.Nodes;
108 | ///
109 | /// Accesses NetworkData.Edges
110 | ///
111 | public DataSet? Edges => NetworkData?.Edges;
112 | ///
113 | /// Network.fit()
114 | ///
115 | public void Fit() => Network?.Fit();
116 | ///
117 | /// Clear the network data
118 | ///
119 | public void Clear()
120 | {
121 | NetworkData?.Nodes?.Clear();
122 | NetworkData?.Edges?.Clear();
123 | }
124 |
125 | // https://visjs.org/
126 | // https://visjs.github.io/vis-network/
127 | // https://visjs.github.io/vis-network/examples/network/data/dynamicData.html
128 | // https://visjs.github.io/vis-network/examples/network/nodeStyles/circularImages.html
129 |
130 | ///
131 | protected override async Task OnAfterRenderAsync(bool firstRender)
132 | {
133 | if (firstRender)
134 | {
135 | await InitAsync();
136 | }
137 | }
138 |
139 | ///
140 | protected override bool ShouldRender()
141 | {
142 | // after the initial render, we only need to update the data to redraw the canvas
143 | if (Network != null)
144 | {
145 | _ = Update();
146 | }
147 | return false;
148 | }
149 |
150 | void Network_OnClick(NetworkEvent networkEvent)
151 | {
152 | using var domEvent = networkEvent.Event;
153 | domEvent.PreventDefault();
154 | _ = OnClick.InvokeAsync(networkEvent);
155 | }
156 |
157 | void Network_OnDoubleClick(NetworkEvent networkEvent)
158 | {
159 | using var domEvent = networkEvent.Event;
160 | domEvent.PreventDefault();
161 | _ = OnDoubleClick.InvokeAsync(networkEvent);
162 | }
163 |
164 | void Network_OnContext(NetworkContextEvent networkEvent)
165 | {
166 | using var domEvent = networkEvent.Event;
167 | domEvent.PreventDefault();
168 | _ = OnContext.InvokeAsync(networkEvent);
169 | }
170 |
171 | void Network_OnDragging(NetworkDragEvent networkEvent)
172 | {
173 | using var domEvent = networkEvent.Event;
174 | domEvent.PreventDefault();
175 | _ = OnDragging.InvokeAsync(networkEvent);
176 | }
177 | void Network_OnDragStart(NetworkDragEvent networkEvent)
178 | {
179 | using var domEvent = networkEvent.Event;
180 | domEvent.PreventDefault();
181 | _ = OnDragStart.InvokeAsync(networkEvent);
182 | }
183 | void Network_OnDragEnd(NetworkDragEvent networkEvent)
184 | {
185 | using var domEvent = networkEvent.Event;
186 | domEvent.PreventDefault();
187 | _ = OnDragEnd.InvokeAsync(networkEvent);
188 | }
189 |
190 | void Network_OnHoverNode(NetworkFocusEvent networkEvent)
191 | {
192 | using var domEvent = networkEvent.Event;
193 | domEvent.PreventDefault();
194 | _ = OnHoverNode.InvokeAsync(networkEvent);
195 | }
196 |
197 | void Network_OnBlurNode(NetworkFocusEvent networkEvent)
198 | {
199 | using var domEvent = networkEvent.Event;
200 | domEvent.PreventDefault();
201 | _ = OnBlurNode.InvokeAsync(networkEvent);
202 | }
203 |
204 | void Network_OnSelect(NetworkSelectEvent networkEvent)
205 | {
206 | using var domEvent = networkEvent.Event;
207 | domEvent.PreventDefault();
208 | _ = OnSelect.InvokeAsync(networkEvent);
209 | }
210 |
211 | void Network_OnSelectNode(NetworkSelectEvent networkEvent)
212 | {
213 | using var domEvent = networkEvent.Event;
214 | domEvent.PreventDefault();
215 | _ = OnSelectNode.InvokeAsync(networkEvent);
216 | }
217 |
218 | void Network_OnDeselectNode(NetworkSelectEvent networkEvent)
219 | {
220 | using var domEvent = networkEvent.Event;
221 | domEvent.PreventDefault();
222 | _ = OnDeselectNode.InvokeAsync(networkEvent);
223 | }
224 |
225 | void Network_OnSelectEdge(NetworkSelectEvent networkEvent)
226 | {
227 | using var domEvent = networkEvent.Event;
228 | domEvent.PreventDefault();
229 | _ = OnSelectEdge.InvokeAsync(networkEvent);
230 | }
231 |
232 | void Network_OnDeselectEdge(NetworkSelectEvent networkEvent)
233 | {
234 | using var domEvent = networkEvent.Event;
235 | domEvent.PreventDefault();
236 | _ = OnDeselectEdge.InvokeAsync(networkEvent);
237 | }
238 |
239 | void Network_OnZoom(NetworkZoomEvent networkEvent)
240 | {
241 | _ = OnZoom.InvokeAsync(networkEvent);
242 | }
243 |
244 | void Network_OnShowPopup(string networkEvent)
245 | {
246 | _ = OnShowPopup.InvokeAsync(networkEvent);
247 | }
248 |
249 | void Network_OnHidePopup()
250 | {
251 | _ = OnHidePopup.InvokeAsync();
252 | }
253 |
254 | async Task InitAsync()
255 | {
256 | await JS.LoadScript("_content/SpawnDev.BlazorJS.VisNetwork/vis-network.min.js", "vis"); ;
257 | NetworkData = new NetworkData();
258 | NetworkData.Nodes = new DataSet();
259 | NetworkData.Edges = new DataSet();
260 | if (Options == null)
261 | {
262 | Options = new NetworkOptions();
263 | Options.AutoResize = true;
264 | }
265 | try
266 | {
267 | Network = new Network(_container, NetworkData, Options);
268 | Network.OnClick += Network_OnClick;
269 | Network.OnDoubleClick += Network_OnDoubleClick;
270 | Network.OnContext += Network_OnContext;
271 | Network.OnDragging += Network_OnDragging;
272 | Network.OnDragStart += Network_OnDragStart;
273 | Network.OnDragEnd += Network_OnDragEnd;
274 | Network.OnHoverNode += Network_OnHoverNode;
275 | Network.OnBlurNode += Network_OnBlurNode;
276 | Network.OnSelect += Network_OnSelect;
277 | Network.OnSelectNode += Network_OnSelectNode;
278 | Network.OnDeselectNode += Network_OnDeselectNode;
279 | Network.OnSelectEdge += Network_OnSelectEdge;
280 | Network.OnDeselectEdge += Network_OnDeselectEdge;
281 | Network.OnZoom += Network_OnZoom;
282 | Network.OnShowPopup += Network_OnShowPopup;
283 | Network.OnHidePopup += Network_OnHidePopup;
284 | #if DEBUG
285 | JS.Set("_network", Network);
286 | #endif
287 | Ready = true;
288 | await OnReady.InvokeAsync(this);
289 | await Update();
290 | }
291 | catch (Exception ex)
292 | {
293 | JS.Log($"InitAsync failed: {ex.ToString()}");
294 | }
295 | }
296 | ///
297 | /// Releases resources
298 | ///
299 | public void Dispose()
300 | {
301 | if (Network != null)
302 | {
303 | Network.OnClick -= Network_OnClick;
304 | Network.OnDoubleClick -= Network_OnDoubleClick;
305 | Network.OnContext -= Network_OnContext;
306 | Network.OnDragging -= Network_OnDragging;
307 | Network.OnDragStart -= Network_OnDragStart;
308 | Network.OnDragEnd -= Network_OnDragEnd;
309 | Network.OnHoverNode -= Network_OnHoverNode;
310 | Network.OnBlurNode -= Network_OnBlurNode;
311 | Network.OnSelect -= Network_OnSelect;
312 | Network.OnSelectNode -= Network_OnSelectNode;
313 | Network.OnDeselectNode -= Network_OnDeselectNode;
314 | Network.OnSelectEdge -= Network_OnSelectEdge;
315 | Network.OnDeselectEdge -= Network_OnDeselectEdge;
316 | Network.OnZoom -= Network_OnZoom;
317 | Network.OnShowPopup -= Network_OnShowPopup;
318 | Network.OnHidePopup -= Network_OnHidePopup;
319 | }
320 | NetworkData?.Edges?.Dispose();
321 | NetworkData?.Nodes?.Dispose();
322 | Network?.Dispose();
323 | }
324 | ///
325 | /// Returns true when the component has been initialized and is ready
326 | ///
327 | public bool Ready { get; private set; } = false;
328 | ///
329 | /// Returns true when updating
330 | ///
331 | public bool Updating { get; private set; } = false;
332 | ///
333 | /// UpdateData will be called.
334 | ///
335 | ///
336 | public async Task Update()
337 | {
338 | if (UpdateData == null) return;
339 | if (Updating) return;
340 | Updating = true;
341 | try
342 | {
343 | await UpdateData(this);
344 | }
345 | catch (Exception ex)
346 | {
347 | Console.WriteLine($"UpdateData failed: {ex.ToString()}");
348 | }
349 | finally
350 | {
351 | Updating = false;
352 | }
353 | }
354 | }
355 | }
356 |
--------------------------------------------------------------------------------