JSONCanvas技能Skill json-canvas

JSON Canvas技能用于创建和编辑JSON Canvas文件(.canvas),这些文件在Obsidian等应用程序中用于构建无限画布,支持文本、文件、链接和组节点,以及它们之间的连接,适用于思维导图、流程图、项目板等可视化场景。关键词:JSON Canvas, Obsidian, 画布, 思维导图, 流程图, 数据可视化, 文件格式

数据可视化 0 次安装 0 次浏览 更新于 3/14/2026

name: json-canvas description: 创建和编辑JSON Canvas文件(.canvas),包含节点、边、组和连接。当处理.canvas文件、创建视觉画布、思维导图、流程图,或当用户在Obsidian中提及Canvas文件时使用。

JSON Canvas 技能

此技能使兼容技能的代理能够创建和编辑有效的JSON Canvas文件(.canvas),用于Obsidian和其他应用程序。

概述

JSON Canvas是一种用于无限画布数据的开放文件格式。Canvas文件使用.canvas扩展名,并包含遵循JSON Canvas Spec 1.0的有效JSON。

文件结构

一个canvas文件包含两个顶级数组:

{
  "nodes": [],
  "edges": []
}
  • nodes(可选):节点对象数组
  • edges(可选):连接节点的边对象数组

节点

节点是放置在画布上的对象。有四种节点类型:

  • text - 带有Markdown的文本内容
  • file - 引用文件或附件
  • link - 外部URL
  • group - 其他节点的视觉容器

Z-Index 排序

节点按z-index在数组中排序:

  • 第一个节点 = 底层(显示在其他节点下方)
  • 最后一个节点 = 顶层(显示在其他节点上方)

通用节点属性

所有节点共享这些属性:

属性 必需 类型 描述
id string 节点的唯一标识符
type string 节点类型:textfilelinkgroup
x integer 以像素为单位的X位置
y integer 以像素为单位的Y位置
width integer 以像素为单位的宽度
height integer 以像素为单位的高度
color canvasColor 节点颜色(见颜色部分)

文本节点

文本节点包含Markdown内容。

{
  "id": "6f0ad84f44ce9c17",
  "type": "text",
  "x": 0,
  "y": 0,
  "width": 400,
  "height": 200,
  "text": "# Hello World

This is **Markdown** content."
}
属性 必需 类型 描述
text string 带有Markdown语法的纯文本

文件节点

文件节点引用文件或附件(图像、视频、PDF、笔记等)。

