Deneb Workout 07 - Bubble Chart with Pan and Zoom

Difficulty Rating: 2 out of 5

Deneb Workout 07 - Bubble Chart with Pan and Zoom

Visuals can be panned and zoomed in Power BI using Deneb/Vega-Lite via standard and well-known keyboard and mouse interactions. This workout presents an example.

Goals
Using the PBIX loaded with the Enterprise DNA Practice Dataset supplied, produce a Deneb visual in Power BI that:
• includes a bubble chart of sales by country by month
• includes a legend of bubble size
• uses the current Power BI colour theme and a common border colour
• includes a custom tooltip using Power BI formatting
• includes a parameter to enable the panning-and-zooming of the bubble chart
• includes a title block with subtitle

Submission
Using the supplied Power BI file as the data source/starting point, create your solution, and reply to this post. Upload a screenshot of your solution along with the Deneb/Vega-Lite JSON code used. Please format your JSON code and blur it or place it in a hidden section.

Period
This workout will be released on Monday May 8, 2023, will run for 2 weeks, and the author’s solution will be posted on Sunday May 21, 2023.

Greg
Deneb Workout 07 - Data - Enterprise DNA Practice Dataset.pbix (1.7 MB)

1 Like

@Greg, i was able to reproduce most of your bubble chart with pan and zoom:

repro

Hello, here is my try. I don’t have the same number for the sales - I tried both sales and sales factored but it is not giving me back the same as you have… what am I doing wrong? I also compared the data in a table format, and it all corresponds between DENEB and the table…

Anyway here it is:

Config

{
“autosize”: {
“type”: “fit”,
“contains”: “padding”
},
“view”: {“stroke”: “transparent”}
}

Specification

{
“title”: {
“text”: “Deneb Workout 07”,
“subtitle”: “Bubble Chart with Pan and Zoom”,
“anchor”: “start”,
“align”: “left”,
“font”: “Verdana”,
“fontSize”: 16,
“fontWeight”: “bold”,
“offset”: 10
},
“params”: [
{
“name”: “_pan_and_zoom”,
“select”: “interval”,
“bind”: “scales”
}
],
“data”: {“name”: “dataset”},
“mark”: {
“type”: “circle”,
“tooltip”: true,
“opacity”: 0.8,
“stroke”: “black”,
“strokeWidth”: 1
},
“encoding”: {
“x”: {
“field”: “Month Middle”,
“type”: “temporal”,
“timeUnit”: “month”,
“axis”: {
“grid”: false,
“title”: null,
“offset”: 25
}
},
“y”: {
“field”: “Country”,
“type”: “nominal”,
“axis”: {
“title”: null,
“offset”: 25
}
},
“size”: {
“field”: “Total Sales”,
“type”: “quantitative”,
“legend”: {
“clipHeight”: 70,
“title”: “Total Sales”
},
“scale”: {“rangeMax”: 5000}
},
“color”: {
“field”: “Country”,
“type”: “nominal”,
“legend”: null,
“scale”: {
“scheme”: “pbiColorNominal”
}
},
“tooltip”: [
{“field”: “Country”},
{
“field”: “Month Middle”,
“title”: “Month”,
“format”: “MMMM”,
“formatType”: “pbiFormat”
},
{
“field”: “Month Middle”,
“title”: “Year”,
“format”: “yyyy”,
“formatType”: “pbiFormat”
},
{
“field”: “Total Sales”,
“title”: “Total Sales”,
“format”: “$#,##0.”,
“formatType”: “pbiFormat”
}
]
}
}

Thanks a lot for these workouts - they are really useful to learn!
Kind regards
Valeria

Here’s my solution to this workout, where I used several Deneb/Vega-Lite features, including:

• used a title block complete with subtitle
• used a params block to create a parameter bound to the axes (scales) [roll the mouse wheel while holding the SHIFT key to pan; CTRL key to zoom]
• used a circle mark with border colour (stroke) set to black
• used a temporal type for the X-encoding block with a timeunit: month key-value pair to have Vega-Lite automatically calculate the X-axis and labels
• used an offset of 5 pixels to create a small amount of space between the circles and the Y-axis
• used the clipHeight property to adjust the spacing of the legend
• used the rangeMax property to adjust the symbol size used in the legend
• used the Deneb pbiColorNominal scheme to access the colours of the current Power BI theme
• used a custom tooltip with Deneb’s access to Power Bi formatting strings

Here’s the code:

{
  "title": {
    "anchor": "start",
    "align": "left",
    "offset": 10,
    "text": "Deneb Workout 07",
    "font": "Verdana",
    "fontSize": 16,
    "fontWeight": "bold",
    "fontStyle": "normal",
    "subtitle": "Bubble Chart with Pan and Zoom",
    "subtitleFont": "Verdana",
    "subtitleFontSize": 12,
    "subtitleFontWeight": "normal",
    "subtitleFontStyle": "italic"
  },
  "data": {"name": "dataset"},
  "params": [
    {
      "name": "_pan_and_zoom",
      "select": "interval",
      "bind": "scales"
    }
  ],
  "mark": {
    "type": "circle",
    "tooltip": true,
    "opacity": 0.8,
    "stroke": "black",
    "strokeWidth": 1
  },
  "encoding": {
    "x": {
      "field": "Month Middle",
      "type": "temporal",
      "timeUnit": "month",
      "axis": {
        "title": null,
        "grid": false,
        "offset": 5
      }
    },
    "y": {
      "field": "Country",
      "type": "nominal",
      "axis": {
        "title": null,
        "offset": 5
      }
    },
    "size": {
      "field": "Total Sales",
      "type": "quantitative",
      "legend": {"clipHeight": 70},
      "scale": {"rangeMax": 5000}
    },
    "color": {
      "field": "Country",
      "type": "nominal",
      "legend": null,
      "scale": {
        "scheme": "pbiColorNominal"
      }
    },
    "tooltip": [
      {"field": "Country"},
      {
        "field": "Month Middle",
        "title": "Month",
        "format": "MMMM",
        "formatType": "pbiFormat"
      },
      {
        "field": "Month Middle",
        "title": "Year",
        "format": "yyyy",
        "formatType": "pbiFormat"
      },
      {
        "field": "Total Sales",
        "format": "$#,##0.",
        "formatType": "pbiFormat"
      }
    ]
  }
}

Note: I used a DAX formula to adjust the Total Sales amounts for better visibility on the Deneb/Vega-Lite visual. The code is:

Total Sales (Factored) = 
VAR _Month = SELECTEDVALUE( Dates[MonthOfYear] )
VAR _Result = SWITCH( TRUE(),
    _Month IN {4,5,11}, [Total Sales] * 2,
    [Total Sales] * 0.5)

RETURN
_Result

Congratulations to all who participated, and good luck.
Greg
Deneb Workout 07 - Bubble Chart with Pan and Zoom.pbix (1.7 MB)