欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > D2 - 文本转图表的脚本语言(Go)

D2 - 文本转图表的脚本语言(Go)

2025/9/17 9:24:34 来源:https://blog.csdn.net/lovechris00/article/details/144972978  浏览:    关键词:D2 - 文本转图表的脚本语言(Go)

在这里插入图片描述

文章目录

    • 一、关于 D2
      • D2是什么样子的?
    • 二、快速入门
    • 三、安装
    • 四、D2作为库
    • 五、其它
      • 主题
      • 字体
      • 导出文件类型
      • 语言工具
      • 插件
      • 比较
    • 六、插件
      • 官方插件
      • 社区插件
      • Misc
    • 七、FAQ
    • 八、用D2记录的著名开源项目


一、关于 D2

D2 是一种将 文本转换为图表 的现代图表脚本语言。

  • github : https://github.com/terrastruct/d2
  • 官网:https://d2lang.com/
  • 使用:https://play.d2lang.com/ | 示例
  • 比较:https://text-to-diagram.com/
  • 示例:https://github.com/terrastruct/d2/blob/master/docs/examples
  • Discord
  • 展示视频:https://private-user-images.githubusercontent.com/3120367/206125010-bd1fea8e-248a-43e7-8f85-0bbfca0c6e2a.mp4

D2是什么样子的?

