|
| 1 | +# D2Sharp |
| 2 | + |
| 3 | +D2Sharp is a .NET wrapper for the D2 diagramming library, allowing you to create diagrams programmatically in your .NET applications. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You can install D2Sharp via NuGet Package Manager: |
| 8 | + |
| 9 | +``` |
| 10 | +Install-Package D2Sharp |
| 11 | +``` |
| 12 | + |
| 13 | +Or via .NET CLI: |
| 14 | + |
| 15 | +``` |
| 16 | +dotnet add package D2Sharp |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Here's a basic example of how to use D2Sharp: |
| 22 | + |
| 23 | +```csharp |
| 24 | +using D2Sharp; |
| 25 | +using Microsoft.Extensions.Logging; |
| 26 | + |
| 27 | +// Create a logger (optional) |
| 28 | +var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); |
| 29 | +var logger = loggerFactory.CreateLogger<D2Wrapper>(); |
| 30 | + |
| 31 | +// Create an instance of D2Wrapper |
| 32 | +var wrapper = new D2Wrapper(logger); |
| 33 | + |
| 34 | +// Define your D2 script |
| 35 | +var script = @" |
| 36 | +direction: right |
| 37 | +A -> B -> C |
| 38 | +"; |
| 39 | + |
| 40 | +// Render the diagram |
| 41 | +try |
| 42 | +{ |
| 43 | + string svg = wrapper.RenderDiagram(script); |
| 44 | + // Use the SVG string as needed (e.g., save to file, display in a web page) |
| 45 | +} |
| 46 | +catch (Exception ex) |
| 47 | +{ |
| 48 | + Console.WriteLine($"Error rendering diagram: {ex.Message}"); |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Features |
| 53 | + |
| 54 | +- Render D2 diagrams as SVG |
| 55 | +- Cross-platform support (Windows, macOS, Linux) |
| 56 | +- Integration with .NET logging |
| 57 | + |
| 58 | +## Requirements |
| 59 | + |
| 60 | +- .NET 8.0 or later |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +This project is licensed under the MIT License - see the LICENSE file for details. |
| 65 | + |
| 66 | +## Acknowledgements |
| 67 | + |
| 68 | +D2Sharp is built on top of the following open-source projects: |
| 69 | +- [D2](https://github.com/terrastruct/d2): The underlying diagramming engine |
| 70 | +- [.NET](https://github.com/dotnet/runtime): The runtime and framework |
| 71 | + |
| 72 | +## Issues and Contributions |
| 73 | + |
| 74 | +For issues, feature requests, or contributions, please visit the [GitHub repository](https://github.com/AlrikOlson/D2Sharp). |
0 commit comments