Візуалізація руху електроенергії з та в Україну за даними ENTSO-E

Published

July 21, 2024

Click to expand code
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://raw.githubusercontent.com/olehomelchenko/ua-entso-e-transfers/main/output_daily.json"
  },
  "width": 600,
  "height": 400,
  "title": "За даними ENTSO-E",
  "config": {
    "background": "#FFF",
    "padding": {
      "top": 30,
      "right": 30,
      "bottom": 30,
      "left": 30
    },
    "title": {
      "font": "Menlo, Lucida Console, Monospace",
      "fontSize": 14,
      "fontWeight": "normal",
      "color": "#005",
      "dy": -3,
      "anchor": "middle",
      "subtitleFont": "Menlo, Lucida Console, Monospace",
      "subtitleColor": "#337",
      "subtitlePadding": 5
    },
    "legend": {
      "layout": {
        "bottom": {
          "anchor": "middle"
        }
      },
      "orient": "bottom",
      "gradientLength": 500,
      "labelLimit": 500,
      "columns": 3,
      "clipHeight": 15,
      "rowPadding": 10,
      "gridAlign": "none",
      "labelFont": "Menlo, Lucida Console, Monospace",
      "titleFont": "Menlo, Lucida Console, Monospace",
      "titleFontWeight": "normal",
      "titlePadding": 5,
      "titleAlign": "center",
      "titleAnchor": "middle",
      "titleLimit": 500,
      "titleColor": "#005"
    },
    "text": {
      "font": "Menlo, Lucida Console, Monospace",
      "color": "#005"
    },
    "axis": {
      "labelFont": "Menlo, Lucida Console, Monospace",
      "labelColor": "#005",
      "titleFont": "Menlo, Lucida Console, Monospace",
      "titleColor": "#337"
    },
  },
  "selection": {
    "categoryFilter": {
      "type": "single",
      "fields": [
        "Country"
      ],
      "bind": {
        "input": "select",
        "name": "Вибір країни",
        "options": [
          null,
          "Hungary",
          "Moldova",
          "Poland",
          "Romania",
          "Slovakia"
        ]
      }
    }
  },
  "transform": [
    {
      "calculate": "datum.Export_from_UA * -1",
      "as": "export_neg"
    },
    {
      "calculate": "datum.Export_from_UA - datum.Import_from_UA",
      "as": "balance"
    },
    {
      "filter": {
        "selection": "categoryFilter"
      }
    }
  ],
  "mark": {
    "type": "bar",
    "tooltip": true
  },
  "encoding": {
    "x": {
      "timeUnit": "yearmonthdate",
      "field": "Date",
      "type": "temporal",
      "title": "Month of the year"
    },
    "y": {
      "aggregate": "sum",
      "field": "Import_to_UA",
      "type": "quantitative",
      "title": "Import/Export, mW"
    },
    "y2": {
      "field": "export_neg"
    },
    "color": {
      "field": "Country",
      "type": "nominal"
    }
  }
}
Click to expand code
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://raw.githubusercontent.com/olehomelchenko/ua-entso-e-transfers/main/output.json"
  },
  "config": {
    "background": "#FFF",
    "padding": {
      "top": 30,
      "right": 30,
      "bottom": 30,
      "left": 30
    },
    "title": {
      "font": "Menlo, Lucida Console, Monospace",
      "fontSize": 14,
      "fontWeight": "normal",
      "color": "#005",
      "dy": -3,
      "anchor": "middle",
      "subtitleFont": "Menlo, Lucida Console, Monospace",
      "subtitleColor": "#337",
      "subtitlePadding": 5
    },
    "legend": {
      "layout": {
        "bottom": {
          "anchor": "middle"
        }
      },
      "orient": "bottom",
      "gradientLength": 500,
      "labelLimit": 500,
      "columns": 3,
      "clipHeight": 15,
      "rowPadding": 10,
      "gridAlign": "none",
      "labelFont": "Menlo, Lucida Console, Monospace",
      "titleFont": "Menlo, Lucida Console, Monospace",
      "titleFontWeight": "normal",
      "titlePadding": 5,
      "titleAlign": "center",
      "titleAnchor": "middle",
      "titleLimit": 500,
      "titleColor": "#005"
    },
    "text": {
      "font": "Menlo, Lucida Console, Monospace",
      "color": "#005"
    },
    "axis": {
      "labelFont": "Menlo, Lucida Console, Monospace",
      "labelColor": "#005",
      "titleFont": "Menlo, Lucida Console, Monospace",
      "titleColor": "#337"
    },
  },
  "transform": [
    {
      "calculate": "substring(datum.Time, 0, 2)",
      "as": "Hour"
    },
    {
      "calculate": "substring(datum.Country, 0, 3)",
      "as": "cntr"
    },
    {
      "calculate": "datum.Export_from_UA * -1",
      "as": "export_neg"
    },
  ],
  "vconcat": [
    {
      "hconcat": [
        {
          "title": "Avg. Transfer to/from Ukraine by Hour",
          "transform": [
            {
              "filter": {
                "param": "brush"
              }
            },
          ],
          "mark": "area",
          "encoding": {
            "x": {
              "field": "Hour",
              "type": "ordinal",
              "axis": {
                "title": ""
              }
            },
            "y": {
              "field": "Import_to_UA",
              "type": "quantitative",
              "aggregate": "average",
              "title": "Transfer, MW",
              "scale": {
                "domain": [
                  -200,
                  500
                ]
              }
            },
            "y2": {
              "field": "export_neg",
              "aggregate": "average"
            }
          }
        },
        {"transform": [
            {
              "filter": {
                "param": "brush"
              }
            },
          ],
          "title": ["Share of Import ","by Country"],
          "encoding": {
            "theta": {
              "field": "Import_to_UA",
              "type": "quantitative",
              "aggregate": "sum",
              "stack": true
            },
            "color": {
              "field": "Country",
              "type": "nominal",
              "legend": null
            }
          },
          "layer": [
            {
              "mark": {
                "type": "arc",
                "tooltip": true,
                "outerRadius": 60
              }
            },
            {
              "mark": {
                "type": "text",
                "radius": 80
              },
              "encoding": {
                "text": {
                  "field": "cntr",
                  "type": "nominal"
                }
              }
            }
          ]
        }
      ]
    },
    {
      "width": 480,
      "height": 60,
      "mark": "area",
      "params": [
        {
          "name": "brush",
          "select": {
            "type": "interval",
            "encodings": [
              "x"
            ]
          }
        }
      ],
      "encoding": {
        "x": {
          "field": "Date",
          "type": "temporal"
        },
        "y": {
          "field": "Import_to_UA",
          "type": "quantitative",
          "aggregate": "sum",
          "axis": {
            "tickCount": 3,
            "grid": false
          }
        }
      }
    }
  ]
}