vars: {d2-config: {layout-engine: elk# Terminal theme codetheme-id: 300}
}
network: {cell tower: {satellites: {shape: stored_datastyle.multiple: true}transmittersatellites -> transmitter: sendsatellites -> transmitter: sendsatellites -> transmitter: send}online portal: {ui: {shape: hexagon}}data processor: {storage: {shape: cylinderstyle.multiple: true}}cell tower.transmitter -> data processor.storage: phone logs
}user: {shape: personwidth: 130
}user -> network.cell tower: make call
user -> network.online portal.ui: access {style.stroke-dash: 3
}api server -> network.online portal.ui: display
api server -> logs: persist
logs: {shape: page; style.multiple: true}network.data processor -> api server

在这里插入图片描述


二、快速入门

使用D2最方便的方法是将其作为CLI可执行文件运行,以从.d2文件生成SVG。

# First, install D2
curl -fsSL https://d2lang.com/install.sh | sh -s --echo 'x -> y -> z' > in.d2
d2 --watch in.d2 out.svg

浏览器窗口将打开out.svg,并在更改in.d2时实时重新加载。


三、安装

最简单的安装方法是使用我们的安装脚本:

curl -fsSL https://d2lang.com/install.sh | sh -s --

您可以使用--dry-run运行安装脚本以查看将用于安装而无需执行的命令。

或者,如果您安装了Go,您可以从源代码安装,但您不会获得手册页:

go install oss.terrastruct.com/d2@latest

您还可以从源代码安装包含手册页的版本。请参阅./docs/INSTALL.md#source-release。

要使用安装脚本卸载:

curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall

有关详细的安装文档,请参见./docs/INSTALL.md。我们演示了每个操作系统的替代方法和示例。

此外,还详细描述了安装脚本的功能,以减轻对其使用的任何担忧。我们建议直接使用操作系统的包管理器来提高安全性,但安装脚本绝不是不安全的。


四、D2作为库

除了作为可运行的CLI工具外,D2还可用于从Go程序生成图表。

例如,请参见./docs/示例/lib。这篇博客文章还演示了一个完整的、可运行的示例,该示例使用D2作为实际用例的库。


五、其它


主题

D2包含各种官方主题,可以让您的图表开箱即用。请参阅./d2主题以浏览可用主题并制作或贡献您自己的创作。


字体

D2随附“Source Sans Pro”作为渲染字体。如果您想使用不同的字体,请参阅。/d2renderer/d2fonts。


导出文件类型

D2目前支持SVG、PNG和PDF导出。更多即将推出。


语言工具

D2的设计考虑到了语言工具。D2的解析器可以从损坏的程序中解析多个错误,有一个自动格式化程序,语法突出显示,我们有LSP的计划等等。创建和维护大型图表需要良好的语言工具。

VSCode和Vim的扩展可以在相关部分找到。


插件

D2被设计为可扩展和可组合。插件系统允许您更改布局引擎并自定义渲染管道。插件可以与构建捆绑在一起,也可以作为独立的二进制文件单独安装。

布局引擎:

  • dagre(默认,bundled):一个快速、有向的图形布局引擎,可生成分层/分层布局。基于Graphviz的DOT算法。
  • ELK(bundled):一个有向图布局引擎,特别适合具有固有方向和端口的节点链接图。
  • TALA(bundled):专为软件架构图设计的新颖布局引擎。需要单独安装,请访问Github页面了解更多信息。

D2打算与各种布局引擎集成,例如dot,以及序列图等单一用途布局类型。您可以选择您喜欢并且最适合您正在制作的图表的布局引擎。


比较

有关与其他流行的文本到图表工具的比较,请参阅https://text-to-diagram.com。


六、插件

D2 团队一直在开发新的插件、集成、扩展。欢迎在任何官方或社区插件中做出贡献。如果您在工作流程中的某个地方想要使用D2,请随时展开讨论。我们的带宽有限,通常会选择最高需求的。如果您自己用D2制作了一些很酷的东西,请告诉我们,我们很乐意将其包含在这里!


官方插件

  • VSCode extension: https://github.com/terrastruct/d2-vscode
  • Vim extension: https://github.com/terrastruct/d2-vim
  • Obsidian plugin: https://github.com/terrastruct/d2-obsidian
  • Slack app: https://d2lang.com/tour/slack
  • Discord plugin: https://d2lang.com/tour/discord

社区插件

  • Tree-sitter grammar: https://git.pleshevski.ru/pleshevskiy/tree-sitter-d2
  • Emacs major mode: https://github.com/andorsk/d2-mode
  • Goldmark extension: https://github.com/FurqanSoftware/goldmark-d2
  • Telegram bot: https://github.com/meinside/telegram-d2-bot
  • Postgres importer: https://github.com/zekenie/d2-erd-from-postgres
  • Structurizr to D2 exporter: https://github.com/goto1134/structurizr-d2-exporter
  • MdBook preprocessor: https://github.com/danieleades/mdbook-d2
  • ROS2 D2 Exporter: https://github.com/Greenroom-Robotics/ros-d2
  • D2 org-mode support: https://github.com/xcapaldi/ob-d2
  • Python D2 diagram builder: https://github.com/MrBlenny/py-d2
  • Clojure D2 transpiler: https://github.com/judepayne/dictim
  • JavaScript D2 diagram builder: https://github.com/Kreshnik/d2lang-js
  • C# & dotnet SDK: https://github.com/Stephanvs/d2lang-cs
  • Maven plugin: https://github.com/andrinmeier/unofficial-d2lang-maven-plugin
  • Confluence plugin: https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin
  • CIL (C#, Visual Basic, F#, C++ CLR) to D2: https://github.com/HugoVG/AppDiagram
  • D2 Snippets (for text editors): https://github.com/Paracelsus-Rose/D2-Language-Code-Snippets
  • Mongo to D2: https://github.com/novuhq/mongo-to-D2
  • Pandoc filter: https://github.com/ram02z/d2-filter
  • Logseq-D2: https://github.com/b-yp/logseq-d2
  • ent2d2: https://github.com/tmc/ent2d2
  • MkDocs Plugin: https://github.com/landmaj/mkdocs-d2-plugin
  • Remark Plugin: https://github.com/mech-a/remark-d2
  • Zed extension: https://github.com/gabeidx/zed-d2

Misc

  • Comparison site: https://github.com/terrastruct/text-to-diagram-site
  • Playground: https://github.com/terrastruct/d2-playground
  • Language docs: https://github.com/terrastruct/d2-docs
  • Hosted icons: https://icons.terrastruct.com

七、FAQ

  • D2是否收集遥测数据?
    不,D2在安装后不会使用互联网连接,除非定期检查Github的版本更新。
  • D2需要浏览器才能运行吗?
    不,D2可以完全在服务器端运行。
  • 下一个版本会有什么?
    请参阅./ci/release/changelogs/next.md.
  • 我有问题或需要帮助。
    获得帮助的最佳方式是在D2 Discord 上提问
  • 我有一个功能请求、提案或错误报告。
    请打开Github问题。
  • 我有一个私人调查。
    请联系 hi@d2lang.com 。

八、用D2记录的著名开源项目

您是否拥有或看到带有.d2文件的开源项目?请使用D2提交PR添加到此选定的特色项目列表中。

  • ElasticSearch
  • Sourcegraph
  • Temporal
  • Tauri
    • Rust GUI framework (78.5k stars)
  • Intellij
  • Coder
  • UC Berkeley
  • Coronacheck
    • Official app of the Netherlands for coronavirus entry passes.
  • Block Protocol
    • The Block Protocol is an open standard for building and using data-driven blocks (1.2k stars).
  • Dagger
    • 一个可编程的CI/CD引擎,在容器中运行管道。
  • Ivy Wallet
    • Open-source money manager app for Android (1.1k stars).
  • LocalStack
    • 云服务模拟器 (46k stars)
  • Queue Library
    • Queue是一个用于生成和管理Goroutine池的Golang库

2025-01-06(一)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词