{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jwildfire.github.io/bio.viz/schema/specification.json",
  "title": "bio.viz chart specification",
  "description": "A bio.viz chart written as data: the chart, the bio.viz version that wrote it, its settings and the filters in force. Nothing in it is evaluated. Written by tools/write-specification-schema.mjs from each chart’s settings; documented in docs/output.md.",
  "type": "object",
  "required": [
    "format",
    "format_version",
    "bio_viz_version",
    "chart"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "bio.viz specification"
    },
    "format_version": {
      "const": 1
    },
    "bio_viz_version": {
      "type": "string",
      "pattern": "\\S",
      "description": "The bio.viz version that wrote it."
    },
    "chart": {
      "enum": [
        "group-comparison",
        "association-scatter",
        "correlation-matrix",
        "biomarker-screen",
        "cross-tab",
        "stratified-survival"
      ]
    },
    "settings": {
      "type": "object",
      "description": "Settings of the chart, by name; a setting left out keeps its default.",
      "properties": {
        "filters": {
          "type": [
            "array",
            "null"
          ]
        }
      },
      "additionalProperties": {
        "allOf": [
          {
            "$ref": "#/$defs/data"
          },
          {
            "not": {
              "enum": [
                "__proto__",
                "constructor",
                "prototype"
              ]
            }
          }
        ]
      }
    },
    "filters": {
      "type": "array",
      "description": "The filters in force.",
      "items": {
        "$ref": "#/$defs/filter"
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "chart": {
            "const": "group-comparison"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "start_value",
                "visits",
                "value_type",
                "group_by",
                "levels",
                "color_by",
                "panel_by",
                "mark",
                "y_scale",
                "measures",
                "groups",
                "max_levels",
                "filters",
                "overview_limit",
                "page",
                "details",
                "page_size",
                "statistic",
                "test",
                "pairwise",
                "waiting_note",
                "profile",
                "profile_details",
                "studyday_col",
                "normal_col_high",
                "normal_col_low",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "start_value": {
                "default": null
              },
              "visits": {
                "default": null
              },
              "value_type": {
                "default": "raw"
              },
              "group_by": {
                "default": null
              },
              "levels": {
                "default": null
              },
              "color_by": {
                "default": null
              },
              "panel_by": {
                "default": null
              },
              "mark": {
                "default": "box"
              },
              "y_scale": {
                "default": "linear"
              },
              "measures": {
                "default": null
              },
              "groups": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "overview_limit": {
                "default": 12
              },
              "page": {
                "default": 0
              },
              "details": {
                "default": null
              },
              "page_size": {
                "default": 10
              },
              "statistic": {
                "default": "Analyze_GroupDifference"
              },
              "test": {
                "default": "t"
              },
              "pairwise": {
                "default": false
              },
              "waiting_note": {
                "default": null
              },
              "profile": {
                "default": true
              },
              "profile_details": {
                "default": null
              },
              "studyday_col": {
                "default": null
              },
              "normal_col_high": {
                "default": null
              },
              "normal_col_low": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "chart": {
            "const": "association-scatter"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "x",
                "y",
                "color_by",
                "panel_by",
                "x_scale",
                "y_scale",
                "fit",
                "measures",
                "numbers",
                "groups",
                "max_levels",
                "filters",
                "details",
                "page_size",
                "statistic",
                "method",
                "fit_statistic",
                "waiting_note",
                "profile",
                "profile_details",
                "studyday_col",
                "normal_col_high",
                "normal_col_low",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "x": {
                "default": null
              },
              "y": {
                "default": null
              },
              "color_by": {
                "default": null
              },
              "panel_by": {
                "default": null
              },
              "x_scale": {
                "default": "linear"
              },
              "y_scale": {
                "default": "linear"
              },
              "fit": {
                "default": "none"
              },
              "measures": {
                "default": null
              },
              "numbers": {
                "default": null
              },
              "groups": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "details": {
                "default": null
              },
              "page_size": {
                "default": 10
              },
              "statistic": {
                "default": "Analyze_Correlation"
              },
              "method": {
                "default": "pearson"
              },
              "fit_statistic": {
                "default": "Analyze_Fit"
              },
              "waiting_note": {
                "default": null
              },
              "profile": {
                "default": true
              },
              "profile_details": {
                "default": null
              },
              "studyday_col": {
                "default": null
              },
              "normal_col_high": {
                "default": null
              },
              "normal_col_low": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "chart": {
            "const": "correlation-matrix"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "mode",
                "visit",
                "biomarkers",
                "measure",
                "visits",
                "value_type",
                "view",
                "limit",
                "measures",
                "max_levels",
                "filters",
                "statistic",
                "method",
                "min_pairs",
                "waiting_note",
                "scatter",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "mode": {
                "default": "biomarkers"
              },
              "visit": {
                "default": null
              },
              "biomarkers": {
                "default": null
              },
              "measure": {
                "default": null
              },
              "visits": {
                "default": null
              },
              "value_type": {
                "default": "raw"
              },
              "view": {
                "default": "grid"
              },
              "limit": {
                "default": 12
              },
              "measures": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "statistic": {
                "default": "Analyze_CorrelationMatrix"
              },
              "method": {
                "default": "pearson"
              },
              "min_pairs": {
                "default": null
              },
              "waiting_note": {
                "default": null
              },
              "scatter": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "chart": {
            "const": "biomarker-screen"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "comparison",
                "visit",
                "value_type",
                "group_by",
                "levels",
                "with",
                "method",
                "outcome_id_col",
                "endpoint_col",
                "endpoint_label_col",
                "time_col",
                "censor_col",
                "event_col",
                "endpoint",
                "adjustment",
                "sort",
                "limit",
                "page",
                "measures",
                "groups",
                "numbers",
                "max_levels",
                "filters",
                "statistic",
                "waiting_note",
                "group_comparison",
                "association_scatter",
                "stratified_survival",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "comparison": {
                "default": "difference"
              },
              "visit": {
                "default": null
              },
              "value_type": {
                "default": "raw"
              },
              "group_by": {
                "default": null
              },
              "levels": {
                "default": null
              },
              "with": {
                "default": null
              },
              "method": {
                "default": "pearson"
              },
              "outcome_id_col": {
                "default": null
              },
              "endpoint_col": {
                "default": "PARAMCD"
              },
              "endpoint_label_col": {
                "default": "PARAM"
              },
              "time_col": {
                "default": "AVAL"
              },
              "censor_col": {
                "default": "CNSR"
              },
              "event_col": {
                "default": null
              },
              "endpoint": {
                "default": null
              },
              "adjustment": {
                "default": "BH"
              },
              "sort": {
                "default": "estimate"
              },
              "limit": {
                "default": 20
              },
              "page": {
                "default": 0
              },
              "measures": {
                "default": null
              },
              "groups": {
                "default": null
              },
              "numbers": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "statistic": {
                "default": "Analyze_Screen"
              },
              "waiting_note": {
                "default": null
              },
              "group_comparison": {
                "default": null
              },
              "association_scatter": {
                "default": null
              },
              "stratified_survival": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "chart": {
            "const": "cross-tab"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "row_by",
                "col_by",
                "percent",
                "cuts",
                "measures",
                "groups",
                "max_levels",
                "filters",
                "details",
                "page_size",
                "statistic",
                "test",
                "waiting_note",
                "profile",
                "profile_details",
                "studyday_col",
                "normal_col_high",
                "normal_col_low",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "row_by": {
                "default": null
              },
              "col_by": {
                "default": null
              },
              "percent": {
                "default": "row"
              },
              "cuts": {
                "default": null
              },
              "measures": {
                "default": null
              },
              "groups": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "details": {
                "default": null
              },
              "page_size": {
                "default": 10
              },
              "statistic": {
                "default": "Analyze_Contingency"
              },
              "test": {
                "default": "chisq"
              },
              "waiting_note": {
                "default": null
              },
              "profile": {
                "default": true
              },
              "profile_details": {
                "default": null
              },
              "studyday_col": {
                "default": null
              },
              "normal_col_high": {
                "default": null
              },
              "normal_col_low": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "chart": {
            "const": "stratified-survival"
          }
        },
        "required": [
          "chart"
        ]
      },
      "then": {
        "properties": {
          "settings": {
            "propertyNames": {
              "enum": [
                "id_col",
                "measure_col",
                "value_col",
                "visit_col",
                "visit_order_col",
                "unit_col",
                "participant_id_col",
                "baseline_visits",
                "baseline_stat",
                "outcome_id_col",
                "endpoint_col",
                "endpoint_label_col",
                "time_col",
                "censor_col",
                "event_col",
                "endpoint",
                "group_by",
                "cuts",
                "at_risk_times",
                "measures",
                "groups",
                "max_levels",
                "filters",
                "details",
                "page_size",
                "statistic",
                "waiting_note",
                "profile",
                "profile_details",
                "studyday_col",
                "normal_col_high",
                "normal_col_low",
                "title",
                "subtitle",
                "footnotes",
                "downloads",
                "png_scale"
              ]
            },
            "properties": {
              "id_col": {
                "default": "USUBJID"
              },
              "measure_col": {
                "default": "TEST"
              },
              "value_col": {
                "default": "STRESN"
              },
              "visit_col": {
                "default": "VISIT"
              },
              "visit_order_col": {
                "default": "VISITNUM"
              },
              "unit_col": {
                "default": "STRESU"
              },
              "participant_id_col": {
                "default": null
              },
              "baseline_visits": {
                "default": null
              },
              "baseline_stat": {
                "default": "mean"
              },
              "outcome_id_col": {
                "default": null
              },
              "endpoint_col": {
                "default": "PARAMCD"
              },
              "endpoint_label_col": {
                "default": "PARAM"
              },
              "time_col": {
                "default": "AVAL"
              },
              "censor_col": {
                "default": "CNSR"
              },
              "event_col": {
                "default": null
              },
              "endpoint": {
                "default": null
              },
              "group_by": {
                "default": null
              },
              "cuts": {
                "default": null
              },
              "at_risk_times": {
                "default": null
              },
              "measures": {
                "default": null
              },
              "groups": {
                "default": null
              },
              "max_levels": {
                "default": 12
              },
              "filters": {
                "default": null
              },
              "details": {
                "default": null
              },
              "page_size": {
                "default": 10
              },
              "statistic": {
                "default": "Analyze_Survival"
              },
              "waiting_note": {
                "default": null
              },
              "profile": {
                "default": true
              },
              "profile_details": {
                "default": null
              },
              "studyday_col": {
                "default": null
              },
              "normal_col_high": {
                "default": null
              },
              "normal_col_low": {
                "default": null
              },
              "title": {
                "default": null
              },
              "subtitle": {
                "default": null
              },
              "footnotes": {
                "default": null
              },
              "downloads": {
                "default": true
              },
              "png_scale": {
                "default": 2
              }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "data": {
      "description": "Data only: text, a number, true, false, null, a list or an object of these.",
      "type": [
        "null",
        "boolean",
        "number",
        "string",
        "array",
        "object"
      ],
      "items": {
        "$ref": "#/$defs/data"
      },
      "additionalProperties": {
        "$ref": "#/$defs/data"
      }
    },
    "filter": {
      "type": "object",
      "required": [
        "column",
        "operator",
        "values"
      ],
      "additionalProperties": false,
      "properties": {
        "column": {
          "type": "string",
          "pattern": "\\S",
          "not": {
            "enum": [
              "__proto__",
              "constructor",
              "prototype"
            ]
          }
        },
        "operator": {
          "enum": [
            "in"
          ]
        },
        "values": {
          "type": "array",
          "uniqueItems": true,
          "description": "The values it lets through; none lets nobody through.",
          "items": {
            "type": [
              "string",
              "number"
            ]
          }
        }
      }
    }
  }
}
