Different colors for bars in barchart by their value

This is pretty basic functionality that is missing either in the docs or worse in the Plotly package.

An example of my problem is in extending the ‘Customizing Individual Bar Colors’ example in the docs to show a customized legend:

How does one show the legend whilst retaining a sorted order of the bars? Any help would be much appreciated.