Skip to content

Commit cbe6a17

Browse files
committed
初始化项目,添加NodeGraph基础画布
1 parent c0a252e commit cbe6a17

14 files changed

Lines changed: 10651 additions & 8 deletions

File tree

src/components/BootstrapBlazor.Graph/Components/GraphCanvas.razor

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/components/BootstrapBlazor.Graph/Components/GraphCanvas.razor.css

Whitespace-only changes.

src/components/BootstrapBlazor.Graph/BootstrapBlazor.Graph.csproj renamed to src/components/BootstrapBlazor.NodeGraph/BootstrapBlazor.NodeGraph.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<Folder Include="wwwroot\" />
21+
<Folder Include="wwwroot\css\" />
22+
<Folder Include="wwwroot\js\" />
2223
</ItemGroup>
2324

2425
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@namespace BootstrapBlazor.Components
2+
@using Microsoft.Extensions.Logging
3+
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.NodeGraph/js/Graph.js", AutoInvokeDispose = false, JSObjectReference = true)]
4+
@inherits BootstrapModuleComponentBase
5+
6+
@inject ILogger<NodeGraphCanvas> Logger
7+
8+
<div class="@ClassString" @attributes="@AdditionalAttributes" id="@Id">
9+
<canvas @ref="_graphCanvas"></canvas>
10+
</div>
11+
12+
@code {
13+
14+
private string? ClassString => CssBuilder.Default("graph-main-container")
15+
.AddClassFromAttributes(AdditionalAttributes)
16+
.Build();
17+
18+
[Parameter]
19+
public Graph? Graph { get; set; }
20+
21+
private IJSObjectReference _graphCanvasRef = null!;
22+
private ElementReference _graphCanvas;
23+
24+
25+
/// <inheritdoc />
26+
protected override async Task InvokeInitAsync()
27+
{
28+
await InvokeVoidAsync("init", Id);
29+
var graphRef = await InvokeAsync<IJSObjectReference>("createLGraph");
30+
Graph = new Graph(graphRef!);
31+
_graphCanvasRef = await InvokeAsync<IJSObjectReference>("createLGraphCanvas", _graphCanvas, graphRef)
32+
?? throw new InvalidOperationException("Create GraphCanvas failed!");
33+
// await InvokeVoidAsync("constructGraphNode", "测试节点");
34+
}
35+
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.graph-main-container{
2+
position: relative;
3+
width: 100%;
4+
height: 100%;
5+
margin: 0;
6+
padding: 0;
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
public class Graph
8+
{
9+
public IJSObjectReference GraphRef { get; }
10+
11+
internal Graph(IJSObjectReference lGraphRef)
12+
{
13+
GraphRef = lGraphRef;
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
public class GraphNode
8+
{
9+
10+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
public class NodeGraphService : IAsyncDisposable
8+
{
9+
private IJSRuntime _jsRuntime;
10+
private DotNetObjectReference<NodeGraphService> _reference;
11+
private readonly Lazy<Task<IJSObjectReference>> _moduleTask;
12+
13+
public NodeGraphService(IJSRuntime jsRuntime)
14+
{
15+
_jsRuntime = jsRuntime;
16+
_moduleTask = new Lazy<Task<IJSObjectReference>>(_jsRuntime
17+
.InvokeAsync<IJSObjectReference>("import", "./_content/SyminDesign/symin-litegraph.js")
18+
.AsTask());
19+
_reference = DotNetObjectReference.Create(this);
20+
}
21+
22+
/// <inheritdoc />
23+
public async ValueTask DisposeAsync()
24+
{
25+
if (_moduleTask.IsValueCreated)
26+
{
27+
var module = await _moduleTask.Value;
28+
await module.DisposeAsync();
29+
}
30+
}
31+
32+
private Dictionary<string,Action<GraphNode>> _nodeExecuteActions = new ();
33+
34+
public async Task RegisterNodeType(string typePath, string displayText,
35+
List<NodeInput> inputs, List<NodeOutput> outputs, Action<GraphNode>? onExecute)
36+
{
37+
38+
}
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
public class NodeInput
8+
{
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace BootstrapBlazor.Components;
6+
7+
public class NodeOutput
8+
{
9+
10+
}

0 commit comments

Comments
 (0)