{
  "data": [
    {},
    {},
    {},
    {},
    {},
    {
      "name": "ranks",
      "source": "table",
      "transform": [
        {
          "type": "window",
          "sort": {
            "field": "dateTime",
            "order": "ascending"
          },
          "ops": [
            "rank"
          ],
          "fields": [
            "value"
          ],
          "as": [
            "rank"
          ]
        },
        {
          "type": "formula",
          "expr": "datum.rank + 1",
          "as": "nextRank"
        },
        {
          "type": "formula",
          "expr": "datum.rank - 1",
          "as": "prevRank"
        }
      ]
    },
    {
      "name": "lookup",
      "source": "ranks",
      "transform": [
        {
          "type": "lookup",
          "from": "ranks",
          "key": "rank",
          "fields": [
            "nextRank"
          ],
          "as": [
            "nextObj"
          ]
        },
        {
          "type": "lookup",
          "from": "ranks",
          "key": "rank",
          "fields": [
            "prevRank"
          ],
          "as": [
            "prevObj"
          ]
        },
        {
          "type": "formula",
          "expr": "datum.prevObj != null ?  (time(datum.prevObj.dateTime) + time(datum.dateTime)) / 2 : (datum.nextObj != null ? (3 * time(datum.dateTime) - time(datum.nextObj.dateTime)) / 2 : data('range')[0].dateMin)",
          "as": "tempDateStart"
        },
        {
          "type": "formula",
          "expr": "datum.nextObj != null ?  (time(datum.nextObj.dateTime) + time(datum.dateTime)) / 2 : (datum.prevObj != null ? ( 3 * time(datum.dateTime) - time(datum.prevObj.dateTime)) / 2 : data('range')[0].dateMax)",
          "as": "tempDateEnd"
        },
        {
          "type": "formula",
          "expr": "(datum.tempDateEnd - datum.tempDateStart) * 0.05",
          "as": "tempDateToAdd"
        },
        {
          "type": "formula",
          "expr": "datum.tempDateStart + datum.tempDateToAdd",
          "as": "dateStart"
        },
        {
          "type": "formula",
          "expr": "datum.tempDateEnd - datum.tempDateToAdd",
          "as": "dateEnd"
        }
      ]
    }
  ],
  "marks": [
    {
      "scales": [
        {},
        {
          "name": "yDetail",
          "type": "linear",
          "range": [
            390,
            0
          ],
          "domain": {
            "fields": [
              {"data": "range", "field": "valueMax"},
              {"data":  "table", "field": "value"}
            ]
          },
          "nice": true,
          "zero": false,
          "padding": 0
        }
      ],
      "axes": [
        {},
        {
          "orient": "left",
          "scale": "yDetail"
        }
      ],
      "marks": [
        {
          "marks": [
            {
              "type": "rect",
              "from": {
                "data": "lookup"
              },
              "encode": {
                "enter": {
                  "tooltip": {
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'value': datum.value + 'mm', 'gid': datum.gid }"
                  }
                },
                "update": {
                  "x": {
                    "scale": "xDetail",
                    "field": "dateStart"
                  },
                  "x2": {
                    "scale": "xDetail",
                    "field": "dateEnd"
                  },
                  "y": {
                    "scale": "yDetail",
                    "field": "value"
                  },
                  "y2": {
                    "scale": "yDetail",
                    "value": 0
                  },
                  "color": {
                    "value": "both"
                  },
                  "fill": {
                    "value": "steelBlue"
                  }
                },
                "hover": {
                  "fill": {
                    "value": "red"
                  },
                  "size": {
                    "value": 60
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "signals": [
        {
          "value": 0,
          "on": [
            {},
            {
              "events": "@overview:mousedown",
              "update": "[x(), x()]"
            },
            {
              "events": "[@overview:mousedown, window:mouseup] > window:mousemove!",
              "update": "[brush[0], clamp(x(), 0, width)]"
            }
          ]
        }
      ],
      "marks": [
        {},
        {},
        {},
        {
          "type": "rect",
          "from": {
            "data": "lookup"
          },
          "encode": {
            "update": {
              "x": {
                "scale": "xOverview",
                "field": "dateStart"
              },
              "x2": {
                "scale": "xOverview",
                "field": "dateEnd"
              },
              "y": {
                "scale": "yOverview",
                "field": "value"
              },
              "y2": {
                "scale": "yOverview",
                "value": 0
              },
              "color": {
                "value": "both"
              },
              "fill": {
                "value": "steelBlue"
              }
            }
          }
        }
      ]
    }
  ]
}
