Giter VIP home page Giter VIP logo

d3sharp's Introduction

D3Sharp

C# implementation for D3.js on .Net Standard 2.1 .

Available

Examples

D3Sharp.QuadTree

Definition:

public class QuadTree<TData, TNode>
    where TData : IQuadData
    where TNode : QuadNode<TData>, new()

By default use QuadNode create tree nodes:

...
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<CustomData, QuadNode<CustomData>>();
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:

...

public class CustomNode<T> : QuadNode<T> 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<CustomData> {
   new CustomData{X=0,Y=0,Id=0},
   new CustomData{X=0.9,Y=0.9,Id=1},
};
   
var q = new QuadTree<CustomData, CustomNode<CustomData>>(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:

public class Link
public interface INode : QuadTree.IQuadData 
public abstract class Force<TNode> : IDisposable where TNode : INode
public class Simulation<TNode> : IDisposable where TNode : INode      

Sample:

...
using D3Sharp.Force;
...

var simulation = new Simulation<Node>(Nodes)
    .AddForce("Links", new ForceLink<Node,Link>(Links)
    .AddForce("Centering", new ForceCenter<Node>(300, 300).SetStrength(1))
    .AddForce("Collision", new ForceCollide<Node>(50, 0.3, 5)
    .AddForce("Many-Body", new ForceManyBody<Node>().SetStrength(-100);
simulation.Start();

Screenshot:

force-demo

d3sharp's People

Contributors

leisn avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jonpahl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.