D2 是一种可以用来绘制图表的脚本语言,使用 Go 实现,可以直接使用 go install 安装

go install oss.terrastruct.com/d2@latest

repo: https://github.com/terrastruct/d2

以下是 D2 官方文档提供的例子,由于我的个人配置,样式可能和官方文档存在差异

source code
vars: {
  d2-config: {
    layout-engine: elk
    # Terminal theme code
    theme-id: 300
  }
}
network: {
  cell tower: {
    satellites: {
      shape: stored_data
      style.multiple: true
    }
 
    transmitter
 
    satellites -> transmitter: send
    satellites -> transmitter: send
    satellites -> transmitter: send
  }
 
  online portal: {
    ui: {shape: hexagon}
  }
 
  data processor: {
    storage: {
      shape: cylinder
      style.multiple: true
    }
  }
 
  cell tower.transmitter -> data processor.storage: phone logs
}
 
user: {
  shape: person
  width: 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