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

Add a way to filter items in the tooltip #3494

Merged
merged 1 commit into from
Oct 23, 2016
Merged

Conversation

etimberg
Copy link
Member

Adds a function, itemFilter to the tooltip config. If this function is specified, it is used to filter the items that show in the tooltip.

I added a test to cover this case.

Fixes #1889

@@ -225,6 +225,7 @@ mode | String | 'nearest' | Sets which elements appear in the tooltip. See [Inte
intersect | Boolean | true | if true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times.
position | String | 'average' | The mode for positioning the tooltip. 'average' mode will place the tooltip at the average position of the items displayed in the tooltip. 'nearest' will place the tooltip at the position of the element closest to the event position. New modes can be defined by adding functions to the Chart.Tooltip.positioners map.
itemSort | Function | undefined | Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). This function can also accept a third parameter that is the data object passed to the chart.
itemFilter | Function | undefined | Allows filtering of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a second parameter that is the data object passed to the chart.
Copy link
Member

Choose a reason for hiding this comment

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

I was about to suggest to simply call this option filter, but then I looked above and see the itemSort, which one I would have called sorter, just because I like concise name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can change this to filter since it is better.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what the best: consistency with itemSort or simplicity with filter :)

@etimberg etimberg force-pushed the filter-tooltip-items branch from 67adb2e to 0b45eac Compare October 23, 2016 17:35
@etimberg etimberg force-pushed the filter-tooltip-items branch from 0b45eac to b682c6e Compare October 23, 2016 17:37
@etimberg
Copy link
Member Author

Renamed function to filter

@etimberg etimberg merged commit 5ae268e into master Oct 23, 2016
@etimberg etimberg deleted the filter-tooltip-items branch October 23, 2016 21:33
@simonbrunel simonbrunel added this to the Version 2.4 milestone Oct 24, 2016
@samueljo
Copy link
Contributor

I'm having issues with the filter function hiding the data of the tooltip but ends up leaving an empty tooltip instead. Is that the expected behavior or am I missing something?

@etimberg
Copy link
Member Author

@samueljo currently if all items are removed using the filter function, the tooltip will be blank. I'm happy to merge a PR that prevents this. I think it could be as simple as bailing out of draw inside the tooltip if there are no items.

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

Successfully merging this pull request may close these issues.

3 participants