```json JSON 画布规范 ```
JSON Canvas Spec

原始链接: https://jsoncanvas.org/spec/1.0/

## JSON Canvas 概要 JSON Canvas 定义了一种使用 JSON 格式创建可视化画布的结构。一个画布包含两个可选的数组:`nodes` 和 `edges`。 **Nodes(节点)** 代表元素,例如文本、文件、链接或组,并按 z-index(从前到后)排序。每个节点需要一个 `id`、`type`、`x`、`y`、`width` 和 `height`。节点类型具有特定属性:`text` 节点包含 Markdown 文本,`file` 节点链接到文件,并带有可选的子路径,`link` 节点引用 URL,`group` 节点充当容器,并带有可选的标签和背景图像。 **Edges(边)** 使用唯一的 `id` 连接节点,指定 `fromNode`、`toNode` 以及可选的连接侧面 (`fromSide`、`toSide`) 和可自定义的端点 (`fromEnd`、`toEnd`)。边还可以具有 `color` 和 `label`。 **Colors(颜色)** 使用十六进制代码(例如 "#FF0000")或预设数字 1-6(红色、橙色、黄色、绿色、青色、紫色)定义,允许针对特定应用程序的颜色方案。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 JSON Canvas Spec (jsoncanvas.org) 13 分,作者 tobr,1小时前 | 隐藏 | 过去 | 收藏 | 1 条评论 帮助 makeitrain 3分钟前 [–] 看起来很不错。我最近在使用 mermaid 时遇到了一些限制,这个似乎更灵活。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Version 1.0 — 2024-03-11

Top level

The top level of JSON Canvas contains two arrays:

  • nodes (optional, array of nodes)
  • edges (optional, array of edges)

Nodes

Nodes are objects within the canvas. Nodes may be text, files, links, or groups.

Nodes are placed in the array in ascending order by z-index. The first node in the array should be displayed below all other nodes, and the last node in the array should be displayed on top of all other nodes.

Generic node

All nodes include the following attributes:

  • id (required, string) is a unique ID for the node.
  • type (required, string) is the node type.
  • x (required, integer) is the x position of the node in pixels.
  • y (required, integer) is the y position of the node in pixels.
  • width (required, integer) is the width of the node in pixels.
  • height (required, integer) is the height of the node in pixels.
  • color (optional, canvasColor) is the color of the node, see the Color section.

Text type nodes

Text type nodes store text. Along with generic node attributes, text nodes include the following attribute:

  • text (required, string) in plain text with Markdown syntax.

File type nodes

File type nodes reference other files or attachments, such as images, videos, etc. Along with generic node attributes, file nodes include the following attributes:

  • file (required, string) is the path to the file within the system.
  • subpath (optional, string) is a subpath that may link to a heading or a block. Always starts with a #.

Link type nodes reference a URL. Along with generic node attributes, link nodes include the following attribute:

Group type nodes

Group type nodes are used as a visual container for nodes within it. Along with generic node attributes, group nodes include the following attributes:

  • label (optional, string) is a text label for the group.
  • background (optional, string) is the path to the background image.
  • backgroundStyle (optional, string) is the rendering style of the background image. Valid values:
    • cover fills the entire width and height of the node.
    • ratio maintains the aspect ratio of the background image.
    • repeat repeats the image as a pattern in both x/y directions.

Edges

Edges are lines that connect one node to another.

  • id (required, string) is a unique ID for the edge.
  • fromNode (required, string) is the node id where the connection starts.
  • fromSide (optional, string) is the side where this edge starts. Valid values:
  • fromEnd (optional, string) is the shape of the endpoint at the edge start. Defaults to none if not specified. Valid values:
  • toNode (required, string) is the node id where the connection ends.
  • toSide (optional, string) is the side where this edge ends. Valid values:
  • toEnd (optional, string) is the shape of the endpoint at the edge end. Defaults to arrow if not specified. Valid values:
  • color (optional, canvasColor) is the color of the line, see the Color section.
  • label (optional, string) is a text label for the edge.

Color

The canvasColor type is used to encode color data for nodes and edges. Colors attributes expect a string. Colors can be specified in hex format e.g. "#FF0000", or using one of the preset colors, e.g. "1" for red. Six preset colors exist, mapped to the following numbers:

  • "1" red
  • "2" orange
  • "3" yellow
  • "4" green
  • "5" cyan
  • "6" purple

Specific values for the preset colors are intentionally not defined so that applications can tailor the presets to their specific brand colors or color scheme.

联系我们 contact @ memedata.com