biocore / empress

A fast and scalable phylogenetic tree viewer for microbiome data analysis
BSD 3-Clause "New" or "Revised" License
45 stars 31 forks source link

Don't resize legend when changing non-color-related things? #533

Open fedarko opened 3 years ago

fedarko commented 3 years ago

This isn't really a bug, but I think some users might get annoyed by this.

The changes I added in #512 automatically resize the tree coloring legend whenever sample/feature metadata coloring is updated. This is usually a good thing, since it means the legend will adjust to the size of its contents (so it'll get small if the tree is only colored by a few categories, and it'll expand -- up to its maximum size -- if the tree includes lots of categories).

However, a minor problem with this is that the legend is also resized when the tree coloring assignments aren't actually changed but when other things about tree coloring are changed: e.g. toggling clade collapsing, reversing the color map, adjusting the tip vs.all option for feature metadata coloring*, adjusting line width. This can get annoying if we're coloring the tree by a field, we've resized the legend, and we're adjusting other things about the tree -- because the legend will keep snapping back to its default size. This is especially noticeable in EMPire plots when the available screen space is small:

Peek 2021-07-16 20-49

There are probably a few different ways we can handle this, but maybe the most straightforward would be something analogous to what @ElDeveloper proposed (albeit in a different context) in #526 -- where we make note of the currently selected field for tree coloring and don't call Empress.resizeLegend() from Empress.updateLegendCategorical() unless the currently selected field differs from the previously selected field.

* Note: Adjusting the legend size does actually make sense for this case -- since changing the tip vs. all thing can change the unique values shown in the legend. But for e.g. clade collapsing or color map reversing, I think it'd be better if the legend size wasn't adjusted here.