https://github.com/leisn/d3sharp
D3Sharp is implementation for D3.js on C# .Net Standard 2.1 . Currently available: D3Sharp.QuadTree/D3Sharp.Force
https://github.com/leisn/d3sharp
csharp d3-force d3-quadtree d3js netstandard21
Last synced: 7 months ago
JSON representation
D3Sharp is implementation for D3.js on C# .Net Standard 2.1 . Currently available: D3Sharp.QuadTree/D3Sharp.Force
- Host: GitHub
- URL: https://github.com/leisn/d3sharp
- Owner: leisn
- License: bsd-3-clause
- Created: 2020-12-28T03:20:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-04T12:06:51.000Z (almost 5 years ago)
- Last Synced: 2025-01-29T23:14:38.702Z (8 months ago)
- Topics: csharp, d3-force, d3-quadtree, d3js, netstandard21
- Language: C#
- Homepage:
- Size: 122 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# D3Sharp
C# implementation for [D3.js](https://github.com/d3/d3) on .Net Standard 2.1 .## Available
* [D3Sharp.QuadTree](#d3sharpquadtree) for [d3-quadtree](https://github.com/d3/d3-quadtree).
* [D3Sharp.Force](#d3sharpforce) for [d3-force](https://github.com/d3/d3-force).## Examples
### D3Sharp.QuadTree
Definition:
```c#
public class QuadTree
where TData : IQuadData
where TNode : QuadNode, new()
```By default use `QuadNode` create tree nodes:
``` c#
...
using D3Sharp.QuadTree;public class CustomData : IQuadData
{
public double X { get; set; } = double.NaN;
public double Y { get; set; } = double.NaN;public string Location => X + "," + Y;
public int Id { get; set; }
}
var q = new QuadTree>();
q.Extent(0, 0, 2, 2).Add(new CustomData{X=3,Y=1,CustomField="Custom"});
Console.WriteLine($"Bounds = {q.Extents}");
//output: new double[,] { { 0, 0 }, { 4, 4 } }
Console.WriteLine($"Node type = {q.Root.GetType().Name}");
//output: QuadNode`1
```Use custom tree node:
``` c#
...public class CustomNode : QuadNode where T : CustomData
{
public int Index { get; set; }public override T Data
{
get => base.Data;
set
{
base.Data = value;
this.Index = value.Id;
}
}
}var datas = new List {
new CustomData{X=0,Y=0,Id=0},
new CustomData{X=0.9,Y=0.9,Id=1},
};
var q = new QuadTree>(datas);
Console.WriteLine($"Bounds = {q.Extents}");
//output: new double[,] { { 0, 0 }, { 1, 1 } }
Console.WriteLine($"Node type = {q.Root.GetType().Name}");
//output: CustomNode`1
```### D3Sharp.Force
Definition:
``` csharp
public class Link
public interface INode : QuadTree.IQuadData
public abstract class Force : IDisposable where TNode : INode
public class Simulation : IDisposable where TNode : INode
```Sample:
```csharp
...
using D3Sharp.Force;
...var simulation = new Simulation(Nodes)
.AddForce("Links", new ForceLink(Links)
.AddForce("Centering", new ForceCenter(300, 300).SetStrength(1))
.AddForce("Collision", new ForceCollide(50, 0.3, 5)
.AddForce("Many-Body", new ForceManyBody().SetStrength(-100);
simulation.Start();
```Screenshot:
