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

TimeSeries/BarChart: Add support for sorting series in the tooltip #43615

Merged
merged 6 commits into from Jan 10, 2022

Conversation

dprokop
Copy link
Member

@dprokop dprokop commented Jan 3, 2022

Closes #38861

This PR brings ability to sort series in the Timeseries panel's tooltip as it was possible with the old graph panel. Additionally, a migration for legacy tooltip options is added.

Note that the null/undefined values are sorted at the end of the tooltip regardless the sort order configured.

Screen.Recording.2022-01-03.at.14.10.24.mov

@dprokop dprokop added the area/panel/timeseries The main time series Graph panel label Jan 3, 2022
@dprokop dprokop added this to the 8.4.0 milestone Jan 3, 2022
@dprokop dprokop self-assigned this Jan 3, 2022
@dprokop dprokop requested review from a team as code owners January 3, 2022 13:01
@dprokop dprokop requested review from meanmina, jackw, joshhunt and axelavargas and removed request for a team January 3, 2022 13:01
* Null values are always sorted to the end regardless of the sort order
*/
function sortValues(sort: TooltipSortOrder) {
return (a: number | null | undefined, b: number | null | undefined) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return (a: number | null | undefined, b: number | null | undefined) => {
return (a: any, b: any) => {

Copy link
Member Author

Choose a reason for hiding this comment

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

@ryantxu this fn is now moved to grafana-data/arrayUtils and now has the support for string values (using localeCompare)

Comment on lines 320 to 324

if (sort === TooltipSortOrder.Descending) {
return b - a;
}
return a - b;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (sort === TooltipSortOrder.Descending) {
return b - a;
}
return a - b;
const order = a > b ? 1: -1;
if (sort === TooltipSortOrder.Descending) {
return order * -1;
}
return order;

Can we implement this so it also works for string inputs? Maybe something like the above (untested!!!) approach. For the time series tooltip it likely makes no difference, but if forced to numbers, then we will for sure need custom implementations for other panels (though we are already working on that anyway)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

That's done now, thanks for the feedback folks!

Copy link
Member

@zoltanbedi zoltanbedi left a comment

Choose a reason for hiding this comment

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

This worked as expected in time series panel. What was strange that it showed up in barchart but didn't work.

@dprokop dprokop requested a review from a team January 4, 2022 13:54
@dprokop
Copy link
Member Author

dprokop commented Jan 4, 2022

This worked as expected in time series panel. What was strange that it showed up in barchart but didn't work.

That's tru and it's because of the custom tooltip being used there. But In the latest comit I've added this feature to BarChart too

@dprokop dprokop changed the title TimeSeries: Add support for sorting series in the tooltip TimeSeries/BarChart: Add support for sorting series in the tooltip Jan 4, 2022
Copy link
Member

@zoltanbedi zoltanbedi left a comment

Choose a reason for hiding this comment

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

Awesome!

Copy link
Member

@ryantxu ryantxu left a comment

Choose a reason for hiding this comment

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

This looks great!

@@ -230,6 +235,10 @@ export const TooltipPlugin: React.FC<TooltipPluginProps> = ({
});
}

if (sortOrder !== SortOrder.None) {
series.sort((a, b) => arrayUtils.sortValues(sortOrder)(a.value, b.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

In this, a.valueandb.value is formatted display value, whether should use the original value to sort ? I am not clearly on the context, hope someone can explain it if i wrong :)

Copy link
Contributor

Choose a reason for hiding this comment

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

for example this:
8xbmBITuvb

Copy link
Member

Choose a reason for hiding this comment

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

Can you please open a separate issue with your findings?

Copy link
Contributor

Choose a reason for hiding this comment

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

sure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants