2

I Have been given a project to produce a european parliament seating arrangement visual. I have tried to seart on the net without luck. Can anyone sugest any custom visual that look like below? enter image description here

Davide Bacci
  • 16,647
  • 3
  • 10
  • 36
JonWay
  • 1,585
  • 17
  • 37

1 Answers1

3

You're in luck!. I have literally just produced something like this in Deneb.

enter image description here

Full code:

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 550,
  "height": 300,
  "signals": [
    {"name": "dataLength", "update": "length(data('penguins'))"},
    {"name": "row0Radius", "value": 280},
    {"name": "row1Radius", "value": 260},
    {"name": "row2Radius", "value": 240},
    {"name": "row3Radius", "value": 220},
    {"name": "row4Radius", "value": 200},
    {"name": "row5Radius", "value": 180},
    {"name": "row6Radius", "value": 160},
    {"name": "row0Circ", "update": "PI*row0Radius"},
    {"name": "row1Circ", "update": "PI*row1Radius"},
    {"name": "row2Circ", "update": "PI*row2Radius"},
    {"name": "row3Circ", "update": "PI*row3Radius"},
    {"name": "row4Circ", "update": "PI*row4Radius"},
    {"name": "row5Circ", "update": "PI*row5Radius"},
    {"name": "row6Circ", "update": "PI*row6Radius"},
    {
      "name": "totalLength",
      "update": "row0Circ+row1Circ+row2Circ+row3Circ+row4Circ+row5Circ+row6Circ "
    }
  ],
  "data": [
    {
      "name": "penguins",
      "url": "data/penguins.json",
      "transform": [
        {"type": "project", "fields": ["Species", "Island"]},
        {
          "type": "window",
          "ops": ["row_number"],
          "fields": [null],
          "as": ["index"],
          "sort": {"field": "Island", "order": "ascending"}
        }
      ]
    },
    {
      "name": "placement",
      "transform": [
        {
          "type": "sequence",
          "start": 1,
          "stop": {"signal": "dataLength+1"},
          "as": "index"
        },
        {
          "type": "formula",
          "as": "wholeCirc",
          "expr": "totalLength/dataLength"
        },
        {
          "type": "window",
          "ops": ["sum"],
          "fields": ["wholeCirc"],
          "as": ["cumWholeCirc"]
        },
        {
          "type": "formula",
          "as": "row",
          "expr": "datum.cumWholeCirc <row0Circ?0:datum.cumWholeCirc <row0Circ+row1Circ?1:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ?2:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ?3:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ+row4Circ?4:datum.cumWholeCirc <row0Circ+row1Circ+row2Circ+row3Circ+row4Circ+row5Circ?5:6 "
        },
        {
          "type": "joinaggregate",
          "fields": ["Species"],
          "ops": ["count"],
          "groupby": ["row"],
          "as": ["rowCount"]
        },
        {
          "type": "formula",
          "as": "rowCirc",
          "expr": "datum.row==0?(row0Circ/(datum.rowCount-1)):datum.row==1?(row1Circ/(datum.rowCount-1)):datum.row==2?(row2Circ/(datum.rowCount-1)):datum.row==3?(row3Circ/(datum.rowCount-1)):datum.row==4?(row4Circ/(datum.rowCount-1)):datum.row==5?(row5Circ/(datum.rowCount-1)):datum.row==6?(row6Circ/(datum.rowCount-1)):0"
        },
        {
          "type": "window",
          "ops": ["sum"],
          "fields": ["rowCirc"],
          "groupby": ["row"],
          "sort": {"field": "index", "order": "descending"},
          "as": ["cumRowCirc"]
        },
        {
          "type": "formula",
          "as": "cumRowCircAct",
          "expr": "datum.cumRowCirc - datum.rowCirc "
        },
        {
          "type": "formula",
          "as": "theta",
          "expr": "datum.cumRowCircAct==0?0:datum.row==0?(datum.cumRowCircAct/row0Radius):datum.row==1?(datum.cumRowCircAct/row1Radius):datum.row==2?datum.cumRowCircAct/row2Radius:datum.row==3?datum.cumRowCircAct/row3Radius:datum.row==4?datum.cumRowCircAct/row4Radius:datum.row==5?datum.cumRowCircAct/row5Radius:datum.row==6?datum.cumRowCircAct/row6Radius:0"
        },
        {
          "type": "formula",
          "as": "x",
          "expr": "datum.row==0?row0Radius*cos(datum.theta):datum.row==1?row1Radius*cos(datum.theta):datum.row==2?row2Radius*cos(datum.theta):datum.row==3?row3Radius*cos(datum.theta):datum.row==4?row4Radius*cos(datum.theta):datum.row==5?row5Radius*cos(datum.theta):datum.row==6?row6Radius*cos(datum.theta):0"
        },
        {
          "type": "formula",
          "as": "y",
          "expr": "datum.row==0?row0Radius*sin(datum.theta):datum.row==1?row1Radius*sin(datum.theta):datum.row==2?row2Radius*sin(datum.theta):datum.row==3?row3Radius*sin(datum.theta):datum.row==4?row4Radius*sin(datum.theta):datum.row==5?row5Radius*sin(datum.theta):datum.row==6?row6Radius*sin(datum.theta):0"
        },
        {
          "type": "window",
          "sort": {"field": "theta", "order": "ascending"},
          "ops": ["row_number"],
          "fields": ["row_number"],
          "as": ["lookup"]
        },
        {
          "type": "lookup",
          "from": "penguins",
          "key": "index",
          "fields": ["lookup"],
          "values": ["Island"],
          "as": ["finalIsland"]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "linear",
      "round": true,
      "nice": true,
      "zero": true,
      "domain": {"field": "x", "data": "placement"},
      "range": "width"
    },
    {
      "name": "y",
      "type": "linear",
      "round": true,
      "nice": true,
      "zero": true,
      "domain": {"field": "y", "data": "placement"},
      "range": "height"
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "placement", "field": "finalIsland"},
      "range": {"scheme": "category10"}
    }
  ],
  "marks": [
    {
      "name": "marks",
      "type": "symbol",
      "from": {"data": "placement"},
      "encode": {
        "update": {
          "x": {"scale": "x", "field": "x"},
          "y": {"scale": "y", "field": "y"},
          "shape": {"value": "circle"},
          "size": {"value": 130},
          "stroke": {"value": "#4682b4"},
          "tooltip": {"signal": "datum"},
          "fill": {"scale": "color", "field": "finalIsland"}
        }
      }
    }
  ]
}
Davide Bacci
  • 16,647
  • 3
  • 10
  • 36
  • Thanks so much. where should i paste this code in power BI pbix – JonWay Oct 28 '22 at 16:27
  • You need to download the Deneb custom visual and paste it in there. There will be some slight amendments you will need to make for your data. – Davide Bacci Oct 28 '22 at 16:49
  • @David - I have used your code but I am getting error. What changes do I need to make. I am using one column (Party) and a measure (count seat). Error message I got: Invalid specification {"$schema":"https://vega.github.io/schema/vega/v5.json","data":[{"name":"penguins","transform":[{"fields":["Species","Island"],"type":"project"},{"as":["index"],"fields":[null],"ops":["row_number"],"sort":{"field":"Island","order":"ascending"},"type":"window"}],"url":"data/penguins.json"},{"name":"placement","transform":[{"as":"index","start":1,"stop": – Tim Oct 29 '22 at 10:09
  • You need to change the dataset within the spec. Have a look at the docs for Deneb to understand how it all works. – Davide Bacci Oct 29 '22 at 10:39
  • You will also need to update the column/field references. – Davide Bacci Oct 29 '22 at 10:40
  • @David - I have tried to reference the dataset and column and measure but I am getting a blank canvas. I guess because I am new to Deneb and JSON. Please in the your code above, can you point the area or region I need to reference dataset, column and measure? – Tim Oct 29 '22 at 22:58
  • It is crucial your data is in the correct tabular format before adding to Deneb (non-aggregated). I suggest trying to make a simple bar chart using the tutorial to get the hang of things and make sure everything is working fine. To use my code, anywhere it says "penguins" should be replaced with "dataset". You can remove "Species" or replace it with your column used to colour the circles. Also, replace anything that says "Island" with the same column that will be used to colour code the circles. – Davide Bacci Oct 30 '22 at 08:08
  • Do you have test data you can post? – Davide Bacci Oct 30 '22 at 08:09
  • @David - Yes I have a test data. How can I share it – Tim Oct 31 '22 at 11:17
  • Upload a .pbix file somewhere and share a link by updating your question. – Davide Bacci Oct 31 '22 at 11:34
  • @David - This is the link to Test PBIX file [link](https://1drv.ms/u/s!AoVhy8hcwNisjnttouupPfQ7jt_t?e=bLkJi4) – Tim Oct 31 '22 at 12:02
  • I've looked at your .pbix and it seems to be working when I download it. What are you expecting to see that is not working? You seem to have 181 different parties over 6 years so not sure how you're planning to slice and filter this. – Davide Bacci Oct 31 '22 at 12:38
  • @David - I want to group the colors and slicer will by Year – Tim Oct 31 '22 at 13:24
  • That's my point. If you slice by year, some years only have two parties (2017) which is two circles which means a parliament chart is not suitable. And the colours are derived from party of which you have 181 different ones. Apologies but I'm not sure I understand your data. – Davide Bacci Oct 31 '22 at 13:41
  • @David - Thanks for explain. It make sense. Thank you for your time – Tim Oct 31 '22 at 14:01