Skip to content

Stephanvs/d2lang-cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

d2lang-cs

Banner

An unofficial interface for building D2 diagram files in C# and dotnet.

Installation

dotnet add package d2lang-cs

Usage

using d2;

var umbrella = new D2Shape("alphabet", "Alphabet Inc", Shape.Rectangle);
var company = new D2Shape("google", null, Shape.Rectangle);

company.Add(new D2Shape("gmail", "Gmail", Shape.Rectangle));
company.Add(new D2Shape("meet", "Meet", Shape.Rectangle));
company.Add(new D2Shape("deepmind", "DeepMind", Shape.Rectangle));

company.Icon = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png";

var connection = new D2Connection(company.Name, umbrella.Name, Direction.TO, "BELONGS_TO");

var diagram = new D2Diagram(new[] { umbrella, company }, new[] { connection });

Console.WriteLine(diagram.ToString());

D2 Output

alphabet: Alphabet Inc {
  shape: rectangle
}
google: {
  gmail: Gmail {
    shape: rectangle
  }
  meet: Meet {
    shape: rectangle
  }
  deepmind: DeepMind {
    shape: rectangle
  }
  icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png
  shape: rectangle
}
google -> alphabet: BELONGS_TO

Diagram Output

Diagram

Documentation

Supported

  • Shapes (nodes)
  • Connections (edges)
  • Styles
  • Containers (nodes/links in nodes)
  • Arrow directions
  • Markdown / latex / block strings / code in shapes
  • Shape icons
  • SQL table shapes
  • Class shapes
  • Comments

Inspiration & Thanks

Thank me!

If you like what I'm doing and you would like to thank me, please consider:

Buy Me A Coffee!

Thank you for your support!


Copyright © 2023 Stephan van Stekelenburg - Provided under MIT License