stiankroknes / visnetwork.blazor Goto Github PK
View Code? Open in Web Editor NEWBlazor component for vis-js/vis-network javascript library.
Home Page: https://stiankroknes.github.io/VisNetwork.Blazor/
License: MIT License
Blazor component for vis-js/vis-network javascript library.
Home Page: https://stiankroknes.github.io/VisNetwork.Blazor/
License: MIT License
AddVisNetwork
adds a singleton IJsModule
which has a dependency on IJsRuntime
therefore requiring that IJsRuntime
also be a singleton
On Blazor server IJsRuntime
is scoped (see https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-7.0#default-services)
Current workaround:
IVersionProvider
VersionProvider
is internal
not public
Suggestions:
AddVisNetwork
for scoped usedVersionProvider
public, this makes it easier to build the equivalent to AddVisNetwork
@stiankroknes I've come up with a potential solution to the problem that the output of the DOT parser isn't necessarily complete objects since vis.js supports simplified form for some of it's parameters.
Example with tests in #29
The basic problem is that the default JsonConverter
is expecting an json object and throws an exception when it gets something else.
The standard way around this to to write a custom JsonConverter<T>
(which I did, see ArrowsJsonConverter
in the PR)
However, we want the default converter when there is an object but to do something special when there isn't.
Proposed solution:
For types that have a simplified format (like Arrows
and Font
) create a class that derives from the proper object and knows how to construct a full object from the simplified form.
Then create a converter for the wrapper class (and when it detects the simplified form it constructs from that), otherwise it can get the default converter and use that to deserialize the full object.
In the branch the Arrows
and Font
classes are now the wrapper classes around ArrowsInternal
and FontInternal
.
I gave the wrapper classes the original names so when you are constructing the network in code it looks correct and you don't have to worry about the wrapper/internal versions unless you are deserializing from the simplified format.
I tried to add some high level checks where it looks for either a string or number token to convert from but this might be overkill and it should just take the string output and try and work with that.
Have a look and I'm happy to take any feedback, I feel like there are some ways to simplify it but my C# isn't quite good enough to know how to.
Edge.Smooth options (see: https://visjs.github.io/vis-network/docs/network/edges.html - smooth) not currently reflected into the C# code.
PR adding this and a sample page: #25
Doc: https://visjs.github.io/vis-network/docs/network/edges.html
#3 My Pull request, which add all the arrows options
Hi, I'm trying create a graph where nodes and edges can be automatically updated via the users actions. I can create a graph if I set the NetworkData in the constructor but I'm unable to change it. if you see my code I've simplified it to add a new node when a button is pressed. I can see the new data in the network object in the debugger but it never refreshes on the display?
I've tried various ways of updating the Network data and the last try was to instantiate a new NetworkData object as you can see below.
I only appear to be able to set the data for the graph in the constructor. If i do it through the ValidFormSubmitted click for example nothing shows on the page.
....various html bits n bobs
<div>
<Network Id="mynetwork" @ref="network" Data="data" class="vis-network-container" />
</div>
@code {
private Network network;
private NetworkData data;
private HashSet<Node> nodes = new HashSet<Node>();
private HashSet<Edge> edges = new HashSet<Edge>();
public Analyze()
{
nodes.Add(new Node("1", "Node 100", 1, "circle"));
nodes.Add(new Node("2", "Node 200", 2, "circle"));
edges.Add(new Edge("1", "2"));
nodes.Add(new Node("3", "Node 300", 4, "circle"));
edges.Add(new Edge("2", "3"));
data = new NetworkData
{
Nodes = nodes,
Edges = edges
};
}
protected async Task ValidFormSubmitted()
{
nodes.Add(new Node("4", "Node 400", 5, "circle"));
data = new NetworkData
{
Nodes = nodes,
Edges = edges
};
await network.Redraw();
StateHasChanged();
}
}
I'm new to Blazor so I might be missing something really obvious.
Whenever options change after render of linkage there is no way to rerender component so page will take new options.
ForceAtlast2Based is given with extra "t" letter and it is not recognized from solver, so it need to be removed.
Hello,
thanks you for work. I would like to ask you how can i destroy the visnetwork. Actually, i have a modal that includes the Network and when i close it, the console have the following error
Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'id')
TypeError: Cannot read properties of null (reading 'id')
at Module.hR (https://localhost:7114/_content/VisNetwork.Blazor/BlazorVisNetwork.js?v=2.0.0.0:2:697560)
at https://localhost:7114/_framework/blazor.webassembly.js:1:3332
at new Promise (<anonymous>)
at Object.beginInvokeJSFromDotNet (https://localhost:7114/_framework/blazor.webassembly.js:1:3306)
at Object.St [as invokeJSFromDotNet] (https://localhost:7114/_framework/blazor.webassembly.js:1:59960)
at _mono_wasm_invoke_js_blazor (https://localhost:7114/_framework/dotnet.6.0.15.33m2xdwuzc.js:1:195300)
at wasm://wasm/00971dfa:wasm-function[219]:0x1a4c1
at wasm://wasm/00971dfa:wasm-function[167]:0xce8f
at wasm://wasm/00971dfa:wasm-function[166]:0xbd73
at wasm://wasm/00971dfa:wasm-function[2815]:0xabef3
at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
at VisNetwork.Blazor.JSModule.InvokeVoidAsync(String identifier, Object[] args)
at VisNetwork.Blazor.Network.System.IAsyncDisposable.DisposeAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.<ProcessDisposalQueueInExistingBatch>g__GetHandledAsynchronousDisposalErrorsTask|64_0(Task result)
I assume that is searching for the Id when the StateHasChanged (the modal has changed).
Can you tell me if there is any way to solve this error ?
Thank you in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.