{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jarroba.com/tools/jtd.schema.json",
  "title": "JTD  -  Jarroba Tools Diagram",
  "description": "JSON authoring format for an editable diagram. Pasted into the 'Import Mermaid' box. See docs/jtd.md.",
  "type": "object",
  "required": ["jtd"],
  "additionalProperties": false,
  "properties": {
    "jtd": { "const": 1, "description": "Format version." },
    "layout": { "enum": ["flow-down", "flow-right", "free", "grid", "radial"], "default": "flow-down", "description": "flow-* = auto-layout in layers following edges; grid = square grid; radial = first node at center and the rest in a circle; free = manual coordinates (x/y)." },
    "title": { "type": "string", "description": "Optional diagram heading: big centered text placed above all content." },
    "background": { "type": "string", "description": "Canvas background color (#rrggbb)." },
    "nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } },
    "edges": { "type": "array", "items": { "$ref": "#/$defs/edge" } },
    "charts": { "type": "array", "items": { "$ref": "#/$defs/chart" } }
  },
  "$defs": {
    "node": {
      "type": "object",
      "required": ["id"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "text": { "type": "string" },
        "shape": { "enum": ["rect", "round", "ellipse", "diamond", "parallelogram", "cylinder", "hexagon", "note", "text", "container", "triangle", "star", "cloud", "document", "card", "callout", "actor", "cross", "process"], "default": "rect" },
        "icon": { "type": "string", "description": "Material Icons name -> icon node." },
        "fill": { "type": "string", "description": "Hex (#rrggbb) or a theme token: surface, stroke, text, accent, edge, bg, muted." },
        "stroke": { "type": "string", "description": "Hex or a theme token (see fill)." },
        "runs": { "type": "array", "description": "Mixed formatting: text chunks concatenated in order (use instead of text).", "items": { "type": "object", "required": ["t"], "properties": { "t": { "type": "string" }, "b": { "type": "boolean" }, "i": { "type": "boolean" }, "c": { "type": "string" } } } },
        "borderStyle": { "enum": ["solid", "dashed", "dashfine", "dashlong", "dotted", "dashdot", "dashdotdot", "double", "frame", "none"] },
        "borderWidth": { "type": "number" },
        "corners": { "enum": ["none", "all", "top", "bottom", "left", "right", "one", "diag", "three"], "description": "Which corners are rounded (rect/round)." },
        "titleSide": { "enum": ["top", "left", "right"], "description": "For shape 'container': which side the title bar sits on. 'top' = horizontal title (default); 'left'/'right' = vertical title with the reserved margin on that side." },
        "titleH": { "type": "number", "description": "For shape 'container': title-bar thickness in canvas units. Omit for AUTO (fits the title text, so a 2-line title isn't clipped); set a number to force a fixed size (e.g. to match sibling containers)." },
        "bold": { "type": "boolean" }, "italic": { "type": "boolean" },
        "textColor": { "type": "string", "description": "Hex or a theme token (see fill)." }, "fontSize": { "type": "number" }, "font": { "type": "string" },
        "align": { "enum": ["left", "center", "right", "justify"] },
        "valign": { "enum": ["top", "middle", "bottom"] },
        "textRotation": { "type": "number" },
        "opacity": { "type": "number", "minimum": 0, "maximum": 1 },
        "rotation": { "type": "number" },
        "skin": { "enum": ["flat", "soft", "glass", "neon", "shadow", "ornate", "sketch"], "description": "Visual finish of the node." },
        "group": { "type": "string", "description": "Group label (nodes with the same value are grouped). If the value is the id of another node (e.g. a container/card), this node becomes its child and x/y are RELATIVE to that parent's top-left corner." },
        "x": { "type": "number", "description": "TOP-LEFT corner X (canvas units). With a group parent, relative to the parent's top-left. Only used with layout:\"free\"." },
        "y": { "type": "number", "description": "TOP-LEFT corner Y. See x." },
        "w": { "type": "number" }, "h": { "type": "number" }
      }
    },
    "edge": {
      "type": "object",
      "required": ["from", "to"],
      "additionalProperties": false,
      "properties": {
        "from": { "type": "string" }, "to": { "type": "string" },
        "label": { "type": "string" },
        "arrow": { "enum": ["none", "start", "end", "both"], "default": "end" },
        "style": { "enum": ["straight", "orthogonal", "rounded"], "default": "orthogonal" },
        "color": { "type": "string" },
        "dash": { "enum": ["solid", "dashed", "dashfine", "dashlong", "dotted", "dashdot", "dashdotdot"] },
        "width": { "type": "number" },
        "head": { "enum": ["line", "triangle", "diamond", "circle"], "description": "Arrowhead type." },
        "fromPort": { "enum": ["top", "bottom", "left", "right", "auto"], "description": "Fixed side the line leaves the source by. Omit to let the layout choose." },
        "toPort": { "enum": ["top", "bottom", "left", "right", "auto"], "description": "Fixed side the line enters the target by. Omit to let the layout choose." }
      }
    },
    "chart": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "enum": ["bar", "barh", "pie", "donut", "line", "area", "scatter", "quadrant", "radar", "gauge", "voronoi", "sankey", "boxplot", "heatmap", "treemap"] },
        "id": { "type": "string" },
        "x": { "type": "number" }, "y": { "type": "number" }, "w": { "type": "number" }, "h": { "type": "number" },
        "title": { "type": "string" },
        "categories": { "type": "array", "items": { "type": "string" } },
        "series": { "type": "array", "items": {
          "type": "object",
          "properties": {
            "values": { "type": "array", "items": { "type": "number" } },
            "name": { "type": "string" },
            "kind": { "enum": ["bar", "line", "area"] },
            "axis": { "enum": ["left", "right"] }
          }
        } },
        "points": { "type": "array", "items": {
          "type": "object",
          "properties": { "x": { "type": "number" }, "y": { "type": "number" }, "label": { "type": "string" } }
        } },
        "links": { "type": "array", "items": {
          "type": "object",
          "properties": { "from": { "type": "string" }, "to": { "type": "string" }, "value": { "type": "number" } }
        } },
        "showValues": { "type": "boolean" },
        "legend": { "type": "boolean" },
        "grid": { "type": "boolean" },
        "xTitle": { "type": "string" }, "yTitle": { "type": "string" },
        "yMin": { "type": "number" }, "yMax": { "type": "number" },
        "max": { "type": "number" }
      }
    }
  }
}
