{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://higlass.io/#viewconf",
  "title": "HiGlass viewconf",
  "type": "object",
  "additionalProperties": false,
  "required": [],
  "properties": {
    "editable": {
      "type": "boolean",
      "default": true
    },
    "viewEditable": {
      "type": "boolean",
      "default": true
    },
    "tracksEditable": {
      "type": "boolean",
      "default": true
    },
    "zoomFixed": { "type": "boolean" },
    "compactLayout": { "type": "boolean" },
    "exportViewUrl": { "type": "string" },
    "trackSourceServers": {
      "type": "array",
      "items": { "type": "string" },
      "minLength": 1
    },
    "zoomLocks": { "$ref": "#/definitions/locks/zoomLocks" },
    "locationLocks": { "$ref": "#/definitions/locks/locationLocks" },
    "valueScaleLocks": { "$ref": "#/definitions/locks/valueScaleLocks" },
    "views": {
      "type": "array",
      "items": { "$ref": "#/definitions/view" },
      "minLength": 1
    },
    "chromInfoPath": { "type": "string" }
  },
  "definitions": {
    "data": {
      "type": "object",
      "properties": {
        "url": { "type": "string" },
        "server": { "type": "string" },
        "filetype": { "type": "string" },
        "type": { "type": "string" },
        "tilesetInfo": { "type": "object" },
        "children": { "type": "array" },
        "tiles": { "type": "object" }
      }
    },

    "locks": {
      "slug": { "type": "string" },

      "locksByViewUid": {
        "type": "object",
        "additionalProperties": false,
        "patternProperties": {
          ".": { "$ref": "#/definitions/locks/slug" }
        }
      },

      "axisSpecificLocks": {
        "additionalProperties": false,
        "properties": {
          "axis": {
            "enum": ["x", "y"],
            "type": "string"
          },
          "lock": {
            "type": "string"
          }
        },
        "required": ["lock", "axis"],
        "type": "object"
      },

      "locationLocksByViewUid": {
        "type": "object",
        "additionalProperties": false,
        "patternProperties": {
          ".": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "x": {
                    "$ref": "#/definitions/locks/axisSpecificLocks"
                  },
                  "y": {
                    "$ref": "#/definitions/locks/axisSpecificLocks"
                  }
                },
                "type": "object"
              }
            ]
          }
        }
      },

      "zoomLocks": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "locksByViewUid": { "$ref": "#/definitions/locks/locksByViewUid" },
          "locksDict": {
            "type": "object",
            "additionalProperties": false,
            "patternProperties": {
              ".": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uid": { "$ref": "#/definitions/locks/slug" }
                },
                "patternProperties": {
                  "^(?!uid).": {
                    "type": "array",
                    "minLength": 3,
                    "maxLength": 3,
                    "items": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      },

      "locationLocks": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "locksByViewUid": {
            "$ref": "#/definitions/locks/locationLocksByViewUid"
          },
          "locksDict": {
            "type": "object",
            "additionalProperties": false,
            "patternProperties": {
              ".": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uid": { "$ref": "#/definitions/locks/slug" }
                },
                "patternProperties": {
                  "^(?!uid).": {
                    "type": "array",
                    "minLength": 3,
                    "maxLength": 3,
                    "items": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      },

      "valueScaleLocks": {
        "type": "object",
        "additionalProperties": false,
        "required": ["locksByViewUid", "locksDict"],
        "properties": {
          "locksByViewUid": { "$ref": "#/definitions/locks/locksByViewUid" },
          "locksDict": {
            "type": "object",
            "additionalProperties": false,
            "patternProperties": {
              ".": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uid": { "$ref": "#/definitions/locks/slug" },
                  "ignoreOffScreenValues": { "type": "boolean" }
                },
                "patternProperties": {
                  "^(?!(uid|ignoreOffScreenValues)).": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["view", "track"],
                    "properties": {
                      "view": { "type": "string" },
                      "track": { "$ref": "#/definitions/locks/slug" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },

    "view": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tracks", "layout"],
      "properties": {
        "autocompleteSource": { "type": "string" },
        "chromInfoPath": { "type": "string" },
        "genomePositionSearchBox": {
          "$ref": "#/definitions/viewProperties/genomePositionSearchBox"
        },
        "genomePositionSearchBoxVisible": { "type": "boolean" },
        "initialXDomain": { "$ref": "#/definitions/viewProperties/domain" },
        "initialYDomain": { "$ref": "#/definitions/viewProperties/domain" },
        "layout": { "$ref": "#/definitions/viewProperties/layout" },
        "overlays": {
          "type": "array",
          "items": { "$ref": "#/definitions/viewProperties/overlay" }
        },
        "selectionView": { "type": "boolean" },
        "tracks": { "$ref": "#/definitions/viewProperties/tracks_object" },
        "uid": { "type": "string" },
        "zoomFixed": { "type": "boolean" },
        "zoomLimits": {
          "type": "array",
          "minLength": 2,
          "maxLength": 2,
          "default": [1, null]
        }
      }
    },

    "viewProperties": {
      "genomePositionSearchBox": {
        "type": "object",
        "title": "The Genome Position Search Box Schema",
        "required": ["chromInfoServer", "chromInfoId"],
        "properties": {
          "autocompleteServer": {
            "type": "string",
            "title": "The Autocomplete Server URL",
            "default": "",
            "examples": ["//higlass.io/api/v1"],
            "pattern": "^(.*)$"
          },
          "autocompleteId": {
            "type": "string",
            "title": "The Autocomplete ID",
            "default": "",
            "examples": ["OHJakQICQD6gTD7skx4EWA"],
            "pattern": "^(.*)$"
          },
          "chromInfoServer": {
            "type": "string",
            "title": "The Chrominfo Server URL",
            "default": "",
            "examples": ["//higlass.io/api/v1"],
            "pattern": "^(.*)$"
          },
          "chromInfoId": {
            "type": "string",
            "title": "The Chromosome Info ID",
            "default": "",
            "examples": ["hg19"],
            "pattern": "^(.*)$"
          },
          "visible": {
            "type": "boolean",
            "title": "The Visible Schema",
            "default": false
          }
        }
      },

      "overlay": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "chromInfoPath": { "type": "string" },
          "includes": { "type": "array" },
          "options": {
            "type": "object",
            "properties": {
              "extent": { "type": "array" },
              "minWidth": { "type": "number" },
              "fill": { "type": "string" },
              "fillOpacity": { "type": "number" },
              "stroke": { "type": "string" },
              "strokeOpacity": { "type": "number" },
              "strokeWidth": { "type": "number" },
              "strokePos": { "type": ["string", "array"] },
              "outline": { "type": "string" },
              "outlineOpacity": { "type": "number" },
              "outlineWidth": { "type": "number" },
              "outlinePos": { "type": ["string", "array"] }
            }
          },
          "type": { "type": "string" },
          "uid": { "type": "string" }
        }
      },

      "layout": {
        "type": "object",
        "additionalProperties": false,
        "required": ["w", "h", "x", "y"],
        "properties": {
          "x": {
            "type": "integer",
            "title": "The X Position",
            "default": 0
          },
          "y": {
            "type": "integer",
            "title": "The Y Position",
            "default": 0
          },
          "w": {
            "type": "integer",
            "title": "Width",
            "default": 12
          },
          "h": {
            "type": "integer",
            "title": "Height",
            "default": 12
          },
          "moved": { "type": "boolean" },
          "static": { "type": "boolean" }
        }
      },

      "tracks_object": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "left": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "right": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "top": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "bottom": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "center": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "whole": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "gallery": { "$ref": "#/definitions/viewProperties/tracks_array" }
        }
      },

      "tracks_array": {
        "type": "array",
        "items": {
          "oneOf": [
            { "$ref": "#/definitions/tracks/enum_track" },
            { "$ref": "#/definitions/tracks/combined_track" },
            { "$ref": "#/definitions/tracks/heatmap_track" },
            {
              "$ref": "#/definitions/tracks/independent_viewport_projection_track"
            }
          ]
        }
      },

      "domain": {
        "type": "array",
        "items": { "type": "number" },
        "maxItems": 2,
        "minItems": 2
      }
    },

    "tracks": {
      "heatmap_track": {
        "type": "object",
        "additionalProperties": false,
        "required": [],
        "properties": {
          "uid": { "type": "string" },
          "type": { "const": "heatmap" },
          "data": { "$ref": "#/definitions/data" },
          "height": { "type": "number" },
          "options": { "type": "object" },
          "position": { "type": "string" },
          "server": { "type": "string" },
          "tilesetUid": { "type": "string" },
          "width": { "type": "number" },
          "transforms": { "type": "array" }
        }
      },

      "combined_track": {
        "type": "object",
        "additionalProperties": false,
        "required": ["contents"],
        "properties": {
          "contents": { "$ref": "#/definitions/viewProperties/tracks_array" },
          "height": { "type": "number" },
          "options": {},
          "position": { "type": "string" },
          "type": { "const": "combined" },
          "uid": { "type": "string" },
          "width": { "type": "number" }
        }
      },

      "enum_track": {
        "type": "object",
        "additionalProperties": false,
        "required": ["type"],
        "properties": {
          "server": { "type": "string" },
          "tilesetUid": { "type": "string" },
          "data": { "$ref": "#/definitions/data" },
          "uid": { "type": "string" },
          "type": {
            "enum": [
              "multivec",
              "1d-heatmap",
              "line",
              "point",
              "bar",
              "divergent-bar",
              "stacked-interval",
              "gene-annotations",
              "linear-2d-rectangle-domains",
              "chromosome-labels",
              "linear-heatmap",
              "1d-value-interval",
              "2d-annotations",
              "2d-chromosome-annotations",
              "2d-chromosome-grid",
              "2d-chromosome-labels",
              "2d-rectangle-domains",
              "2d-tiles",
              "arrowhead-domains",
              "bedlike",
              "cross-rule",
              "dummy",
              "horizontal-1d-annotations",
              "horizontal-1d-heatmap",
              "horizontal-1d-tiles",
              "horizontal-1d-value-interval",
              "horizontal-2d-rectangle-domains",
              "horizontal-bar",
              "horizontal-chromosome-grid",
              "horizontal-chromosome-labels",
              "horizontal-divergent-bar",
              "horizontal-gene-annotations",
              "horizontal-heatmap",
              "horizontal-line",
              "horizontal-multivec",
              "horizontal-point",
              "horizontal-rule",
              "horizontal-vector-heatmap",
              "image-tiles",
              "left-axis",
              "left-stacked-interval",
              "mapbox-tiles",
              "osm-2d-tile-ids",
              "osm-tiles",
              "raster-tiles",
              "simple-svg",
              "square-markers",
              "top-axis",
              "top-stacked-interval",
              "vertical-1d-annotations",
              "vertical-1d-heatmap",
              "vertical-1d-tiles",
              "vertical-1d-value-interval",
              "vertical-2d-rectangle-domains",
              "vertical-bar",
              "vertical-bedlike",
              "vertical-chromosome-grid",
              "vertical-chromosome-labels",
              "vertical-gene-annotations",
              "vertical-heatmap",
              "vertical-line",
              "vertical-multivec",
              "vertical-point",
              "vertical-rule",
              "vertical-vector-heatmap",
              "viewport-projection-center",
              "viewport-projection-horizontal",
              "viewport-projection-vertical"
            ]
          },
          "chromInfoPath": { "type": "string" },
          "fromViewUid": { "type": "string" },
          "height": { "type": "number" },
          "options": { "type": "object" },
          "width": { "type": "number" },
          "x": { "type": "number" },
          "y": { "type": "number" }
        }
      },
      "independent_viewport_projection_track": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "uid": { "type": "string" },
          "type": {
            "enum": [
              "viewport-projection-horizontal",
              "viewport-projection-vertical",
              "viewport-projection-center"
            ]
          },
          "fromViewUid": { "type": "null" },
          "projectionXDomain": {
            "$ref": "#/definitions/viewProperties/domain"
          },
          "projectionYDomain": {
            "$ref": "#/definitions/viewProperties/domain"
          },
          "options": { "type": "object" },
          "transforms": { "type": "array" },
          "width": { "type": "number" },
          "x": { "type": "number" },
          "y": { "type": "number" }
        }
      }
    }
  }
}
