Dynamic legend

Legend is dynamic and updates when index or scale is updated. Code is
dirty and needs cleaning (generalization).