-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNodeGraphCanvas.razor
More file actions
41 lines (34 loc) · 1.53 KB
/
NodeGraphCanvas.razor
File metadata and controls
41 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@namespace BootstrapBlazor.Components
@using Microsoft.Extensions.Logging
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.NodeGraph/js/Graph.js", AutoInvokeDispose = false, JSObjectReference = true)]
@inherits BootstrapModuleComponentBase
@inject NodeGraphService NodeGraphService
@inject ILogger<NodeGraphCanvas> Logger
<div class="@ClassString" @attributes="@AdditionalAttributes" id="@Id">
<canvas @ref="_graphCanvas"></canvas>
</div>
@code {
public Graph Graph { get; private set; } = null!;
private string? ClassString => CssBuilder.Default("graph-main-container")
.AddClassFromAttributes(AdditionalAttributes)
.Build();
private IJSObjectReference _graphCanvasRef = null!;
private ElementReference _graphCanvas;
/// <inheritdoc />
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
// 初始化并添加引用
await InvokeVoidAsync("init", Id, DotNetObjectReference.Create(NodeGraphService));
// 创建图表配置
var graphRef = await InvokeAsync<IJSObjectReference>("createLGraph");
Graph = new Graph(graphRef!);
// var graph = new Graph(graphRef!);
// 创建图表画布
_graphCanvasRef = await InvokeAsync<IJSObjectReference>("createLGraphCanvas", _graphCanvas, graphRef)
?? throw new InvalidOperationException("Create GraphCanvas failed!");
}
}
}