The challenge this week from Ann Jackson was all about map layers, a feature introduced in v 2020.4. As an extra twist Ann specified that you couldn’t use table calculations or LoDs, and that the viz should all be on a single sheet.
The key features of this challenge are
- display the map segmented by region
- colour the borders of each region with different colours
- display the cities sized by sales
- display sales per region
- on hover of a city, display city sales, city name and % of regional sales
Display the map segmented by region
Maps work with geographic data types, so to split map by Region, the field needs to be converted to this type. To do this, right click on Region > Geographic Role > Create From > State
Double clicking on Region should automatically create a map visual. Change the mark type to filled map, and you’ll see the region boundaries.
Strip off all the background & labels etc via the Map > Map Layers menu. Uncheck all the options on the right hand side.
Set the colour of the map to grey (via the Colour shelf), then set the background of the worksheet to a darker grey/black. Remove row & column dividers.
Colour the borders of each region with different colours
On the colour shelf, you can set a border colour, but this is a fixed single colour, not one that can be associated to a field. This is where the map layers start to come in.
We need to create a layer per region.
To start we need a calculated field
IF [Region]=’West’ THEN [Region] END
This should still be a geographic role (if it hasn’t got a globe symbol next to it, then make it geographic as you did above).
Drag this field onto the map, and drop it on the Add a Marks Layer symbol that displays. A new West Region marks card will display. Change the mark type to filled map.
Finally, and this is the really sneaky bit that took me some time to figure out, right click on the Null on the legend on the right hand side, and Hide. Only the West region now has the coloured border.
Repeat these same steps for the Central (#82d7d6), East (#b6b6dd) and South (#fd8b59) regions.
A final step at this point is to turn off tooltips across all 5 layers. Also, we don’t want the regions ‘highlighting’ as you hover the mouse over the map, so on each layer, disable selection
Display the cities sized by sales
Drag the City field onto the map, and drop it to create another layer. Drag State onto the Detail shelf of the City marks card (as there are some cities that are associated to different states).
Add Sales to Size and adjust accordingly.
Add Region to Colour, and reduce the Opacity to suit. Remove tooltips from displaying.
Display sales per region
Add another layer by dragging Region onto the map again. Change the mark type to Text. Add Sales to the Text shelf. Format appropriately. Set Disable Selection on the layer.
Good practice, rename the layer to Sales Text or similar.
On hover of a city, display city sales, city name and % of regional sales
For this we need to store a selected city, and we’ll use sets to do this. I did this by right-clicking on one of the cities in the viz, and choosing Create Set. Rename the set Selected City.
We can now work out the value of the Sales for this city, and the % of sales.
Selected City Sales
IF [Selected City] THEN [Sales] END
format to $ 0dp
% Total Sales
SUM([Selected City Sales])/SUM([Sales])
format to % 1dp.
Add these onto the Text shelf of the Sales Text marks card and format.
Now we want to add the City Name, some other additional text.
Selected City Name
IF [Selected City] THEN [City] END
However, if you add this field to the Text shelf, the marks move and things go a bit crazy.
I had to ponder about this for a long time, and I can’t explain why it does it. However it didn’t happen when I added measures (green pills) to the Text shelf. So I converted the field to a measure by editing the field and changing it to
Selected City Name
MIN(IF [Selected City] THEN [City] END)
Adding this to the Text shelf and the text stayed where it was.
A further calculated field is required, which is simply
Selected City Sub Text
MIN(IF [Selected City] THEN ‘OF REGION TOTAL’ END)
Add this and adjust the text.
So now we have the text showing, we need to make it change based on hover.
Add the map to a dashboard, then add a set action (Dashboard > Action > Add Action > Change Set Values)
Set the properties as below, and then test the interactivity by hovering over different cities.
Hopefully that’s everything you need to complete this challenge. The borders and the ‘moving marks’ certainly caused me sometime of puzzlement, but it is a very satisfying feeling when you get that ‘lightbulb’ moment. My published viz is here.
Happy vizzin’! Stay Safe!