Skip to content

添加NodeGraph组件#438

Closed
syminomega wants to merge 5 commits intomasterfrom
graph
Closed

添加NodeGraph组件#438
syminomega wants to merge 5 commits intomasterfrom
graph

Conversation

@syminomega
Copy link
Copy Markdown

@syminomega syminomega commented May 11, 2025

Link issues

fixes #{issue number}

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a new NodeGraph component and supporting infrastructure for building and interacting with node-based graphs, including UI, service, data models, and configuration options.

New Features:

  • Introduce NodeGraph component for visual node-based graph editing.
  • Add NodeGraphCanvas UI component for rendering and interacting with node graphs.
  • Provide NodeGraphService for node type registration, execution, and widget callback handling.
  • Support for defining custom node input/output slots and widgets with configurable options and callbacks.
  • Expose Graph and GraphNode classes for programmatic graph and node manipulation.

Enhancements:

  • Add service extension for easy NodeGraphService registration in DI container.

Build:

  • Add new BootstrapBlazor.NodeGraph project with supporting files and resources.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 11, 2025

Reviewer's Guide

This pull request introduces a new NodeGraph component to the BootstrapBlazor library, implementing a node-based graph editor with extensible node and widget types, service registration, and Blazor/JS interop for graph operations.

File-Level Changes

Change Details Files
Added NodeGraph component and supporting infrastructure for node-based graph editing.
  • Created NodeGraphCanvas.razor component and associated CSS for rendering the graph UI.
  • Implemented NodeGraphService for node registration, execution, and JS interop.
  • Defined node and widget data structures, interfaces, and configuration DTOs.
  • Added service extension for DI registration of NodeGraphService.
  • Introduced Graph and GraphNode classes for graph and node manipulation via JS interop.
  • Added various node slot and widget types with configuration options.
src/components/BootstrapBlazor.NodeGraph/Components/NodeGraphCanvas.razor
src/components/BootstrapBlazor.NodeGraph/Components/NodeGraphCanvas.razor.css
src/components/BootstrapBlazor.NodeGraph/Services/NodeGraphService.cs
src/components/BootstrapBlazor.NodeGraph/Services/ServiceExtension.cs
src/components/BootstrapBlazor.NodeGraph/Graph.cs
src/components/BootstrapBlazor.NodeGraph/GraphNode.cs
src/components/BootstrapBlazor.NodeGraph/NodeSlots.cs
src/components/BootstrapBlazor.NodeGraph/NodeWidgets.cs
src/components/BootstrapBlazor.NodeGraph/Data/Interop/NodeRegister.cs
src/components/BootstrapBlazor.NodeGraph/Data/WidgetsConfig.cs
src/components/BootstrapBlazor.NodeGraph/Interfaces/INodeSlot.cs
src/components/BootstrapBlazor.NodeGraph/Interfaces/INodeWidget.cs
Added static and theme CSS for graph UI styling.
  • Added graph.css for LiteGraph and custom graph UI styles.
src/components/BootstrapBlazor.NodeGraph/wwwroot/css/graph.css
Created new project for NodeGraph component.
  • Added BootstrapBlazor.NodeGraph.csproj to define the new component library.
src/components/BootstrapBlazor.NodeGraph/BootstrapBlazor.NodeGraph.csproj

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto
Copy link
Copy Markdown

bb-auto Bot commented May 11, 2025

Thanks for your PR, @syminomega. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@bb-auto bb-auto Bot requested a review from ArgoZhang May 11, 2025 04:42
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @syminomega - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 21 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

_moduleTask = new Lazy<Task<IJSObjectReference>>(_jsRuntime
.InvokeAsync<IJSObjectReference>("import", "./_content/BootstrapBlazor.NodeGraph/js/Graph.js")
.AsTask());
_reference = DotNetObjectReference.Create(this);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Created DotNetObjectReference but never used

Since _reference isn’t passed to JS, callbacks like OnNodeActionExecuted won’t run. Remove the unused field or pass _reference into your interop calls (e.g. during registration).

Comment on lines +41 to +42
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): DisposeAsync does not clean up the DotNetObjectReference

Also call _reference.Dispose() after disposing the JS module to release the .NET reference and prevent memory leaks.

Suggested change
}
}
}
}
// Dispose the DotNetObjectReference to prevent memory leaks
_reference.Dispose();

Comment on lines +72 to +75
if (_registeredNodes.ContainsKey(typePath))
{
_registeredNodes.Remove(typePath);
// TODO: 更新节点
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Re-registering a node type only updates local state

After removing the node from _registeredNodes, implement the corresponding JS-side unregister or update logic so both sides stay in sync.

@@ -0,0 +1,41 @@
@namespace BootstrapBlazor.Components
@using Microsoft.Extensions.Logging
@attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.NodeGraph/js/Graph.js", AutoInvokeDispose = false, JSObjectReference = true)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Graph.js is imported both here and in the service

This creates two module instances. Unify to a single import to prevent duplicate downloads and ensure state is shared.

Suggested implementation:



}

var jsModule = await _moduleTask.Value;
await jsModule.InvokeVoidAsync("registerNodeType", graphNodeConfig);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Missing .NET reference when registering node type

Include a DotNetObjectReference (e.g., _reference or a new one) when calling registerNodeType so JS can invoke your [JSInvokable] methods.

var be = (f) => {
throw TypeError(f);
};
var Je = (f, t, i) => t in f ? Ze(f, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : f[t] = i;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide

Comment on lines +8 to +15
var Ie = (f, t, i, n) => ({
set _(s) {
W(f, t, s, i);
},
get _() {
return L(f, t, n);
}
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide

Comment on lines +83 to +85
function T(G, b, R, C) {
t.fillStyle = C, t.fillText(R, G, b);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines +86 to +88
function O(G, b, R) {
t.beginPath(), t.fillStyle = R, A(G, b), t.fill();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines +89 to +91
function A(G, b) {
t.arc(G, b, i, n, s);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

@ArgoZhang ArgoZhang closed this May 21, 2025
@ArgoZhang ArgoZhang deleted the graph branch May 21, 2025 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants