What is the best practice to create smart legend?

We want to create smart legend which only display in the legend symbol of the entites that are on the visible extent of the map, not by layers but by entities.

layers that has value dependent renderer will only show the symbol of the features in the extent (if the layer has 30 different values and only 2 are with in the extent, the legend will only show 2 swatches)