Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

measurements: order means by legend values #1566

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

joverlee521
Copy link
Contributor

Keep the color-by means in a stable order so that order does not change when applying different filters to the data. This makes it easier to do comparisons across groups and across different filters.

This is the easier route for stable ordering, but in the future we can consider ordering by display order of groups in the tree.

@nextstrain-bot nextstrain-bot temporarily deployed to auspice-measurements-im-cja7xm October 7, 2022 20:17 Inactive
Copy link
Contributor

@huddlej huddlej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment much on the implementation details, but the ordering works as expected for me with our measurements panel build! 🚀

Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this feature -- it'll be a nice improvement 😄

// Order the color groups by the legend value order so that we have a stable order for the means
orderBy(
Object.entries(colorByGroups),
([attribute]) => legendValues.indexOf(attribute),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work when the legendValues are numerics (legendValues.indexOf(attribute)=-1) and thus the ordering isn't working for continuous colour scales (date, antigenic advance etc).

The legendValues are inherently ordered, so could we not simply replace the orderBy call with the following?

    legendValues.filter((v) => String(v) in colorByGroups)
      .forEach((attribute) => {
        const {color, values} = colorByGroups[attribute];
        ...

This same incantation is used in one other place in auspice, so might be worth reviewing that as well (I haven't done so):

const orderedFields = orderBy(displayFields, (field) => fieldOrder.indexOf(field));

Copy link
Contributor Author

@joverlee521 joverlee521 Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you for catching that! I'll update to your suggestion. That's much easier to read and understand
(Updated in b445e43)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other use of orderBy that you pointed out, the fieldOrder is not guaranteed to include every single display field. We want to order displayFields by the fieldOrder first then the remaining fields can fall into their existing order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other use of orderBy that you pointed out, the fieldOrder is not guaranteed to include every single display field. We want to order displayFields by the fieldOrder first then the remaining fields can fall into their existing order.

👍 Sounds good. And since displayFields is a list of keys, they won't be numeric (which is the underlying potential bug here).

@@ -305,7 +305,12 @@ export const drawMeansForColorBy = (ref, svgData, treeStrainColors) => {
// 2 x subplotPadding for padding around the overall mean display
const ySpacing = (layout.subplotHeight - 4 * layout.subplotPadding) / (numberOfColorByAttributes - 1);
let yValue = layout.subplotPadding;
Object.entries(colorByGroups).forEach(([attribute, {color, values}]) => {
// Order the color groups by the legend value order so that we have a stable order for the means
orderBy(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against lodash per-se (we use it a little bit in lots of places in auspice, and orderBy is used elsewhere in the measurements panel) but each time I feel there's a trade-off between learning another function vs writing out the slightly longer JS code. This trade-off varies across different lodash functions. Here I think a sort call would be simpler (at least, for others reading the code), but I'm interested in your general thoughts here? (It's not a request to change, especially as we're already importing it elsewhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lodash is my personal preference because I trust it to do the right thing more than my own version of a sort call. I think that has definitely made me over-reliant on lodash and then miss the simpler ways of doing things like your suggestion above.

@@ -305,7 +305,12 @@ export const drawMeansForColorBy = (ref, svgData, treeStrainColors) => {
// 2 x subplotPadding for padding around the overall mean display
const ySpacing = (layout.subplotHeight - 4 * layout.subplotPadding) / (numberOfColorByAttributes - 1);
let yValue = layout.subplotPadding;
Object.entries(colorByGroups).forEach(([attribute, {color, values}]) => {
// Order the color groups by the legend value order so that we have a stable order for the means
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we ever consider doing this for the raw dots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we've discussed ordering the raw dots by color before (it's part of #1463).
I think that will be a bigger change because of the jitter. Currently, the jitter is calculated during loading of the sidecar JSON, so will need to think through how to rework that...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that will be a bigger change because of the jitter. Currently, the jitter is calculated during loading of the sidecar JSON, so will need to think through how to rework that...

Thanks for the reference. I agree it's not for this PR, it just became apparent while reviewing it 😄

@joverlee521 joverlee521 force-pushed the measurements-improvements branch from 90623cc to b445e43 Compare October 10, 2022 17:36
@nextstrain-bot nextstrain-bot temporarily deployed to auspice-measurements-im-cja7xm October 10, 2022 17:36 Inactive
Keep the color-by means in a stable order so that order does not change
when applying different filters to the data. This makes it easier to
do comparisons across groups and across different filters.

This is the easier route for stable ordering, but in the future we can
consider ordering by display order of groups in the tree.
@joverlee521 joverlee521 force-pushed the measurements-improvements branch from b445e43 to 9a03e6b Compare October 10, 2022 18:00
@nextstrain-bot nextstrain-bot temporarily deployed to auspice-measurements-im-cja7xm October 10, 2022 18:00 Inactive
@joverlee521 joverlee521 merged commit e8e1e74 into master Oct 11, 2022
@joverlee521 joverlee521 deleted the measurements-improvements branch October 11, 2022 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

4 participants