{
  "id": "a1b2c3d4e5f67890",
  "type": "file",
  "x": 500,
  "y": 0,
  "width": 400,
  "height": 300,
  "file": "Attachments/diagram.png"
}
{
  "id": "b2c3d4e5f6789012",
  "type": "file",
  "x": 500,
  "y": 400,
  "width": 400,
  "height": 300,
  "file": "Notes/Project Overview.md",
  "subpath": "#Implementation"
}
属性 必需 类型 描述
file string 系统内的文件路径
subpath string 链接到标题或块(以#开头)

链接节点

链接节点显示外部URL。

{
  "id": "c3d4e5f678901234",
  "type": "link",
  "x": 1000,
  "y": 0,
  "width": 400,
  "height": 200,
  "url": "https://obsidian.md"
}
属性 必需 类型 描述
url string 外部URL

组节点

组节点是用于组织其他节点的视觉容器。

{
  "id": "d4e5f6789012345a",
  "type": "group",
  "x": -50,
  "y": -50,
  "width": 1000,
  "height": 600,
  "label": "Project Overview",
  "color": "4"
}
{
  "id": "e5f67890123456ab",
  "type": "group",
  "x": 0,
  "y": 700,
  "width": 800,
  "height": 500,
  "label": "Resources",
  "background": "Attachments/background.png",
  "backgroundStyle": "cover"
}
属性 必需 类型 描述
label string 组的文本标签
background string 背景图像路径
backgroundStyle string 背景渲染样式

背景样式

描述
cover 填充节点的整个宽度和高度
ratio 保持背景图像的纵横比
repeat 在两个方向上重复图像作为图案

边是连接节点的线。

{
  "id": "f67890123456789a",
  "fromNode": "6f0ad84f44ce9c17",
  "toNode": "a1b2c3d4e5f67890"
}
{
  "id": "0123456789abcdef",
  "fromNode": "6f0ad84f44ce9c17",
  "fromSide": "right",
  "fromEnd": "none",
  "toNode": "b2c3d4e5f6789012",
  "toSide": "left",
  "toEnd": "arrow",
  "color": "1",
  "label": "leads to"
}
属性 必需 类型 默认 描述
id string - 边的唯一标识符
fromNode string - 连接起始的节点ID
fromSide string - 边起始的侧边
fromEnd string none 边起始的形状
toNode string - 连接结束的节点ID
toSide string - 边结束的侧边
toEnd string arrow 边结束的形状
color canvasColor - 线条颜色
label string - 边的文本标签

侧边值

描述
top 节点的顶部边缘
right 节点的右侧边缘
bottom 节点的底部边缘
left 节点的左侧边缘

端点形状

描述
none 无端点形状
arrow 箭头端点

颜色

canvasColor类型可以以两种方式指定:

十六进制颜色

{
  "color": "#FF0000"
}

预设颜色

{
  "color": "1"
}
预设 颜色
"1" 红色
"2" 橙色
"3" 黄色
"4" 绿色
"5" 青色
"6" 紫色

注意:预设的具体颜色值故意未定义,允许应用程序使用自己的品牌颜色。

完整示例

简单画布带文本和连接

{
  "nodes": [
    {
      "id": "8a9b0c1d2e3f4a5b",
      "type": "text",
      "x": 0,
      "y": 0,
      "width": 300,
      "height": 150,
      "text": "# Main Idea

This is the central concept."
    },
    {
      "id": "1a2b3c4d5e6f7a8b",
      "type": "text",
      "x": 400,
      "y": -100,
      "width": 250,
      "height": 100,
      "text": "## Supporting Point A

Details here."
    },
    {
      "id": "2b3c4d5e6f7a8b9c",
      "type": "text",
      "x": 400,
      "y": 100,
      "width": 250,
      "height": 100,
      "text": "## Supporting Point B

More details."
    }
  ],
  "edges": [
    {
      "id": "3c4d5e6f7a8b9c0d",
      "fromNode": "8a9b0c1d2e3f4a5b",
      "fromSide": "right",
      "toNode": "1a2b3c4d5e6f7a8b",
      "toSide": "left"
    },
    {
      "id": "4d5e6f7a8b9c0d1e",
      "fromNode": "8a9b0c1d2e3f4a5b",
      "fromSide": "right",
      "toNode": "2b3c4d5e6f7a8b9c",
      "toSide": "left"
    }
  ]
}

项目板带组

{
  "nodes": [
    {
      "id": "5e6f7a8b9c0d1e2f",
      "type": "group",
      "x": 0,
      "y": 0,
      "width": 300,
      "height": 500,
      "label": "To Do",
      "color": "1"
    },
    {
      "id": "6f7a8b9c0d1e2f3a",
      "type": "group",
      "x": 350,
      "y": 0,
      "width": 300,
      "height": 500,
      "label": "In Progress",
      "color": "3"
    },
    {
      "id": "7a8b9c0d1e2f3a4b",
      "type": "group",
      "x": 700,
      "y": 0,
      "width": 300,
      "height": 500,
      "label": "Done",
      "color": "4"
    },
    {
      "id": "8b9c0d1e2f3a4b5c",
      "type": "text",
      "x": 20,
      "y": 50,
      "width": 260,
      "height": 80,
      "text": "## Task 1

Implement feature X"
    },
    {
      "id": "9c0d1e2f3a4b5c6d",
      "type": "text",
      "x": 370,
      "y": 50,
      "width": 260,
      "height": 80,
      "text": "## Task 2

Review PR #123",
      "color": "2"
    },
    {
      "id": "0d1e2f3a4b5c6d7e",
      "type": "text",
      "x": 720,
      "y": 50,
      "width": 260,
      "height": 80,
      "text": "## Task 3

~~Setup CI/CD~~"
    }
  ],
  "edges": []
}

研究画布带文件和链接

{
  "nodes": [
    {
      "id": "1e2f3a4b5c6d7e8f",
      "type": "text",
      "x": 300,
      "y": 200,
      "width": 400,
      "height": 200,
      "text": "# Research Topic

## Key Questions

- How does X affect Y?
- What are the implications?",
      "color": "5"
    },
    {
      "id": "2f3a4b5c6d7e8f9a",
      "type": "file",
      "x": 0,
      "y": 0,
      "width": 250,
      "height": 150,
      "file": "Literature/Paper A.pdf"
    },
    {
      "id": "3a4b5c6d7e8f9a0b",
      "type": "file",
      "x": 0,
      "y": 200,
      "width": 250,
      "height": 150,
      "file": "Notes/Meeting Notes.md",
      "subpath": "#Key Insights"
    },
    {
      "id": "4b5c6d7e8f9a0b1c",
      "type": "link",
      "x": 0,
      "y": 400,
      "width": 250,
      "height": 100,
      "url": "https://example.com/research"
    },
    {
      "id": "5c6d7e8f9a0b1c2d",
      "type": "file",
      "x": 750,
      "y": 150,
      "width": 300,
      "height": 250,
      "file": "Attachments/diagram.png"
    }
  ],
  "edges": [
    {
      "id": "6d7e8f9a0b1c2d3e",
      "fromNode": "2f3a4b5c6d7e8f9a",
      "fromSide": "right",
      "toNode": "1e2f3a4b5c6d7e8f",
      "toSide": "left",
      "label": "supports"
    },
    {
      "id": "7e8f9a0b1c2d3e4f",
      "fromNode": "3a4b5c6d7e8f9a0b",
      "fromSide": "right",
      "toNode": "1e2f3a4b5c6d7e8f",
      "toSide": "left",
      "label": "informs"
    },
    {
      "id": "8f9a0b1c2d3e4f5a",
      "fromNode": "4b5c6d7e8f9a0b1c",
      "fromSide": "right",
      "toNode": "1e2f3a4b5c6d7e8f",
      "toSide": "left",
      "toEnd": "arrow",
      "color": "6"
    },
    {
      "id": "9a0b1c2d3e4f5a6b",
      "fromNode": "1e2f3a4b5c6d7e8f",
      "fromSide": "right",
      "toNode": "5c6d7e8f9a0b1c2d",
      "toSide": "left",
      "label": "visualized by"
    }
  ]
}

流程图

{
  "nodes": [
    {
      "id": "a0b1c2d3e4f5a6b7",
      "type": "text",
      "x": 200,
      "y": 0,
      "width": 150,
      "height": 60,
      "text": "**Start**",
      "color": "4"
    },
    {
      "id": "b1c2d3e4f5a6b7c8",
      "type": "text",
      "x": 200,
      "y": 100,
      "width": 150,
      "height": 60,
      "text": "Step 1:
Gather data"
    },
    {
      "id": "c2d3e4f5a6b7c8d9",
      "type": "text",
      "x": 200,
      "y": 200,
      "width": 150,
      "height": 80,
      "text": "**Decision**

Is data valid?",
      "color": "3"
    },
    {
      "id": "d3e4f5a6b7c8d9e0",
      "type": "text",
      "x": 400,
      "y": 200,
      "width": 150,
      "height": 60,
      "text": "Process data"
    },
    {
      "id": "e4f5a6b7c8d9e0f1",
      "type": "text",
      "x": 0,
      "y": 200,
      "width": 150,
      "height": 60,
      "text": "Request new data",
      "color": "1"
    },
    {
      "id": "f5a6b7c8d9e0f1a2",
      "type": "text",
      "x": 400,
      "y": 320,
      "width": 150,
      "height": 60,
      "text": "**End**",
      "color": "4"
    }
  ],
  "edges": [
    {
      "id": "a6b7c8d9e0f1a2b3",
      "fromNode": "a0b1c2d3e4f5a6b7",
      "fromSide": "bottom",
      "toNode": "b1c2d3e4f5a6b7c8",
      "toSide": "top"
    },
    {
      "id": "b7c8d9e0f1a2b3c4",
      "fromNode": "b1c2d3e4f5a6b7c8",
      "fromSide": "bottom",
      "toNode": "c2d3e4f5a6b7c8d9",
      "toSide": "top"
    },
    {
      "id": "c8d9e0f1a2b3c4d5",
      "fromNode": "c2d3e4f5a6b7c8d9",
      "fromSide": "right",
      "toNode": "d3e4f5a6b7c8d9e0",
      "toSide": "left",
      "label": "Yes",
      "color": "4"
    },
    {
      "id": "d9e0f1a2b3c4d5e6",
      "fromNode": "c2d3e4f5a6b7c8d9",
      "fromSide": "left",
      "toNode": "e4f5a6b7c8d9e0f1",
      "toSide": "right",
      "label": "No",
      "color": "1"
    },
    {
      "id": "e0f1a2b3c4d5e6f7",
      "fromNode": "e4f5a6b7c8d9e0f1",
      "fromSide": "top",
      "fromEnd": "none",
      "toNode": "b1c2d3e4f5a6b7c8",
      "toSide": "left",
      "toEnd": "arrow"
    },
    {
      "id": "f1a2b3c4d5e6f7a8",
      "fromNode": "d3e4f5a6b7c8d9e0",
      "fromSide": "bottom",
      "toNode": "f5a6b7c8d9e0f1a2",
      "toSide": "top"
    }
  ]
}

ID 生成

节点和边ID必须是唯一的字符串。Obsidian生成16个字符的十六进制ID:

"id": "6f0ad84f44ce9c17"
"id": "a3b2c1d0e9f8g7h6"
"id": "1234567890abcdef"

此格式是一个16字符的小写十六进制字符串(64位随机值)。

布局指南

定位

  • 坐标可以为负(画布无限延伸)
  • x 向右增加
  • y 向下增加
  • 位置指节点的左上角

推荐尺寸

节点类型 建议宽度 建议高度
小文本 200-300 80-150
中文本 300-450 150-300
大文本 400-600 300-500
文件预览 300-500 200-400
链接预览 250-400 100-200
可变 可变

间距

  • 在组内留20-50px的填充
  • 将节点间距50-100px以提高可读性
  • 对齐节点到网格(10或20的倍数)以获得更清晰的布局

验证规则

  1. 所有id值必须在节点和边中唯一
  2. fromNodetoNode必须引用现有的节点ID
  3. 每个节点类型的必需字段必须存在
  4. type必须是以下之一:textfilelinkgroup
  5. backgroundStyle必须是以下之一:coverratiorepeat
  6. fromSidetoSide必须是以下之一:toprightbottomleft
  7. fromEndtoEnd必须是以下之一:nonearrow
  8. 颜色预设必须是"1""6"或有效的十六进制颜色

参考资料