mattijn
11/1/2018 - 3:51 PM

vega4_voorspellingen_oms.json

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "autosize": "pad",
  "padding": 5,
  "width": 600,
  "height": 300,
  "style": "cell",
  "data": [
    {"name": "location_store"},
    {"name": "nearest_store"},
    {
      "name": "source_0",
      "url": "https://raw.githubusercontent.com/mattijn/datasets/master/altair-data-928d5ff00413bb2e18d24515e3758eee.csv",
      "format": {"type": "csv", "parse": {"date": "date"}}
    },
    {
      "name": "data_0",
      "source": "source_0",
      "transform": [
        {
          "type": "filter",
          "expr": "!(length(data(\"location_store\"))) || (vlSelectionTest(\"location_store\", datum))"
        }
      ]
    },
    {
      "name": "data_1",
      "source": "data_0",
      "transform": [
        {
          "type": "impute",
          "field": "value",
          "groupby": ["parameterId", "locationId", "stationName"],
          "key": "date",
          "method": "value",
          "value": 0
        },
        {
          "type": "stack",
          "groupby": ["date"],
          "field": "value",
          "sort": {
            "field": ["parameterId", "locationId", "stationName"],
            "order": ["descending", "descending", "descending"]
          },
          "as": ["value_start", "value_end"],
          "offset": "zero"
        }
      ]
    },
    {
      "name": "data_2",
      "source": "source_0",
      "transform": [
        {
          "type": "filter",
          "expr": "(vlSelectionTest(\"nearest_store\", datum))"
        }
      ]
    }
  ],
  "signals": [
    {
      "name": "unit",
      "value": {},
      "on": [
        {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"}
      ]
    },
    {
      "name": "location_stationName",
      "value": "Holwerd - VA25",
      "on": [
        {
          "events": [{"source": "scope", "type": "click"}],
          "update": "datum && item().mark.marktype !== 'group' ? datum[\"stationName\"] : null"
        }
      ],
      "bind": {
        "input": "select",
        "options": [
          "Den Helder - Texel, Vaarweg",
          "Den Helder veerhaven, Vak A",
          "Den Helder veerhaven, Vak B",
          "Den Helder veerhaven, Vak C",
          "Texel veerhaven, Vak A",
          "Texel veerhaven, Vak B",
          "Texel veerhaven, Vak C",
          "Texel veerhaven, Vak D",
          "Texel veerhaven, Vak E",
          "Texel veerhaven, Vak F",
          "Den Helder - Noordzee",
          "Visjagersgaatje",
          "Den Helder - Den Oever, Malzwin",
          "Den Helder - Den Oever, Visjagersgaatje -Den Oever",
          "Den Oever, Toegangsgeul",
          "Den Oever, Buitenhaven",
          "Den Oever, Voorhaven",
          "Den Oever, Noorderhaven",
          "Den Oever, Waddenhaven",
          "Den Oever, Vissershaven",
          "Den Oever, Bodem bij remmingwerken / steiger",
          "Den Oever, Bodem bij beweegbare brug / sluis",
          "Kornwerderzand, Toegangsgeul",
          "Kornwerderzand, Buitenhaven",
          "Kornwerderzand, Voorhaven",
          "Kornwerderzand, Bodem bij remmingwerken / steiger",
          "Kornwerderzand, Bodem bij beweegbare brug / sluis",
          "Breezanddijk Noorderhaven",
          "Den Helder - Kornwerderzand, Texelstroom",
          "Den Helder - Kornwerderzand, Doove Balg",
          "Den Helder - Kornwerderzand, Gedeelte van Boontjes",
          "Boontjes, Vak 1",
          "Boontjes, Vak 2",
          "Boontjes, Vak 3",
          "Boontjes, Vak 4",
          "Boontjes, Vak 5",
          "Boontjes, Vak 6",
          "Boontjes, Vak 7",
          "Boontjes, Vak 8",
          "Boontjes, Vak 9",
          "Boontjes, Vak 10",
          "Boontjes, Vak 11",
          "Boontjes, Vak 12",
          "Boontjes, Vak 13",
          "Boontjes, Vak 14",
          "Boontjes, Vak 15",
          "Kornwerderzand - Harlingen, Zuid",
          "Kornwerderzand - Harlingen, Noord",
          "Slenk",
          "Harlingen - Terschelling, Westmeep - Noordmeep",
          "Harlingen - Terschelling, Schuitengat",
          "Terschelling, Jachthaven",
          "Terschelling, Veerkade",
          "Vliesloot",
          "Harlingen - Vlieland, Zuiderstortemelk",
          "Harlingen - Vlieland, Vliesloot",
          "Vlieland, Veerdienst deel",
          "Vlieland, Sneldienst deel",
          "Vlieland, Jachthaven",
          "Vlieland, Voormalige werkhaven",
          "Pollendam",
          "Harlingen - Noordzee, Pollendam",
          "Harlingen - Noordzee, Blauwe Slenk",
          "Harlingen - Noordzee, Vliestroom",
          "Harlingen - Noordzee, Stortemelk",
          "Blauwe Slenk",
          "Pannengat",
          "Holwerd - VA25",
          "VA4 - VA6",
          "VA9 - VA13",
          "Reegeul",
          "Holwerd, Veerdienst deel",
          "Holwerd, Rijkssteiger",
          "Holwerd, Westkant",
          "Nes, Veerdienst deel",
          "Nes, Voormalige rijkssteiger",
          "Nes, Toegangsgeul",
          "Nes, Oostkant",
          "Nes, Jachthaven Nes Ameland",
          "Holwerd - Ameland, VA13 - VA25",
          "Holwerd - Ameland, VA9 - VA6",
          "Holwerd - Ameland, VA4 - Reegeul",
          "Ballumerbocht, Loswal",
          "Ballumerbocht, Vaargeul",
          "Ameland - Noordzee",
          "Glinder",
          "Lauwersoog - Glinder",
          "Glinder - Groote Siege",
          "Groote Siege",
          "Schiermonnikoog, Veerdienst deel zuid",
          "Schiermonnikoog, Zuidkant Veerdam KNRM",
          "Schiermonnikoog, Veerdienst deel noord",
          "Schiermonnikoog, Noordkant KNRM Ponton",
          "Schiermonnikoog, Jachthaven",
          "Lauwersoog, Veerdienst deel",
          "Lauwersoog, Toegangsgeul",
          "Lauwersoog, Visserijhaven",
          "Lauwersoog - Noordzee",
          "Haven Noordpolderzijl, Havendeel",
          "Schanskerdiep"
        ]
      }
    },
    {"name": "location", "update": "vlSelectionResolve(\"location_store\")"},
    {"name": "nearest", "update": "vlSelectionResolve(\"nearest_store\")"},
    {
      "name": "location_tuple",
      "update": "location_stationName !== null ? {fields: location_tuple_fields, values: [location_stationName]} : null"
    },
    {
      "name": "location_tuple_fields",
      "update": "[{\"field\":\"stationName\",\"type\":\"E\"}]"
    },
    {
      "name": "location_modify",
      "on": [
        {
          "events": {"signal": "location_tuple"},
          "update": "modify(\"location_store\", location_tuple, true)"
        }
      ]
    },
    {
      "name": "nearest_tuple",
      "value": {},
      "on": [
        {
          "events": [{"source": "scope", "type": "mouseover"}],
          "update": "datum && item().mark.marktype !== 'group' ? {unit: \"layer_1\", fields: nearest_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"date\"]]} : null",
          "force": true
        }
      ]
    },
    {
      "name": "nearest_tuple_fields",
      "update": "[{\"field\":\"date\",\"type\":\"E\"}]"
    },
    {
      "name": "nearest_modify",
      "on": [
        {
          "events": {"signal": "nearest_tuple"},
          "update": "modify(\"nearest_store\", nearest_tuple, true)"
        }
      ]
    }
  ],
  "marks": [
    {
      "name": "layer_0_pathgroup",
      "type": "group",
      "from": {
        "facet": {
          "name": "faceted_path_layer_0_main",
          "data": "data_1",
          "groupby": ["parameterId"]
        }
      },
      "encode": {
        "update": {
          "width": {"field": {"group": "width"}},
          "height": {"field": {"group": "height"}}
        }
      },
      "marks": [
        {
          "name": "layer_0_marks",
          "type": "area",
          "style": ["area"],
          "sort": {"field": "datum[\"date\"]", "order": "descending"},
          "from": {"data": "faceted_path_layer_0_main"},
          "encode": {
            "update": {
              "opacity": {"value": 0.3},
              "interpolate": {"value": "step-after"},
              "orient": {"value": "vertical"},
              "fill": {"scale": "color", "field": "parameterId"},
              "tooltip": {
                "signal": "{\"locationId\": ''+datum[\"locationId\"], \"stationName\": ''+datum[\"stationName\"], \"value\": format(datum[\"value\"], \"\")}"
              },
              "x": {"scale": "x", "field": "date"},
              "y": {"scale": "y", "field": "value_end"},
              "y2": {"scale": "y", "field": "value_start"},
              "defined": {
                "signal": "datum[\"date\"] !== null && !isNaN(datum[\"date\"]) && datum[\"value\"] !== null && !isNaN(datum[\"value\"])"
              }
            }
          }
        }
      ]
    },
    {
      "name": "layer_1_marks",
      "type": "symbol",
      "style": ["point"],
      "from": {"data": "data_0"},
      "encode": {
        "update": {
          "opacity": {"value": 0},
          "fill": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"])",
              "value": null
            },
            {"value": "transparent"}
          ],
          "stroke": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"])",
              "value": null
            },
            {"value": "#4c78a8"}
          ],
          "tooltip": {
            "signal": "{\"date\": timeFormat(datum[\"date\"], '%b %d, %Y')}"
          },
          "x": {"scale": "x", "field": "date"},
          "y": {"signal": "height", "mult": 0.5}
        }
      }
    },
    {
      "name": "layer_1_voronoi",
      "type": "path",
      "from": {"data": "layer_1_marks"},
      "encode": {
        "enter": {
          "fill": {"value": "transparent"},
          "strokeWidth": {"value": 0.35},
          "stroke": {"value": "transparent"},
          "isVoronoi": {"value": true}
        }
      },
      "transform": [
        {
          "type": "voronoi",
          "x": {"expr": "datum.datum.x || 0"},
          "y": {"expr": "datum.datum.y || 0"},
          "size": [{"signal": "width"}, {"signal": "height"}]
        }
      ]
    },
    {
      "name": "layer_2_marks",
      "type": "symbol",
      "style": ["point"],
      "from": {"data": "data_0"},
      "encode": {
        "update": {
          "opacity": [
            {"test": "(vlSelectionTest(\"nearest_store\", datum))", "value": 1},
            {"value": 0}
          ],
          "fill": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"]) || datum[\"value\"] === null || isNaN(datum[\"value\"])",
              "value": null
            },
            {"value": "transparent"}
          ],
          "stroke": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"]) || datum[\"value\"] === null || isNaN(datum[\"value\"])",
              "value": null
            },
            {"scale": "color", "field": "parameterId"}
          ],
          "tooltip": {
            "signal": "{\"locationId\": ''+datum[\"locationId\"], \"stationName\": ''+datum[\"stationName\"], \"value\": format(datum[\"value\"], \"\")}"
          },
          "x": {"scale": "x", "field": "date"},
          "y": {"scale": "y", "field": "value"}
        }
      }
    },
    {
      "name": "layer_3_marks",
      "type": "rule",
      "style": ["rule"],
      "from": {"data": "data_2"},
      "encode": {
        "update": {
          "stroke": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"])",
              "value": null
            },
            {"value": "gray"}
          ],
          "tooltip": {
            "signal": "{\"date\": timeFormat(datum[\"date\"], '%b %d, %Y')}"
          },
          "x": {"scale": "x", "field": "date"},
          "y": {"field": {"group": "height"}},
          "y2": {"value": 0}
        }
      }
    },
    {
      "name": "layer_4_marks",
      "type": "text",
      "style": ["text"],
      "from": {"data": "data_0"},
      "encode": {
        "update": {
          "align": {"value": "left"},
          "dx": {"value": 5},
          "dy": {"value": -5},
          "fill": [
            {
              "test": "datum[\"date\"] === null || isNaN(datum[\"date\"]) || datum[\"value\"] === null || isNaN(datum[\"value\"])",
              "value": null
            },
            {"scale": "color", "field": "parameterId"}
          ],
          "tooltip": {
            "signal": "{\"locationId\": ''+datum[\"locationId\"], \"stationName\": ''+datum[\"stationName\"], \"value\": format(datum[\"value\"], \"\")}"
          },
          "x": {"scale": "x", "field": "date"},
          "y": {"scale": "y", "field": "value"},
          "text": [
            {
              "test": "(vlSelectionTest(\"nearest_store\", datum))",
              "signal": "format(datum[\"value\"], \"\")"
            },
            {"value": " "}
          ]
        }
      }
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "time",
      "domain": {
        "fields": [
          {"data": "data_1", "field": "date"},
          {"data": "data_0", "field": "date"},
          {"data": "data_2", "field": "date"}
        ]
      },
      "range": [0, {"signal": "width"}]
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {
        "fields": [
          {"data": "data_1", "field": "value_start"},
          {"data": "data_1", "field": "value_end"},
          {"data": "data_0", "field": "value"}
        ]
      },
      "range": [{"signal": "height"}, 0],
      "zero": false,
      "nice": true
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {
        "fields": [
          {"data": "data_1", "field": "parameterId"},
          {"data": "data_0", "field": "parameterId"}
        ],
        "sort": true
      },
      "range": "category"
    }
  ],
  "axes": [
    {
      "scale": "x",
      "orient": "bottom",
      "grid": false,
      "title": "date",
      "labelFlush": true,
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "zindex": 1
    },
    {
      "scale": "x",
      "orient": "bottom",
      "gridScale": "y",
      "grid": true,
      "tickCount": {"signal": "ceil(width/40)"},
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    },
    {
      "scale": "y",
      "orient": "left",
      "grid": false,
      "title": "volume (m³)",
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "zindex": 1
    },
    {
      "scale": "y",
      "orient": "left",
      "gridScale": "x",
      "grid": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "domain": false,
      "labels": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    }
  ],
  "legends": [
    {
      "title": "Cut tov NGD (m³)",
      "fill": "color",
      "encode": {"symbols": {"update": {"opacity": {"value": 0.3}}}},
      "stroke": "color"
    }
  ],
  "config": {"axisY": {"minExtent": 30}}
}