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

fix(interactions): change allowBrushingLastHistogramBin to true #1396

Merged

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Sep 21, 2021

Summary

This PR changes the default boolean value of allowBrushingLastHIstogramBucket to true instead of false. This setting change more accurately shows the correct value when brushing over the last bucket in a histogram

BREAKING CHANGE

allowBrushingLastHistogramBucket renamed to allowBrushingLastHistogramBin on the Settings component defaults true and is only applied for histogram type charts.

Details

This setting wasn't removed and users are still able to set this to false if they would prefer. The naming of this setting was changed to bin instead of bucket after team discussion.

Issues

Closes #1371

Checklist

  • The proper feature labels have been added (e.g. :interactions, :axis)
  • All related issues have been linked (i.e. closes #123, fixes #123)
  • Unit tests have been added or updated to match the most common scenarios

@rshen91 rshen91 changed the title fix(settings): change allowBrushingLastHistogramBucket to true fix(interactions): change allowBrushingLastHistogramBucket to true Sep 21, 2021
@nickofthyme
Copy link
Collaborator

nickofthyme commented Sep 21, 2021

This setting wasn't removed and users are still able to set this to false if they would prefer.

@markov00 -- What are your thoughts about removing this setting altogether?

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Looking at the changes in the test looks like that we aren't properly using the allowBrushingLastHistogramBucket with the required constraint that the series needs to be an Histogram (histogramEnabled=true). Instead it looks like we just forget about that and we use directly allowBrushingLastHistogramBucket in the calculation like

const maxDomainValue = xScale.domain[1] + (allowBrushingLastHistogramBucket ? xScale.minInterval : 0);

This create the issue that is visible in the test: in a simple bar chart, with the current default enabled allowBrushingLastHistogramBucket we are changing the behavior of the brush. The scope of the allowBrushingLastHistogramBucket should only apply to histograms.

I've noticed the same wrong logic applied to the roundHistogramBrushValues
we are rounding brush values also to non histogram based charts.

@nickofthyme it looks like that you added those properties, do you remember the reason why these logics are not strictly applied to histogram only charts?

@nickofthyme
Copy link
Collaborator

@nickofthyme it looks like that you added those properties, do you remember the reason why these logics are not strictly applied to histogram only charts?

@markov00 I think you are correct, that should only apply to histogram mode.

@rshen91 rshen91 changed the title fix(interactions): change allowBrushingLastHistogramBucket to true fix(interactions): change allowBrushingLastHistogramBin to true Sep 23, 2021
@rshen91 rshen91 requested a review from markov00 September 23, 2021 14:12
@@ -136,9 +134,10 @@ function getXBrushExtent(
histogramMode: boolean,
xScale: Scale<number>,
smallMultipleScales: SmallMultipleScales,
allowBrushingLastHistogramBin: boolean = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: allowBrushingLastHistogramBin is a mandatory argument to getXBrushExtent which we can tell from the presence of a parameter that's to the right of it, seriesSpecs, which is mandatory (no question mark, no default). So wherever getXBrushExtent is used, we already pass something for allowBrushingLastHistogramBin otherwise the type checkers would shout. So the default value = true can be removed, assuming we are not passing the function undefined for this param (this is the only case the true default value would be in effect). So it's worth revisiting the caller places, and pass true instead of undefined if we currently pass undefined anywhere.

This is a very small thing that supports the larger theme of type simplicity: it's simpler to have boolean than boolean | undefined. Union types like this, and optional parameters should preferably be avoided, unless it leads to convoluted code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is great thanks! 1f5186a

@rshen91 rshen91 requested a review from monfera September 23, 2021 20:12
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Code changes LGTM. Tested locally on storybook and looks good. 🎉

@nickofthyme
Copy link
Collaborator

@rshen91 make sure you note the rename here as a breaking change.

@nickofthyme nickofthyme added :interactions Interactions related issue :xy Bar/Line/Area chart related breaking change labels Oct 5, 2021
*/
allowBrushingLastHistogramBucket?: boolean;
allowBrushingLastHistogramBin: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice removal of an optional here 😍 Also, the Bucket -> Bin change 👍

@rshen91 rshen91 requested a review from monfera October 6, 2021 13:21
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.

LGTM, nice and compact work with simplifications on the side 🎉

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM!

@rshen91 rshen91 merged commit 9fa9783 into elastic:master Oct 6, 2021
nickofthyme pushed a commit that referenced this pull request Oct 15, 2021
# [38.0.0](v37.0.0...v38.0.0) (2021-10-15)

### Bug Fixes

* **deps:** update dependency @elastic/eui to v39 ([#1422](#1422)) ([2ee97aa](2ee97aa))
* **goal:** reduce whitespace for circular charts ([#1413](#1413)) ([6517523](6517523))
* **interactions:** change allowBrushingLastHistogramBin to true ([#1396](#1396)) ([9fa9783](9fa9783))
* **xy:** remove wrongly represented null/missing values in tooltip ([#1415](#1415)) ([e5963a3](e5963a3)), closes [#1414](#1414)

### Code Refactoring

* scales ([#1410](#1410)) ([a53a2ba](a53a2ba))

### Features

* **scales:** add `LinearBinary` scale type ([#1389](#1389)) ([9f2e427](9f2e427))
* **xy:** adaptive tick raster ([#1420](#1420)) ([200577b](200577b))
* **xy:** apply the data value formatter to data values over bars ([#1419](#1419)) ([e673fc7](e673fc7))

### BREAKING CHANGES

* **interactions:** allowBrushingLastHistogramBucket renamed to allowBrushingLastHistogramBin on the Settings component defaults true and is only applied for histogram type charts
* LogScaleOptions.logBase` is now a `number` instead of the object enum `LogBase`. Some edge case data or configuration _might_, with a deemed low likelihood, lead to a situation where the earlier version would have silently not rendered a bar, line or point, while the new code doesn't `catch`, therefore throw an exception (see the last item). General risk of regressions due to the quantity of code changes (altogether 3.5k)
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 38.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change :interactions Interactions related issue released Issue released publicly :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Brushing on last bucket in histogram produce wrong results
4 participants