Custom (re)ordering of legend/bar segments in Einstein Analytics

Problem: Recently I tacked with the problem of ordering the legend/bar segments in Einstein Analytics and this is how I solved it. Using the Einstein Analytics user interface, I could sort bar segments of a stacked column chart in asc/desc order or keep it unsorted. However, I needed to sort them in a custom fashion …