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

feat: order ordinal values by sum #814

Merged
merged 9 commits into from
Sep 12, 2020

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Sep 9, 2020

Summary

Sort ordinal labels by sum of all bin values. The orderOrdinalBinsBySum option is added to the Settings spec to enable this functionality. Allows ascending and descending order.

These changes only affects Ordinal scales.

Screenshots

Screen Recording 2020-09-10 at 10 25 AM

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

@nickofthyme nickofthyme added enhancement New feature or request :axis Axis related issue :vislib Relating to vislib replacement :xy Bar/Line/Area chart related labels Sep 9, 2020
@nickofthyme nickofthyme requested a review from monfera September 9, 2020 22:24
Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

Works great, added some notes, the request part is the removal of the word bucket and answering if making the API more general would make sense, to avoid a future breaking change when some other agg eg. count or avg is added, and serve the asc order which is equally important to desc.

src/chart_types/xy_chart/utils/series.test.ts Outdated Show resolved Hide resolved
BasicSeriesSpec,
'id' | 'data' | 'xAccessor' | 'yAccessors' | 'y0Accessors' | 'splitSeriesAccessors' | 'markSizeAccessor'
>,
xValueSums: Map<string | number, number>,
Copy link
Contributor

@monfera monfera Sep 10, 2020

Choose a reason for hiding this comment

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

Is it important to bake in the fact that we're sorting by sum at the moment? It could be different in the future, e.g. sort by count, min, max, average, or even, something totally unrelated to what's currently visualized

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I agree this could be more extensible to use count, min, max, average or a custom metric. However, I think this can be addressed in #795 to provide a more robust api for such sorting.

This feature is another final thing needed for the vislib replacement. I was debating whether to add it to the SettingsSpec or just use a blind prop. What do you think?

The only thing I think that might be worth it, is to make orderOrdinalBucketsBySum into asc | desc instead of a boolean, but beyond that is a little out of scope.

Copy link
Contributor

@monfera monfera Sep 10, 2020

Choose a reason for hiding this comment

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

I think this can be addressed in #795 to provide a more robust api

So that will be a breaking change, isn't it simpler to avoid it? I wasn't suggesting implementing count, min, max etc. right now (ie. "sum" is enough, and can even be the default), just trying to avoid names in the API that we know will be outdated in no time. So mostly, a naming thing and maybe, if feasible, a type signature that permits a string for an agg spec and a direction spec as optionals (or something similar).

whether to add it to the SettingsSpec or just use a blind prop

I don't have as much info as you do; the feature, albeit triggered by vislib, isn't vislib specific, so if we go for a somewhat stable API (see earlier point) I'd put it in SettingsSpec, if it's super temporary, then a blind one is OK I guess. Depends in part on what you think the consumer will be happy with

src/chart_types/xy_chart/utils/series.ts Outdated Show resolved Hide resolved
src/specs/settings.tsx Outdated Show resolved Hide resolved
@monfera monfera self-requested a review September 10, 2020 16:41
Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

Thanks Nick for the changes!
The only item remaining is that, if I understand, orderOrdinalBinsBySum would soon get obsoleted with the introduction of alternative ordering aggs (count, min, max, avg etc.), we could remove Sum from the name and pick something like { binAgg = 'sum', direction = 'desc' } as value. But you likely have more info on the tradeoff and need for expediency.

@monfera monfera changed the title feat: order ordinal buckets by sum feat: order ordinal values by sum Sep 10, 2020
@nickofthyme
Copy link
Collaborator Author

jenkins retest this please

@nickofthyme nickofthyme merged commit 5b2758b into elastic:master Sep 12, 2020
@nickofthyme nickofthyme deleted the sort-by-sum branch September 12, 2020 03:08
markov00 pushed a commit that referenced this pull request Sep 14, 2020
# [21.2.0](v21.1.2...v21.2.0) (2020-09-14)

### Features

* blind sorting option for vislib ([#813](#813)) ([8afce43](8afce43))
* order ordinal values by sum ([#814](#814)) ([5b2758b](5b2758b))
* **series:** add simple mark formatter ([#775](#775)) ([ab95284](ab95284))
@markov00
Copy link
Member

🎉 This PR is included in version 21.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Sep 14, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:axis Axis related issue enhancement New feature or request released Issue released publicly :vislib Relating to vislib replacement :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants